From 3e85d580f9c19e4d49dd5725bab37c956f7a7b03 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 26 Nov 2018 12:54:08 -0330 Subject: [PATCH 1/4] Revert "Don't open MetaMask website after install" --- app/scripts/background.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/scripts/background.js b/app/scripts/background.js index c75f514d5209..5e0bc433d4a2 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -41,6 +41,7 @@ const { const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_TEST_CONFIG) const STORAGE_KEY = 'metamask-config' +const METAMASK_DEBUG = process.env.METAMASK_DEBUG log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn') @@ -472,3 +473,11 @@ function openPopup () { } ) } + +// On first install, open a window to MetaMask website to how-it-works. +extension.runtime.onInstalled.addListener(function (details) { + if ((details.reason === 'install') && (!METAMASK_DEBUG)) { + extension.tabs.create({url: 'https://metamask.io/#how-it-works'}) + } +}) + From a9d3c1a87d474e283c90ed6e17f6f3d9a4181111 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 26 Nov 2018 13:00:04 -0330 Subject: [PATCH 2/4] Open full-screen UI on install --- app/scripts/background.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 5e0bc433d4a2..110852779547 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -474,10 +474,9 @@ function openPopup () { ) } -// On first install, open a window to MetaMask website to how-it-works. -extension.runtime.onInstalled.addListener(function (details) { - if ((details.reason === 'install') && (!METAMASK_DEBUG)) { - extension.tabs.create({url: 'https://metamask.io/#how-it-works'}) +// On first install, open a new tab with MetaMask +extension.runtime.onInstalled.addListener(({reason}) => { + if ((reason === 'install') && (!METAMASK_DEBUG)) { + platform.openExtensionInBrowser() } }) - From ec4c93c59fccb83453d538e2d4a71dfc400ba4aa Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 26 Nov 2018 17:13:01 -0330 Subject: [PATCH 3/4] Add JSDoc to closeAllWindowHandlesExcept e2e helper fn --- test/e2e/beta/helpers.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/e2e/beta/helpers.js b/test/e2e/beta/helpers.js index 5e3f45b2b6a5..b6fc35e08572 100644 --- a/test/e2e/beta/helpers.js +++ b/test/e2e/beta/helpers.js @@ -120,6 +120,13 @@ async function switchToWindowWithTitle (driver, title, windowHandles) { } } +/** + * Closes all windows except those in the given list of exceptions + * @param {object} driver the WebDriver instance + * @param {string|Array} exceptions the list of window handle exceptions + * @param {Array?} windowHandles the full list of window handles + * @returns {Promise} + */ async function closeAllWindowHandlesExcept (driver, exceptions, windowHandles) { exceptions = typeof exceptions === 'string' ? [ exceptions ] : exceptions windowHandles = windowHandles || await driver.getAllWindowHandles() From 34da38817a14080982f514cee614abcd3758b0f7 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 26 Nov 2018 17:15:59 -0330 Subject: [PATCH 4/4] Update e2e tests to handle any post-install window creation --- test/e2e/beta/from-import-beta-ui.spec.js | 14 +++++++++++--- .../beta/metamask-beta-responsive-ui.spec.js | 17 ++++++++++++++--- test/e2e/beta/metamask-beta-ui.spec.js | 16 +++++++++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/test/e2e/beta/from-import-beta-ui.spec.js b/test/e2e/beta/from-import-beta-ui.spec.js index 2b2e3361d503..a180689e5c61 100644 --- a/test/e2e/beta/from-import-beta-ui.spec.js +++ b/test/e2e/beta/from-import-beta-ui.spec.js @@ -12,6 +12,7 @@ const { } = require('../func') const { checkBrowserForConsoleErrors, + closeAllWindowHandlesExcept, verboseReportOnFailure, findElement, findElements, @@ -32,13 +33,14 @@ describe('Using MetaMask with an existing account', function () { this.bail(true) before(async function () { + let extensionUrl switch (process.env.SELENIUM_BROWSER) { case 'chrome': { const extensionPath = path.resolve('dist/chrome') driver = buildChromeWebDriver(extensionPath) extensionId = await getExtensionIdChrome(driver) - await driver.get(`chrome-extension://${extensionId}/home.html`) await delay(regularDelayMs) + extensionUrl = `chrome-extension://${extensionId}/home.html` break } case 'firefox': { @@ -47,11 +49,17 @@ describe('Using MetaMask with an existing account', function () { await installWebExt(driver, extensionPath) await delay(regularDelayMs) extensionId = await getExtensionIdFirefox(driver) - await driver.get(`moz-extension://${extensionId}/home.html`) - await delay(regularDelayMs) + extensionUrl = `moz-extension://${extensionId}/home.html` break } } + // Depending on the state of the application built into the above directory (extPath) and the value of + // METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we + // are closing any extraneous windows to reset us to a single window before continuing. + const [tab1] = await driver.getAllWindowHandles() + await closeAllWindowHandlesExcept(driver, [tab1]) + await driver.switchTo().window(tab1) + await driver.get(extensionUrl) }) afterEach(async function () { diff --git a/test/e2e/beta/metamask-beta-responsive-ui.spec.js b/test/e2e/beta/metamask-beta-responsive-ui.spec.js index 107f9aa6c052..8b34f90279ea 100644 --- a/test/e2e/beta/metamask-beta-responsive-ui.spec.js +++ b/test/e2e/beta/metamask-beta-responsive-ui.spec.js @@ -12,6 +12,7 @@ const { } = require('../func') const { checkBrowserForConsoleErrors, + closeAllWindowHandlesExcept, findElement, findElements, loadExtension, @@ -31,23 +32,33 @@ describe('MetaMask', function () { this.bail(true) before(async function () { + let extensionUrl switch (process.env.SELENIUM_BROWSER) { case 'chrome': { const extPath = path.resolve('dist/chrome') driver = buildChromeWebDriver(extPath, { responsive: true }) extensionId = await getExtensionIdChrome(driver) - await driver.get(`chrome-extension://${extensionId}/home.html`) + await delay(largeDelayMs) + extensionUrl = `chrome-extension://${extensionId}/home.html` break } case 'firefox': { const extPath = path.resolve('dist/firefox') driver = buildFirefoxWebdriver({ responsive: true }) await installWebExt(driver, extPath) - await delay(700) + await delay(largeDelayMs) extensionId = await getExtensionIdFirefox(driver) - await driver.get(`moz-extension://${extensionId}/home.html`) + extensionUrl = `moz-extension://${extensionId}/home.html` + break } } + // Depending on the state of the application built into the above directory (extPath) and the value of + // METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we + // are closing any extraneous windows to reset us to a single window before continuing. + const [tab1] = await driver.getAllWindowHandles() + await closeAllWindowHandlesExcept(driver, [tab1]) + await driver.switchTo().window(tab1) + await driver.get(extensionUrl) }) afterEach(async function () { diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index 9e96ceee625a..e91af5303b30 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -37,23 +37,33 @@ describe('MetaMask', function () { this.bail(true) before(async function () { + let extensionUrl switch (process.env.SELENIUM_BROWSER) { case 'chrome': { const extPath = path.resolve('dist/chrome') driver = buildChromeWebDriver(extPath) extensionId = await getExtensionIdChrome(driver) - await driver.get(`chrome-extension://${extensionId}/home.html`) + await delay(largeDelayMs) + extensionUrl = `chrome-extension://${extensionId}/home.html` break } case 'firefox': { const extPath = path.resolve('dist/firefox') driver = buildFirefoxWebdriver() await installWebExt(driver, extPath) - await delay(700) + await delay(largeDelayMs) extensionId = await getExtensionIdFirefox(driver) - await driver.get(`moz-extension://${extensionId}/home.html`) + extensionUrl = `moz-extension://${extensionId}/home.html` + break } } + // Depending on the state of the application built into the above directory (extPath) and the value of + // METAMASK_DEBUG we will see different post-install behaviour and possibly some extra windows. Here we + // are closing any extraneous windows to reset us to a single window before continuing. + const [tab1] = await driver.getAllWindowHandles() + await closeAllWindowHandlesExcept(driver, [tab1]) + await driver.switchTo().window(tab1) + await driver.get(extensionUrl) }) afterEach(async function () {