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

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed May 10, 2017
1 parent 57a853c commit 1c1239c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const tabsReducer = (state, action, immutableAction) => {

setImmediate(() => {
if (action.get('activateIfOpen')) {
tabs.maybeCreateTab(state, action)
tabs.maybeCreateTab(state, action, action.get('createProperties'))
} else {
tabs.createTab(action)
tabs.create(action.get('createProperties'), null, action.get('isRestore'))
}
})
break
Expand Down
23 changes: 12 additions & 11 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,18 @@ const api = {
return true
},

create: (createProperties, cb = null) => {
create: (createProperties, cb = null, isRestore = false) => {
setImmediate(() => {
createProperties = makeImmutable(createProperties).toJS()

// handle deprecated `location` property
if (createProperties.location) {
console.warn('Using `location` in createProperties is deprecated. Please use `url` instead')
createProperties.url = createProperties.location
delete createProperties.location
}
const switchToNewTabsImmediately = getSetting(settings.SWITCH_TO_NEW_TABS) === true
if (createProperties.active == null && switchToNewTabsImmediately) {
if (!isRestore && switchToNewTabsImmediately) {
createProperties.active = true
}
if (!createProperties.url) {
Expand Down Expand Up @@ -557,11 +564,6 @@ const api = {
win.loadURL('about:blank')
},

createTab: (action) => {
action = makeImmutable(action)
api.create(action.get('createProperties'))
},

moveTo: (state, tabId, frameOpts, browserOpts, windowId) => {
frameOpts = makeImmutable(frameOpts)
browserOpts = makeImmutable(browserOpts)
Expand Down Expand Up @@ -602,9 +604,8 @@ const api = {
}
},

maybeCreateTab: (state, action) => {
action = makeImmutable(action)
let createProperties = makeImmutable(action.get('createProperties'))
maybeCreateTab: (state, createProperties) => {
createProperties = makeImmutable(createProperties)
const url = normalizeUrl(createProperties.get('url'))
createProperties = createProperties.set('url', url)
const windowId = createProperties.get('windowId')
Expand All @@ -615,7 +616,7 @@ const api = {
if (tabData) {
api.setActive(tabData.get('id'))
} else {
api.createTab(action)
api.create(createProperties)
}
},

Expand Down
2 changes: 2 additions & 0 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ class UrlBar extends React.Component {
if (this.urlInput.value !== newValue) {
this.urlInput.value = newValue
if (!this.keyPress) {
// if this is a key press don't sent the update until keyUp so
// showAutocompleteResult can handle the result
windowActions.setNavBarUserInput(val)
}
}
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ const appActions = {
* A request for a new tab has been made with the specified createProperties
* @param {Object} createProperties
*/
createTabRequested: function (createProperties, activateIfOpen) {
createTabRequested: function (createProperties, activateIfOpen = false, isRestore = false) {
AppDispatcher.dispatch({
actionType: appConstants.APP_CREATE_TAB_REQUESTED,
createProperties,
activateIfOpen
activateIfOpen,
isRestore
})
},

Expand Down
2 changes: 1 addition & 1 deletion js/components/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Window extends React.Component {
title: frame.title,
faviconUrl: frame.icon,
index: i
})
}, false, true /* isRestore */)
}
})
}
Expand Down
29 changes: 19 additions & 10 deletions test/tab-components/tabTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ describe('tab tests', function () {
.windowByUrl(Brave.browserWindowUrl)
.newTab({
location: this.page1,
discarded: true
discarded: true,
active: false
}, false)
.waitForElementCount('[data-test-id="tab"]', 2)
// This ensures it's actually unloaded
Expand Down Expand Up @@ -326,24 +327,32 @@ describe('tab tests', function () {
yield setup(this.app.client)
this.page1 = Brave.server.url('page1.html')
this.page2 = Brave.server.url('page2.html')
})
it('new tab opens in background by default', function * () {
yield this.app.client
.newTab({ url: this.page1, active: false })
})
it('new tab opens in background when `active == false`', function * () {
yield this.app.client
.waitForUrl(this.page1)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('[data-test-id="tab"][data-frame-key="2"]')
.waitForExist('.frameWrapper:not(.isActive) webview[data-frame-key="2"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForTab({index: 1, active: false})
})
it('changing new tab default makes new tabs open in background by default', function * () {
yield this.app.client
.changeSetting(settings.SWITCH_TO_NEW_TABS, true)
.newTab({ url: this.page2, active: false })
.waitForUrl(this.page2)
.windowByUrl(Brave.browserWindowUrl)
.waitForTab({index: 2, active: true})
describe('change setting to SWITCH_TO_NEW_TABS', function * () {
before(function * () {
yield this.app.client
.changeSetting(settings.SWITCH_TO_NEW_TABS, true)
.newTab({ url: this.page2, active: false })
})
it('forces `active == false` to open in the foreground', function * () {
yield this.app.client
.waitForUrl(this.page2)
.waitForExist('[data-test-id="tab"][data-frame-key="2"]')
.waitForExist('.frameWrapper .isActive webview[data-frame-key="2"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForTab({index: 1, active: true})
})
})
})

Expand Down

0 comments on commit 1c1239c

Please sign in to comment.