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

Update frameKey in aboutDetails when clone about pages #5015

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function getPartition (frameOpts) {
return partition
}

function cloneFrame (frameOpts, guestInstanceId) {
function cloneFrame (frameOpts, guestInstanceId, key) {
const cloneableAttributes = [
'audioMuted',
'canGoBack',
Expand All @@ -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
}

Expand Down
16 changes: 11 additions & 5 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/unit/state/frameStateUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down