From 99dbc3fc72973c56a0c4da5c6001d77462f8c169 Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Tue, 2 May 2017 15:39:43 -0300 Subject: [PATCH 1/2] Fix loading tab regression - Auditors: @bbondy, @bsclifton - Fix #8550 - Test Plan: loading icon should be visible --- js/stores/windowStore.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 845ae05e95..8f1f519f94 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -324,22 +324,24 @@ const doAction = (action) => { break case windowConstants.WINDOW_WEBVIEW_LOAD_START: { - const framePath = ['frames', frameStateUtil.getFramePropsIndex(frameStateUtil.getFrames(windowState), action.frameProps)] + const statePath = path => + [path, frameStateUtil.getFramePropsIndex(frameStateUtil.getFrames(windowState), action.frameProps)] + // Reset security state windowState = - windowState.deleteIn(framePath.concat(['security', 'blockedRunInsecureContent'])) - windowState = windowState.mergeIn(framePath.concat(['security']), { + windowState.deleteIn(statePath('frames').concat(['security', 'blockedRunInsecureContent'])) + windowState = windowState.mergeIn(statePath('frames').concat(['security']), { isSecure: null, runInsecureContent: false }) // Update loading UI - windowState = windowState.mergeIn(framePath, { + windowState = windowState.mergeIn(statePath('frames'), { loading: true, provisionalLocation: action.location, startLoadTime: new Date().getTime(), endLoadTime: null }) - windowState = windowState.mergeIn(['tabs'].concat(framePath), { + windowState = windowState.mergeIn(statePath('tabs'), { loading: true, provisionalLocation: action.location }) From e23e1be3804078ac31f42ee6a177b92f6a258a75 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Wed, 3 May 2017 00:54:43 -0700 Subject: [PATCH 2/2] Add unit test for windowStore Run using `npm run unittest -- --grep="Window store unit tests"` Auditors: @cezaraugusto --- test/unit/js/stores/windowStoreTest.js | 133 +++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 test/unit/js/stores/windowStoreTest.js diff --git a/test/unit/js/stores/windowStoreTest.js b/test/unit/js/stores/windowStoreTest.js new file mode 100644 index 0000000000..b28c738507 --- /dev/null +++ b/test/unit/js/stores/windowStoreTest.js @@ -0,0 +1,133 @@ +/* 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, before, after, it */ + +const mockery = require('mockery') +const assert = require('assert') +// const sinon = require('sinon') +const Immutable = require('immutable') +const fakeElectron = require('../../lib/fakeElectron') +const windowConstants = require('../../../../js/constants/windowConstants') +let doAction +let windowStore +require('../../braveUnit') + +describe('Window store unit tests', function () { + const fakeDispatcher = { + register: (actionHandler) => { + doAction = actionHandler + } + } + + const reducers = [ + '../../app/renderer/reducers/urlBarReducer', + '../../app/renderer/reducers/urlBarSuggestionsReducer', + '../../app/renderer/reducers/frameReducer', + '../../app/renderer/reducers/contextMenuReducer' + ] + + before(function () { + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false, + useCleanCache: true + }) + mockery.registerMock('electron', fakeElectron) + mockery.registerMock('../dispatcher/appDispatcher', fakeDispatcher) + windowStore = require('../../../../js/stores/windowStore.js') + }) + + after(function () { + mockery.disable() + }) + + describe('doAction', function () { + describe('WINDOW_WEBVIEW_LOAD_START', function () { + let windowState + + before(function () { + const fakeReducer = (state, action) => { + // return the window state we want for our test :) + return Immutable.fromJS({ + frames: [{ + tabId: 0, + key: 0, + loading: false, + startLoadTime: new Date().getTime(), + endLoadTime: 1337, + security: { + isSecure: 'sure!!!', + runInsecureContent: 'nespresso_is_safe_trust_me', + blockedRunInsecureContent: { + nespresso: 'whatElse' + } + } + }] + }) + } + + // since reducers always run first, just return whatever + // window state we want our test to have + reducers.forEach((reducer) => { + mockery.registerMock(reducer, fakeReducer) + }) + + // call doAction for WINDOW_WEBVIEW_LOAD_START + doAction({ + actionType: windowConstants.WINDOW_WEBVIEW_LOAD_START, + frameProps: { + tabId: 0, + key: 0 + } + }) + + // get the updated windowState (AFTER doAction runs) + windowStore = require('../../../../js/stores/windowStore.js') + windowState = windowStore.getState() + }) + + after(function () { + reducers.forEach((reducer) => { + mockery.deregisterMock(reducer) + }) + }) + + describe('security state', function () { + it('resets security state', function () { + assert.deepEqual( + windowState.getIn(['frames', 0, 'security']), + Immutable.fromJS({ + isSecure: null, + runInsecureContent: false + })) + }) + }) + + describe('update loading UI', function () { + describe('for frames', function () { + it('sets loading=true', function () { + assert.equal(windowState.getIn(['frames', 0, 'loading']), true) + }) + it('sets startLoadTime to current time', function () { + assert.deepEqual( + windowState.getIn(['frames', 0, 'startLoadTime']), + windowState.getIn(['frames', 0, 'startLoadTime']) + ) + }) + it('sets endLoadTime=null', function () { + assert.equal(windowState.getIn(['frames', 0, 'endLoadTime']), null) + }) + }) + + describe('for tabs', function () { + it('sets loading=true for tab', function () { + assert.equal(windowState.getIn(['tabs', 0, 'loading']), true) + }) + }) + }) + }) + + // TODO: add your tests if you modify windowStore.js :) + }) +})