Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect popup tests 2 #17173

Merged
merged 2 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/connect-popup/e2e/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export const openPopup = (
} else {
triggerPopup.push(explorerPage.waitForEvent('popup'));
}
triggerPopup.push(explorerPage.click("div[data-testid='@api-playground/collapsible-box']"));
triggerPopup.push(explorerPage.click("button[data-testid='@submit-button']"));
triggerPopup.push(explorerPage.getByTestId('@api-playground/collapsible-box').click());
triggerPopup.push(explorerPage.getByTestId('@submit-button').click());
triggerPopup.push(explorerPage.waitForSelector("[data-testid='@submit-button/spinner']"));

return Promise.all(triggerPopup) as Promise<Page[]>;
Expand Down Expand Up @@ -149,7 +149,9 @@ export const setConnectSettings = async (
{ trustedHost = false, connectSrc }: { trustedHost?: boolean; connectSrc?: string },
_isWebExtension?: boolean,
) => {
await explorerPage.goto(formatUrl(explorerUrl, `settings/index.html`));
await explorerPage.goto(
formatUrl(explorerUrl, _isWebExtension ? `settings/index.html` : `settings`),
);
/*if (isWebExtension) {
// When webextension and using service-worker we need to wait for handshake is confirmed with proxy.
await explorerPage.waitForSelector("div[data-testid='@settings/handshake-confirmed']");
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-popup/e2e/tests/browser-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const openPopup = async (page: Page) =>
// It is important to call waitForEvent before click to set up waiting.
page.waitForEvent('popup'),
// Opens popup.
page.click("div[data-testid='@api-playground/collapsible-box']"),
page.getByTestId('@api-playground/collapsible-box').click(),
page.click("button[data-testid='@submit-button']"),
])
)[0];
Expand Down
32 changes: 26 additions & 6 deletions packages/connect-popup/e2e/tests/popup-close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,13 @@ test('when user cancels permissions in popup it closes automatically', async ({

await popupClosedPromise;

await explorerPage.goto(formatUrl(explorerUrl, `methods/bitcoin/getAddress/index.html`));
await explorerPage.click("[data-testid='@api-playground/collapsible-box']");
await explorerPage.goto(
formatUrl(
explorerUrl,
`methods/bitcoin/getAddress` + (isWebExtension ? `/index.html` : ''),
),
);
await explorerPage.getByTestId('@api-playground/collapsible-box').click();
await explorerPage.waitForSelector("button[data-testid='@submit-button']", {
state: 'visible',
});
Expand Down Expand Up @@ -261,7 +266,12 @@ test('device dialogue cancelled IN POPUP by user', async ({ page, context }) =>

await popupClosedPromise;

await explorerPage.goto(formatUrl(explorerUrl, `methods/bitcoin/getAddress/index.html`));
await explorerPage.goto(
formatUrl(
explorerUrl,
`methods/bitcoin/getAddress` + (isWebExtension ? `/index.html` : ''),
),
);
await explorerPage.click("[data-testid='@api-playground/collapsible-box']");
await explorerPage.waitForSelector("button[data-testid='@submit-button']", {
state: 'visible',
Expand Down Expand Up @@ -336,7 +346,12 @@ test('popup should be focused when a call is in progress and user triggers new c

await popupClosedPromise;

await explorerPage.goto(formatUrl(explorerUrl, `methods/bitcoin/getAddress/index.html`));
await explorerPage.goto(
formatUrl(
explorerUrl,
`methods/bitcoin/getAddress` + (isWebExtension ? `/index.html` : ''),
),
);
await explorerPage.click("[data-testid='@api-playground/collapsible-box']");
await explorerPage.waitForSelector("button[data-testid='@submit-button']", {
state: 'visible',
Expand Down Expand Up @@ -391,7 +406,12 @@ test('popup should close when third party is closed', async ({ page, context })

await popupClosedPromise;

await explorerPage.goto(formatUrl(explorerUrl, `methods/bitcoin/getAddress/index.html`));
await explorerPage.goto(
formatUrl(
explorerUrl,
`methods/bitcoin/getAddress` + (isWebExtension ? `/index.html` : ''),
),
);
await explorerPage.click("[data-testid='@api-playground/collapsible-box']");
await explorerPage.waitForSelector("button[data-testid='@submit-button']", {
state: 'visible',
Expand Down Expand Up @@ -433,7 +453,7 @@ test.skip('popup should behave properly with subsequent calls', async ({ page, c
});
await popupClosedPromise;

await explorerPage.goto(formatUrl(explorerUrl, `test/index.html`));
await explorerPage.goto(formatUrl(explorerUrl, `test` + (isWebExtension ? `/index.html` : '')));
await waitAndClick(explorerPage, ['@testpage/init']);
await waitAndClick(explorerPage, ['@testpage/subsequentCalls']);
log('waiting for popup open');
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-popup/e2e/tests/popup-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('popup should display error page when device disconnected and debug mode',

log('waiting for explorer to load');
await waitAndClick(page, ['@api-playground/collapsible-box']);
await page.waitForSelector("div[data-testid='@api-playground/collapsible-box']");
await page.getByTestId('@api-playground/collapsible-box').waitFor({ state: 'visible' });
await explorerPage.waitForSelector("button[data-testid='@submit-button']", {
state: 'visible',
});
Expand Down
1 change: 0 additions & 1 deletion packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"dependencies": {
"@trezor/schema-utils": "workspace:*",
"long": "5.2.4",
"protobufjs": "7.4.0"
},
"devDependencies": {
Expand Down
11 changes: 0 additions & 11 deletions packages/protobuf/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
// Long.js needed to make protobuf encoding work with numbers over Number.MAX_SAFE_INTEGER
// Docs claim that it should be enough to only install this dependency and it will be required automatically
// see: https://github.com/protobufjs/protobuf.js/#compatibility
// But we found that it does not work in browser environment
// see: https://github.com/protobufjs/protobuf.js/issues/758
import Long from 'long';
import * as protobuf from 'protobufjs/light';

protobuf.util.Long = Long;
protobuf.configure();

export * from './decode';
export * from './encode';
export * as Messages from './messages';
Expand Down
1 change: 1 addition & 0 deletions packages/transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@trezor/protocol": "workspace:*",
"@trezor/utils": "workspace:*",
"cross-fetch": "^4.0.0",
"long": "^5.2.0",
"protobufjs": "7.4.0",
"usb": "^2.14.0"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/transport/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Long.js needed to make protobuf encoding work with numbers over Number.MAX_SAFE_INTEGER
// Docs claim that it should be enough to only install this dependency and it will be required automatically
// see: https://github.com/protobufjs/protobuf.js/#compatibility
// But we found that it does not work in browser environment
// see: https://github.com/protobufjs/protobuf.js/issues/758
import Long from 'long';
import * as protobuf from 'protobufjs/light';

export * as TRANSPORT_ERROR from './errors';

protobuf.util.Long = Long;
protobuf.configure();

export type { Descriptor, Session } from './types';
export { TREZOR_USB_DESCRIPTORS, TRANSPORT } from './constants';

Expand Down
2 changes: 1 addition & 1 deletion packages/transport/src/utils/receive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Root } from 'protobufjs/light';
import { Root } from 'protobufjs/light';

import { createMessageFromType, decode as decodeProtobuf } from '@trezor/protobuf';
import { TransportProtocol } from '@trezor/protocol';
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/src/utils/send.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Logic of sending data to trezor
//
// Logic of "call" is broken to two parts - sending and receiving
import { type Root } from 'protobufjs/light';
import { Root } from 'protobufjs/light';

import { createMessageFromName, encode as encodeProtobuf } from '@trezor/protobuf';
import { TransportProtocolEncode } from '@trezor/protocol';
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12172,7 +12172,6 @@ __metadata:
resolution: "@trezor/protobuf@workspace:packages/protobuf"
dependencies:
"@trezor/schema-utils": "workspace:*"
long: "npm:5.2.4"
protobufjs: "npm:7.4.0"
protobufjs-cli: "npm:^1.1.3"
tsx: "npm:^4.16.3"
Expand Down Expand Up @@ -12767,6 +12766,7 @@ __metadata:
cross-fetch: "npm:^4.0.0"
jest: "npm:29.7.0"
jest-environment-node: "npm:^29.7.0"
long: "npm:^5.2.0"
protobufjs: "npm:7.4.0"
ts-node: "npm:^10.9.1"
tsx: "npm:^4.16.3"
Expand Down Expand Up @@ -30039,7 +30039,7 @@ __metadata:
languageName: node
linkType: hard

"long@npm:5.2.4, long@npm:^5.0.0":
"long@npm:^5.0.0, long@npm:^5.2.0":
version: 5.2.4
resolution: "long@npm:5.2.4"
checksum: 10/c27c060a683d4d76dc48da12ded0ae49c610aaf10d028ec938829d7bebe916979dcc8b67ed71f8bf6d845a90151b66a9b741a3ee51ec874908e496c2a576697a
Expand Down
Loading