Skip to content
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
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: [['html', { open: 'never' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1 class="heading-lg">This website might be harmful</h1>
<img src="./x-logo-white.png" alt="X Icon" class="twitter-icon" />
<a
class="twitter-share"
href="https://twitter.com/intent/tweet?text=MetaMask%20just%20protected%20me%20from%20a%20phishing%20attack!%20Remember%20to%20always%20stay%20vigilant%20when%20clicking%20on%20links.%20Learn%20more%20at&url=https://metamask.io"
href="https://x.com/intent/post?text=MetaMask%20just%20protected%20me%20from%20a%20phishing%20attack%21%20Remember%20to%20always%20stay%20vigilant%20when%20clicking%20on%20links.%20Learn%20more%20at&url=https%3A%2F%2Fmetamask.com"
target="_blank"
rel="noopener noreferrer"
>
Expand Down
22 changes: 15 additions & 7 deletions tests/defaults.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,27 @@ test('logs that the service worker is registered', async ({ page }) => {
expect(infoLogs[0]).toMatch(expectedMessage);
});

test('redirects to X share page when clicked', async ({ page }) => {
test('redirects to X share page when clicked', async ({ page, context }) => {
// Stub X so the test doesn't depend on its live redirects or availability.
await context.route('https://x.com/**', async (route) =>
route.fulfill({ status: 200, contentType: 'text/html', body: '' }),
);

await page.goto('/');

const shareLink = page.getByRole('link', {
name: 'If you found this helpful, click here to share on X!',
});
await expect(shareLink).toHaveAttribute('rel', /noopener/u);

const [newPage] = await Promise.all([
page.waitForEvent('popup'),
page
.getByRole('link', {
name: 'If you found this helpful, click here to share on X!',
})
.click(),
shareLink.click(),
]);

await expect(newPage).toHaveURL(
'https://x.com/intent/post?text=MetaMask%20just%20protected%20me%20from%20a%20phishing%20attack!%20Remember%20to%20always%20stay%20vigilant%20when%20clicking%20on%20links.%20Learn%20more%20at&url=https%3A%2F%2Fmetamask.io',
'https://x.com/intent/post?text=MetaMask%20just%20protected%20me%20from%20a%20phishing%20attack%21%20Remember%20to%20always%20stay%20vigilant%20when%20clicking%20on%20links.%20Learn%20more%20at&url=https%3A%2F%2Fmetamask.com',
);
// The opened tab must not be able to control or redirect the warning page.
expect(await newPage.evaluate(() => window.opener)).toBeNull();
});
Loading