mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
Fix shared e2e desktop tests after reload on lock (#24673)
This commit is contained in:
@@ -43,11 +43,24 @@ export async function lockAll(
|
||||
}
|
||||
|
||||
// Armed before the click, so the crash cannot be missed.
|
||||
const crashed = window.waitForEvent("crash", { timeout: CRASH_TIMEOUT_MS });
|
||||
const reload = watchReload(window);
|
||||
await clickMenuItem(app, MenuItem.LockAll);
|
||||
await crashed;
|
||||
|
||||
const reloaded = await reloadedWindow();
|
||||
const reloaded = await reload();
|
||||
await new LockScreen(reloaded).waitUntilShown();
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the process reload of the next lock, wherever it comes from, e.g. the extension
|
||||
* through shared unlock. Call before locking; the returned function resolves to the reloaded
|
||||
* window, since `window` is dead after the crash.
|
||||
*/
|
||||
export function watchReload(window: Page): () => Promise<Page> {
|
||||
const crashed = window.waitForEvent("crash", { timeout: CRASH_TIMEOUT_MS });
|
||||
|
||||
return async () => {
|
||||
await crashed;
|
||||
return reloadedWindow();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,12 +40,14 @@ export async function skipOnboardingDialogs(page: Page) {
|
||||
for (const { heading, dismiss } of ONBOARDING_DIALOGS) {
|
||||
const dialog = page.getByRole("dialog").filter({ hasText: heading });
|
||||
|
||||
// The same dialog can open twice, stacked. Close the topmost copy until none is left: it
|
||||
// covers the ones below, so their buttons cannot be clicked first.
|
||||
// A dialog can sit under another one: a second copy of itself, or e.g. desktop settings
|
||||
// opened from the app menu. A pointer click hits whatever covers its button, so dispatch
|
||||
// the click to the button itself.
|
||||
const close = dialog.getByRole("button", { name: dismiss });
|
||||
await page.addLocatorHandler(dialog, async () => {
|
||||
// first(): the handler's visibility check is strict, and fails on stacked copies.
|
||||
await page.addLocatorHandler(dialog.first(), async () => {
|
||||
for (let open = await close.count(); open > 0; open = await close.count()) {
|
||||
await close.last().click();
|
||||
await close.first().dispatchEvent("click");
|
||||
await expect(close).toHaveCount(open - 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@ import { AccountSecurityPage } from "../../../src/browser/account-security";
|
||||
import { lockNow as lockExtensionNow } from "../../../src/browser/account-switcher";
|
||||
import { account } from "../../../src/credentials";
|
||||
import { clickMenuItem, MenuItem } from "../../../src/desktop/app-menu";
|
||||
import { BiometricRequestType } from "../../../src/desktop/biometrics";
|
||||
import { BiometricRequestType, Biometrics } from "../../../src/desktop/biometrics";
|
||||
import { watchReload } from "../../../src/desktop/lock";
|
||||
import { DesktopSettings } from "../../../src/desktop/settings";
|
||||
import { FeatureFlag } from "../../../src/feature-flags";
|
||||
import { LockScreen } from "../../../src/lock-screen";
|
||||
@@ -21,6 +22,8 @@ import { expect, test } from "../../../src/shared/desktop-fixtures";
|
||||
/**
|
||||
* Extension and desktop app lock and unlock together ("Sync unlock with desktop app"), and the
|
||||
* extension unlocks with the desktop app's biometrics. Biometrics go over SDK IPC.
|
||||
*
|
||||
* Every desktop lock crashes and reloads its renderer, so tests go on in the reloaded window.
|
||||
*/
|
||||
|
||||
const FLAGS = [FeatureFlag.SharedUnlock, FeatureFlag.BiometricsSdkIpc];
|
||||
@@ -48,12 +51,14 @@ test.describe("shared unlock between extension and desktop app", () => {
|
||||
context,
|
||||
window,
|
||||
}) => {
|
||||
const desktopReload = watchReload(window);
|
||||
extension = await lockExtension(context, extension, () => clickMenuItem(app, MenuItem.LockAll));
|
||||
const extensionLock = new LockScreen(extension.popup);
|
||||
await extensionLock.waitUntilShown();
|
||||
await window.waitForURL(LOCK_URL);
|
||||
const desktop = await desktopReload();
|
||||
await desktop.waitForURL(LOCK_URL);
|
||||
|
||||
await new LockScreen(window).unlockWithMasterPassword(account().password);
|
||||
await new LockScreen(desktop).unlockWithMasterPassword(account().password);
|
||||
await extensionLock.waitUntilGone();
|
||||
});
|
||||
|
||||
@@ -61,9 +66,11 @@ test.describe("shared unlock between extension and desktop app", () => {
|
||||
context,
|
||||
window,
|
||||
}) => {
|
||||
const desktopReload = watchReload(window);
|
||||
extension = await lockExtension(context, extension, () => lockExtensionNow(extension.popup));
|
||||
await window.waitForURL(LOCK_URL, { timeout: SYNC_TIMEOUT_MS });
|
||||
const desktopLock = new LockScreen(window);
|
||||
const desktop = await desktopReload();
|
||||
await desktop.waitForURL(LOCK_URL, { timeout: SYNC_TIMEOUT_MS });
|
||||
const desktopLock = new LockScreen(desktop);
|
||||
await desktopLock.waitUntilShown();
|
||||
|
||||
await new LockScreen(extension.popup).unlockWithMasterPassword(account().password);
|
||||
@@ -76,11 +83,12 @@ test.describe("shared unlock between extension and desktop app", () => {
|
||||
await settings.setPin(PIN);
|
||||
await settings.close();
|
||||
|
||||
const desktopReload = watchReload(window);
|
||||
extension = await lockExtension(context, extension, () => clickMenuItem(app, MenuItem.LockAll));
|
||||
const extensionLock = new LockScreen(extension.popup);
|
||||
await extensionLock.waitUntilShown();
|
||||
|
||||
await new LockScreen(window).unlockWithPin(PIN);
|
||||
await new LockScreen(await desktopReload()).unlockWithPin(PIN);
|
||||
await extensionLock.waitUntilGone();
|
||||
});
|
||||
|
||||
@@ -89,8 +97,9 @@ test.describe("shared unlock between extension and desktop app", () => {
|
||||
await settings.open(extension.url);
|
||||
await settings.setPin(PIN);
|
||||
|
||||
const desktopReload = watchReload(window);
|
||||
extension = await lockExtension(context, extension, () => clickMenuItem(app, MenuItem.LockAll));
|
||||
const desktopLock = new LockScreen(window);
|
||||
const desktopLock = new LockScreen(await desktopReload());
|
||||
await desktopLock.waitUntilShown();
|
||||
|
||||
await new LockScreen(extension.popup).unlockWithPin(PIN);
|
||||
@@ -108,12 +117,16 @@ test.describe("shared unlock between extension and desktop app", () => {
|
||||
await settings.enableBiometrics(biometrics);
|
||||
await settings.close();
|
||||
|
||||
const desktopReload = watchReload(window);
|
||||
extension = await lockExtension(context, extension, () => clickMenuItem(app, MenuItem.LockAll));
|
||||
const desktopLock = new LockScreen(window);
|
||||
const desktop = await desktopReload();
|
||||
const desktopLock = new LockScreen(desktop);
|
||||
await desktopLock.waitUntilShown();
|
||||
|
||||
// The fake biometrics live in the renderer, so drive them from the reloaded one.
|
||||
const desktopBiometrics = new Biometrics(desktop);
|
||||
await new LockScreen(extension.popup).unlockWithBiometrics(() =>
|
||||
biometrics.approveNext(BiometricRequestType.Unlock),
|
||||
desktopBiometrics.approveNext(BiometricRequestType.Unlock),
|
||||
);
|
||||
await desktopLock.waitUntilGone();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user