Skip to content

Commit

Permalink
Merge branch 'develop' into feat/new-metamask-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
matteoscurati authored May 23, 2024
2 parents 636d009 + 9db82cf commit 09d19d0
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 64 deletions.
16 changes: 15 additions & 1 deletion test/e2e/accounts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
validateContractDetails,
multipleGanacheOptions,
regularDelayMs,
openDapp,
} from '../helpers';
import { Driver } from '../webdriver/driver';
import { TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL } from '../constants';
Expand Down Expand Up @@ -182,7 +183,20 @@ async function switchToAccount2(driver: Driver) {
}

export async function connectAccountToTestDapp(driver: Driver) {
await switchToOrOpenDapp(driver);
try {
// Do an unusually fast switchToWindowWithTitle, just 1 second
await driver.switchToWindowWithTitle(
WINDOW_TITLES.TestDApp,
null,
1000,
1000,
);
} catch {
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await openDapp(driver);
}
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ const DAPP_URL = 'http://127.0.0.1:8080';
const DAPP_ONE_URL = 'http://127.0.0.1:8081';

const openDapp = async (driver, contract = null, dappURL = DAPP_URL) => {
contract
return contract
? await driver.openNewPage(`${dappURL}/?contract=${contract}`)
: await driver.openNewPage(dappURL);
};
Expand Down
35 changes: 10 additions & 25 deletions test/e2e/json-rpc/switchEthereumChain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ describe('Switch Ethereum Chain for two dapps', function () {
await driver.clickElement('.request-queue-toggle');

// open two dapps
await openDapp(driver, undefined, DAPP_URL);
await openDapp(driver, undefined, DAPP_ONE_URL);

// Window Handling
const windowHandles = await driver.getAllWindowHandles();
const dappOne = windowHandles[1];
const dappTwo = windowHandles[2];
const dappOne = await openDapp(driver, undefined, DAPP_URL);
const dappTwo = await openDapp(driver, undefined, DAPP_ONE_URL);

// switchEthereumChain request
const switchEthereumChainRequest = JSON.stringify({
Expand Down Expand Up @@ -145,13 +140,9 @@ describe('Switch Ethereum Chain for two dapps', function () {
await driver.clickElement('.request-queue-toggle');

// open two dapps
await openDapp(driver, undefined, DAPP_URL);
const dappOne = await openDapp(driver, undefined, DAPP_URL);
await openDapp(driver, undefined, DAPP_ONE_URL);

// Window Handling
const windowHandles = await driver.getAllWindowHandles();
const dappOne = windowHandles[1];

// Initiate send transaction on Dapp two
await driver.clickElement('#sendButton');
await driver.delay(2000);
Expand Down Expand Up @@ -239,13 +230,9 @@ describe('Switch Ethereum Chain for two dapps', function () {
await driver.clickElement('.request-queue-toggle');

// open two dapps
await openDapp(driver, undefined, DAPP_URL);
const dappOne = await openDapp(driver, undefined, DAPP_URL);
await openDapp(driver, undefined, DAPP_ONE_URL);

// Window Handling
let windowHandles = await driver.getAllWindowHandles();
const dappOne = windowHandles[1];

// switchEthereumChain request
const switchEthereumChainRequest = JSON.stringify({
jsonrpc: '2.0',
Expand Down Expand Up @@ -284,10 +271,12 @@ describe('Switch Ethereum Chain for two dapps', function () {
// Confirm switchEthereumChain with queued pending tx
await driver.clickElement({ text: 'Switch network', tag: 'button' });

// Window handles should only be expanded mm, dapp one, dapp 2 (3 total)
// Window handles should only be expanded mm, dapp one, dapp 2, and the offscreen document
// if this is an MV3 build(3 or 4 total)
await driver.wait(async () => {
windowHandles = await driver.getAllWindowHandles();
return windowHandles.length === 3;
const windowHandles = await driver.getAllWindowHandles();
const numberOfWindowHandlesToExpect = process.env.ENABLE_MV3 ? 4 : 3;
return windowHandles.length === numberOfWindowHandlesToExpect;
});
},
);
Expand Down Expand Up @@ -334,13 +323,9 @@ describe('Switch Ethereum Chain for two dapps', function () {
await driver.clickElement('.request-queue-toggle');

// open two dapps
await openDapp(driver, undefined, DAPP_URL);
const dappOne = await openDapp(driver, undefined, DAPP_URL);
await openDapp(driver, undefined, DAPP_ONE_URL);

// Window Handling
const windowHandles = await driver.getAllWindowHandles();
const dappOne = windowHandles[1];

// switchEthereumChain request
const switchEthereumChainRequest = JSON.stringify({
jsonrpc: '2.0',
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/tests/request-queuing/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,22 @@ async function openDappAndSwitchChain(driver, dappUrl, chainId) {

async function selectDappClickSendGetNetwork(driver, dappUrl) {
await driver.switchToWindowWithUrl(dappUrl);
const currentWindowHandles = await driver.getAllWindowHandles();
await driver.clickElement('#sendButton');
await switchToNotificationWindow(driver, 4);

// Under mv3, we don't need to add to the current number of window handles
// because the offscreen document returned by getAllWindowHandles provides
// an extra window handle
const newWindowHandles = await driver.waitUntilXWindowHandles(
process.env.ENABLE_MV3
? currentWindowHandles.length
: currentWindowHandles.length + 1,
);
const [newNotificationWindowHandle] = newWindowHandles.filter(
(h) => !currentWindowHandles.includes(h),
);
await driver.switchToWindow(newNotificationWindowHandle);

const networkPill = await driver.findElement(
'[data-testid="network-display"]',
);
Expand Down
25 changes: 11 additions & 14 deletions test/e2e/tests/settings/full-size-view-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,25 @@ describe('Full-size View Setting @no-mmi', function () {
await unlockWallet(driver);
await toggleFullSizeViewSetting(driver);
await openDapp(driver);
const windowHandlesPreClick = await driver.waitUntilXWindowHandles(
2,
1000,
10000,
);
await driver.clickElement('#maliciousPermit'); // Opens the extension in popup view.
const windowHandles = await driver.waitUntilXWindowHandles(
const windowHandlesPostClick = await driver.waitUntilXWindowHandles(
3,
1000,
10000,
);
const fullScreenWindowTitle = await driver.getWindowTitleByHandlerId(
windowHandles[0],
const [newWindowHandle] = windowHandlesPostClick.filter(
(handleId) => !windowHandlesPreClick.includes(handleId),
);
const dappWindowTitle = await driver.getWindowTitleByHandlerId(
windowHandles[1],
);
const popUpWindowTitle = await driver.getWindowTitleByHandlerId(
windowHandles[2],
const newWindowTitle = await driver.getWindowTitleByHandlerId(
newWindowHandle,
);

assert.equal(
fullScreenWindowTitle,
WINDOW_TITLES.ExtensionInFullScreenView,
);
assert.equal(dappWindowTitle, WINDOW_TITLES.TestDApp);
assert.equal(popUpWindowTitle, WINDOW_TITLES.Dialog);
assert.equal(newWindowTitle, WINDOW_TITLES.Dialog);
},
);
});
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/tests/transaction/edit-gas-fee.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { strict: assert } = require('assert');
const {
getWindowHandles,
withFixtures,
openDapp,
unlockWallet,
generateGanacheOptions,
WINDOW_TITLES,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');

Expand Down Expand Up @@ -176,8 +176,7 @@ describe('Editing Confirm Transaction', function () {
});

// check transaction in extension popup
const windowHandles = await getWindowHandles(driver, 3);
await driver.switchToWindow(windowHandles.popup);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({
text: 'Site suggested',
});
Expand Down Expand Up @@ -207,7 +206,9 @@ describe('Editing Confirm Transaction', function () {
await driver.clickElement({ text: 'Confirm', tag: 'button' });

// transaction should correct values in activity tab
await driver.switchToWindow(windowHandles.extension);
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
Expand Down
27 changes: 13 additions & 14 deletions test/e2e/tests/transaction/multiple-transactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
regularDelayMs,
unlockWallet,
generateGanacheOptions,
WINDOW_TITLES,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');

Expand All @@ -30,27 +31,23 @@ describe('Multiple transactions', function () {
tag: 'button',
});
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
const extensionTab = windowHandles[0];
const dApp = windowHandles[1];
const confirmation = windowHandles[2];

await driver.switchToWindow(dApp);
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

// creates second transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.switchToWindow(confirmation);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// confirms second transaction
await driver.waitForSelector({
text: 'Reject 2 transactions',
tag: 'a',
});
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.switchToWindow(confirmation);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// wait for the "Reject 2 transactions" to disappear
await driver.assertElementNotPresent(
Expand All @@ -61,7 +58,9 @@ describe('Multiple transactions', function () {
await driver.clickElement({ text: 'Confirm', tag: 'button' });

await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extensionTab);
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.waitForSelector(
Expand Down Expand Up @@ -98,17 +97,15 @@ describe('Multiple transactions', function () {
tag: 'button',
});
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
const confirmation = windowHandles[2];
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

// creates second transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.switchToWindow(confirmation);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// rejects second transaction
await driver.waitForSelector({
Expand All @@ -121,7 +118,9 @@ describe('Multiple transactions', function () {
await driver.clickElement({ text: 'Reject', tag: 'button' });

await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="home__activity-tab"]');

Expand Down
9 changes: 5 additions & 4 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ class Driver {
}

async openNewPage(url) {
const newHandle = await this.driver.switchTo().newWindow();
await this.driver.switchTo().newWindow();
await this.openNewURL(url);
const newHandle = await this.driver.getWindowHandle();
return newHandle;
}

Expand All @@ -570,12 +571,12 @@ class Driver {
return await this.driver.getAllWindowHandles();
}

async waitUntilXWindowHandles(x, delayStep = 1000, timeout = this.timeout) {
async waitUntilXWindowHandles(_x, delayStep = 1000, timeout = this.timeout) {
const x = process.env.ENABLE_MV3 ? _x + 1 : _x;
let timeElapsed = 0;
let windowHandles = [];
while (timeElapsed <= timeout) {
windowHandles = await this.driver.getAllWindowHandles();

windowHandles = await this.getAllWindowHandles();
if (windowHandles.length === x) {
return windowHandles;
}
Expand Down

0 comments on commit 09d19d0

Please sign in to comment.