Skip to content
Merged
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
39 changes: 23 additions & 16 deletions test/e2e/tests/vault-corruption/vault-corruption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import AccountDetailsModal from '../../page-objects/pages/dialog/account-details
import LoginPage from '../../page-objects/pages/login-page';

describe('Vault Corruption', function () {
this.timeout(120000); // This test is very long, so we need an unusually high timeout
Copy link
Member Author

@seaona seaona Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit this once:

image

/**
* Script template to simulate a broken database.
*
Expand Down Expand Up @@ -127,8 +128,8 @@ describe('Vault Corruption', function () {
// the extension has restarted
return title === WINDOW_TITLES.ExtensionInFullScreenView;
},
// reload and check title as quickly a possible, forever
{ interval: 0, timeout: Infinity },
// reload and check title as quickly a possible
{ interval: 100, timeout: 10000 },
Copy link
Member Author

@seaona seaona Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Infinityvalue here is just taken as null (see last log below), then passing interval 0 and timeout of null effectively means the condition will run only once

image

with this fix, the test is less prone to errors, as we are effectively waiting for the correct title, going to the home page, as many times as needed (until reaching 10 seconds):

image
await driver.waitUntil(
      async () => {
        await driver.navigate(PAGES.HOME, { waitForControllers: false });
        const title = await driver.driver.getTitle();
        // the browser will return an error message for our UI's HOME page until
        // the extension has restarted
        return title === WINDOW_TITLES.ExtensionInFullScreenView;
      },

);
await driver.assertElementNotPresent('.loading-logo', { timeout: 10000 });
}
Expand Down Expand Up @@ -193,10 +194,7 @@ describe('Vault Corruption', function () {
confirm: boolean;
}) {
// click the Recovery/Reset button
const recoveryButton = await driver.findClickableElement(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ this is an anti-pattern which can cause the element being stale, when we try to assert its state later on, if the element refreshed. See example of failure:

image

'#critical-error-button',
);
await recoveryButton.click();
await driver.clickElement('#critical-error-button');

// Confirm we want to recover/reset.
const prompt = await driver.driver.switchTo().alert();
Expand All @@ -206,16 +204,25 @@ describe('Vault Corruption', function () {
await prompt.dismiss();
}

// the button should be disabled while the recovery process is in progress,
// and enabled if the user dismissed the prompt
const isEnabled = await recoveryButton.isEnabled();
assert.equal(
isEnabled,
!confirm,
confirm
? 'Recovery button should be disabled when prompt is accepted'
: 'Recovery button should be enabled when prompt is dismissed',
);
if (confirm) {
// delay needed to mitigate a race condition where the tab is closed and re-opened after confirming, causing to window to become stale
await driver.delay(3000);
try {
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we switch to the Extension page to make sure we are in the correct window, as sometimes the window is closed and re-opened, causing the error web view has been discarded

} catch (error) {
// to mitigate a race condition where the tab is closed after confirming (issue #36916)
await driver.openNewPage('about:blank');
await driver.navigate();
}
// the button should be disabled if the user confirmed the prompt, but given this is a transient state that goes very fast
// it can cause a race condition where the element becomes stale, so we check directly that the element is not present as that's a stable state that occurs eventually
await driver.assertElementNotPresent('#critical-error-button');
} else {
// the button should be enabled if the user dismissed the prompt
await driver.findClickableElement('#critical-error-button');
}
}

/**
Expand Down
Loading