Skip to content

Commit

Permalink
Cloned tabs appear next to clone source
Browse files Browse the repository at this point in the history
  • Loading branch information
ayumi committed Aug 11, 2016
1 parent 79c1108 commit 0f47e16
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
22 changes: 12 additions & 10 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,17 @@ const newFrame = (frameOpts, openInForeground, insertionIndex) => {

// Find the closest index to the current frame's index which has
// a different ancestor frame key.
if (!insertionIndex) {
if (insertionIndex === undefined) {
insertionIndex = FrameStateUtil.findIndexForFrameKey(frames, frameOpts.parentFrameKey)
}
if (insertionIndex === -1) {
insertionIndex = frames.size
}
while (insertionIndex < frames.size) {
++insertionIndex
if (!FrameStateUtil.isAncestorFrameKey(frames, frames.get(insertionIndex), frameOpts.parentFrameKey)) {
break
if (insertionIndex === -1) {
insertionIndex = frames.size
} else {
while (insertionIndex < frames.size) {
++insertionIndex
if (!FrameStateUtil.isAncestorFrameKey(frames, frames.get(insertionIndex), frameOpts.parentFrameKey)) {
break
}
}
}
}
if (FrameStateUtil.isFrameKeyPinned(frames, frameOpts.parentFrameKey)) {
Expand Down Expand Up @@ -415,7 +416,8 @@ const doAction = (action) => {
newFrame(action.frameOpts, action.openInForeground)
break
case WindowConstants.WINDOW_CLONE_FRAME:
newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId), action.openInForeground)
let insertionIndex = FrameStateUtil.findIndexForFrameKey(windowState.get('frames'), action.frameOpts.key) + 1
newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId), action.openInForeground, insertionIndex)
break
case WindowConstants.WINDOW_CLOSE_FRAME:
// Use the frameProps we passed in, or default to the active frame
Expand Down
39 changes: 38 additions & 1 deletion test/components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,44 @@ describe('clone tab', function () {
})
})

describe('index', function () {
Brave.beforeAll(this)

before(function * () {
this.clickWithTargetPage = Brave.server.url('click_with_target.html')
this.page1 = Brave.server.url('page1.html')

yield setup(this.app.client)
yield this.app.client
.waitUntilWindowLoaded()
.windowByUrl(Brave.browserWindowUrl)
.waitForUrl(Brave.newTabUrl)
.url(this.clickWithTargetPage)
.waitForVisible('#name')
.click('#name')
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('.tab[data-frame-key="2"]')
yield this.app.client
.ipcSend('shortcut-set-active-frame-by-index', 0)
.windowByUrl(Brave.browserWindowUrl)
.ipcSend(messages.SHORTCUT_ACTIVE_FRAME_CLONE)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('.tab[data-frame-key="2"]')
})

it('inserts after the tab to clone', function * () {
var clickWithTargetPage = this.clickWithTargetPage
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.ipcSend('shortcut-set-active-frame-by-index', 1)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
return this.getAttribute(activeWebview, 'src').then((src) => src === clickWithTargetPage)
})
})
})

describe('history', function () {
Brave.beforeAll(this)

Expand Down Expand Up @@ -283,4 +321,3 @@ function * setup (client) {
.waitForVisible('#window')
.waitForVisible(urlInput)
}

0 comments on commit 0f47e16

Please sign in to comment.