Skip to content

Commit

Permalink
fix(18194): redirect to extension expand view when click back button
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDDDanica committed Mar 30, 2023
1 parent c4f85c5 commit 587715f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ node_modules/
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# intellij config files
/.idea

# yarn v3 (w/o zero-install)
# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
Expand Down
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function start() {
}

continueLink.addEventListener('click', async () => {
if (isValidSuspectHref(suspectHref) === false) {
if (!isValidSuspectHref(suspectHref)) {
console.log(`Disallowed Protocol, cannot continue.`);
return;
}
Expand All @@ -208,4 +208,18 @@ function start() {

window.location.href = suspectHref;
});

const backToSafetyLink = document.getElementById('back-to-safety');
if (!backToSafetyLink) {
throw new Error('Unable to locate back to safety link');
}

backToSafetyLink.addEventListener('click', async () => {
phishingSafelistStream.write({
jsonrpc: '2.0',
method: 'backToSafetyPhishingWarning',
params: [],
id: createRandomId(),
});
});
}
4 changes: 2 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang='en' xmlns:about='http://www.w3.org/1999/xhtml'>
<html lang='en'>
<head>
<style id="antiClickjack">
#content__body {
Expand Down Expand Up @@ -71,7 +71,7 @@ <h1>
</br>
<p>If we're flagging a legitimate website, please <a id="new-issue-link" href="#">report a detection problem.</a></p>
<p>If you understand the risks and still want to proceed, you can <a id="unsafe-continue">continue to the site.</a></p>
<button class="button-secondary" type="submit" onclick='location.replace("about:blank")'>Back to safety</button>
<button class="button-secondary" type="submit" id="back-to-safety">Back to safety</button>
</div>
<div id="content__framed-body" class="content__framed-body">
<p>
Expand Down
16 changes: 4 additions & 12 deletions tests/defaults.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';
import config from '../playwright.config';
import { setupDefaultMocks } from './helpers/default-mocks';

test.beforeEach(async ({ context }) => {
Expand Down Expand Up @@ -55,20 +54,13 @@ test('does nothing when the user tries to bypass the warning', async ({
await expect(page.isClosed()).toBe(false);
});

test('replaces tab with a new blank page when the user clicks "Back to safety"', async ({
test('does not close page when the user clicks "Back to safety"', async ({
page,
}) => {
// Calling `replace` here instead of `goto` to ensure that the page loads with a browser history
// of length 1. Using `goto` would result in a length of 2, because Playwright starts each page
// on `about:blank`.
// We need a 1-length history so that the browser allows `window.close()` to work.
const baseURL = config.use?.baseURL;
await page.evaluate((url) => window.location.replace(url), `${baseURL}/`);

const onReloadNewBlankPage = page.waitForURL('about:blank');
await page.goto('/');
await page.getByRole('button', { name: 'Back to safety' }).click();

await onReloadNewBlankPage;
await expect(page.isClosed()).toBe(false);
// the redirection to MM extension will be tested in MM Extension e2e test
});

test('logs that the service worker is registered', async ({ page }) => {
Expand Down

0 comments on commit 587715f

Please sign in to comment.