This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10420 from brave/test/muon-tests
Start adding muon.url.parse tests
- Loading branch information
Showing
4 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="availableLanguages" content=""> | ||
<meta name="defaultLanguage" content="en-US"> | ||
<meta name="referrer" content="no-referrer"> | ||
<title>Muon tests</title> | ||
<script src="ext/l20n.min.js"></script> | ||
<script src="gen/muonTest.entry.js" async></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const urlParse = require('../app/common/urlParse') | ||
const urlUtil = require('./lib/urlutil') | ||
const assert = require('assert') | ||
|
||
const assertEqual = (actual, expected, name) => { | ||
const elem = document.createElement('div') | ||
elem.id = name | ||
elem.innerText = 'fail' | ||
|
||
try { | ||
assert.deepEqual(actual, expected) | ||
elem.innerText = 'success' | ||
} catch (e) { | ||
elem.innerText = JSON.stringify(actual) | ||
} | ||
document.body.appendChild(elem) | ||
} | ||
|
||
const defaultParsedUrl = { | ||
hash: '', | ||
host: '', | ||
hostname: '', | ||
href: '', | ||
origin: '', | ||
path: '/', | ||
pathname: '/', | ||
port: '', | ||
protocol: 'http:', | ||
query: '', | ||
search: '' | ||
} | ||
|
||
const runTests = () => { | ||
assertEqual(urlParse('http://bing.com'), | ||
Object.assign(defaultParsedUrl, { | ||
host: 'bing.com', | ||
hostname: 'bing.com', | ||
origin: 'http://bing.com/', | ||
href: 'http://bing.com/' | ||
}), 'urlParseSimple') | ||
|
||
assertEqual(urlParse('https://brave.com:333/test?abc=123&def#fff'), | ||
{ | ||
host: 'brave.com:333', | ||
hostname: 'brave.com', | ||
origin: 'https://brave.com:333/', | ||
protocol: 'https:', | ||
port: '333', | ||
hash: '#fff', | ||
pathname: '/test', | ||
path: '/test?abc=123&def', | ||
search: '?abc=123&def', | ||
query: 'abc=123&def', | ||
href: 'https://brave.com:333/test?abc=123&def#fff' | ||
}, 'urlParseComplex') | ||
|
||
assertEqual(urlUtil.getOrigin('http://www.brave.com/foo'), 'http://www.brave.com', 'getOriginSimple') | ||
assertEqual(urlUtil.getOrigin('file:///aaa'), 'file:///', 'getOriginFile') | ||
assertEqual(urlUtil.getOrigin('http://brave.com:333/foo'), 'http://brave.com:333', 'getOriginWithPort') | ||
assertEqual(urlUtil.getOrigin('http://127.0.0.1:443/?test=1#abc'), 'http://127.0.0.1:443', 'getOriginIP') | ||
assertEqual(urlUtil.getOrigin('about:preferences#abc'), 'about:preferences', 'getOriginAbout') | ||
assertEqual(urlUtil.getOrigin('http://http/test'), 'http://http', 'getOriginSchemeHost') | ||
assertEqual(urlUtil.getOrigin(''), null, 'getOriginNull') | ||
assertEqual(urlUtil.getOrigin('abc'), null, 'getOriginInvalid') | ||
} | ||
|
||
runTests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* global describe, it, before */ | ||
|
||
const Brave = require('../lib/brave') | ||
|
||
const testUrl = 'chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/muon-tests.html' | ||
|
||
function * setup (client) { | ||
yield client.waitForUrl(Brave.newTabUrl).waitForBrowserWindow() | ||
} | ||
|
||
describe('muon tests', function () { | ||
Brave.beforeAll(this) | ||
before(function * () { | ||
yield setup(this.app.client) | ||
yield this.app.client | ||
.tabByIndex(0) | ||
.url(testUrl) | ||
}) | ||
it('muon.url.parse', function * () { | ||
yield this.app.client | ||
.waitForTextValue('#urlParseSimple', 'success') | ||
.waitForTextValue('#urlParseComplex', 'success') | ||
}) | ||
it('urlUtil.getOrigin', function * () { | ||
yield this.app.client | ||
.waitForTextValue('#getOriginSimple', 'success') | ||
.waitForTextValue('#getOriginFile', 'success') | ||
.waitForTextValue('#getOriginWithPort', 'success') | ||
.waitForTextValue('#getOriginIP', 'success') | ||
.waitForTextValue('#getOriginAbout', 'success') | ||
.waitForTextValue('#getOriginNull', 'success') | ||
.waitForTextValue('#getOriginInvalid', 'success') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters