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

Commit

Permalink
Update tab bookmarked state
Browse files Browse the repository at this point in the history
Fix #8977

Auditors: @bsclifton @bbondy

Test Plan:
1. Open https://github.com
2. Bookmark the page
3. Click the middle mouse button to open it in a new tab and switch to the new tab quickly (before it finishes loading)
4. Tab should have bookmark star icon
  • Loading branch information
ayumi authored and bsclifton committed May 23, 2017
1 parent b3fc514 commit 97fb76e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app/browser/reducers/sitesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ const syncEnabled = () => {
return getSetting(settings.SYNC_ENABLED) === true
}

const updateTabBookmarked = (state, tabValue) => {
if (!tabValue || !tabValue.get('tabId')) {
return state
}
const bookmarked = siteUtil.isLocationBookmarked(state, tabValue.get('url'))
return tabState.updateTabValue(state, tabValue.set('bookmarked', bookmarked))
}

const updateActiveTabBookmarked = (state) => {
const tab = tabState.getActiveTab(state)
if (!tab) {
return state
}
const bookmarked = siteUtil.isLocationBookmarked(state, tab.get('url'))
return tabState.updateTabValue(state, tab.set('bookmarked', bookmarked))
return updateTabBookmarked(state, tab)
}

const sitesReducer = (state, action, immutableAction) => {
Expand Down Expand Up @@ -135,6 +142,7 @@ const sitesReducer = (state, action, immutableAction) => {
state = syncUtil.updateSiteCache(state, siteDetail)
}
}
state = updateTabBookmarked(state, action.tabValue)
break
case appConstants.APP_CREATE_TAB_REQUESTED: {
const createProperties = immutableAction.get('createProperties')
Expand Down
37 changes: 36 additions & 1 deletion test/bookmark-components/bookmarksTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it, before */
/* global describe, it, before, beforeEach */

const Brave = require('../lib/brave')
const Immutable = require('immutable')
Expand Down Expand Up @@ -249,6 +249,41 @@ describe('bookmark tests', function () {
})
})

describe('bookmark star button is preserved', function () {
Brave.beforeEach(this)
beforeEach(function * () {
this.page1Url = Brave.server.url('page1.html')
this.page2Url = Brave.server.url('page2.html')
yield setup(this.app.client)
yield this.app.client
.addSite({
location: this.page1Url,
folderId: 1,
parentFolderId: 0,
tags: [siteTags.BOOKMARK]
}, siteTags.BOOKMARK)
})

it('on new active tabs', function * () {
yield this.app.client
.waitForVisible(navigatorNotBookmarked)
.newTab({ url: this.page1Url })
.waitForVisible(navigatorBookmarked)
})
it('on new active tabs', function * () {
yield this.app.client
.waitForVisible(navigatorNotBookmarked)
.newTab({ url: this.page1Url, active: false })
.waitForUrl(this.page1Url)
.tabByIndex(0)
.loadUrl(this.page2Url)
.waitForUrl(this.page2Url)
.windowByUrl(Brave.browserWindowUrl)
.ipcSend('shortcut-next-tab')
.waitForVisible(navigatorBookmarked)
})
})

describe('menu behavior', function () {
Brave.beforeAll(this)

Expand Down

0 comments on commit 97fb76e

Please sign in to comment.