From 9829baed46def1c61ae18e80fec5cdcad0ef81c6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 16:10:21 -0700 Subject: [PATCH 1/7] Open about:blank when window.open is called with no URL --- lib/renderer/override.js | 6 +++++- spec/chromium-spec.js | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/renderer/override.js b/lib/renderer/override.js index f7f2b8be648..b5d6cb2e46d 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -139,7 +139,11 @@ window.open = function (url, frameName, features) { } // Resolve relative urls. - url = resolveURL(url) + if (url == null || url == '') { + url = 'about:blank' + } else { + url = resolveURL(url) + } for (j = 0, len1 = ints.length; j < len1; j++) { name = ints[j] if (options[name] != null) { diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 991da316ec9..e26cba87c38 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -250,8 +250,7 @@ describe('chromium feature', function () { it('defines a window.location setter', function (done) { // Load a page that definitely won't redirect - var b - b = window.open('about:blank') + var b = window.open('about:blank') webContents.fromId(b.guestId).once('did-finish-load', function () { // When it loads, redirect b.location = 'file://' + fixtures + '/pages/base-page.html' @@ -262,6 +261,23 @@ describe('chromium feature', function () { }) }) }) + + it('open a blank page when no URL is specified', function (done) { + let b = window.open() + webContents.fromId(b.guestId).once('did-finish-load', function () { + const {location} = b + b.close() + assert.equal(location, 'about:blank') + + let c = window.open('') + webContents.fromId(c.guestId).once('did-finish-load', function () { + const {location} = c + c.close() + assert.equal(location, 'about:blank') + done() + }) + }) + }) }) describe('window.opener', function () { From ea069805d197257269b12be24061b2b44ba3676f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 16:40:31 -0700 Subject: [PATCH 2/7] Add failing specs for empty preload/src attribute --- spec/webview-spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 8e4779d8099..3629c5ec2ed 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -75,6 +75,12 @@ describe(' tag', function () { webview.src = 'file://' + fixtures + '/pages/a.html' document.body.appendChild(webview) }) + + it('ignores empty values', function () { + assert.equal(webview.src, '') + webview.src = '' + assert.equal(webview.src, '') + }) }) describe('nodeintegration attribute', function () { @@ -198,6 +204,12 @@ describe(' tag', function () { webview.src = 'file://' + fixtures + '/pages/base-page.html' document.body.appendChild(webview) }) + + it('ignores empty values', function () { + assert.equal(webview.preload, '') + webview.preload = '' + assert.equal(webview.preload, '') + }) }) describe('httpreferrer attribute', function () { From 1dbaf4987e91bd7b35a2d50d80a5078b6769effd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 16:48:30 -0700 Subject: [PATCH 3/7] Don't resolve empty src/preload attribute values --- lib/renderer/web-view/web-view-attributes.js | 1 + spec/webview-spec.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/renderer/web-view/web-view-attributes.js b/lib/renderer/web-view/web-view-attributes.js index e918578900c..01eb77727c7 100644 --- a/lib/renderer/web-view/web-view-attributes.js +++ b/lib/renderer/web-view/web-view-attributes.js @@ -9,6 +9,7 @@ const remote = require('electron').remote var a = document.createElement('a') var resolveURL = function (url) { + if (url === '') return '' a.href = url return a.href } diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 3629c5ec2ed..2083d6d2eb8 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -80,6 +80,10 @@ describe(' tag', function () { assert.equal(webview.src, '') webview.src = '' assert.equal(webview.src, '') + webview.src = null + assert.equal(webview.src, '') + webview.src = undefined + assert.equal(webview.src, '') }) }) @@ -209,6 +213,10 @@ describe(' tag', function () { assert.equal(webview.preload, '') webview.preload = '' assert.equal(webview.preload, '') + webview.preload = null + assert.equal(webview.preload, '') + webview.preload = undefined + assert.equal(webview.preload, '') }) }) From bfd48fe2ada89ddc91a92fcb64541ef08017a57f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 16:56:29 -0700 Subject: [PATCH 4/7] Add specs for resolving attribute URLs --- spec/webview-spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 2083d6d2eb8..899112bd033 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -76,6 +76,11 @@ describe(' tag', function () { document.body.appendChild(webview) }) + it('resolves relative URLs', function () { + webview.preload = '../fixtures/test.js' + assert.equal(webview.preload, 'file://' + fixtures + '/test.js') + }) + it('ignores empty values', function () { assert.equal(webview.src, '') webview.src = '' @@ -209,6 +214,11 @@ describe(' tag', function () { document.body.appendChild(webview) }) + it('resolves relative URLs', function () { + webview.src = '../fixtures/test.html' + assert.equal(webview.src, 'file://' + fixtures + '/test.html') + }) + it('ignores empty values', function () { assert.equal(webview.preload, '') webview.preload = '' From 7d24df34fcf3e1f8f9f54c6e3aade2ff6b1a5a23 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 17:08:49 -0700 Subject: [PATCH 5/7] Place resolve specs in correct outer block --- spec/webview-spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 899112bd033..7df09bfe839 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -77,8 +77,8 @@ describe(' tag', function () { }) it('resolves relative URLs', function () { - webview.preload = '../fixtures/test.js' - assert.equal(webview.preload, 'file://' + fixtures + '/test.js') + webview.src = '../fixtures/test.html' + assert.equal(webview.src, 'file://' + fixtures + '/test.html') }) it('ignores empty values', function () { @@ -215,8 +215,8 @@ describe(' tag', function () { }) it('resolves relative URLs', function () { - webview.src = '../fixtures/test.html' - assert.equal(webview.src, 'file://' + fixtures + '/test.html') + webview.preload = '../fixtures/test.js' + assert.equal(webview.preload, 'file://' + fixtures + '/test.js') }) it('ignores empty values', function () { From daf1eec5ecc021acabb35583836ff2efefbb7870 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 17:11:10 -0700 Subject: [PATCH 6/7] Use === for string comparison --- lib/renderer/override.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/renderer/override.js b/lib/renderer/override.js index b5d6cb2e46d..29cf9f5acae 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -139,7 +139,7 @@ window.open = function (url, frameName, features) { } // Resolve relative urls. - if (url == null || url == '') { + if (url == null || url === '') { url = 'about:blank' } else { url = resolveURL(url) From 64d436682c22c6013a5394104d59b728014714e8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 17:38:40 -0700 Subject: [PATCH 7/7] Verify resolving URL via console-message event --- spec/webview-spec.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 7df09bfe839..6b36c84fd64 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -76,9 +76,15 @@ describe(' tag', function () { document.body.appendChild(webview) }) - it('resolves relative URLs', function () { - webview.src = '../fixtures/test.html' - assert.equal(webview.src, 'file://' + fixtures + '/test.html') + it('resolves relative URLs', function (done) { + var listener = function (e) { + assert.equal(e.message, 'Window script is loaded before preload script') + webview.removeEventListener('console-message', listener) + done() + } + webview.addEventListener('console-message', listener) + webview.src = '../fixtures/pages/e.html' + document.body.appendChild(webview) }) it('ignores empty values', function () { @@ -214,9 +220,16 @@ describe(' tag', function () { document.body.appendChild(webview) }) - it('resolves relative URLs', function () { - webview.preload = '../fixtures/test.js' - assert.equal(webview.preload, 'file://' + fixtures + '/test.js') + it('resolves relative URLs', function (done) { + var listener = function (e) { + assert.equal(e.message, 'function object object') + webview.removeEventListener('console-message', listener) + done() + } + webview.addEventListener('console-message', listener) + webview.src = 'file://' + fixtures + '/pages/e.html' + webview.preload = '../fixtures/module/preload.js' + document.body.appendChild(webview) }) it('ignores empty values', function () {