From 6d643369787d99247578a727ead20b5dc13477ec Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Tue, 16 May 2017 15:35:12 +0200 Subject: [PATCH 1/4] Add test for #9468 --- spec/api-web-contents-spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 9bbeefc4d7a8..03cc990aa6bc 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -647,4 +647,20 @@ describe('webContents module', function () { gen.next() }) }) + + describe('History API', () => { + it('should push state after calling history.pushState() from the same url', (done) => { + w.loadURL('about:blank') + w.webContents.once('did-finish-load', () => { + // History should have current page by now. + assert.equal(w.webContents.length(), 1) + + w.webContents.executeJavaScript('window.history.pushState({}, "")', (result) => { + // Initial page + pushed state + assert.equal(w.webContents.length(), 2) + done() + }) + }) + }) + }) }) From 3a9b035d369ecec257dd6ab9356e594082b526f0 Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Mon, 15 May 2017 16:03:25 +0200 Subject: [PATCH 2/4] Remove page url check in `history.pushState` Current implementation of NavigationController does not allow using `history.pushState()` if page url is not changed. It worked by mistake in versions < 1.3.6 and got visible after fix 180a77e6. --- lib/browser/api/navigation-controller.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/browser/api/navigation-controller.js b/lib/browser/api/navigation-controller.js index 0bccf0c6dcc5..7eb21ddb3ea9 100644 --- a/lib/browser/api/navigation-controller.js +++ b/lib/browser/api/navigation-controller.js @@ -27,7 +27,6 @@ var NavigationController = (function () { this.history.push(this.webContents._getURL()) } this.webContents.on('navigation-entry-commited', (event, url, inPage, replaceEntry) => { - var currentEntry if (this.inPageIndex > -1 && !inPage) { // Navigated to a new page, clear in-page mark. this.inPageIndex = -1 @@ -46,12 +45,8 @@ var NavigationController = (function () { } else { // Normal navigation. Clear history. this.history = this.history.slice(0, this.currentIndex + 1) - currentEntry = this.history[this.currentIndex] - - if (currentEntry !== url) { - this.currentIndex++ - this.history.push(url) - } + this.currentIndex++ + this.history.push(url) } }) } From 777b5b17dea6505e3575a9a554154a050593fa08 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 5 Jun 2017 14:45:22 -0700 Subject: [PATCH 3/4] Move pushState spec chromium-spec with other history specs --- spec/api-web-contents-spec.js | 16 ---------------- spec/chromium-spec.js | 31 ++++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 03cc990aa6bc..9bbeefc4d7a8 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -647,20 +647,4 @@ describe('webContents module', function () { gen.next() }) }) - - describe('History API', () => { - it('should push state after calling history.pushState() from the same url', (done) => { - w.loadURL('about:blank') - w.webContents.once('did-finish-load', () => { - // History should have current page by now. - assert.equal(w.webContents.length(), 1) - - w.webContents.executeJavaScript('window.history.pushState({}, "")', (result) => { - // Initial page + pushed state - assert.equal(w.webContents.length(), 2) - done() - }) - }) - }) - }) }) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index fe132166d602..32f774f9ffd2 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -1100,11 +1100,32 @@ describe('chromium feature', function () { }) }) - describe('window.history.go(offset)', function () { - it('throws an exception when the argumnet cannot be converted to a string', function () { - assert.throws(function () { - window.history.go({toString: null}) - }, /Cannot convert object to primitive value/) + describe('window.history', function () { + describe('window.history.go(offset)', function () { + it('throws an exception when the argumnet cannot be converted to a string', function () { + assert.throws(function () { + window.history.go({toString: null}) + }, /Cannot convert object to primitive value/) + }) + }) + + describe('window.history.pushState', function () { + it('should push state after calling history.pushState() from the same url', (done) => { + w = new BrowserWindow({ + show: false + }) + w.loadURL('about:blank') + w.webContents.once('did-finish-load', () => { + // History should have current page by now. + assert.equal(w.webContents.length(), 1) + + w.webContents.executeJavaScript('window.history.pushState({}, "")', () => { + // Initial page + pushed state + assert.equal(w.webContents.length(), 2) + done() + }) + }) + }) }) }) }) From af1d0c45ca5063b150e24dd2a8b35559af049ab6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 5 Jun 2017 14:47:11 -0700 Subject: [PATCH 4/4] Load URL after registering listener --- spec/chromium-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 32f774f9ffd2..f33fb284a47b 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -1114,7 +1114,6 @@ describe('chromium feature', function () { w = new BrowserWindow({ show: false }) - w.loadURL('about:blank') w.webContents.once('did-finish-load', () => { // History should have current page by now. assert.equal(w.webContents.length(), 1) @@ -1125,6 +1124,7 @@ describe('chromium feature', function () { done() }) }) + w.loadURL('about:blank') }) }) })