diff --git a/app/browser/api/textCalc.js b/app/browser/api/textCalc.js
deleted file mode 100644
index 7525acca8f4..00000000000
--- a/app/browser/api/textCalc.js
+++ /dev/null
@@ -1,147 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const Immutable = require('immutable')
-
-// Actions
-const appActions = require('../../../js/actions/appActions')
-
-// Constant
-const siteTags = require('../../../js/constants/siteTags')
-
-// Utils
-const tabs = require('../../browser/tabs')
-const {makeImmutable} = require('../../common/state/immutableUtil')
-
-// Styles
-const globalStyles = require('../../renderer/components/styles/global')
-
-const fontSize = globalStyles.spacing.bookmarksItemFontSize
-const fontFamily = globalStyles.typography.default.family
-
-const calcText = (item, type) => {
- let title = type === siteTags.BOOKMARK
- ? item.get('title') || item.get('location')
- : item.get('title')
-
- if (title && title.length === 0) {
- return
- }
-
- title = title
- .replace(/'/g, '!')
- .replace(/\\"/g, '!')
- .replace(/\\\\/g, '//')
-
- const param = `
- (function() {
- let ctx = document.createElement('canvas').getContext('2d')
- ctx.font = '${fontSize} ${fontFamily}'
- const width = ctx.measureText('${title}').width
-
- return width
- })()
- `
-
- tabs.executeScriptInBackground(param, (err, url, result) => {
- if (err) {
- throw err
- }
-
- if (type === siteTags.BOOKMARK) {
- appActions.onBookmarkWidthChanged(Immutable.fromJS([
- {
- key: item.get('key'),
- parentFolderId: item.get('parentFolderId'),
- width: result[0]
- }
- ]))
- } else {
- appActions.onBookmarkFolderWidthChanged(Immutable.fromJS([
- {
- key: item.get('key'),
- parentFolderId: item.get('parentFolderId'),
- width: result[0]
- }
- ]))
- }
- })
-}
-
-const calcTextList = (list) => {
- const take = 500
- list = makeImmutable(list)
-
- if (list.size === 0) {
- return
- }
-
- let paramList = JSON.stringify(list.take(take))
- .replace(/'/g, '!')
- .replace(/\\"/g, '!')
- .replace(/\\\\/g, '//')
-
- const param = `
- (function() {
- const ctx = document.createElement('canvas').getContext('2d')
- ctx.font = '${fontSize} ${fontFamily}'
- const bookmarks = []
- const folders = []
- const list = JSON.parse('${paramList}')
-
- list.forEach(item => {
- if (item.type === '${siteTags.BOOKMARK}') {
- bookmarks.push({
- key: item.key,
- parentFolderId: item.parentFolderId,
- width: ctx.measureText(item.title || item.location).width
- })
- } else {
- folders.push({
- key: item.key,
- parentFolderId: item.parentFolderId,
- width: ctx.measureText(item.title).width
- })
- }
- })
-
- const result = {
- bookmarks: bookmarks,
- folders: folders
- }
-
- return JSON.stringify(result)
- })()
- `
-
- tabs.executeScriptInBackground(param, (err, url, result) => {
- if (err) {
- console.error('Error in executeScriptInBackground (textCalcUtil.js)')
- }
-
- if (result[0]) {
- const data = JSON.parse(result[0])
- if (data.bookmarks.length > 0) {
- appActions.onBookmarkWidthChanged(Immutable.fromJS(data.bookmarks))
- }
-
- if (data.folders.length > 0) {
- appActions.onBookmarkFolderWidthChanged(Immutable.fromJS(data.folders))
- }
- } else {
- console.error('Error, cant parse bookmarks in executeScriptInBackground')
- }
-
- list = list.skip(take)
-
- if (list.size > 0) {
- calcTextList(list)
- }
- })
-}
-
-module.exports = {
- calcText,
- calcTextList
-}
diff --git a/app/browser/reducers/bookmarkFoldersReducer.js b/app/browser/reducers/bookmarkFoldersReducer.js
index 9bc48632343..2c7339fecb8 100644
--- a/app/browser/reducers/bookmarkFoldersReducer.js
+++ b/app/browser/reducers/bookmarkFoldersReducer.js
@@ -7,17 +7,14 @@ const Immutable = require('immutable')
// State
const bookmarksState = require('../../common/state/bookmarksState')
const bookmarkFoldersState = require('../../common/state/bookmarkFoldersState')
-const bookmarkToolbarState = require('../../common/state/bookmarkToolbarState')
// Constants
const appConstants = require('../../../js/constants/appConstants')
-const siteTags = require('../../../js/constants/siteTags')
const {STATE_SITES} = require('../../../js/constants/stateConstants')
// Utils
const {makeImmutable} = require('../../common/state/immutableUtil')
const syncUtil = require('../../../js/state/syncUtil')
-const textCalc = require('../../browser/api/textCalc')
const bookmarkFolderUtil = require('../../common/lib/bookmarkFoldersUtil')
const bookmarkFoldersReducer = (state, action, immutableAction) => {
@@ -40,12 +37,10 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
state = syncUtil.updateObjectCache(state, folderDetails, STATE_SITES.BOOKMARK_FOLDERS)
folderList = folderList.push(folderDetails)
})
- textCalc.calcTextList(folderList)
} else {
const folderDetails = bookmarkFolderUtil.buildFolder(folder, bookmarkFoldersState.getFolders(state))
state = bookmarkFoldersState.addFolder(state, folderDetails, closestKey)
state = syncUtil.updateObjectCache(state, folderDetails, STATE_SITES.BOOKMARK_FOLDERS)
- textCalc.calcText(folderDetails, siteTags.BOOKMARK_FOLDER)
}
break
}
@@ -66,12 +61,6 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
state = bookmarkFoldersState.editFolder(state, key, oldFolder, folder)
state = syncUtil.updateObjectCache(state, folder, STATE_SITES.BOOKMARK_FOLDERS)
- const folderDetails = bookmarkFoldersState.getFolder(state, key)
- textCalc.calcText(folderDetails, siteTags.BOOKMARK_FOLDER)
-
- if (folder.has('parentFolderId') && oldFolder.get('parentFolderId') !== folder.get('parentFolderId')) {
- state = bookmarkToolbarState.setToolbars(state)
- }
break
}
@@ -83,8 +72,6 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
break
}
- const oldFolder = bookmarkFoldersState.getFolder(state, key)
-
state = bookmarkFoldersState.moveFolder(
state,
key,
@@ -95,13 +82,6 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
const destinationDetail = bookmarksState.findBookmark(state, action.get('destinationKey'))
state = syncUtil.updateObjectCache(state, destinationDetail, STATE_SITES.BOOKMARK_FOLDERS)
- if (
- destinationDetail.get('parentFolderId') === 0 ||
- action.get('destinationKey') === 0 ||
- oldFolder.get('parentFolderId') === 0
- ) {
- state = bookmarkToolbarState.setToolbars(state)
- }
break
}
case appConstants.APP_REMOVE_BOOKMARK_FOLDER:
@@ -118,33 +98,10 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
state = bookmarkFoldersState.removeFolder(state, key)
state = syncUtil.updateObjectCache(state, folder, STATE_SITES.BOOKMARK_FOLDERS)
})
- state = bookmarkToolbarState.setToolbars(state)
} else {
const folder = bookmarkFoldersState.getFolder(state, folderKey)
state = bookmarkFoldersState.removeFolder(state, folderKey)
state = syncUtil.updateObjectCache(state, folder, STATE_SITES.BOOKMARK_FOLDERS)
- if (folder.get('parentFolderId') === 0) {
- state = bookmarkToolbarState.setToolbars(state)
- }
- }
- break
- }
- case appConstants.APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED:
- {
- if (action.get('folderList', Immutable.List()).isEmpty()) {
- break
- }
-
- let updateToolbar = false
- action.get('folderList').forEach(item => {
- state = bookmarkFoldersState.setWidth(state, item.get('key'), item.get('width'))
- if (item.get('parentFolderId') === 0) {
- updateToolbar = true
- }
- })
-
- if (updateToolbar) {
- state = bookmarkToolbarState.setToolbars(state)
}
break
}
diff --git a/app/browser/reducers/bookmarkToolbarReducer.js b/app/browser/reducers/bookmarkToolbarReducer.js
deleted file mode 100644
index cc75a48dcd8..00000000000
--- a/app/browser/reducers/bookmarkToolbarReducer.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const Immutable = require('immutable')
-
-// Constants
-const appConstants = require('../../../js/constants/appConstants')
-
-// State
-const bookmarksState = require('../../common/state/bookmarksState')
-const bookmarkFoldersState = require('../../common/state/bookmarkFoldersState')
-
-// Util
-const {makeImmutable} = require('../../common/state/immutableUtil')
-const textCalc = require('../../browser/api/textCalc')
-
-const bookmarkToolbarReducer = (state, action, immutableAction) => {
- action = immutableAction || makeImmutable(action)
- switch (action.get('actionType')) {
- case appConstants.APP_SET_STATE:
- {
- // update session for 0.21.x version
- const bookmarks = bookmarksState.getBookmarks(state)
- let list = Immutable.List()
- if (bookmarks.first() && !bookmarks.first().has('width')) {
- list = bookmarks.toList()
- }
-
- const bookmarkFolders = bookmarkFoldersState.getFolders(state)
- if (bookmarkFolders.first() && !bookmarkFolders.first().has('width')) {
- list = list.concat(bookmarkFolders.toList())
- }
-
- if (!list.isEmpty()) {
- textCalc.calcTextList(list)
- }
- }
- break
- }
- return state
-}
-
-module.exports = bookmarkToolbarReducer
diff --git a/app/browser/reducers/bookmarksReducer.js b/app/browser/reducers/bookmarksReducer.js
index aed8d035b84..62315e60b58 100644
--- a/app/browser/reducers/bookmarksReducer.js
+++ b/app/browser/reducers/bookmarksReducer.js
@@ -6,11 +6,9 @@ const Immutable = require('immutable')
// State
const bookmarksState = require('../../common/state/bookmarksState')
-const bookmarkToolbarState = require('../../common/state/bookmarkToolbarState')
// Constants
const appConstants = require('../../../js/constants/appConstants')
-const siteTags = require('../../../js/constants/siteTags')
const {STATE_SITES} = require('../../../js/constants/stateConstants')
// Utils
@@ -18,7 +16,6 @@ const {makeImmutable} = require('../../common/state/immutableUtil')
const syncUtil = require('../../../js/state/syncUtil')
const bookmarkUtil = require('../../common/lib/bookmarkUtil')
const bookmarkLocationCache = require('../../common/cache/bookmarkLocationCache')
-const textCalc = require('../../browser/api/textCalc')
const bookmarksReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
@@ -44,12 +41,10 @@ const bookmarksReducer = (state, action, immutableAction) => {
state = syncUtil.updateObjectCache(state, bookmarkDetail, STATE_SITES.BOOKMARKS)
bookmarkList = bookmarkList.push(bookmarkDetail)
})
- textCalc.calcTextList(bookmarkList)
} else {
const bookmarkDetail = bookmarkUtil.buildBookmark(state, bookmark)
state = bookmarksState.addBookmark(state, bookmarkDetail, closestKey, !isLeftSide)
state = syncUtil.updateObjectCache(state, bookmarkDetail, STATE_SITES.BOOKMARKS)
- textCalc.calcText(bookmarkDetail, siteTags.BOOKMARK)
}
state = bookmarkUtil.updateActiveTabBookmarked(state)
@@ -72,12 +67,8 @@ const bookmarksReducer = (state, action, immutableAction) => {
const bookmarkDetail = bookmarkUtil.buildEditBookmark(oldBookmark, bookmark)
state = bookmarksState.editBookmark(state, oldBookmark, bookmarkDetail)
state = syncUtil.updateObjectCache(state, bookmark, STATE_SITES.BOOKMARKS)
- textCalc.calcText(bookmarkDetail, siteTags.BOOKMARK)
state = bookmarkUtil.updateActiveTabBookmarked(state)
- if (oldBookmark.get('parentFolderId') !== bookmarkDetail.get('parentFolderId')) {
- state = bookmarkToolbarState.setToolbars(state)
- }
break
}
case appConstants.APP_MOVE_BOOKMARK:
@@ -88,8 +79,6 @@ const bookmarksReducer = (state, action, immutableAction) => {
break
}
- const oldBookmark = bookmarksState.getBookmark(state, key)
-
state = bookmarksState.moveBookmark(
state,
key,
@@ -100,14 +89,6 @@ const bookmarksReducer = (state, action, immutableAction) => {
const destinationDetail = bookmarksState.findBookmark(state, action.get('destinationKey'))
state = syncUtil.updateObjectCache(state, destinationDetail, STATE_SITES.BOOKMARKS)
-
- if (
- destinationDetail.get('parentFolderId') === 0 ||
- action.get('destinationKey') === 0 ||
- oldBookmark.get('parentFolderId') === 0
- ) {
- state = bookmarkToolbarState.setToolbars(state)
- }
break
}
case appConstants.APP_REMOVE_BOOKMARK:
@@ -121,36 +102,12 @@ const bookmarksReducer = (state, action, immutableAction) => {
action.get('bookmarkKey', Immutable.List()).forEach((key) => {
state = bookmarksState.removeBookmark(state, key)
})
- state = bookmarkToolbarState.setToolbars(state)
} else {
- const bookmark = bookmarksState.getBookmark(state, bookmarkKey)
state = bookmarksState.removeBookmark(state, bookmarkKey)
- if (bookmark.get('parentFolderId') === 0) {
- state = bookmarkToolbarState.setToolbars(state)
- }
}
state = bookmarkUtil.updateActiveTabBookmarked(state)
break
}
- case appConstants.APP_ON_BOOKMARK_WIDTH_CHANGED:
- {
- if (action.get('bookmarkList', Immutable.List()).isEmpty()) {
- break
- }
-
- let updateToolbar = false
- action.get('bookmarkList').forEach(item => {
- state = bookmarksState.setWidth(state, item.get('key'), item.get('width'))
- if (item.get('parentFolderId') === 0) {
- updateToolbar = true
- }
- })
-
- if (updateToolbar) {
- state = bookmarkToolbarState.setToolbars(state)
- }
- break
- }
}
return state
diff --git a/app/browser/reducers/windowsReducer.js b/app/browser/reducers/windowsReducer.js
index 808a44345db..4a436ff1e15 100644
--- a/app/browser/reducers/windowsReducer.js
+++ b/app/browser/reducers/windowsReducer.js
@@ -316,10 +316,7 @@ const windowsReducer = (state, action, immutableAction) => {
case appConstants.APP_WINDOW_CREATED:
case appConstants.APP_WINDOW_RESIZED:
{
- const bookmarkToolbarState = require('../../common/state/bookmarkToolbarState')
state = windowState.maybeCreateWindow(state, action)
- const windowId = action.getIn(['windowValue', 'windowId'], windowState.WINDOW_ID_NONE)
- state = bookmarkToolbarState.setToolbar(state, windowId)
break
}
case appConstants.APP_TAB_STRIP_EMPTY:
diff --git a/app/browser/tabs.js b/app/browser/tabs.js
index c1b6bc89f9a..7f7f9d636b7 100644
--- a/app/browser/tabs.js
+++ b/app/browser/tabs.js
@@ -4,11 +4,10 @@
const appActions = require('../../js/actions/appActions')
const tabActions = require('../common/actions/tabActions')
-const config = require('../../js/constants/config')
const Immutable = require('immutable')
const { shouldDebugTabEvents } = require('../cmdLine')
const tabState = require('../common/state/tabState')
-const {app, BrowserWindow, extensions, session, ipcMain} = require('electron')
+const {app, extensions, session, ipcMain} = require('electron')
const {makeImmutable, makeJS} = require('../common/state/immutableUtil')
const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil')
@@ -438,29 +437,6 @@ const createNavigationState = (navigationHandle, controller) => {
})
}
-let backgroundProcess = null
-let backgroundProcessTimer = null
-/**
- * Execute script in the browser tab
- * @param win{object} - window in which we want to execute script
- * @param debug{boolean} - would you like to close window or not
- * @param script{string} - script that you want to execute
- * @param cb{function} - function that we call after script is completed
- */
-const runScript = (win, debug, script, cb) => {
- win.webContents.executeScriptInTab(config.braveExtensionId, script, {}, (err, url, result) => {
- cb(err, url, result)
- if (!debug) {
- backgroundProcessTimer = setTimeout(() => {
- if (backgroundProcess) {
- win.close()
- backgroundProcess = null
- }
- }, 2 * 60 * 1000) // 2 min
- }
- })
-}
-
const api = {
init: (state, action) => {
process.on('open-url-from-tab', (e, source, targetUrl, disposition) => {
@@ -1047,34 +1023,6 @@ const api = {
})
},
- /**
- * Execute script in the background browser window
- * @param script{string} - script that we want to run
- * @param cb{function} - function that we want to call when script is done
- * @param debug{boolean} - would you like to keep browser window when script is done
- */
- executeScriptInBackground: (script, cb, debug = false) => {
- if (backgroundProcessTimer) {
- clearTimeout(backgroundProcessTimer)
- }
-
- if (backgroundProcess === null) {
- backgroundProcess = new BrowserWindow({
- show: debug,
- webPreferences: {
- partition: 'default'
- }
- })
-
- backgroundProcess.webContents.on('did-finish-load', () => {
- runScript(backgroundProcess, debug, script, cb)
- })
- backgroundProcess.loadURL('about:blank')
- } else {
- runScript(backgroundProcess, debug, script, cb)
- }
- },
-
moveTo: (state, tabId, frameOpts, browserOpts, toWindowId) => {
if (shouldDebugTabEvents) {
console.log(`Tab ${tabId}] tabs.moveTo(window: ${toWindowId})`)
diff --git a/app/common/lib/bookmarkToolbarUtil.js b/app/common/lib/bookmarkToolbarUtil.js
deleted file mode 100644
index 872338cd6e2..00000000000
--- a/app/common/lib/bookmarkToolbarUtil.js
+++ /dev/null
@@ -1,93 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const Immutable = require('immutable')
-
-// Utils
-const bookmarkUtil = require('../lib/bookmarkUtil')
-const bookmarkFoldersUtil = require('../lib/bookmarkFoldersUtil')
-
-// Styles
-const globalStyles = require('../../renderer/components/styles/global')
-const {iconSize} = require('../../../js/constants/config')
-const maxWidth = parseInt(globalStyles.spacing.bookmarksItemMaxWidth, 10)
-const padding = parseInt(globalStyles.spacing.bookmarksItemPadding, 10) * 2
-const itemMargin = parseInt(globalStyles.spacing.bookmarksItemMargin, 10)
-const toolbarPadding = parseInt(globalStyles.spacing.bookmarksToolbarPadding)
-const overflowButtonWidth = parseInt(globalStyles.spacing.bookmarksToolbarOverflowButtonWidth, 10)
-const chevronMargin = parseInt(globalStyles.spacing.bookmarksItemChevronMargin)
-const chevronFontSize = parseInt(globalStyles.spacing.bookmarksItemChevronFontSize)
-const chevronWidth = chevronMargin + chevronFontSize
-
-const getBookmarkKeys = (width, bookmarks) => {
- if (bookmarks == null) {
- return {
- toolbar: Immutable.List(),
- other: Immutable.List()
- }
- }
-
- let widthAccountedFor = 0
-
- const onlyText = bookmarkUtil.showOnlyText()
- const textAndFavicon = bookmarkUtil.showTextAndFavicon()
- const onlyFavicon = bookmarkUtil.showOnlyFavicon()
-
- // No margin for show only fav icons
- const margin = onlyFavicon ? 0 : (itemMargin * 2)
- const maximumBookmarksToolbarWidth = width - overflowButtonWidth
-
- widthAccountedFor += toolbarPadding
-
- // Loop through until we fill up the entire bookmark toolbar width
- let i = 0
- for (let item of bookmarks) {
- let iconWidth
- const isFolder = bookmarkFoldersUtil.isFolder(item)
-
- if (onlyText) {
- iconWidth = 0
- } else if (textAndFavicon || isFolder) {
- iconWidth = iconSize + itemMargin
- } else if (onlyFavicon) {
- iconWidth = iconSize
- }
-
- let extraWidth = 0
-
- if (onlyText) {
- extraWidth = padding + item.get('width')
- } else if (textAndFavicon) {
- extraWidth = padding + iconWidth + item.get('width')
- } else if (onlyFavicon) {
- extraWidth = padding + iconWidth
-
- if (isFolder) {
- extraWidth += item.get('width')
- }
- }
-
- if (isFolder) {
- extraWidth += chevronWidth
- }
-
- extraWidth = Math.min(extraWidth, maxWidth)
- widthAccountedFor += extraWidth + margin
-
- if (widthAccountedFor >= maximumBookmarksToolbarWidth) {
- break
- }
-
- i++
- }
-
- return {
- toolbar: bookmarks.take(i).map((item) => item.get('key')).toList(),
- other: bookmarks.skip(i).take(100).map((item) => item.get('key')).toList()
- }
-}
-
-module.exports = {
- getBookmarkKeys
-}
diff --git a/app/common/lib/bookmarkUtil.js b/app/common/lib/bookmarkUtil.js
index afd20aa9f1d..248c9404496 100644
--- a/app/common/lib/bookmarkUtil.js
+++ b/app/common/lib/bookmarkUtil.js
@@ -198,8 +198,7 @@ const buildBookmark = (state, bookmarkDetail) => {
themeColor: dataItem.get('themeColor'),
type: siteTags.BOOKMARK,
key: key,
- skipSync: bookmarkDetail.get('skipSync', null),
- width: 0
+ skipSync: bookmarkDetail.get('skipSync', null)
})
}
diff --git a/app/common/state/bookmarkFoldersState.js b/app/common/state/bookmarkFoldersState.js
index 4db477cacd4..7cbfb29ccc6 100644
--- a/app/common/state/bookmarkFoldersState.js
+++ b/app/common/state/bookmarkFoldersState.js
@@ -198,17 +198,6 @@ const bookmarkFoldersState = {
append
)
return state
- },
-
- setWidth: (state, key, width) => {
- state = validateState(state)
- width = parseFloat(width)
-
- if (key == null || isNaN(width)) {
- return state
- }
-
- return state.setIn([STATE_SITES.BOOKMARK_FOLDERS, key, 'width'], width)
}
}
diff --git a/app/common/state/bookmarkToolbarState.js b/app/common/state/bookmarkToolbarState.js
deleted file mode 100644
index 9b10bcc577e..00000000000
--- a/app/common/state/bookmarkToolbarState.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const assert = require('assert')
-const Immutable = require('immutable')
-
-// State
-const bookmarksState = require('./bookmarksState')
-const windowState = require('./windowState')
-
-// Utils
-const {makeImmutable, isList, isMap} = require('./immutableUtil')
-const bookmarkToolbarUtil = require('../lib/bookmarkToolbarUtil')
-
-const validateState = function (state) {
- state = makeImmutable(state)
- assert.ok(isMap(state), 'state must be an Immutable.Map')
- assert.ok(isList(state.get('windows'), 'state must contain an Immutable.List of windows'))
- return state
-}
-
-const bookmarkToolbarState = {
- setToolbars: (state) => {
- validateState(state)
- const bookmarks = bookmarksState.getBookmarksWithFolders(state, 0)
-
- state.get('windows').forEach((item, index) => {
- const width = state.getIn(['windows', index, 'width'])
- const data = bookmarkToolbarUtil.getBookmarkKeys(width, bookmarks)
-
- if (!state.hasIn(['windows', index])) {
- return state
- }
-
- state = state
- .setIn(['windows', index, 'bookmarksToolbar', 'toolbar'], data.toolbar)
- .setIn(['windows', index, 'bookmarksToolbar', 'other'], data.other)
- })
-
- return state
- },
-
- setToolbar: (state, windowId) => {
- validateState(state)
- const bookmarks = bookmarksState.getBookmarksWithFolders(state, 0)
- const windowIndex = windowState.getWindowIndexByWindowId(state, windowId)
-
- if (!state.hasIn(['windows', windowIndex])) {
- return state
- }
-
- const width = state.getIn(['windows', windowIndex, 'width'])
- const data = bookmarkToolbarUtil.getBookmarkKeys(width, bookmarks)
-
- return state
- .setIn(['windows', windowIndex, 'bookmarksToolbar', 'toolbar'], data.toolbar)
- .setIn(['windows', windowIndex, 'bookmarksToolbar', 'other'], data.other)
- },
-
- getToolbar: (state, windowId) => {
- const index = windowState.getWindowIndexByWindowId(state, windowId)
- return state.getIn(['windows', index, 'bookmarksToolbar', 'toolbar'], Immutable.List())
- },
-
- getOther: (state, windowId) => {
- const index = windowState.getWindowIndexByWindowId(state, windowId)
- return state.getIn(['windows', index, 'bookmarksToolbar', 'other'], Immutable.List())
- }
-}
-
-module.exports = bookmarkToolbarState
diff --git a/app/common/state/bookmarksState.js b/app/common/state/bookmarksState.js
index 1053e7a0378..320c71fef9f 100644
--- a/app/common/state/bookmarksState.js
+++ b/app/common/state/bookmarksState.js
@@ -290,16 +290,6 @@ const bookmarksState = {
const cache = bookmarkOrderCache.getBookmarksByParentId(state, folderKey)
return cache.map((item) => bookmarksState.getBookmark(state, item.get('key')))
- },
-
- setWidth: (state, key, width) => {
- width = parseFloat(width)
-
- if (key == null || isNaN(width)) {
- return state
- }
-
- return state.setIn([STATE_SITES.BOOKMARKS, key, 'width'], width)
}
}
diff --git a/app/renderer/components/bookmarks/bookmarkToolbarButton.js b/app/renderer/components/bookmarks/bookmarkToolbarButton.js
index 950730bbbc3..55217f5e69c 100644
--- a/app/renderer/components/bookmarks/bookmarkToolbarButton.js
+++ b/app/renderer/components/bookmarks/bookmarkToolbarButton.js
@@ -242,6 +242,7 @@ class BookmarkToolbarButton extends React.Component {
draggable
ref={(node) => { this.bookmarkNode = node }}
title={hoverTitle}
+ data-bookmark-key={this.props.bookmarkKey}
onClick={this.onClick}
onMouseOver={this.onMouseOver}
onDragStart={this.onDragStart}
@@ -312,21 +313,22 @@ module.exports = ReduxComponent.connect(BookmarkToolbarButton)
const styles = StyleSheet.create({
bookmarkToolbarButton: {
- display: 'flex',
- alignItems: 'center',
+ WebkitAppRegion: 'no-drag',
boxSizing: 'border-box',
borderRadius: '3px',
color: globalStyles.color.mediumGray,
cursor: 'default',
fontSize: globalStyles.spacing.bookmarksItemFontSize,
lineHeight: '1.3',
- margin: `auto ${globalStyles.spacing.bookmarksItemMargin}`,
+ // margin-bottom hides the second row of items on the bookmark bar
+ margin: `0 ${globalStyles.spacing.bookmarksItemMargin} 0 ${globalStyles.spacing.bookmarksItemMargin}`,
maxWidth: globalStyles.spacing.bookmarksItemMaxWidth,
padding: `2px ${globalStyles.spacing.bookmarksItemPadding}`,
textOverflow: 'ellipsis',
userSelect: 'none',
whiteSpace: 'nowrap',
- WebkitAppRegion: 'no-drag',
+ display: 'flex',
+ alignItems: 'center',
':hover': {
background: '#fff',
diff --git a/app/renderer/components/bookmarks/bookmarksToolbar.js b/app/renderer/components/bookmarks/bookmarksToolbar.js
index 1608a3e0187..e7c44bf255c 100644
--- a/app/renderer/components/bookmarks/bookmarksToolbar.js
+++ b/app/renderer/components/bookmarks/bookmarksToolbar.js
@@ -18,7 +18,7 @@ const windowActions = require('../../../../js/actions/windowActions')
// State
const windowState = require('../../../common/state/windowState')
-const bookmarkToolbarState = require('../../../common/state/bookmarkToolbarState')
+const bookmarksState = require('../../../common/state/bookmarksState')
// Constants
const dragTypes = require('../../../../js/constants/dragTypes')
@@ -31,13 +31,36 @@ const dnd = require('../../../../js/dnd')
const dndData = require('../../../../js/dndData')
const isWindows = require('../../../common/lib/platformUtil').isWindows()
const frameStateUtil = require('../../../../js/state/frameStateUtil')
-const bookmarkUtil = require('../../../common/lib/bookmarkUtil')
const {elementHasDataset} = require('../../../../js/lib/eventUtil')
-const {getCurrentWindowId} = require('../../currentWindow')
+const bookmarkUtil = require('../../../common/lib/bookmarkUtil')
// Styles
const globalStyles = require('../styles/global')
+function getHiddenKeys (elements, immutableAllKeys) {
+ if (!elements || !elements.length) {
+ return
+ }
+ let firstOtherKey
+ // check again which ones are missing as now the indicator is there, we may have additional
+ for (let i = 1; i < elements.length; i++) {
+ // skip first item (0)
+ const thisElement = elements[i]
+ if (thisElement.offsetTop > 10) {
+ // the [i]th item is the first that does not fit
+ firstOtherKey = thisElement.dataset.bookmarkKey
+ break
+ }
+ }
+ if (firstOtherKey) {
+ const firstOtherIndex = immutableAllKeys.indexOf(firstOtherKey)
+ if (firstOtherIndex !== -1) {
+ const hiddenKeys = immutableAllKeys.slice(firstOtherIndex)
+ return hiddenKeys
+ }
+ }
+}
+
class BookmarksToolbar extends React.Component {
constructor (props) {
super(props)
@@ -46,6 +69,7 @@ class BookmarksToolbar extends React.Component {
this.onDragOver = this.onDragOver.bind(this)
this.onContextMenu = this.onContextMenu.bind(this)
this.onMoreBookmarksMenu = this.onMoreBookmarksMenu.bind(this)
+ this.setBookmarksToolbarRef = this.setBookmarksToolbarRef.bind(this)
}
onDrop (e) {
@@ -155,7 +179,7 @@ class BookmarksToolbar extends React.Component {
onMoreBookmarksMenu (e) {
const rect = e.target.getBoundingClientRect()
- windowActions.onMoreBookmarksMenu(this.props.hiddenBookmarks, rect.bottom)
+ windowActions.onMoreBookmarksMenu(this.hiddenBookmarkKeys, rect.bottom)
}
onContextMenu (e) {
@@ -172,70 +196,138 @@ class BookmarksToolbar extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
- const currentWindowId = getCurrentWindowId()
const props = {}
// used in renderer
- props.showOnlyFavicon = bookmarkUtil.showOnlyFavicon()
- props.showFavicon = bookmarkUtil.showFavicon()
props.shouldAllowWindowDrag = !isWindows && windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused(state))
- props.visibleBookmarks = bookmarkToolbarState.getToolbar(state, currentWindowId)
- props.hiddenBookmarks = bookmarkToolbarState.getOther(state, currentWindowId)
+ props.toolbarBookmarks = bookmarksState.getBookmarksWithFolders(state, 0).map(item => item.get('key'))
// used in other functions
- props.activeFrameKey = activeFrame.get('key')
props.title = activeFrame.get('title')
props.location = activeFrame.get('location')
-
+ props.showOnlyFavicon = bookmarkUtil.showOnlyFavicon()
+ props.showFavicon = bookmarkUtil.showFavicon()
+ props.bookmarkDisplayMode =
+ bookmarkUtil.showOnlyFavicon()
+ ? 1
+ : bookmarkUtil.showFavicon()
+ ? 2
+ : 3
return props
}
+ calculateNonFirstRowItems () {
+ if (!this.bookmarksToolbarRef) {
+ return
+ }
+ const bookmarkRefs = this.bookmarksToolbarRef.children
+ const classNameShowOverflow = css(styles.bookmarksToolbar_hasOverflow)
+ this.hiddenBookmarkKeys = null
+ // first check which items overflow with indicator visible
+ this.bookmarksToolbarRef.classList.add(classNameShowOverflow)
+ // and save which keys were hidden for the overflow menu to open
+ this.hiddenBookmarkKeys = getHiddenKeys(bookmarkRefs, this.props.toolbarBookmarks)
+ // we don't need indicator if there were no hidden items with / without it
+ this.bookmarksToolbarRef.classList.remove(classNameShowOverflow)
+ // if there were hidden items with the indicator
+ if (this.hiddenBookmarkKeys && this.hiddenBookmarkKeys.size) {
+ // check again to see if we really need the indicator
+ const hiddenKeysWithNoIndicator = getHiddenKeys(bookmarkRefs, this.props.toolbarBookmarks)
+ if (hiddenKeysWithNoIndicator && hiddenKeysWithNoIndicator.size) {
+ // add overflow indicator as needed
+ this.bookmarksToolbarRef.classList.add(classNameShowOverflow)
+ }
+ }
+ }
+
+ setBookmarksToolbarRef (ref) {
+ this.bookmarksToolbarRef = ref
+ // recalculate which items are not on a single line on resize
+ // (only once before the next paint frame)
+ let debounceAnimationFrame
+ this.resizeObserver = this.resizeObserver || new window.ResizeObserver(() => {
+ debounceAnimationFrame = debounceAnimationFrame || window.requestAnimationFrame(() => {
+ debounceAnimationFrame = null
+ this.calculateNonFirstRowItems()
+ })
+ })
+ this.resizeObserver.observe(this.bookmarksToolbarRef)
+ }
+
+ componentDidUpdate (prevProps) {
+ // Only recalc which bookmark items are overflowed if the bookmarks changed
+ // or the display mode changed.
+ if (prevProps.bookmarkDisplayMode !== this.props.bookmarkDisplayMode || !prevProps.toolbarBookmarks.equals(this.props.toolbarBookmarks)) {
+ // No need to wait for the new DOM render result to paint
+ // before measuring since reading offsetTop of the elements
+ // will force layout to be computed.
+ this.calculateNonFirstRowItems()
+ }
+ }
+
render () {
this.bookmarkRefs = []
return
{
- this.props.visibleBookmarks.map((bookmarkKey, i) =>
- this.bookmarkRefs.push(node)}
- key={`toolbar-button-${i}`}
- bookmarkKey={bookmarkKey}
- />)
+ this.props.toolbarBookmarks.slice(0, 100).map((bookmarkKey, i) =>
+ this.bookmarkRefs.push(node)}
+ key={`toolbar-button-${i}`}
+ bookmarkKey={bookmarkKey}
+ />)
}
- {
- this.props.hiddenBookmarks.size !== 0
- ?
+
- : null
- }
+
}
}
const styles = StyleSheet.create({
bookmarksToolbar: {
+ '--bookmarks-toolbar-overflow-indicator-width': '0px',
+ flex: 1,
boxSizing: 'border-box',
+ height: globalStyles.spacing.bookmarksToolbarHeight,
display: 'flex',
- flex: 1,
- alignItems: 'center', // to align bookmarksToolbar__overflowIndicator to the center
- padding: `0 ${globalStyles.spacing.bookmarksToolbarPadding}`,
- margin: `${globalStyles.spacing.navbarMenubarMargin} 0`
+ flexDirection: 'row',
+ flexWrap: 'wrap',
+ alignItems: 'center',
+ overflow: 'hidden',
+ // leave space on the right for the overflow button when appropriate
+ // aphrodite cannot have a calc in a shorthand padding declaration :-(
+ paddingRight: `calc(${globalStyles.spacing.bookmarksToolbarPadding} + var(--bookmarks-toolbar-overflow-indicator-width))`,
+ paddingTop: 0,
+ paddingBottom: 0,
+ paddingLeft: globalStyles.spacing.bookmarksToolbarPadding,
+ margin: `${globalStyles.spacing.navbarMenubarMargin} 0`,
+ position: 'relative'
+ },
+
+ bookmarksToolbar_hasOverflow: {
+ '--bookmarks-toolbar-overflow-indicator-visibility': 'visible',
+ '--bookmarks-toolbar-overflow-indicator-width': `${globalStyles.spacing.bookmarksToolbarOverflowButtonWidth} !important`
},
bookmarksToolbar_allowDragging: {
@@ -246,12 +338,15 @@ const styles = StyleSheet.create({
WebkitAppRegion: 'no-drag'
},
- bookmarksToolbar_showOnlyFavicon: {
- padding: `0 0 0 ${globalStyles.spacing.bookmarksToolbarPadding}`
- },
-
bookmarksToolbar__overflowIndicator: {
- margin: '0 5px 0 auto'
+ position: 'absolute',
+ top: 0,
+ right: 0,
+ height: globalStyles.spacing.bookmarksToolbarHeight,
+ margin: `0 calc(${globalStyles.spacing.bookmarksToolbarPadding} + 5px) 0 auto`,
+ visibility: 'var(--bookmarks-toolbar-overflow-indicator-visibility, hidden)',
+ display: 'flex',
+ alignItems: 'center'
}
})
diff --git a/app/renderer/components/styles/global.js b/app/renderer/components/styles/global.js
index 5aa455b48b2..74f86c9b06e 100644
--- a/app/renderer/components/styles/global.js
+++ b/app/renderer/components/styles/global.js
@@ -154,7 +154,7 @@ const globalStyles = {
tabsToolbarHeight: '29px',
tabPagesHeight: '7px',
bookmarkHangerMaxWidth: '350px',
- bookmarksToolbarHeight: '24px',
+ bookmarksToolbarHeight: '19px',
bookmarksToolbarWithFaviconsHeight: '24px',
bookmarksFileIconSize: '13px',
bookmarksFolderIconSize: '15px',
@@ -166,7 +166,7 @@ const globalStyles = {
bookmarksToolbarPadding: '10px',
bookmarksItemFontSize: '11px',
bookmarksToolbarButtonDraggingMargin: '25px',
- bookmarksToolbarOverflowButtonWidth: '25px',
+ bookmarksToolbarOverflowButtonWidth: '14px',
navbarMenubarMargin: '7px',
navbarButtonSpacing: '4px',
navbarButtonWidth: '20px',
diff --git a/docs/state.md b/docs/state.md
index 18a8845f37c..65547e3be34 100644
--- a/docs/state.md
+++ b/docs/state.md
@@ -63,8 +63,7 @@ AppStore
parentFolderId: number,
partitionNumber: number, // optionally specifies a specific session
skipSync: boolean,
- title: string,
- width: float // bookmark text width
+ title: string
}
},
bookmarkFolders: {
@@ -75,8 +74,7 @@ AppStore
originalSeed: Array., // only set for bookmarks that have been synced before a sync profile reset
parentFolderId: number, // set for bookmarks and bookmark folders only
skipSync: boolean, // Set for objects FETCHed by sync
- title: string,
- width: float // bookmark folder text width
+ title: string
}
},
cache: {
@@ -631,10 +629,6 @@ AppStore
},
windows: [{
// persistent properties
- bookmarksToolbar: {
- toolbar: Array, // bookmark and folder keys that we want to display
- other: Array // bookmark and folder keys that we display in more menu (limited to 100)
- },
focused: boolean,
height: number,
left: number,
diff --git a/js/actions/appActions.js b/js/actions/appActions.js
index 1e086667dd2..94f633bb12c 100644
--- a/js/actions/appActions.js
+++ b/js/actions/appActions.js
@@ -1804,28 +1804,6 @@ const appActions = {
})
},
- /**
- * Dispatches a message that bookmark calculation was done
- * @param bookmarkList {Object} - Object is a list of bookmarks with key, width and parentFolderId as a property
- */
- onBookmarkWidthChanged: function (bookmarkList) {
- dispatch({
- actionType: appConstants.APP_ON_BOOKMARK_WIDTH_CHANGED,
- bookmarkList
- })
- },
-
- /**
- * Dispatches a message that bookmark calculation was done
- * @param folderList {Object} - Object is a list of folders with key, width and parentFolderId as a property
- */
- onBookmarkFolderWidthChanged: function (folderList) {
- dispatch({
- actionType: appConstants.APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED,
- folderList
- })
- },
-
/**
* Dispatches a message that window was resized
* @param windowValue - window properties
diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js
index 213eee30a61..6a0d971a76f 100644
--- a/js/constants/appConstants.js
+++ b/js/constants/appConstants.js
@@ -157,8 +157,6 @@ const appConstants = {
APP_MOVE_BOOKMARK: _,
APP_ENABLE_PEPPER_MENU: _,
APP_INSPECT_ELEMENT: _,
- APP_ON_BOOKMARK_WIDTH_CHANGED: _,
- APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED: _,
APP_WINDOW_RESIZED: _,
APP_ON_FAVICON_RECEIVED: _,
APP_ON_PUBLISHER_OPTION_UPDATE: _,
diff --git a/js/stores/appStore.js b/js/stores/appStore.js
index 8625cffbc90..63448ef6615 100644
--- a/js/stores/appStore.js
+++ b/js/stores/appStore.js
@@ -45,7 +45,6 @@ const tabState = require('../../app/common/state/tabState')
const bookmarksState = require('../../app/common/state/bookmarksState')
const bookmarkFoldersState = require('../../app/common/state/bookmarkFoldersState')
const historyState = require('../../app/common/state/historyState')
-const bookmarkToolbarState = require('../../app/common/state/bookmarkToolbarState')
// Only used internally
const CHANGE_EVENT = 'app-state-change'
@@ -176,9 +175,6 @@ function handleChangeSettingAction (state, settingKey, settingValue) {
state = state.setIn(['settings', settingKey], homeArray.join('|'))
break
}
- case settings.BOOKMARKS_TOOLBAR_MODE:
- state = bookmarkToolbarState.setToolbars(state)
- break
}
return state
@@ -224,7 +220,6 @@ const handleAppAction = (action) => {
require('../../app/browser/reducers/updatesReducer'),
require('../../app/browser/reducers/aboutNewTabReducer'),
require('../../app/browser/reducers/braverySettingsReducer'),
- require('../../app/browser/reducers/bookmarkToolbarReducer'),
require('../../app/browser/reducers/siteSettingsReducer'),
require('../../app/browser/reducers/pageDataReducer'),
ledgerReducer,
diff --git a/test/unit/app/browser/reducers/bookmarkFoldersReducerTest.js b/test/unit/app/browser/reducers/bookmarkFoldersReducerTest.js
index 4758bc52aba..80a54d9fd92 100644
--- a/test/unit/app/browser/reducers/bookmarkFoldersReducerTest.js
+++ b/test/unit/app/browser/reducers/bookmarkFoldersReducerTest.js
@@ -16,7 +16,7 @@ const {STATE_SITES} = require('../../../../../js/constants/stateConstants')
require('../../../braveUnit')
describe('bookmarkFoldersReducer unit test', function () {
- let bookmarkFoldersReducer, bookmarkFoldersState, bookmarkToolbarState
+ let bookmarkFoldersReducer, bookmarkFoldersState
const state = Immutable.fromJS({
windows: [
@@ -118,11 +118,6 @@ describe('bookmarkFoldersReducer unit test', function () {
}
})
- const fakeTextCalc = {
- calcText: () => true,
- calcTextList: () => true
- }
-
before(function () {
mockery.enable({
warnOnReplace: false,
@@ -131,10 +126,8 @@ describe('bookmarkFoldersReducer unit test', function () {
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('ad-block', fakeAdBlock)
- mockery.registerMock('../../browser/api/textCalc', fakeTextCalc)
bookmarkFoldersReducer = require('../../../../../app/browser/reducers/bookmarkFoldersReducer')
bookmarkFoldersState = require('../../../../../app/common/state/bookmarkFoldersState')
- bookmarkToolbarState = require('../../../../../app/common/state/bookmarkToolbarState')
})
after(function () {
@@ -142,27 +135,23 @@ describe('bookmarkFoldersReducer unit test', function () {
})
describe('APP_ADD_BOOKMARK_FOLDER', function () {
- let spy, spyCalc
+ let spy
afterEach(function () {
spy.restore()
- spyCalc.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarkFoldersState, 'addFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK_FOLDER
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(state, newState)
})
it('folder data is map (single folder)', function () {
spy = sinon.spy(bookmarkFoldersState, 'addFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK_FOLDER,
folderDetails: {
@@ -193,13 +182,11 @@ describe('bookmarkFoldersReducer unit test', function () {
]
}))
assert.equal(spy.calledOnce, true)
- assert.equal(spyCalc.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
it('folder data is list (multiple folders)', function () {
spy = sinon.spy(bookmarkFoldersState, 'addFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcTextList')
const newState = bookmarkFoldersReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK_FOLDER,
folderDetails: [
@@ -270,45 +257,38 @@ describe('bookmarkFoldersReducer unit test', function () {
]
}))
assert.equal(spy.callCount, 3)
- assert.equal(spyCalc.callCount, 1)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
})
describe('APP_EDIT_BOOKMARK_FOLDER', function () {
- let spy, spyCalc
+ let spy
afterEach(function () {
spy.restore()
- spyCalc.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarkFoldersState, 'editFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_EDIT_BOOKMARK_FOLDER
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(stateWithData, newState)
})
it('folder data is missing', function () {
spy = sinon.spy(bookmarkFoldersState, 'editFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_EDIT_BOOKMARK_FOLDER,
editKey: '1'
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(stateWithData, newState)
})
it('folder key is missing', function () {
spy = sinon.spy(bookmarkFoldersState, 'editFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_EDIT_BOOKMARK_FOLDER,
folderDetails: {
@@ -317,13 +297,11 @@ describe('bookmarkFoldersReducer unit test', function () {
}
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(stateWithData, newState)
})
it('folder data is correct', function () {
spy = sinon.spy(bookmarkFoldersState, 'editFolder')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_EDIT_BOOKMARK_FOLDER,
folderDetails: {
@@ -334,33 +312,28 @@ describe('bookmarkFoldersReducer unit test', function () {
})
const expectedState = stateWithData.setIn([STATE_SITES.BOOKMARK_FOLDERS, '1', 'title'], 'folder1 new')
assert.equal(spy.calledOnce, true)
- assert.equal(spyCalc.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
})
describe('APP_MOVE_BOOKMARK_FOLDER', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarkFoldersState, 'moveFolder')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarkFoldersReducer(state, {
actionType: appConstants.APP_MOVE_BOOKMARK_FOLDER
})
assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
assert.deepEqual(state, newState)
})
it('check if move is working', function () {
spy = sinon.spy(bookmarkFoldersState, 'moveFolder')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_MOVE_BOOKMARK_FOLDER,
folderKey: '1',
@@ -380,58 +353,29 @@ describe('bookmarkFoldersReducer unit test', function () {
type: siteTags.BOOKMARK_FOLDER
}
]))
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- '69',
- '1'
- ]))
assert.equal(spy.calledOnce, true)
- assert.equal(spyToolbar.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
-
- it('folder is moved from one folder to another', function () {
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- bookmarkFoldersReducer(stateWithData, {
- actionType: appConstants.APP_MOVE_BOOKMARK_FOLDER,
- folderKey: '81',
- destinationKey: '80'
- })
- assert.equal(spyToolbar.notCalled, true)
- })
-
- it('folder is moved from the toolbar into other bookmarks', function () {
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- bookmarkFoldersReducer(stateWithData, {
- actionType: appConstants.APP_MOVE_BOOKMARK_FOLDER,
- folderKey: '1',
- destinationKey: '-1'
- })
- assert.equal(spyToolbar.calledOnce, true)
- })
})
describe('APP_REMOVE_BOOKMARK_FOLDER', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarkFoldersState, 'removeFolder')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarkFoldersReducer(state, {
actionType: appConstants.APP_REMOVE_BOOKMARK_FOLDER
})
assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
assert.deepEqual(state, newState)
})
it('folder key is list (multiple folders)', function () {
spy = sinon.spy(bookmarkFoldersState, 'removeFolder')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_REMOVE_BOOKMARK_FOLDER,
folderKey: [
@@ -440,13 +384,11 @@ describe('bookmarkFoldersReducer unit test', function () {
]
})
assert.equal(spy.callCount, 4)
- assert.equal(spyToolbar.calledOnce, true)
assert.deepEqual(newState.toJS(), state.toJS())
})
it('folder key is map (single folder)', function () {
spy = sinon.spy(bookmarkFoldersState, 'removeFolder')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarkFoldersReducer(stateWithData, {
actionType: appConstants.APP_REMOVE_BOOKMARK_FOLDER,
folderKey: '1'
@@ -462,89 +404,7 @@ describe('bookmarkFoldersReducer unit test', function () {
.deleteIn(['cache', 'bookmarkOrder', '1'])
.deleteIn([STATE_SITES.BOOKMARK_FOLDERS, '1'])
.deleteIn([STATE_SITES.BOOKMARK_FOLDERS, '81'])
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- '69'
- ]))
assert.equal(spy.calledTwice, true)
- assert.equal(spyToolbar.calledOnce, true)
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
- })
-
- describe('APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED', function () {
- let spy, spyToolbar
-
- afterEach(function () {
- spy.restore()
- spyToolbar.restore()
- })
-
- it('null case', function () {
- spy = sinon.spy(bookmarkFoldersState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarkFoldersReducer(state, {
- actionType: appConstants.APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED
- })
- assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
- assert.deepEqual(state, newState)
- })
-
- it('we update multiple items', function () {
- spy = sinon.spy(bookmarkFoldersState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarkFoldersReducer(stateWithData, {
- actionType: appConstants.APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED,
- folderList: Immutable.fromJS([
- {
- key: '1',
- width: 10,
- parentFolderId: 0
- },
- {
- key: '69',
- width: 15,
- parentFolderId: 0
- },
- {
- key: '80',
- width: 20,
- parentFolderId: 69
- }
- ])
- })
- assert.equal(spy.callCount, 3)
- assert.equal(spyToolbar.calledOnce, true)
- const expectedState = stateWithData
- .setIn([STATE_SITES.BOOKMARK_FOLDERS, '1', 'width'], 10)
- .setIn([STATE_SITES.BOOKMARK_FOLDERS, '69', 'width'], 15)
- .setIn([STATE_SITES.BOOKMARK_FOLDERS, '80', 'width'], 20)
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- '1'
- ]))
- .setIn(['windows', 0, 'bookmarksToolbar', 'other'], Immutable.fromJS([
- '69'
- ]))
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
-
- it('we update one and dont trigger toolbar update (parentFolderId is not 0)', function () {
- spy = sinon.spy(bookmarkFoldersState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarkFoldersReducer(stateWithData, {
- actionType: appConstants.APP_ON_BOOKMARK_FOLDER_WIDTH_CHANGED,
- folderList: Immutable.fromJS([
- {
- key: '80',
- width: 20,
- parentFolderId: 69
- }
- ])
- })
- assert.equal(spy.callCount, 1)
- assert.equal(spyToolbar.notCalled, true)
- const expectedState = stateWithData
- .setIn([STATE_SITES.BOOKMARK_FOLDERS, '80', 'width'], 20)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
})
diff --git a/test/unit/app/browser/reducers/bookmarkToolbarReducerTest.js b/test/unit/app/browser/reducers/bookmarkToolbarReducerTest.js
deleted file mode 100644
index 32330bad97e..00000000000
--- a/test/unit/app/browser/reducers/bookmarkToolbarReducerTest.js
+++ /dev/null
@@ -1,140 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* global describe, it, before, after, afterEach */
-const mockery = require('mockery')
-const Immutable = require('immutable')
-const assert = require('assert')
-const sinon = require('sinon')
-const fakeElectron = require('../../../lib/fakeElectron')
-const fakeAdBlock = require('../../../lib/fakeAdBlock')
-
-const appConstants = require('../../../../../js/constants/appConstants')
-const siteTags = require('../../../../../js/constants/siteTags')
-const {STATE_SITES} = require('../../../../../js/constants/stateConstants')
-require('../../../braveUnit')
-
-describe('bookmarkToolbarReducer unit test', function () {
- let bookmarkToolbarReducer
-
- const fakeTextCalc = {
- calcTextList: () => true
- }
-
- const stateWithData = Immutable.fromJS({
- windows: [],
- bookmarks: {
- 'https://brave.com/|0|0': {
- favicon: undefined,
- title: 'Brave',
- location: 'https://brave.com/',
- key: 'https://brave.com/|0|0',
- parentFolderId: 0,
- partitionNumber: 0,
- objectId: null,
- themeColor: undefined,
- type: siteTags.BOOKMARK
- },
- 'https://brianbondy.com/|0|1': {
- favicon: undefined,
- title: 'Clifton',
- location: 'https://clifton.io/',
- key: 'https://clifton.io/|0|1',
- parentFolderId: 1,
- partitionNumber: 0,
- objectId: null,
- themeColor: undefined,
- type: siteTags.BOOKMARK
- }
- },
- bookmarkFolders: {
- '1': {
- title: 'folder1',
- folderId: 1,
- key: '1',
- parentFolderId: 0,
- partitionNumber: 0,
- objectId: null,
- type: siteTags.BOOKMARK_FOLDER
- }
- },
- cache: {
- bookmarkOrder: {
- '0': [
- {
- key: 'https://brave.com/|0|0',
- order: 0,
- type: siteTags.BOOKMARK
- },
- {
- key: '1',
- order: 1,
- type: siteTags.BOOKMARK_FOLDER
- }
- ],
- '1': [
- {
- key: 'https://brianbondy.com/|0|1',
- order: 0,
- type: siteTags.BOOKMARK
- }
- ]
- },
- bookmarkLocation: {
- 'https://brave.com/': [
- 'https://brave.com/|0|0'
- ],
- 'https://brianbondy.com/': [
- 'https://brianbondy.com/|0|1'
- ]
- }
- },
- historySites: {},
- tabs: []
- })
-
- before(function () {
- mockery.enable({
- warnOnReplace: false,
- warnOnUnregistered: false,
- useCleanCache: true
- })
- mockery.registerMock('electron', fakeElectron)
- mockery.registerMock('ad-block', fakeAdBlock)
- mockery.registerMock('../../browser/api/textCalc', fakeTextCalc)
- bookmarkToolbarReducer = require('../../../../../app/browser/reducers/bookmarkToolbarReducer')
- })
-
- after(function () {
- mockery.disable()
- })
-
- describe('APP_SET_STATE', function () {
- let spyCalc
-
- afterEach(function () {
- spyCalc.restore()
- })
-
- it('we are upgrading from version 0.20 to 0.21', function () {
- spyCalc = sinon.spy(fakeTextCalc, 'calcTextList')
- bookmarkToolbarReducer(stateWithData, {
- actionType: appConstants.APP_SET_STATE
- })
- assert.equal(spyCalc.callCount, 1)
- })
-
- it('we are on version 0.21', function () {
- spyCalc = sinon.spy(fakeTextCalc, 'calcTextList')
- const newState = stateWithData
- .setIn([STATE_SITES.BOOKMARKS, 'https://brave.com/|0|0', 'width'], 10)
- .setIn([STATE_SITES.BOOKMARKS, 'https://brianbondy.com/|0|1', 'width'], 10)
- .setIn([STATE_SITES.BOOKMARK_FOLDERS, '1', 'width'], 10)
- bookmarkToolbarReducer(newState, {
- actionType: appConstants.APP_SET_STATE
- })
- assert.equal(spyCalc.notCalled, true)
- })
- })
-})
diff --git a/test/unit/app/browser/reducers/bookmarksReducerTest.js b/test/unit/app/browser/reducers/bookmarksReducerTest.js
index 3dcb00cc746..0f5148a8b5f 100644
--- a/test/unit/app/browser/reducers/bookmarksReducerTest.js
+++ b/test/unit/app/browser/reducers/bookmarksReducerTest.js
@@ -15,17 +15,13 @@ const siteTags = require('../../../../../js/constants/siteTags')
require('../../../braveUnit')
describe('bookmarksReducer unit test', function () {
- let bookmarksReducer, bookmarksState, bookmarkLocationCache, bookmarkToolbarState
+ let bookmarksReducer, bookmarksState, bookmarkLocationCache
const state = Immutable.fromJS({
windows: [
{
windowId: 1,
- width: 100,
- bookmarksToolbar: {
- toolbar: [],
- other: []
- }
+ width: 100
}
],
bookmarks: {},
@@ -42,11 +38,7 @@ describe('bookmarksReducer unit test', function () {
windows: [
{
windowId: 1,
- width: 100,
- bookmarksToolbar: {
- toolbar: [],
- other: []
- }
+ width: 100
}
],
bookmarks: {
@@ -144,11 +136,6 @@ describe('bookmarksReducer unit test', function () {
tabs: []
})
- const fakeTextCalc = {
- calcText: () => true,
- calcTextList: () => true
- }
-
before(function () {
mockery.enable({
warnOnReplace: false,
@@ -157,11 +144,9 @@ describe('bookmarksReducer unit test', function () {
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('ad-block', fakeAdBlock)
- mockery.registerMock('../../browser/api/textCalc', fakeTextCalc)
bookmarksReducer = require('../../../../../app/browser/reducers/bookmarksReducer')
bookmarksState = require('../../../../../app/common/state/bookmarksState')
bookmarkLocationCache = require('../../../../../app/common/cache/bookmarkLocationCache')
- bookmarkToolbarState = require('../../../../../app/common/state/bookmarkToolbarState')
})
after(function () {
@@ -187,27 +172,23 @@ describe('bookmarksReducer unit test', function () {
})
describe('APP_ADD_BOOKMARK', function () {
- let spy, spyCalc
+ let spy
afterEach(function () {
spy.restore()
- spyCalc.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarksState, 'addBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(state, newState)
})
it('bookmark data is map (single bookmark)', function () {
spy = sinon.spy(bookmarksState, 'addBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK,
siteDetail: {
@@ -228,8 +209,7 @@ describe('bookmarksReducer unit test', function () {
themeColor: undefined,
title: 'Clifton',
type: siteTags.BOOKMARK,
- key: 'https://clifton.io/|0|0',
- width: 0
+ key: 'https://clifton.io/|0|0'
}
}))
.setIn(['cache', 'bookmarkLocation'], Immutable.fromJS({
@@ -247,13 +227,11 @@ describe('bookmarksReducer unit test', function () {
]
}))
assert.equal(spy.calledOnce, true)
- assert.equal(spyCalc.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
it('bookmark data is list (multiple bookmarks)', function () {
spy = sinon.spy(bookmarksState, 'addBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcTextList')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_ADD_BOOKMARK,
siteDetail: [
@@ -282,8 +260,7 @@ describe('bookmarksReducer unit test', function () {
themeColor: undefined,
title: 'Clifton',
type: siteTags.BOOKMARK,
- key: 'https://clifton.io/|0|0',
- width: 0
+ key: 'https://clifton.io/|0|0'
},
'https://brianbondy.com/|0|0': {
favicon: undefined,
@@ -295,8 +272,7 @@ describe('bookmarksReducer unit test', function () {
themeColor: undefined,
title: 'Bondy',
type: siteTags.BOOKMARK,
- key: 'https://brianbondy.com/|0|0',
- width: 0
+ key: 'https://brianbondy.com/|0|0'
}
}))
.setIn(['cache', 'bookmarkLocation'], Immutable.fromJS({
@@ -322,7 +298,6 @@ describe('bookmarksReducer unit test', function () {
]
}))
assert.equal(spy.callCount, 2)
- assert.equal(spyCalc.callCount, 1)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
@@ -404,8 +379,7 @@ describe('bookmarksReducer unit test', function () {
partitionNumber: 0,
skipSync: null,
themeColor: undefined,
- type: 'bookmark',
- width: 0
+ type: 'bookmark'
},
'https://www.bridiver.io|0|0': {
lastAccessedTime: 0,
@@ -444,39 +418,33 @@ describe('bookmarksReducer unit test', function () {
})
describe('APP_EDIT_BOOKMARK', function () {
- let spy, spyCalc
+ let spy
afterEach(function () {
spy.restore()
- spyCalc.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarksState, 'editBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_EDIT_BOOKMARK
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(state, newState)
})
it('bookmark data is missing', function () {
spy = sinon.spy(bookmarksState, 'editBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_EDIT_BOOKMARK,
editKey: 'https://clifton.io|0|0'
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(state, newState)
})
it('bookmark key is missing', function () {
spy = sinon.spy(bookmarksState, 'editBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_EDIT_BOOKMARK,
siteDetail: {
@@ -485,13 +453,11 @@ describe('bookmarksReducer unit test', function () {
}
})
assert.equal(spy.notCalled, true)
- assert.equal(spyCalc.notCalled, true)
assert.deepEqual(state, newState)
})
it('bookmark data is correct', function () {
spy = sinon.spy(bookmarksState, 'editBookmark')
- spyCalc = sinon.spy(fakeTextCalc, 'calcText')
const newState = bookmarksReducer(stateWithData, {
actionType: appConstants.APP_EDIT_BOOKMARK,
siteDetail: {
@@ -502,33 +468,28 @@ describe('bookmarksReducer unit test', function () {
const expectedState = stateWithData
.setIn(['bookmarks', 'https://clifton.io/|0|0', 'title'], 'Bondy')
assert.equal(spy.calledOnce, true)
- assert.equal(spyCalc.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
})
describe('APP_MOVE_BOOKMARK', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarksState, 'moveBookmark')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_MOVE_BOOKMARK
})
assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
assert.deepEqual(state, newState)
})
it('data is correct', function () {
spy = sinon.spy(bookmarksState, 'moveBookmark')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarksReducer(stateWithData, {
actionType: appConstants.APP_MOVE_BOOKMARK,
bookmarkKey: 'https://clifton.io/|0|0',
@@ -548,58 +509,29 @@ describe('bookmarksReducer unit test', function () {
type: siteTags.BOOKMARK
}
]))
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- 'https://clifton.io/|0|0',
- 'https://brave.com/|0|0'
- ]))
assert.equal(spy.calledOnce, true)
- assert.equal(spyToolbar.calledOnce, true)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
-
- it('bookmark is moved from folder to another folder', function () {
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- bookmarksReducer(stateWithData, {
- actionType: appConstants.APP_MOVE_BOOKMARK,
- bookmarkKey: 'https://brianbondy.com/|0|1',
- destinationKey: 'https://test.com/|0|2'
- })
- assert.equal(spyToolbar.notCalled, true)
- })
-
- it('bookmark is moved from toolbar to another folder', function () {
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- bookmarksReducer(stateWithData, {
- actionType: appConstants.APP_MOVE_BOOKMARK,
- bookmarkKey: 'https://clifton.io/|0|0',
- destinationKey: 'https://test.com/|0|2'
- })
- assert.equal(spyToolbar.calledOnce, true)
- })
})
describe('APP_REMOVE_BOOKMARK', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('null case', function () {
spy = sinon.spy(bookmarksState, 'removeBookmark')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarksReducer(state, {
actionType: appConstants.APP_REMOVE_BOOKMARK
})
assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
assert.deepEqual(state, newState)
})
it('check if delete is working', function () {
spy = sinon.spy(bookmarksState, 'removeBookmark')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
const newState = bookmarksReducer(stateWithData, {
actionType: appConstants.APP_REMOVE_BOOKMARK,
bookmarkKey: 'https://clifton.io/|0|0'
@@ -614,87 +546,7 @@ describe('bookmarksReducer unit test', function () {
]))
.deleteIn(['bookmarks', 'https://clifton.io/|0|0'])
.deleteIn(['cache', 'bookmarkLocation', 'https://clifton.io/'])
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- 'https://brave.com/|0|0'
- ]))
assert.equal(spy.calledOnce, true)
- assert.equal(spyToolbar.calledOnce, true)
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
- })
-
- describe('APP_ON_BOOKMARK_WIDTH_CHANGED', function () {
- let spy, spyToolbar
-
- afterEach(function () {
- spy.restore()
- spyToolbar.restore()
- })
-
- it('null case', function () {
- spy = sinon.spy(bookmarksState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarksReducer(state, {
- actionType: appConstants.APP_ON_BOOKMARK_WIDTH_CHANGED
- })
- assert.equal(spy.notCalled, true)
- assert.equal(spyToolbar.notCalled, true)
- assert.deepEqual(state, newState)
- })
-
- it('we update multiple items', function () {
- spy = sinon.spy(bookmarksState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarksReducer(stateWithData, {
- actionType: appConstants.APP_ON_BOOKMARK_WIDTH_CHANGED,
- bookmarkList: Immutable.fromJS([
- {
- key: 'https://brave.com/|0|0',
- width: 10,
- parentFolderId: 0
- },
- {
- key: 'https://clifton.io/|0|0',
- width: 15,
- parentFolderId: 0
- },
- {
- key: 'https://brianbondy.com/|0|1',
- width: 20,
- parentFolderId: 69
- }
- ])
- })
- assert.equal(spy.callCount, 3)
- assert.equal(spyToolbar.calledOnce, true)
- const expectedState = stateWithData
- .setIn(['bookmarks', 'https://brave.com/|0|0', 'width'], 10)
- .setIn(['bookmarks', 'https://clifton.io/|0|0', 'width'], 15)
- .setIn(['bookmarks', 'https://brianbondy.com/|0|1', 'width'], 20)
- .setIn(['windows', 0, 'bookmarksToolbar', 'toolbar'], Immutable.fromJS([
- 'https://brave.com/|0|0',
- 'https://clifton.io/|0|0'
- ]))
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
-
- it('we update one and trigger toolbar update', function () {
- spy = sinon.spy(bookmarksState, 'setWidth')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbars')
- const newState = bookmarksReducer(stateWithData, {
- actionType: appConstants.APP_ON_BOOKMARK_WIDTH_CHANGED,
- bookmarkList: Immutable.fromJS([
- {
- key: 'https://brianbondy.com/|0|1',
- width: 20,
- parentFolderId: 1
- }
- ])
- })
- assert.equal(spy.callCount, 1)
- assert.equal(spyToolbar.notCalled, true)
- const expectedState = stateWithData
- .setIn(['bookmarks', 'https://brianbondy.com/|0|1', 'width'], 20)
assert.deepEqual(newState.toJS(), expectedState.toJS())
})
})
diff --git a/test/unit/app/browser/reducers/windowReducerTest.js b/test/unit/app/browser/reducers/windowReducerTest.js
index a50751484bf..055fa978e30 100644
--- a/test/unit/app/browser/reducers/windowReducerTest.js
+++ b/test/unit/app/browser/reducers/windowReducerTest.js
@@ -13,7 +13,7 @@ const appConstants = require('../../../../../js/constants/appConstants')
require('../../../braveUnit')
describe('windowsReducer unit test', function () {
- let windowsReducer, bookmarkToolbarState
+ let windowsReducer
const fakeElectron = Object.assign({}, require('../../../lib/fakeElectron'))
const fakeWindowState = {
@@ -22,8 +22,7 @@ describe('windowsReducer unit test', function () {
const state = Immutable.fromJS({
windows: [],
- defaultWindowParams: {},
- bookmarks: {}
+ defaultWindowParams: {}
})
before(function () {
@@ -36,7 +35,6 @@ describe('windowsReducer unit test', function () {
mockery.registerMock('ad-block', fakeAdBlock)
mockery.registerMock('../../common/state/windowState', fakeWindowState)
windowsReducer = require('../../../../../app/browser/reducers/windowsReducer')
- bookmarkToolbarState = require('../../../../../app/common/state/bookmarkToolbarState')
})
after(function () {
@@ -44,16 +42,14 @@ describe('windowsReducer unit test', function () {
})
describe('APP_WINDOW_CREATED', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('check if functions are called', function () {
spy = sinon.spy(fakeWindowState, 'maybeCreateWindow')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbar')
windowsReducer(state, {
actionType: appConstants.APP_WINDOW_CREATED,
windowValue: Immutable.fromJS({
@@ -61,21 +57,18 @@ describe('windowsReducer unit test', function () {
})
})
assert.equal(spy.calledOnce, true)
- assert.equal(spyToolbar.calledOnce, true)
})
})
describe('APP_WINDOW_RESIZED', function () {
- let spy, spyToolbar
+ let spy
afterEach(function () {
spy.restore()
- spyToolbar.restore()
})
it('check if functions are called', function () {
spy = sinon.spy(fakeWindowState, 'maybeCreateWindow')
- spyToolbar = sinon.spy(bookmarkToolbarState, 'setToolbar')
windowsReducer(state, {
actionType: appConstants.APP_WINDOW_RESIZED,
windowValue: Immutable.fromJS({
@@ -83,7 +76,6 @@ describe('windowsReducer unit test', function () {
})
})
assert.equal(spy.calledOnce, true)
- assert.equal(spyToolbar.calledOnce, true)
})
})
})
diff --git a/test/unit/app/common/lib/bookmarkToolbarUtilTest.js b/test/unit/app/common/lib/bookmarkToolbarUtilTest.js
deleted file mode 100644
index a0750357f1f..00000000000
--- a/test/unit/app/common/lib/bookmarkToolbarUtilTest.js
+++ /dev/null
@@ -1,94 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* global describe, it, before, after */
-const assert = require('assert')
-const mockery = require('mockery')
-const sinon = require('sinon')
-const Immutable = require('immutable')
-const siteTags = require('../../../../../js/constants/siteTags')
-
-require('../../../braveUnit')
-
-describe('bookmarkToolbarUtil unit test', function () {
- let bookmarkToolbarUtil, bookmarkUtil
-
- const generateBookmarks = (num) => {
- return Immutable.fromJS(new Array(num).fill().map((_, i) => {
- return {
- type: siteTags.BOOKMARK,
- title: `Bookmark ${i}`,
- key: `bookmark-${i}|0|0`,
- width: 10 * i
- }
- }))
- }
-
- const generateBookmarksKeys = (num, skip = 0) => {
- return Immutable.fromJS(new Array(num).fill().map((_, i) => {
- const id = skip + i
- return `bookmark-${id}|0|0`
- }))
- }
-
- before(function () {
- mockery.enable({
- warnOnReplace: false,
- warnOnUnregistered: false,
- useCleanCache: true
- })
- bookmarkToolbarUtil = require('../../../../../app/common/lib/bookmarkToolbarUtil')
- bookmarkUtil = require('../../../../../app/common/lib/bookmarkUtil')
- })
-
- after(function () {
- mockery.disable()
- })
-
- describe('getToolbarBookmarks', function () {
- let showOnlyText
-
- before(function () {
- showOnlyText = sinon.stub(bookmarkUtil, 'showOnlyText', () => true)
- })
-
- after(function () {
- showOnlyText.restore()
- })
-
- it('null scenario', function () {
- assert.deepEqual(bookmarkToolbarUtil.getBookmarkKeys(), {
- toolbar: Immutable.List(),
- other: Immutable.List()
- })
- })
-
- it('we only have bookmark for the toolbar', function () {
- const bookmarks = generateBookmarks(5)
-
- assert.deepEqual(bookmarkToolbarUtil.getBookmarkKeys(500, bookmarks), {
- toolbar: generateBookmarksKeys(5),
- other: Immutable.List()
- })
- })
-
- it('we have bookmarks for toolbar and other', function () {
- const bookmarks = generateBookmarks(50)
-
- assert.deepEqual(bookmarkToolbarUtil.getBookmarkKeys(500, bookmarks), {
- toolbar: generateBookmarksKeys(8),
- other: generateBookmarksKeys(42, 8)
- })
- })
-
- it('other limit is set to 100', function () {
- const bookmarks = generateBookmarks(500)
-
- assert.deepEqual(bookmarkToolbarUtil.getBookmarkKeys(500, bookmarks), {
- toolbar: generateBookmarksKeys(8),
- other: generateBookmarksKeys(100, 8)
- })
- })
- })
-})
diff --git a/test/unit/app/common/lib/bookmarkUtilTest.js b/test/unit/app/common/lib/bookmarkUtilTest.js
index f5fde0be313..67387ff07ec 100644
--- a/test/unit/app/common/lib/bookmarkUtilTest.js
+++ b/test/unit/app/common/lib/bookmarkUtilTest.js
@@ -497,8 +497,7 @@ describe('bookmarkUtil unit test', function () {
themeColor: undefined,
type: siteTags.BOOKMARK,
key: 'https://brave.com|0|0',
- skipSync: null,
- width: 0
+ skipSync: null
}
assert.deepEqual(bookmarkUtil.buildBookmark(state, bookmark).toJS(), expectedResult)
@@ -527,8 +526,7 @@ describe('bookmarkUtil unit test', function () {
themeColor: '#000',
type: siteTags.BOOKMARK,
key: 'https://brave.com|0|0',
- skipSync: null,
- width: 0
+ skipSync: null
}
assert.deepEqual(bookmarkUtil.buildBookmark(newState, bookmark).toJS(), expectedResult)
@@ -550,8 +548,7 @@ describe('bookmarkUtil unit test', function () {
themeColor: '#FFF',
type: siteTags.BOOKMARK,
key: 'https://brave.com/|0|0',
- skipSync: null,
- width: 0
+ skipSync: null
}
assert.deepEqual(bookmarkUtil.buildBookmark(stateWithData, bookmark).toJS(), expectedResult)
@@ -573,8 +570,7 @@ describe('bookmarkUtil unit test', function () {
themeColor: 'rgb(59, 89, 152)',
type: siteTags.BOOKMARK,
key: 'https://www.facebook.com/BraveSoftware/|0|0',
- skipSync: null,
- width: 0
+ skipSync: null
}
assert.deepEqual(bookmarkUtil.buildBookmark(stateWithData, bookmark).toJS(), expectedResult)
diff --git a/test/unit/app/common/state/bookmarkFoldersStateTest.js b/test/unit/app/common/state/bookmarkFoldersStateTest.js
index 7c5dcf36421..d68088bd663 100644
--- a/test/unit/app/common/state/bookmarkFoldersStateTest.js
+++ b/test/unit/app/common/state/bookmarkFoldersStateTest.js
@@ -788,22 +788,4 @@ describe('bookmarkFoldersState unit test', function () {
assert(findBookmarkSpy.calledOnce)
})
})
-
- describe('setWidth', function () {
- it('null case', function () {
- const result = bookmarkFoldersState.setWidth(stateWithData)
- assert.deepEqual(result.toJS(), stateWithData.toJS())
- })
-
- it('parse width', function () {
- const result = bookmarkFoldersState.setWidth(stateWithData, '1', 'dsfsdfds')
- assert.deepEqual(result.toJS(), stateWithData.toJS())
- })
-
- it('set width', function () {
- const result = bookmarkFoldersState.setWidth(stateWithData, '1', 100)
- const expectedResult = stateWithData.setIn(['bookmarkFolders', '1', 'width'], 100)
- assert.deepEqual(result.toJS(), expectedResult.toJS())
- })
- })
})
diff --git a/test/unit/app/common/state/bookmarkToolbarStateTest.js b/test/unit/app/common/state/bookmarkToolbarStateTest.js
deleted file mode 100644
index 7e31463bfd2..00000000000
--- a/test/unit/app/common/state/bookmarkToolbarStateTest.js
+++ /dev/null
@@ -1,158 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* global before, after, describe, it */
-const Immutable = require('immutable')
-const assert = require('assert')
-const mockery = require('mockery')
-
-describe('bookmarkToolbarState unit test', function () {
- let bookmarkToolbarState
-
- const state = Immutable.fromJS({
- windows: [],
- bookmarks: {},
- bookmarkFolders: {},
- cache: {
- bookmarkOrder: {},
- bookmarkLocation: {}
- },
- historySites: {},
- tabs: []
- })
-
- const stateWithData = Immutable.fromJS({
- windows: [
- {
- windowId: 1
- },
- {
- windowId: 2
- }
- ],
- bookmarks: {},
- bookmarkFolders: {},
- cache: {
- bookmarkOrder: {},
- bookmarkLocation: {}
- },
- historySites: {},
- tabs: []
- })
-
- const stateWithToolbar = Immutable.fromJS({
- windows: [
- {
- windowId: 1,
- bookmarksToolbar: {
- toolbar: ['1'],
- other: ['2']
- }
- }
- ],
- bookmarks: {},
- bookmarkFolders: {},
- cache: {
- bookmarkOrder: {},
- bookmarkLocation: {}
- },
- historySites: {},
- tabs: []
- })
-
- before(function () {
- mockery.enable({
- warnOnReplace: false,
- warnOnUnregistered: false,
- useCleanCache: true
- })
- mockery.registerMock('../lib/bookmarkToolbarUtil', {
- getBookmarkKeys: () => {
- return {
- toolbar: Immutable.fromJS(['1']),
- other: Immutable.fromJS(['2'])
- }
- }
- })
- bookmarkToolbarState = require('../../../../../app/common/state/bookmarkToolbarState')
- })
-
- after(function () {
- mockery.disable()
- })
-
- describe('setToolbars', function () {
- it('null case', function () {
- const newState = bookmarkToolbarState.setToolbars(state)
- assert.deepEqual(newState, state)
- })
-
- it('set data', function () {
- const newState = bookmarkToolbarState.setToolbars(stateWithData)
- const expectedState = stateWithData
- .setIn(['windows', 0, 'bookmarksToolbar'], Immutable.fromJS({
- 'other': [
- '2'
- ],
- 'toolbar': [
- '1'
- ]
- }))
- .setIn(['windows', 1, 'bookmarksToolbar'], Immutable.fromJS({
- 'other': [
- '2'
- ],
- 'toolbar': [
- '1'
- ]
- }))
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
- })
-
- describe('setToolbar', function () {
- it('null case', function () {
- const newState = bookmarkToolbarState.setToolbar(state, 1)
- assert.deepEqual(newState.toJS(), state.toJS())
- })
-
- it('set data', function () {
- const newState = bookmarkToolbarState.setToolbar(stateWithData, 2)
- const expectedState = stateWithData
- .setIn(['windows', 1, 'bookmarksToolbar'], Immutable.fromJS({
- 'other': [
- '2'
- ],
- 'toolbar': [
- '1'
- ]
- }))
- assert.deepEqual(newState.toJS(), expectedState.toJS())
- })
- })
-
- describe('getToolbar', function () {
- it('null case', function () {
- const newState = bookmarkToolbarState.getToolbar(state, 1)
- assert.deepEqual(newState, Immutable.List())
- })
-
- it('return data', function () {
- const newState = bookmarkToolbarState.getToolbar(stateWithToolbar, 1)
- assert.deepEqual(newState, Immutable.fromJS(['1']))
- })
- })
-
- describe('getOther', function () {
- it('null case', function () {
- const newState = bookmarkToolbarState.getOther(state, 1)
- assert.deepEqual(newState, Immutable.List())
- })
-
- it('return data', function () {
- const newState = bookmarkToolbarState.getOther(stateWithToolbar, 1)
- assert.deepEqual(newState, Immutable.fromJS(['2']))
- })
- })
-})
diff --git a/test/unit/app/common/state/bookmarksStateTest.js b/test/unit/app/common/state/bookmarksStateTest.js
index dbeb0e6013e..297c13d0f29 100644
--- a/test/unit/app/common/state/bookmarksStateTest.js
+++ b/test/unit/app/common/state/bookmarksStateTest.js
@@ -314,24 +314,6 @@ describe('bookmarkState unit test', function () {
})
})
- describe('setWidth', function () {
- it('null case', function () {
- const result = bookmarksState.setWidth(stateWithData)
- assert.deepEqual(result.toJS(), stateWithData.toJS())
- })
-
- it('parse width', function () {
- const result = bookmarksState.setWidth(stateWithData, '1', 'dsfsdfds')
- assert.deepEqual(result.toJS(), stateWithData.toJS())
- })
-
- it('set width', function () {
- const result = bookmarksState.setWidth(stateWithData, '1', 100)
- const expectedResult = stateWithData.setIn(['bookmarks', '1', 'width'], 100)
- assert.deepEqual(result.toJS(), expectedResult.toJS())
- })
- })
-
describe('getBookmarksWithFolders', function () {
let getBookmarksWithFoldersSpy
before(function () {