From 14e31cb9bec57fca470686e08437798a773ab6ff Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 7 Aug 2019 08:52:05 -0300 Subject: [PATCH 1/5] Allow overriding GANACHE_ARGS for e2e tests (#6970) This allows the environment variable `GANACHE_ARGS` to override the default set of optional flags used. By default, the flag `--quiet` is set. Setting `GANACHE_ARGS` will override the default. For example, you can now run the e2e tests without the `--quiet` flag by running this: ```bash GANACHE_ARGS='' yarn test:e2e:chrome ``` This change also prevents the arguments from being needlessly repeated. Previously this script accidentally build up `GANACHE_ARGS`, adding to the set of flags used with each change in arguments. This PR is based upon #6870 --- test/e2e/run-all.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/e2e/run-all.sh b/test/e2e/run-all.sh index 0e3fdfcc4..cb161f0b8 100755 --- a/test/e2e/run-all.sh +++ b/test/e2e/run-all.sh @@ -5,8 +5,13 @@ set -e set -u set -o pipefail +# Set the environment variable 'GANACHE_ARGS' to change any optional ganache flags +# By default, the flag `--quiet` is used. Setting 'GANACHE_ARGS' will override the default. +OPTIONAL_GANACHE_ARGS="${GANACHE_ARGS---quiet}" +BASE_GANACHE_ARGS="${OPTIONAL_GANACHE_ARGS} --blockTime 2" + export PATH="$PATH:./node_modules/.bin" -export GANACHE_ARGS='--blockTime 2 --quiet' +export GANACHE_ARGS="${BASE_GANACHE_ARGS}" concurrently --kill-others \ --names 'ganache,dapp,e2e' \ @@ -24,7 +29,7 @@ concurrently --kill-others \ 'yarn dapp' \ 'sleep 5 && mocha test/e2e/metamask-responsive-ui.spec' -export GANACHE_ARGS="$GANACHE_ARGS --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" +export GANACHE_ARGS="${BASE_GANACHE_ARGS} --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" concurrently --kill-others \ --names 'ganache,e2e' \ --prefix '[{time}][{name}]' \ @@ -32,7 +37,7 @@ concurrently --kill-others \ 'yarn ganache:start' \ 'sleep 5 && mocha test/e2e/from-import-ui.spec' -export GANACHE_ARGS="$GANACHE_ARGS --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" +export GANACHE_ARGS="${BASE_GANACHE_ARGS} --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" concurrently --kill-others \ --names 'ganache,e2e' \ --prefix '[{time}][{name}]' \ @@ -41,7 +46,7 @@ concurrently --kill-others \ 'sleep 5 && mocha test/e2e/send-edit.spec' -export GANACHE_ARGS="$GANACHE_ARGS --deterministic --account=0x250F458997A364988956409A164BA4E16F0F99F916ACDD73ADCD3A1DE30CF8D1,0 --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" +export GANACHE_ARGS="${BASE_GANACHE_ARGS} --deterministic --account=0x250F458997A364988956409A164BA4E16F0F99F916ACDD73ADCD3A1DE30CF8D1,0 --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" concurrently --kill-others \ --names 'ganache,sendwithprivatedapp,e2e' \ --prefix '[{time}][{name}]' \ @@ -50,7 +55,7 @@ concurrently --kill-others \ 'npm run sendwithprivatedapp' \ 'sleep 5 && mocha test/e2e/incremental-security.spec' -export GANACHE_ARGS="$GANACHE_ARGS --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" +export GANACHE_ARGS="${BASE_GANACHE_ARGS} --deterministic --account=0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9,25000000000000000000" concurrently --kill-others \ --names 'ganache,dapp,e2e' \ --prefix '[{time}][{name}]' \ From da7fe65599d4a1d0f779c826b862a9482f20fd40 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 8 Aug 2019 09:08:41 -0230 Subject: [PATCH 2/5] Ensure seed phrase backup only shows up for new users (#6975) --- app/scripts/controllers/onboarding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/controllers/onboarding.js b/app/scripts/controllers/onboarding.js index 18fec4993..a29c8407a 100644 --- a/app/scripts/controllers/onboarding.js +++ b/app/scripts/controllers/onboarding.js @@ -23,7 +23,7 @@ class OnboardingController { */ constructor (opts = {}) { const initState = extend({ - seedPhraseBackedUp: null, + seedPhraseBackedUp: true, }, opts.initState) this.store = new ObservableStore(initState) } From aceb6f0d3ef77b8fa84fda5d42bb2223d3043b96 Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Thu, 8 Aug 2019 11:40:52 +0000 Subject: [PATCH 3/5] Version v7.0.1 --- CHANGELOG.md | 2 ++ app/manifest.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b96fab508..b4ab66cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Develop Branch +## 7.0.1 Thu Aug 08 2019 + ## 7.0.0 Fri Aug 02 2019 - [#6828](https://github.com/MetaMask/metamask-extension/pull/6828): Capitalized speed up label to match rest of UI - [#6874](https://github.com/MetaMask/metamask-extension/pull/6928): Allows skipping of seed phrase challenge during onboarding, and completing it at a later time diff --git a/app/manifest.json b/app/manifest.json index 1ca2215eb..f8c150281 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "__MSG_appName__", - "version": "7.0.0", + "version": "7.0.1", "manifest_version": 2, "author": "https://metamask.io", "description": "__MSG_appDescription__", From 9ac2720981c489a18359932b124fd869a2d2adb0 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 8 Aug 2019 09:24:38 -0230 Subject: [PATCH 4/5] Changelog update for v7.0.1 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ab66cea..93dc1b0b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current Develop Branch ## 7.0.1 Thu Aug 08 2019 +- [#6975](https://github.com/MetaMask/metamask-extension/pull/6975): Ensure seed phrase backup notification only shows up for new users ## 7.0.0 Fri Aug 02 2019 - [#6828](https://github.com/MetaMask/metamask-extension/pull/6828): Capitalized speed up label to match rest of UI From 12e055a37c54c6fe12c1c02676041b8d29c753bd Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 8 Aug 2019 11:50:32 -0300 Subject: [PATCH 5/5] Close window after opening fullscreen (#6966) * Add background environment type The `getEnvironmentType` method now checks for the background environment as well, instead of returning 'notification' for that case. Instead of adding another regex for the background path, the regexes for each environment have been replaced with the URL constructor[0]. This is the standard method of parsing URLs, and is available in all supported browsers. [0]: https://developer.mozilla.org/en-US/docs/Web/API/URL * Add note regarding a missing manifest permission The `url` parameter to `tabs.query(...)` requires the `tabs` permission, and will be ignored otherwise. We are missing this permission, so that call does not work. * Close window after opening full screen The browser behaviour when opening a new tab differs between Chrome and Firefox. In the case of a popup, Chrome will close the popup whereas Firefox will leave it open. In the case of the notification window, Chrome will move the new tab to the foreground, whereas Firefox will leave the notification window in the foreground when opening a new tab. We always want to close the current UI (popup or notification) when switching to a full-screen view. The only exception to this is when the switch is triggered from the background, which has no UI. Closes #6513, #6685 --- app/scripts/lib/enums.js | 2 ++ app/scripts/lib/util.js | 11 +++++-- app/scripts/platforms/extension.js | 6 ++++ app/vendor/trezor/usb-permissions.js | 3 +- test/unit/app/util-test.js | 44 +++++++++++++++++++++++++++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/enums.js b/app/scripts/lib/enums.js index c6d57a1bc..32c0947a3 100644 --- a/app/scripts/lib/enums.js +++ b/app/scripts/lib/enums.js @@ -1,6 +1,7 @@ const ENVIRONMENT_TYPE_POPUP = 'popup' const ENVIRONMENT_TYPE_NOTIFICATION = 'notification' const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen' +const ENVIRONMENT_TYPE_BACKGROUND = 'background' const PLATFORM_BRAVE = 'Brave' const PLATFORM_CHROME = 'Chrome' @@ -12,6 +13,7 @@ module.exports = { ENVIRONMENT_TYPE_POPUP, ENVIRONMENT_TYPE_NOTIFICATION, ENVIRONMENT_TYPE_FULLSCREEN, + ENVIRONMENT_TYPE_BACKGROUND, PLATFORM_BRAVE, PLATFORM_CHROME, PLATFORM_EDGE, diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index ea13b26be..2eb71c0a0 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -5,6 +5,7 @@ const { ENVIRONMENT_TYPE_POPUP, ENVIRONMENT_TYPE_NOTIFICATION, ENVIRONMENT_TYPE_FULLSCREEN, + ENVIRONMENT_TYPE_BACKGROUND, PLATFORM_FIREFOX, PLATFORM_OPERA, PLATFORM_CHROME, @@ -28,17 +29,21 @@ function getStack () { * - 'popup' refers to the extension opened through the browser app icon (in top right corner in chrome and firefox) * - 'responsive' refers to the main browser window * - 'notification' refers to the popup that appears in its own window when taking action outside of metamask + * - 'background' refers to the background page * * @returns {string} A single word label that represents the type of window through which the app is being viewed * */ const getEnvironmentType = (url = window.location.href) => { - if (url.match(/popup.html(?:#.*)*$/)) { + const parsedUrl = new URL(url) + if (parsedUrl.pathname === '/popup.html') { return ENVIRONMENT_TYPE_POPUP - } else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) { + } else if (parsedUrl.pathname === '/home.html') { return ENVIRONMENT_TYPE_FULLSCREEN - } else { + } else if (parsedUrl.pathname === '/notification.html') { return ENVIRONMENT_TYPE_NOTIFICATION + } else { + return ENVIRONMENT_TYPE_BACKGROUND } } diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index 43820515d..d54a8a7b3 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -1,6 +1,9 @@ const extension = require('extensionizer') const {createExplorerLink: explorerLink} = require('etherscan-link') +const {getEnvironmentType} = require('../lib/util') +const {ENVIRONMENT_TYPE_BACKGROUND} = require('../lib/enums') + class ExtensionPlatform { // @@ -35,6 +38,9 @@ class ExtensionPlatform { extensionURL += `#${route}` } this.openWindow({ url: extensionURL }) + if (getEnvironmentType() !== ENVIRONMENT_TYPE_BACKGROUND) { + window.close() + } } getPlatformInfo (cb) { diff --git a/app/vendor/trezor/usb-permissions.js b/app/vendor/trezor/usb-permissions.js index 9de47e0a1..18f70f94f 100644 --- a/app/vendor/trezor/usb-permissions.js +++ b/app/vendor/trezor/usb-permissions.js @@ -25,6 +25,7 @@ const switchToPopupTab = (event) => { return; } + // TODO: remove this query, or add `tabs` permission. This does not work. // triggered from 'beforeunload' event // find tab by popup pattern and switch to it chrome.tabs.query({ @@ -47,4 +48,4 @@ window.addEventListener('message', event => { } }); -window.addEventListener('beforeunload', switchToPopupTab); \ No newline at end of file +window.addEventListener('beforeunload', switchToPopupTab); diff --git a/test/unit/app/util-test.js b/test/unit/app/util-test.js index 656b22d92..259bd708b 100644 --- a/test/unit/app/util-test.js +++ b/test/unit/app/util-test.js @@ -1,6 +1,48 @@ const assert = require('assert') -const { sufficientBalance } = require('../../../app/scripts/lib/util') +const { getEnvironmentType, sufficientBalance } = require('../../../app/scripts/lib/util') +const { + ENVIRONMENT_TYPE_POPUP, + ENVIRONMENT_TYPE_NOTIFICATION, + ENVIRONMENT_TYPE_FULLSCREEN, + ENVIRONMENT_TYPE_BACKGROUND, +} = require('../../../app/scripts/lib/enums') +describe('getEnvironmentType', function () { + it('should return popup type', function () { + const environmentType = getEnvironmentType('http://extension-id/popup.html') + assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP) + }) + + it('should return notification type', function () { + const environmentType = getEnvironmentType('http://extension-id/notification.html') + assert.equal(environmentType, ENVIRONMENT_TYPE_NOTIFICATION) + }) + + it('should return fullscreen type', function () { + const environmentType = getEnvironmentType('http://extension-id/home.html') + assert.equal(environmentType, ENVIRONMENT_TYPE_FULLSCREEN) + }) + + it('should return background type', function () { + const environmentType = getEnvironmentType('http://extension-id/_generated_background_page.html') + assert.equal(environmentType, ENVIRONMENT_TYPE_BACKGROUND) + }) + + it('should return the correct type for a URL with a hash fragment', function () { + const environmentType = getEnvironmentType('http://extension-id/popup.html#hash') + assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP) + }) + + it('should return the correct type for a URL with query parameters', function () { + const environmentType = getEnvironmentType('http://extension-id/popup.html?param=foo') + assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP) + }) + + it('should return the correct type for a URL with query parameters and a hash fragment', function () { + const environmentType = getEnvironmentType('http://extension-id/popup.html?param=foo#hash') + assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP) + }) +}) describe('SufficientBalance', function () { it('returns true if max tx cost is equal to balance.', function () {