From fa7b57ffcd1273b47d55fcd4d0e9cf12a1b69769 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 12 Apr 2017 19:29:36 -0400 Subject: [PATCH] Update the correct frame's text on nav aborted Auditors: @bsclifton Fix #8251 If a background tab event came in it would cause the active frame's input text to change. This could have caused some intermittent strangeness in urlbar previously as well The fix is to pass the frame path to update to updateNavBarInput so it doesn't use the active frame. --- app/renderer/reducers/urlBarReducer.js | 5 +-- .../renderer/reducers/urlBarReducerTest.js | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/renderer/reducers/urlBarReducer.js b/app/renderer/reducers/urlBarReducer.js index 63f751ca968..9a5b67a836e 100644 --- a/app/renderer/reducers/urlBarReducer.js +++ b/app/renderer/reducers/urlBarReducer.js @@ -35,9 +35,10 @@ const navigationAborted = (state, action) => { if (frame) { let location = action.location || frame.get('provisionalLocation') if (location) { + const frameStatePath = frameStatePathForFrame(state, frame) location = getLocation(location) - state = updateNavBarInput(state, location) - state = state.mergeIn(frameStatePathForFrame(state, frame), { + state = updateNavBarInput(state, location, frameStatePath) + state = state.mergeIn(frameStatePath, { location }) } diff --git a/test/unit/app/renderer/reducers/urlBarReducerTest.js b/test/unit/app/renderer/reducers/urlBarReducerTest.js index ad520646a96..982eab054e4 100644 --- a/test/unit/app/renderer/reducers/urlBarReducerTest.js +++ b/test/unit/app/renderer/reducers/urlBarReducerTest.js @@ -10,9 +10,16 @@ require('../../../braveUnit') const windowState = Immutable.fromJS({ activeFrameKey: 2, frames: [{ - key: 1 + key: 1, + tabId: 1, + navbar: { + urlbar: { + location: 'https://www.twitter.com' + } + } }, { key: 2, + tabId: 2, title: 'test', adblock: {blocked: []}, audioPlaybackActive: true, @@ -20,6 +27,11 @@ const windowState = Immutable.fromJS({ httpsEverywhere: {a: '1'}, icon: 'https://www.brave.com/favicon.ico', location: 'https://www.brave.com/2', + navbar: { + urlbar: { + location: 'https://www.brave.com/2' + } + }, noScript: {blocked: []}, themeColor: '#ffffff', trackingProtection: {blocked: []}, @@ -41,7 +53,6 @@ describe('urlBarReducer', function () { mockery.registerMock('electron', fakeElectron) urlBarReducer = require('../../../../../app/renderer/reducers/urlBarReducer') }) - after(function () { mockery.disable() }) @@ -57,7 +68,7 @@ describe('urlBarReducer', function () { }) it('Does not change url bar state of non active frame key', function () { - assert.equal(this.newState.getIn(['frames', 0, 'navbar', 'urlbar', 'location']), undefined) + assert.equal(this.newState.getIn(['frames', 0, 'navbar', 'urlbar', 'location']), 'https://www.twitter.com') }) }) @@ -113,4 +124,20 @@ describe('urlBarReducer', function () { }) }) }) + + describe('WINDOW_SET_NAVIGATION_ABORTED', function () { + before(function () { + }) + it('sets the correct frame\'s text', function () { + // Active frame key is 2 but let's update tabId 1 (frameKey 1 too) + const action = { + actionType: windowConstants.WINDOW_SET_NAVIGATION_ABORTED, + tabId: 1, + location: 'https://facebook.com/' + } + this.newState = urlBarReducer(windowState, action) + assert.equal(this.newState.getIn(['frames', 0, 'navbar', 'urlbar', 'location']), action.location) + assert.equal(this.newState.getIn(['frames', 0, 'location']), action.location) + }) + }) })