Skip to content

Commit fe6c719

Browse files
wip
1 parent ed240b0 commit fe6c719

7 files changed

Lines changed: 50 additions & 32 deletions

File tree

app/scripts/metamask-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ export default class MetamaskController extends EventEmitter {
12051205
},
12061206
);
12071207

1208-
if (isManifestV3 && globalThis.isFirstTimeProfileLoaded === false) {
1208+
if (isManifestV3 && globalThis.isFirstTimeProfileLoaded === undefined) {
12091209
const { serviceWorkerLastActiveTime } =
12101210
this.appStateController.store.getState();
12111211
const metametricsPayload = {

development/build/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ async function defineAndRunBuildTasks() {
126126
'stateHooks',
127127
'sentryHooks',
128128
'sentry',
129+
'Date',
130+
'JSON',
129131
],
130132
});
131133

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
},
99
"scripts": {
1010
"start": "yarn build:dev dev --apply-lavamoat=false --snow=false",
11-
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
1211
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false",
1312
"start:flask": "yarn start --build-type flask",
13+
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
1414
"dist": "yarn build dist",
1515
"build": "yarn lavamoat:build",
1616
"build:dev": "node development/build/index.js",
1717
"start:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 PORTFOLIO_URL=http://127.0.0.1:8080 yarn build:dev testDev",
18+
"start:test:mv3": "ENABLE_MV3=true SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 PORTFOLIO_URL=http://127.0.0.1:8080 yarn build:dev testDev",
1819
"benchmark:chrome": "SELENIUM_BROWSER=chrome ts-node test/e2e/benchmark.js",
1920
"mv3:stats:chrome": "SELENIUM_BROWSER=chrome ENABLE_MV3=true ts-node test/e2e/mv3-perf-stats/index.js",
2021
"user-actions-benchmark:chrome": "SELENIUM_BROWSER=chrome ts-node test/e2e/user-actions-benchmark.js",

test/e2e/mv3/service-worker-restart.spec.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const FixtureBuilder = require('../fixture-builder');
44
const {
55
ACTION_QUEUE_METRICS_E2E_TEST,
66
} = require('../../../shared/constants/test-flags');
7-
const { EVENT_NAMES, EVENT } = require('../../../shared/constants/metametrics');
7+
const {
8+
MetaMetricsEventName,
9+
MetaMetricsEventCategory,
10+
} = require('../../../shared/constants/metametrics');
811

912
const PRIVATE_KEY =
1013
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC';
@@ -14,15 +17,15 @@ const defaultGanacheOptions = {
1417
accounts: [{ secretKey: PRIVATE_KEY, balance: generateETHBalance(25) }],
1518
};
1619

17-
const numberOfSegmentRequests = 1;
20+
const numberOfSegmentRequests = 2;
1821

1922
async function mockSegment(mockServer) {
2023
return await mockServer
2124
.forPost('https://api.segment.io/v1/batch')
2225
.withJsonBodyIncluding({
2326
batch: [
2427
{
25-
event: EVENT_NAMES.SERVICE_WORKER_RESTARTED,
28+
event: MetaMetricsEventName.ServiceWorkerRestarted,
2629
},
2730
],
2831
})
@@ -50,6 +53,7 @@ describe('MV3 - Service worker restart', function () {
5053
let windowHandles;
5154

5255
it('should continue to add new a account when service worker can not restart immediately', async function () {
56+
const driverOptions = { openDevToolsForTabs: true };
5357
await withFixtures(
5458
{
5559
dapp: true,
@@ -67,6 +71,7 @@ describe('MV3 - Service worker restart', function () {
6771
// because of segment
6872
failOnConsoleError: false,
6973
testSpecificMock: mockPostToSentryEnvelope,
74+
driverOptions,
7075
},
7176
async ({ driver, mockServer }) => {
7277
const mockedSegmentEndpoints = await mockSegment(mockServer);
@@ -126,22 +131,23 @@ describe('MV3 - Service worker restart', function () {
126131
assert.equal(mockedRequests[0].body.json.batch.length, 1);
127132
assert.equal(
128133
mockedRequests[0].body.json.batch[0].event,
129-
EVENT_NAMES.SERVICE_WORKER_RESTARTED,
134+
MetaMetricsEventName.ServiceWorkerRestarted,
130135
);
131136

132137
assert.equal(
133-
mockedRequests[0].body.json.batch[0].properties.service_worker_action_queue_methods.indexOf(
134-
'addNewAccount',
135-
) !== '-1',
136-
true,
138+
typeof mockedRequests[0].body.json.batch[0].properties
139+
.service_worker_restarted_time,
140+
'number',
137141
);
142+
138143
assert.equal(
139-
mockedRequests[0].body.json.batch[0].properties.category,
140-
EVENT.SOURCE.SERVICE_WORKERS,
144+
mockedRequests[0].body.json.batch[0].properties
145+
.service_worker_restarted_time > 0,
146+
true,
141147
);
142148
assert.equal(
143149
mockedRequests[0].body.json.batch[0].properties.category,
144-
EVENT.SOURCE.SERVICE_WORKERS,
150+
MetaMetricsEventCategory.ServiceWorkers,
145151
);
146152
assert.equal(
147153
mockedRequests[0].body.json.batch[0].properties.chain_id,
@@ -159,24 +165,33 @@ describe('MV3 - Service worker restart', function () {
159165
assert.equal(mockedRequests[1].url, 'https://api.segment.io/v1/batch');
160166

161167
assert.equal(mockedRequests[1].body.json.batch.length, 1);
168+
162169
assert.equal(
163-
mockedRequests[1].body.json.batch[1].event,
164-
EVENT_NAMES.SERVICE_WORKER_RESTARTED,
170+
mockedRequests[1].body.json.batch[0].event,
171+
MetaMetricsEventName.ServiceWorkerRestarted,
165172
);
166173

167-
const serviceWorkerRestartTimeRequestProperties =
168-
mockedRequests[1].body.json.batch[1].properties;
169174
assert.equal(
170-
serviceWorkerRestartTimeRequestProperties.category,
171-
EVENT.SOURCE.SERVICE_WORKERS,
175+
mockedRequests[1].body.json.batch[0].properties.service_worker_action_queue_methods.indexOf(
176+
'addNewAccount',
177+
) !== '-1',
178+
true,
179+
);
180+
assert.equal(
181+
mockedRequests[1].body.json.batch[0].properties.category,
182+
MetaMetricsEventCategory.ServiceWorkers,
183+
);
184+
assert.equal(
185+
mockedRequests[1].body.json.batch[0].properties.chain_id,
186+
convertToHexValue(1337),
172187
);
173-
assert(
174-
typeof serviceWorkerRestartTimeRequestProperties.service_worker_action_queue_methods ===
175-
'number',
188+
assert.equal(
189+
mockedRequests[1].body.json.batch[0].properties.environment_type,
190+
'background',
176191
);
177-
assert(
178-
serviceWorkerRestartTimeRequestProperties.service_worker_action_queue_methods >
179-
0,
192+
assert.equal(
193+
mockedRequests[1].body.json.batch[0].properties.locale,
194+
'en',
180195
);
181196
},
182197
);

test/e2e/tests/metamask-responsive-ui.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const FixtureBuilder = require('../fixture-builder');
44

55
describe('MetaMask Responsive UI', function () {
66
it('Creating a new wallet', async function () {
7-
const driverOptions = { responsive: true };
7+
const driverOptions = { openDevToolsForTabs: true };
88

99
await withFixtures(
1010
{
@@ -73,7 +73,7 @@ describe('MetaMask Responsive UI', function () {
7373
});
7474

7575
it('Importing existing wallet from lock page', async function () {
76-
const driverOptions = { responsive: true };
76+
const driverOptions = { openDevToolsForTabs: true };
7777
const testSeedPhrase =
7878
'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent';
7979

@@ -114,7 +114,7 @@ describe('MetaMask Responsive UI', function () {
114114
});
115115

116116
it('Send Transaction from responsive window', async function () {
117-
const driverOptions = { responsive: true };
117+
const driverOptions = { openDevToolsForTabs: true };
118118
const ganacheOptions = {
119119
accounts: [
120120
{

test/e2e/webdriver/chrome.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const HTTPS_PROXY_HOST = '127.0.0.1:8000';
1313
* A wrapper around a {@code WebDriver} instance exposing Chrome-specific functionality
1414
*/
1515
class ChromeDriver {
16-
static async build({ responsive, port }) {
16+
static async build({ openDevToolsForTabs, port }) {
1717
const args = [`load-extension=dist/chrome`];
18-
if (responsive) {
18+
if (openDevToolsForTabs) {
1919
args.push('--auto-open-devtools-for-tabs');
2020
}
2121

test/e2e/webdriver/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const Driver = require('./driver');
33
const ChromeDriver = require('./chrome');
44
const FirefoxDriver = require('./firefox');
55

6-
async function buildWebDriver({ responsive, port, timeOut } = {}) {
6+
async function buildWebDriver({ openDevToolsForTabs, port, timeOut } = {}) {
77
const browser = process.env.SELENIUM_BROWSER;
88

99
const {
1010
driver: seleniumDriver,
1111
extensionId,
1212
extensionUrl,
13-
} = await buildBrowserWebDriver(browser, { responsive, port });
13+
} = await buildBrowserWebDriver(browser, { openDevToolsForTabs, port });
1414
const driver = new Driver(seleniumDriver, browser, extensionUrl, timeOut);
1515

1616
return {

0 commit comments

Comments
 (0)