From 8aa730f15aa09de55a91b7acfc6eb71b16e5f520 Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 11 Aug 2017 00:19:33 +0000 Subject: [PATCH] Start adding muon.url.parse tests partial fix for https://github.com/brave/browser-laptop/issues/10409 --- app/extensions/brave/muon-tests.html | 17 +++++++ js/muonTest.entry.js | 67 ++++++++++++++++++++++++++++ test/misc-components/muonTest.js | 34 ++++++++++++++ webpack.config.js | 3 +- 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 app/extensions/brave/muon-tests.html create mode 100644 js/muonTest.entry.js create mode 100644 test/misc-components/muonTest.js diff --git a/app/extensions/brave/muon-tests.html b/app/extensions/brave/muon-tests.html new file mode 100644 index 00000000000..91944e0e8e6 --- /dev/null +++ b/app/extensions/brave/muon-tests.html @@ -0,0 +1,17 @@ + + + + + + + + + Muon tests + + + + + + diff --git a/js/muonTest.entry.js b/js/muonTest.entry.js new file mode 100644 index 00000000000..3bfd08d8290 --- /dev/null +++ b/js/muonTest.entry.js @@ -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() diff --git a/test/misc-components/muonTest.js b/test/misc-components/muonTest.js new file mode 100644 index 00000000000..e370f71a8e4 --- /dev/null +++ b/test/misc-components/muonTest.js @@ -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') + }) +}) diff --git a/webpack.config.js b/webpack.config.js index ea2bf8f7376..77abfeed9e8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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'),