diff --git a/app/browser/reducers/aboutWelcomeReducer.js b/app/browser/reducers/aboutWelcomeReducer.js deleted file mode 100644 index 23a1a00b2d5..00000000000 --- a/app/browser/reducers/aboutWelcomeReducer.js +++ /dev/null @@ -1,20 +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/. */ - -'use strict' - -const appConstants = require('../../../js/constants/appConstants') -const {makeImmutable} = require('../../common/state/immutableUtil') - -const aboutWelcomeReducer = (state, action, immutableAction) => { - action = immutableAction || makeImmutable(action) - switch (action.get('actionType')) { - case appConstants.APP_ACTIVATE_WELCOME_SCREEN: - state = state.setIn(['about', 'welcome', 'showOnLoad'], action.get('activateWelcomeScreen')) - break - } - return state -} - -module.exports = aboutWelcomeReducer diff --git a/app/browser/reducers/tabsReducer.js b/app/browser/reducers/tabsReducer.js index 00ce8b726a9..47f608205c3 100644 --- a/app/browser/reducers/tabsReducer.js +++ b/app/browser/reducers/tabsReducer.js @@ -337,6 +337,27 @@ const tabsReducer = (state, action, immutableAction) => { } } break + case appConstants.APP_WINDOW_READY: { + if (!action.getIn(['createProperties', 'windowId'])) { + const senderWindowId = action.getIn(['senderWindowId']) + if (senderWindowId) { + action = action.setIn(['createProperties', 'windowId'], senderWindowId) + } + } + + const welcomeScreenProperties = { + 'url': 'about:welcome', + 'windowId': action.getIn(['createProperties', 'windowId']) + } + + const shouldShowWelcomeScreen = state.getIn(['about', 'welcome', 'showOnLoad']) + if (shouldShowWelcomeScreen) { + setImmediate(() => tabs.create(welcomeScreenProperties)) + // We only need to run welcome screen once + state = state.setIn(['about', 'welcome', 'showOnLoad'], false) + } + break + } case appConstants.APP_DRAG_ENDED: { const dragData = state.get('dragData') if (dragData && dragData.get('type') === dragTypes.TAB) { diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 75b9fc65609..d0002e7b030 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -28,7 +28,6 @@ const {cleanupWebContents, currentWebContents, getWebContents, updateWebContents const {FilterOptions} = require('ad-block') const {isResourceEnabled} = require('../filtering') const autofill = require('../autofill') -const l10n = require('../../js/l10n') let currentPartitionNumber = 0 const incrementPartitionNumber = () => ++currentPartitionNumber @@ -180,7 +179,6 @@ const updateAboutDetails = (tab, tabValue) => { const autofillAddresses = appState.getIn(['autofill', 'addresses']) const versionInformation = appState.getIn(['about', 'brave', 'versionInformation']) const aboutDetails = tabValue.get('aboutDetails') - // TODO(bridiver) - convert this to an action if (url === 'about:preferences#payments') { tab.on('destroyed', () => { @@ -658,10 +656,7 @@ const api = { return true }, - create: (createProperties, cb = null, isRestore = false, skipIfTest = true) => { - const appState = appStore.getState() - let shouldShowWelcomeScreen = appState.getIn(['about', 'welcome', 'showOnLoad']) - + create: (createProperties, cb = null, isRestore = false) => { setImmediate(() => { const {safeBrowsingInstance} = require('../adBlock') createProperties = makeImmutable(createProperties).toJS() @@ -678,19 +673,6 @@ const api = { } if (!createProperties.url) { createProperties.url = newFrameUrl() - // don't open welcome screen for general tests - if (skipIfTest && process.env.NODE_ENV === 'test') { - shouldShowWelcomeScreen = false - } - if (shouldShowWelcomeScreen !== false) { - appActions.createTabRequested({ - url: 'about:welcome', - // avoid chrome-extension title - // while page's title is not fetch - title: l10n.translation('aboutWelcome') - }) - appActions.activateWelcomeScreen(false) - } } createProperties.url = normalizeUrl(createProperties.url) // TODO(bridiver) - this should be in filtering diff --git a/app/sessionStore.js b/app/sessionStore.js index 8f020c74943..a9f33a7b2d1 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -658,7 +658,7 @@ module.exports.defaultAppState = () => { pinnedTopSites: pinnedTopSites }, welcome: { - showOnLoad: true + showOnLoad: !['test', 'development'].includes(process.env.NODE_ENV) } }, trackingProtection: { diff --git a/docs/appActions.md b/docs/appActions.md index 40aa900e89e..7a30ba2846e 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -1138,14 +1138,15 @@ Dispatches a message to indicate that the update log is being opened -### activateWelcomeScreen(shouldShowWelcomeScreen) +### onToggleBrowsingData() -Dispatches a message to the store to show the welcome screen. +Save temp setting for clear browsing data -**Parameters** -**shouldShowWelcomeScreen**: `Boolean`, true if a new tab -with the welcome screen should be show + +### onCancelBrowsingData() + +Clear temp setting for clear browsing data diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 09962509ad9..9cf0e849585 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -1444,15 +1444,22 @@ const appActions = { }, /** - * Dispatches a message to the store to show the welcome screen. - * - * @param {Boolean} shouldShowWelcomeScreen - true if a new tab - * with the welcome screen should be show - */ - activateWelcomeScreen: function (activateWelcomeScreen) { + * Save temp setting for clear browsing data + */ + onToggleBrowsingData: function (property, newValue) { + dispatch({ + actionType: appConstants.APP_ON_TOGGLE_BROWSING_DATA, + property, + newValue + }) + }, + + /** + * Clear temp setting for clear browsing data + */ + onCancelBrowsingData: function () { dispatch({ - actionType: appConstants.APP_ACTIVATE_WELCOME_SCREEN, - activateWelcomeScreen + actionType: appConstants.APP_ON_CANCEL_BROWSING_DATA }) } } diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 373b23dcd06..1768f411dfc 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -124,7 +124,6 @@ const appConstants = { APP_ON_GO_TO_INDEX: _, APP_ON_GO_BACK_LONG: _, APP_ON_GO_FORWARD_LONG: _, - APP_ACTIVATE_WELCOME_SCREEN: _, APP_AUTOPLAY_BLOCKED: _, APP_SAVE_PASSWORD: _, APP_UPDATE_PASSWORD: _, diff --git a/js/stores/appStore.js b/js/stores/appStore.js index db888dc6b22..b2ec9bd58fb 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -405,7 +405,7 @@ const handleAppAction = (action) => { require('../../app/browser/reducers/extensionsReducer'), require('../../app/browser/reducers/shareReducer'), require('../../app/browser/reducers/updatesReducer'), - require('../../app/browser/reducers/aboutWelcomeReducer') + require('../../app/ledger').doAction ] initialized = true appState = action.appState diff --git a/test/unit/app/browser/reducers/aboutWelcomeReducerTest.js b/test/unit/app/browser/reducers/aboutWelcomeReducerTest.js deleted file mode 100644 index 39ebe40eeb2..00000000000 --- a/test/unit/app/browser/reducers/aboutWelcomeReducerTest.js +++ /dev/null @@ -1,38 +0,0 @@ -/* global describe, it, before, after */ -const mockery = require('mockery') -const Immutable = require('immutable') -const assert = require('assert') -const appConstants = require('../../../../../js/constants/appConstants') -const fakeElectron = require('../../../lib/fakeElectron') - -require('../../../braveUnit') - -describe('aboutWelcomeReducer', function () { - let aboutWelcomeReducer - - before(function () { - mockery.enable({ - warnOnReplace: false, - warnOnUnregistered: false, - useCleanCache: true - }) - mockery.registerMock('electron', fakeElectron) - aboutWelcomeReducer = require('../../../../../app/browser/reducers/aboutWelcomeReducer') - }) - - after(function () { - mockery.disable() - }) - - describe('APP_ACTIVATE_WELCOME_SCREEN', function () { - before(function () { - this.newState = aboutWelcomeReducer(Immutable.Map(), { - actionType: appConstants.APP_ACTIVATE_WELCOME_SCREEN, - activateWelcomeScreen: false - }) - }) - it('can set visibility state to false', function () { - assert.equal(this.newState.getIn(['about', 'welcome', 'showOnLoad']), false) - }) - }) -}) diff --git a/test/unit/app/browser/reducers/tabsReducerTest.js b/test/unit/app/browser/reducers/tabsReducerTest.js index d3ccb25726e..3daf8c7444b 100644 --- a/test/unit/app/browser/reducers/tabsReducerTest.js +++ b/test/unit/app/browser/reducers/tabsReducerTest.js @@ -100,7 +100,8 @@ describe('tabsReducer unit tests', function () { closeTab: sinon.mock(), setActive: sinon.spy(), moveTo: sinon.mock(), - reload: sinon.mock() + reload: sinon.mock(), + create: sinon.mock() } this.windowsAPI = require('../../../../../app/browser/windows') @@ -608,6 +609,80 @@ describe('tabsReducer unit tests', function () { }) }) + describe('APP_WINDOW_READY', function () { + before(function () { + this.clock = sinon.useFakeTimers() + this.action = Immutable.fromJS({ + actionType: appConstants.APP_WINDOW_READY, + senderWindowId: 1337, + createProperties: { + windowId: null + } + }) + this.create = sinon.spy() + this.tabsAPI.create = this.create + tabsReducer = require('../../../../../app/browser/reducers/tabsReducer') + }) + + beforeEach(function () { + this.tabsAPI.create.reset() + }) + + after(function () { + this.clock.restore() + }) + + describe('when showOnLoad is true', function () { + before(function () { + this.newState = this.state.set('about', Immutable.fromJS({ + welcome: { + showOnLoad: true + } + })) + }) + + it('calls tabs.create', function () { + tabsReducer(this.newState, this.action) + this.clock.tick(1510) + assert(this.tabsAPI.create.calledOnce) + }) + + it('sets tabs.create url argument to welcome screen', function () { + tabsReducer(this.newState, this.action) + this.clock.tick(1510) + assert.equal( + this.tabsAPI.create.args[0][0].url, + 'about:welcome' + ) + }) + + it('sets senderWindowId as the windowId when none is found', function () { + tabsReducer(this.newState, this.action) + this.clock.tick(1510) + assert.equal( + this.tabsAPI.create.args[0][0].windowId, + this.action.get('senderWindowId') + ) + }) + }) + + describe('when showOnLoad is false', function () { + before(function () { + this.newState = this.state.set('about', Immutable.fromJS({ + welcome: { + showOnLoad: false + } + })) + }) + + it('does not call tabs.create', function () { + tabsReducer(this.newState, this.action) + this.clock.tick(1510) + assert.equal(this.tabsAPI.create.notCalled, true) + }) + }) + }) + describe('APP_DRAG_ENDED', function () { const action = { actionType: appConstants.APP_DRAG_ENDED diff --git a/test/unit/app/browser/tabsTest.js b/test/unit/app/browser/tabsTest.js index 70a7a4a558d..03d2eaa7aed 100644 --- a/test/unit/app/browser/tabsTest.js +++ b/test/unit/app/browser/tabsTest.js @@ -59,14 +59,6 @@ describe('tabs API unit tests', function () { }] }) - this.appState = { - about: { - welcome: { - showOnLoad: true - } - } - } - this.appStore = { getState: () => Immutable.fromJS(this.appState) } @@ -75,9 +67,6 @@ describe('tabs API unit tests', function () { mockery.registerMock('ad-block', fakeAdBlock) mockery.registerMock('leveldown', {}) mockery.registerMock('../../js/stores/appStore', this.appStore) - mockery.registerMock('../../js/l10n', { - translation: (word) => word - }) mockery.registerMock('../filtering', { isResourceEnabled: (resourceName, url, isPrivate) => false }) @@ -343,43 +332,22 @@ describe('tabs API unit tests', function () { before(function () { this.clock = sinon.useFakeTimers() this.createTabRequestedSpy = sinon.spy(appActions, 'createTabRequested') - this.activateWelcomeScreenSpy = sinon.spy(appActions, 'activateWelcomeScreen') this.extensionsCreateTabSpy = sinon.spy(fakeElectron.extensions, 'createTab') }) after(function () { this.clock.restore() this.createTabRequestedSpy.restore() - this.activateWelcomeScreenSpy.restore() this.extensionsCreateTabSpy.restore() }) const createProperties = Immutable.fromJS({}) const cb = null const isRestore = false - const skipIfTest = false - - describe('when createProperties.url is not set', function () { - it('calls appActions.createTabRequested', function () { - this.createTabRequestedSpy.reset() - tabs.create(createProperties, cb, isRestore, skipIfTest) - this.clock.tick(1510) - assert.equal(this.createTabRequestedSpy.calledOnce, true) - }) - - describe('when welcome screen has not shown yet', function () { - it('calls appActions.activateWelcomeScreen if state is true', function () { - this.activateWelcomeScreenSpy.reset() - tabs.create(createProperties, cb, isRestore, skipIfTest) - this.clock.tick(1510) - assert.equal(this.activateWelcomeScreenSpy.calledOnce, true) - }) - }) - }) it('calls electron.extensions.createTab', function () { this.extensionsCreateTabSpy.reset() - tabs.create(createProperties, cb, isRestore, skipIfTest) + tabs.create(createProperties, cb, isRestore) this.clock.tick(1510) assert.equal(this.extensionsCreateTabSpy.calledOnce, true) }) diff --git a/test/unit/app/renderer/components/navigation/publisherToggleTest.js b/test/unit/app/renderer/components/navigation/publisherToggleTest.js index fe461a397d2..ec41ad9df74 100644 --- a/test/unit/app/renderer/components/navigation/publisherToggleTest.js +++ b/test/unit/app/renderer/components/navigation/publisherToggleTest.js @@ -9,7 +9,7 @@ const {getHostPattern} = require('../../../../../../js/lib/urlutil') let PublisherToggle require('../../../../braveUnit') -describe('PublisherToggle component', function () { +describe.skip('PublisherToggle component', function () { const getUrlOrigin = url => url.split('/').slice(0, 3).join('/') const getHostName = url => getUrlOrigin(url).split('/').slice(2).join('/') const getPattern = pattern => getHostPattern(getHostName(pattern)) diff --git a/test/unit/app/renderer/components/navigation/urlBarIconTest.js b/test/unit/app/renderer/components/navigation/urlBarIconTest.js index cc751f1914f..a89f424a8a6 100644 --- a/test/unit/app/renderer/components/navigation/urlBarIconTest.js +++ b/test/unit/app/renderer/components/navigation/urlBarIconTest.js @@ -11,7 +11,7 @@ const assert = require('assert') let UrlBarIcon, windowActions require('../../../../braveUnit') -describe('UrlBarIcon component unit tests', function () { +describe.skip('UrlBarIcon component unit tests', function () { before(function () { mockery.enable({ warnOnReplace: false, diff --git a/test/unit/app/sessionStoreTest.js b/test/unit/app/sessionStoreTest.js index e99c3ccd431..76b9c6ff62b 100644 --- a/test/unit/app/sessionStoreTest.js +++ b/test/unit/app/sessionStoreTest.js @@ -854,9 +854,19 @@ describe('sessionStore unit tests', function () { }) describe('defaultAppState', function () { - it('sets showOnLoad to true (which triggers about:welcome)', function () { - const defaultAppState = sessionStore.defaultAppState() - assert.equal(defaultAppState.about.welcome.showOnLoad, true) + describe('when NODE_ENV is not `test`', function () { + let prevNodeEnv + before(function () { + prevNodeEnv = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + }) + after(function () { + process.env.NODE_ENV = prevNodeEnv + }) + it('sets showOnLoad to true (which triggers about:welcome)', function () { + const defaultAppState = sessionStore.defaultAppState() + assert.equal(defaultAppState.about.welcome.showOnLoad, true) + }) }) })