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

Commit

Permalink
Brings falling test from 44 to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed May 13, 2017
1 parent 51de94d commit 38a503d
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 110 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Tab extends ImmutableComponent {
setImmediate(() => {
const currentSize = getTabBreakpoint(this.tabSize)
// Avoid updating breakpoint when user enters fullscreen (see #7301)
!this.props.hasTabInFullScreen && windowActions.setTabBreakpoint(this.frame, currentSize)
!this.props.hasTabInFullScreen && windowActions.setTabBreakpoint(this.frame.get('key'), currentSize)
})
}

Expand Down
8 changes: 4 additions & 4 deletions app/renderer/reducers/urlBarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const windowConstants = require('../../../js/constants/windowConstants')
const {aboutUrls, isNavigatableAboutPage, isSourceAboutUrl, isUrl, getSourceAboutUrl, getSourceMagnetUrl} = require('../../../js/lib/appUrlUtil')
const {isURL, isPotentialPhishingUrl, getUrlFromInput} = require('../../../js/lib/urlutil')
const {getFrameByKey, getFrameKeyByTabId, activeFrameStatePath, frameStatePath, frameStatePathForFrame, getActiveFrame, getFrameByTabId} = require('../../../js/state/frameStateUtil')
const {getFrameByKey, getFrameKeyByTabId, activeFrameStatePath, frameStatePath, getActiveFrame, getFrameByTabId} = require('../../../js/state/frameStateUtil')
const getSetting = require('../../../js/settings').getSetting
const {isBookmark, isDefaultEntry, isHistoryEntry} = require('../../../js/state/siteUtil')
const fetchSearchSuggestions = require('../fetchSearchSuggestions')
Expand Down Expand Up @@ -348,10 +348,10 @@ const navigationAborted = (state, action) => {
if (frame) {
let location = action.location || frame.get('provisionalLocation')
if (location) {
const frameStatePath = frameStatePathForFrame(state, frame)
const framePath = frameStatePath(state, frame.get('key'))
location = getLocation(location)
state = updateNavBarInput(state, location, frameStatePath)
state = state.mergeIn(frameStatePath, {
state = updateNavBarInput(state, location, framePath)
state = state.mergeIn(framePath, {
location
})
}
Expand Down
17 changes: 10 additions & 7 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function getFrameByLastAccessedTime (state) {
lastAccessedTime: 0
})

return (frameProps.lastAccessedTime === 0) ? -1 : getFrameIndex(state, frameProps.get('key'))
return (frameProps.lastAccessedTime === 0) ? -1 : getFrameIndex(state, frameProps.key)
}

/**
Expand Down Expand Up @@ -453,6 +453,7 @@ function removeFrame (state, frameProps, activeFrameKey, framePropsIndex, closeA
}

function getFrameTabPageIndex (state, frameProps, tabsPerTabPage) {
frameProps = makeImmutable(frameProps)
const index = getFrameIndex(state, frameProps.get('key'))
if (index === -1) {
return -1
Expand Down Expand Up @@ -496,16 +497,19 @@ const frameStatePath = (state, frameKey) =>

const activeFrameStatePath = (state) => frameStatePath(state, getActiveFrameKey(state))

const frameStatePathForFrame = (state, frameProps) =>
['frames', frameStatePath(state, frameProps.get('key'))]

const getFramesInternalIndex = (state, frameKey) => {
const index = state.getIn(['framesInternal', 'index', frameKey])
if (frameKey == null) return -1

const index = state.getIn(['framesInternal', 'index', frameKey]) ||
state.getIn(['framesInternal', 'index', frameKey.toString()])
return index == null ? -1 : index
}

const getFramesInternalIndexByTabId = (state, tabId) => {
const index = state.getIn(['framesInternal', 'tabIndex', tabId])
if (tabId == null) return -1

const index = state.getIn(['framesInternal', 'tabIndex', tabId]) ||
state.getIn(['framesInternal', 'tabIndex', tabId.toString()])
return index == null ? -1 : index
}

Expand Down Expand Up @@ -578,7 +582,6 @@ module.exports = {
getFrameTabPageIndex,
frameStatePath,
activeFrameStatePath,
frameStatePathForFrame,
getLastCommittedURL,
getFrameByLastAccessedTime,
onFindBarHide,
Expand Down
48 changes: 26 additions & 22 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const config = require('../constants/config')
const settings = require('../constants/settings')
const Immutable = require('immutable')
const frameStateUtil = require('../state/frameStateUtil')
const {activeFrameStatePath, frameStatePathForFrame} = frameStateUtil
const ipc = require('electron').ipcRenderer
const messages = require('../constants/messages')
const debounce = require('../lib/debounce')
Expand Down Expand Up @@ -257,7 +256,7 @@ const doAction = (action) => {
currentKey = frameStateUtil.getFrames(windowState).reduce((previousVal, frame) => Math.max(previousVal, frame.get('key')), 0)
const activeFrame = frameStateUtil.getActiveFrame(windowState)
if (activeFrame && activeFrame.get('location') !== 'about:newtab') {
focusWebview(activeFrameStatePath(windowState))
focusWebview(frameStateUtil.activeFrameStatePath(windowState))
}
// We should not emit here because the Window already know about the change on startup.
return
Expand Down Expand Up @@ -315,7 +314,7 @@ const doAction = (action) => {
// For about:newtab we want to have the urlbar focused, not the new frame.
// Otherwise we want to focus the new tab when it is a new frame in the foreground.
if (action.location !== getTargetAboutUrl('about:newtab')) {
focusWebview(activeFrameStatePath(windowState))
focusWebview(frameStateUtil.activeFrameStatePath(windowState))
}
break
}
Expand Down Expand Up @@ -389,21 +388,24 @@ const doAction = (action) => {
windowState = updateTabPageIndex(windowState, frameStateUtil.getActiveFrame(windowState))
break
case windowConstants.WINDOW_SET_LINK_HOVER_PREVIEW:
windowState = windowState.mergeIn(activeFrameStatePath(windowState), {
windowState = windowState.mergeIn(frameStateUtil.activeFrameStatePath(windowState), {
hrefPreview: action.href,
showOnRight: action.showOnRight
})
break
case windowConstants.WINDOW_SET_THEME_COLOR:
if (action.themeColor !== undefined) {
windowState = windowState.setIn(frameStatePathForFrame(windowState, action.frameProps).concat(['themeColor']), action.themeColor)
}
if (action.computedThemeColor !== undefined) {
windowState = windowState.setIn(frameStatePathForFrame(windowState, action.frameProps).concat(['computedThemeColor']), action.computedThemeColor)
{
const frameKey = action.frameProps.get('key')
if (action.themeColor !== undefined) {
windowState = windowState.setIn(frameStateUtil.frameStatePath(windowState, frameKey).concat(['themeColor']), action.themeColor)
}
if (action.computedThemeColor !== undefined) {
windowState = windowState.setIn(frameStateUtil.frameStatePath(windowState, frameKey).concat(['computedThemeColor']), action.computedThemeColor)
}
break
}
break
case windowConstants.WINDOW_FRAME_SHORTCUT_CHANGED:
const framePath = action.frameProps ? ['frames', frameStateUtil.getFrameIndex(windowState, action.frameProps.get('key'))] : activeFrameStatePath(windowState)
const framePath = action.frameProps ? ['frames', frameStateUtil.getFrameIndex(windowState, action.frameProps.get('key'))] : frameStateUtil.activeFrameStatePath(windowState)
windowState = windowState.mergeIn(framePath, {
activeShortcut: action.activeShortcut,
activeShortcutDetails: action.activeShortcutDetails
Expand Down Expand Up @@ -527,7 +529,7 @@ const doAction = (action) => {
}
break
case windowConstants.WINDOW_WIDEVINE_SITE_ACCESSED_WITHOUT_INSTALL:
const activeLocation = windowState.getIn(activeFrameStatePath(windowState).concat(['location']))
const activeLocation = windowState.getIn(frameStateUtil.activeFrameStatePath(windowState).concat(['location']))
windowState = windowState.set('widevinePanelDetail', Immutable.Map({
alsoAddRememberSiteSetting: true,
location: activeLocation,
Expand Down Expand Up @@ -561,16 +563,18 @@ const doAction = (action) => {
windowState = windowState.setIn(['ui', 'releaseNotes', 'isVisible'], action.isVisible)
break
case windowConstants.WINDOW_SET_SECURITY_STATE:
let path = frameStatePathForFrame(windowState, action.frameProps)
if (action.securityState.secure !== undefined) {
windowState = windowState.setIn(path.concat(['security', 'isSecure']),
action.securityState.secure)
}
if (action.securityState.runInsecureContent !== undefined) {
windowState = windowState.setIn(path.concat(['security', 'runInsecureContent']),
action.securityState.runInsecureContent)
{
const path = frameStateUtil.frameStatePath(windowState, action.frameProps.get('key'))
if (action.securityState.secure !== undefined) {
windowState = windowState.setIn(path.concat(['security', 'isSecure']),
action.securityState.secure)
}
if (action.securityState.runInsecureContent !== undefined) {
windowState = windowState.setIn(path.concat(['security', 'runInsecureContent']),
action.securityState.runInsecureContent)
}
break
}
break
case windowConstants.WINDOW_SET_BLOCKED_BY:
const blockedByPath = ['frames', frameStateUtil.getFrameIndex(windowState, action.frameProps.get('key')), action.blockType, 'blocked']
let blockedBy = windowState.getIn(blockedByPath) || new Immutable.List()
Expand Down Expand Up @@ -757,7 +761,7 @@ frameShortcuts.forEach((shortcut) => {
if (shortcut === 'toggle-dev-tools') {
appActions.toggleDevTools(frameStateUtil.getActiveFrameTabId(windowState))
} else {
windowState = windowState.mergeIn(activeFrameStatePath(windowState), {
windowState = windowState.mergeIn(frameStateUtil.activeFrameStatePath(windowState), {
activeShortcut: shortcut,
activeShortcutDetails: args
})
Expand Down
7 changes: 6 additions & 1 deletion test/unit/app/renderer/components/messageBoxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ let appState = Immutable.fromJS({
windowUUID: 'uuid',
url: 'https://brave.com',
messageBoxDetail: detail1
}]
}],
tabsInternal: {
index: {
1: 0
}
}
})

describe('MessageBox component unit tests', function () {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/app/renderer/components/navigation/navigatorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const appStoreRenderer = Immutable.fromJS({
canGoForward: true,
windowId: 1
}],
tabsInternal: {
index: {
1: 0
}
},
windows: []
})

Expand Down
23 changes: 21 additions & 2 deletions test/unit/app/renderer/reducers/urlBarReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ const windowState = Immutable.fromJS({
}, {
key: 3,
location: 'about:newtab'
}]
}],
framesInternal: {
index: {
1: 0,
2: 1,
3: 2
},
tabIndex: {
1: 0,
2: 1
}
}
})

const fakeAppStoreRenderer = {
Expand Down Expand Up @@ -210,7 +221,15 @@ describe('urlBarReducer', function () {
}, {
key: 3,
location: 'about:newtab'
}]
}],
framesInternal: {
index: {
2: 1
},
tabIndex: {
2: 1
}
}
})

before(function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/js/stores/windowStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ describe('Window store unit tests', function () {
// call doAction for WINDOW_WEBVIEW_LOAD_START
doAction({
actionType: windowConstants.WINDOW_WEBVIEW_LOAD_START,
frameProps: {
frameProps: Immutable.fromJS({
tabId: 0,
key: 0
}
})
})

// get the updated windowState (AFTER doAction runs)
Expand Down
Loading

0 comments on commit 38a503d

Please sign in to comment.