Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Start adding muon.url.parse tests
Browse files Browse the repository at this point in the history
partial fix for #10409
  • Loading branch information
diracdeltas committed Aug 11, 2017
1 parent f1c4ed2 commit 8aa730f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/extensions/brave/muon-tests.html
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>
67 changes: 67 additions & 0 deletions js/muonTest.entry.js
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()
34 changes: 34 additions & 0 deletions test/misc-components/muonTest.js
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')
})
})
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ var app = {
target: 'web',
entry: {
app: [ path.resolve(__dirname, 'js', 'entry.js') ],
aboutPages: [ path.resolve(__dirname, 'js', 'about', 'entry.js') ]
aboutPages: [ path.resolve(__dirname, 'js', 'about', 'entry.js') ],
muonTest: [ path.resolve(__dirname, 'js', 'muonTest.entry.js') ]
},
output: {
path: path.resolve(__dirname, 'app', 'extensions', 'brave', 'gen'),
Expand Down

0 comments on commit 8aa730f

Please sign in to comment.