From 57f1f914e044eeeb271c8e6d15136e2ed2d0c8d6 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 20 Oct 2016 18:02:01 -0400 Subject: [PATCH] Update frameKey in aboutDetails when clone about pages fix #4984 Auditors: @bsclifton Test Plan: 1. generate error page (ex. connection lost) 2. clone the error tab 3. retry on the cloned tab of step2 4. reload should happen on the cloned tab --- js/state/frameStateUtil.js | 7 +++++-- js/stores/windowStore.js | 16 +++++++++++----- test/unit/state/frameStateUtilTest.js | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/js/state/frameStateUtil.js b/js/state/frameStateUtil.js index e665d011a46..c35defb7b0c 100644 --- a/js/state/frameStateUtil.js +++ b/js/state/frameStateUtil.js @@ -221,7 +221,7 @@ function getPartition (frameOpts) { return partition } -function cloneFrame (frameOpts, guestInstanceId) { +function cloneFrame (frameOpts, guestInstanceId, key) { const cloneableAttributes = [ 'audioMuted', 'canGoBack', @@ -246,7 +246,10 @@ function cloneFrame (frameOpts, guestInstanceId) { clone.location = 'about:blank' clone.src = 'about:blank' clone.parentFrameKey = frameOpts.key - clone.aboutDetails = frameOpts.aboutDetails + if (frameOpts.aboutDetails !== undefined) { + clone.aboutDetails = frameOpts.aboutDetails + clone.aboutDetails.frameKey = key + } return clone } diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 891be3d88c7..b563e43fb75 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -162,7 +162,7 @@ const addToHistory = (frameProps) => { return history.slice(-10) } -const newFrame = (frameOpts, openInForeground, insertionIndex) => { +const newFrame = (frameOpts, openInForeground, insertionIndex, nextKey) => { const frames = windowState.get('frames') if (frameOpts === undefined) { @@ -187,7 +187,9 @@ const newFrame = (frameOpts, openInForeground, insertionIndex) => { } } - const nextKey = incrementNextKey() + if (nextKey === undefined) { + nextKey = incrementNextKey() + } let nextPartitionNumber = 0 if (frameOpts.partitionNumber) { nextPartitionNumber = frameOpts.partitionNumber @@ -434,9 +436,13 @@ const doAction = (action) => { newFrame(action.frameOpts, action.openInForeground) break case WindowConstants.WINDOW_CLONE_FRAME: - let insertionIndex = FrameStateUtil.findIndexForFrameKey(windowState.get('frames'), action.frameOpts.key) + 1 - newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId), action.openInForeground, insertionIndex) - break + { + let insertionIndex = FrameStateUtil.findIndexForFrameKey(windowState.get('frames'), action.frameOpts.key) + 1 + const nextKey = incrementNextKey() + newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId, nextKey), + action.openInForeground, insertionIndex, nextKey) + break + } case WindowConstants.WINDOW_CLOSE_FRAME: // Use the frameProps we passed in, or default to the active frame const frameProps = action.frameProps || FrameStateUtil.getActiveFrame(windowState) diff --git a/test/unit/state/frameStateUtilTest.js b/test/unit/state/frameStateUtilTest.js index 62e3247e79b..a617073f46a 100644 --- a/test/unit/state/frameStateUtilTest.js +++ b/test/unit/state/frameStateUtilTest.js @@ -35,7 +35,16 @@ describe('frameStateUtil', function () { history: ['http://brave.com'], location: 'http://brave.com/about' } + this.aboutFrameOpts = {} + Object.assign(this.aboutFrameOpts, this.frameOpts) + this.aboutFrameOpts['aboutDetails'] = + { + errorCode: -1, + frameKey: 1 + } this.clonedFrame = frameStateUtil.cloneFrame(this.frameOpts, 4) + this.key = 6 + this.aboutClonedFrame = frameStateUtil.cloneFrame(this.aboutFrameOpts, 5, this.key) }) it('does not copy the key', function () { @@ -83,6 +92,15 @@ describe('frameStateUtil', function () { assert.deepEqual(this.clonedFrame.history, ['http://brave.com']) assert(this.clonedFrame.history !== this.frameOpts.history) }) + + it('clone without aboutDetails', function () { + assert.equal(this.clonedFrame.aboutDetails, undefined) + }) + + it('copies aboutDetails with key', function () { + assert.equal(this.aboutClonedFrame.aboutDetails.errorCode, this.aboutFrameOpts.aboutDetails.errorCode) + assert.equal(this.aboutClonedFrame.aboutDetails.frameKey, this.key) + }) }) describe('query', function () {