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

Commit

Permalink
Merge pull request #9537 from brave/tabsbar/9536
Browse files Browse the repository at this point in the history
Don't allow tab preview after close if config is off
  • Loading branch information
bsclifton committed Jun 19, 2017
1 parent 407c672 commit 2324a8f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/renderer/reducers/frameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const windowActions = require('../../../js/actions/windowActions')
// Utils
const frameStateUtil = require('../../../js/state/frameStateUtil')
const {getCurrentWindowId} = require('../currentWindow')
const {getSetting} = require('../../../js/settings')
const settings = require('../../../js/constants/settings')

const setFullScreen = (state, action) => {
const index = frameStateUtil.getFrameIndex(state, action.frameProps.get('key'))
Expand All @@ -28,13 +30,15 @@ const setFullScreen = (state, action) => {
}

const closeFrame = (state, action) => {
const activeFrameIndex = frameStateUtil.getActiveFrameIndex(state)
const index = frameStateUtil.getFrameIndex(state, action.frameKey)
if (index === -1) {
return state
}

const frameProps = frameStateUtil.getFrameByKey(state, action.frameKey)
const hoverState = state.getIn(['frames', index, 'hoverState'])
const framePreviewEnabled = getSetting(settings.SHOW_TAB_PREVIEWS)

state = state.merge(frameStateUtil.removeFrame(
state,
Expand All @@ -50,14 +54,14 @@ const closeFrame = (state, action) => {

const nextFrame = frameStateUtil.getFrameByIndex(state, index)

if (nextFrame) {
// After closing a tab, preview the next frame as long as there is one
windowActions.setPreviewFrame(nextFrame.get('key'))
if (nextFrame && hoverState) {
// Copy the hover state if tab closed with mouse as long as we have a next frame
// This allow us to have closeTab button visible for sequential frames closing,
// until onMouseLeave event happens.
if (hoverState) {
windowActions.setTabHoverState(nextFrame.get('key'), hoverState)
windowActions.setTabHoverState(nextFrame.get('key'), hoverState)
if (framePreviewEnabled && index !== activeFrameIndex) {
// After closing a tab, preview the next frame as long as there is one
windowActions.setPreviewFrame(nextFrame.get('key'))
}
}

Expand Down
68 changes: 68 additions & 0 deletions test/tab-components/tabTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,74 @@ describe('tab tests', function () {
})
})

describe('webview previews the next tab when current hovered tab is closed', function () {
Brave.beforeAll(this)
before(function * () {
const page1 = Brave.server.url('adblock2.html')
const page2 = Brave.server.url('red_bg.html')
const page3 = Brave.server.url('page_favicon_not_found.html')
const page4 = Brave.server.url('yellow_header.html')
const page5 = Brave.server.url('page1.html')
const page6 = Brave.server.url('page2.html')
yield setup(this.app.client)
yield this.app.client
.newTab({ url: page1 })
.waitForUrl(page1)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="2"]')
.newTab({ url: page2 })
.waitForUrl(page2)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="3"]')
.newTab({ url: page3 })
.waitForUrl(page3)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="4"]')
.newTab({ url: page4 })
.waitForUrl(page4)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="5"]')
.newTab({ url: page5 })
.waitForUrl(page5)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="6"]')
.newTab({ url: page6 })
.waitForUrl(page6)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="7"]')
})

it('show active tab content if next tab does not exist', function * () {
yield this.app.client
.moveToObject('[data-test-id="tab"][data-frame-key="2"]')
.click('[data-test-id="tab"][data-frame-key="2"]')
.moveToObject('[data-test-id="tab"][data-frame-key="7"]')
.middleClick('[data-test-id="tab"][data-frame-key="7"]')
// no preview should be shown
.waitForVisible('.frameWrapper.isPreview webview', 500, true)
})
it('preview the next tab if preview option is on', function * () {
yield this.app.client
.moveToObject('[data-test-id="tab"][data-frame-key="2"]')
.click('[data-test-id="tab"][data-frame-key="2"]')
.moveToObject('[data-test-id="tab"][data-frame-key="4"]')
.middleClick('[data-test-id="tab"][data-frame-key="4"]')
.waitForExist('.frameWrapper.isPreview webview[data-frame-key="5"]')
.waitForVisible('.frameWrapper.isPreview webview[data-frame-key="5"]')
})
it('do not preview the next tab if preview option is off', function * () {
yield this.app.client.changeSetting(settings.SHOW_TAB_PREVIEWS, false)
yield this.app.client
.moveToObject('[data-test-id="tab"][data-frame-key="2"]')
.click('[data-test-id="tab"][data-frame-key="2"]')
.moveToObject('[data-test-id="tab"][data-frame-key="5"]')
.middleClick('[data-test-id="tab"][data-frame-key="5"]')
.waitForExist('.frameWrapper.isPreview webview')
// no preview should be shown
.waitForVisible('.frameWrapper.isPreview webview', 500, true)
})
})

describe('new tabs open per the switch to new tabs setting', function () {
Brave.beforeAll(this)
before(function * () {
Expand Down

0 comments on commit 2324a8f

Please sign in to comment.