Skip to content

Commit

Permalink
test(functional): Convert Robots test, oauth webchannel
Browse files Browse the repository at this point in the history
Because:
* We're converting tests from intern to playwright

This commit:
* Converts oauth_webchannel.js,  robots.txt tests
* Does not port over ios v1 sign up since we don't need to support it any longer

Closes FXA-5923
  • Loading branch information
LZoog committed Jun 9, 2023
1 parent 88bcf99 commit 16454ce
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 163 deletions.
22 changes: 22 additions & 0 deletions packages/functional-tests/lib/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export enum FirefoxCommand {
FxAStatus = 'fxaccounts:fxa_status',
OAuthLogin = 'fxaccounts:oauth_login',
Logout = 'fxaccounts:logout',
}

export function createCustomEventDetail(
command: FirefoxCommand,
data: Record<string, any>
) {
return {
id: 'account_updates',
message: {
command,
data,
},
};
}
54 changes: 54 additions & 0 deletions packages/functional-tests/pages/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,58 @@ export abstract class BaseLayout {
addEventListener('WebChannelMessageToChrome', listener);
});
}

/**
* Listens for a `WebChannelMessageToChrome` web channel event which
* occurs when we (web content) send a message to the browser.
*
* Responds with a `WebChannelMessageToContent` event containing event
* details passed in only when the given command matches the command from
* the listened-for event.
*
* @param webChannelMessage - Custom event details to send to the web content.
*/
async respondToWebChannelMessage(webChannelMessage) {
const expectedCommand = webChannelMessage.message.command;
const response = webChannelMessage.message.data;

await this.page.evaluate(
({ expectedCommand, response }) => {
function listener(e) {
const detail = JSON.parse((e as CustomEvent).detail);
const command = detail.message.command;
const messageId = detail.message.messageId;

if (command === expectedCommand) {
window.removeEventListener('WebChannelMessageToChrome', listener);
const event = new CustomEvent('WebChannelMessageToContent', {
detail: {
id: 'account_updates',
message: {
command,
data: response,
messageId,
},
},
});

window.dispatchEvent(event);
}
}

function startListening() {
try {
window.addEventListener('WebChannelMessageToChrome', listener);
} catch (e) {
// problem adding the listener, window may not be
// ready, try again.
setTimeout(startListening, 0);
}
}

startListening();
},
{ expectedCommand, response }
);
}
}
25 changes: 23 additions & 2 deletions packages/functional-tests/pages/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const selectors = {
NOT_EMAIL_MET: '#password-same-as-email.password-strength-met',
NOT_EMAIL_FAIL: '#password-same-as-email.password-strength-fail',
PERMISSION_ACCEPT: '#accept',
CWTS_HEADER: 'text="Choose what to sync"',
CWTS_ENGINE_BOOKMARKS: '#sync-engine-bookmarks',
CWTS_ENGINE_HISTORY: '#sync-engine-history',
};

export class LoginPage extends BaseLayout {
Expand Down Expand Up @@ -320,9 +323,9 @@ export class LoginPage extends BaseLayout {
}

async submit() {
const waitForNavigation = this.page.waitForNavigation();
// const waitForNavigation = this.page.waitForNavigation();
await this.page.locator(selectors.SUBMIT).click();
return waitForNavigation;
// return waitForNavigation;
}

async clickForgotPassword() {
Expand Down Expand Up @@ -355,6 +358,24 @@ export class LoginPage extends BaseLayout {
return this.page.locator(selectors.SUBMIT).click();
}

async waitForCWTSHeader() {
await this.page.waitForSelector(selectors.CWTS_HEADER, {
timeout: 100,
});
}

async waitForCWTSEngineBookmarks() {
await this.page.waitForSelector(selectors.CWTS_ENGINE_BOOKMARKS, {
timeout: 100,
});
}

async waitForCWTSEngineHistory() {
await this.page.waitForSelector(selectors.CWTS_ENGINE_HISTORY, {
timeout: 100,
});
}

async isSyncConnectedHeader() {
return this.page.isVisible(selectors.SYNC_CONNECTED_HEADER, {
timeout: 100,
Expand Down
10 changes: 10 additions & 0 deletions packages/functional-tests/tests/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ test.describe('severity-1', () => {
expect(await relier.isLoggedIn()).toBe(true);
});
});

test.describe('robots.txt', () => {
test('should allow bots to access all pages', async ({ target, page }) => {
await page.goto(`${target.contentServerUrl}/robots.txt`, {
waitUntil: 'networkidle',
});
const text = await page.locator('body').innerText();
expect(/^Allow:/gm.test(text)).toBeTruthy();
});
});
71 changes: 71 additions & 0 deletions packages/functional-tests/tests/oauth/webchannel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { FirefoxCommand, createCustomEventDetail } from '../../lib/channels';
import { test, expect } from '../../lib/fixtures/standard';

const PASSWORD = 'Password123!';

test.describe('oauth webchannel', () => {
test.beforeEach(async ({ pages: { login } }) => {
await login.clearCache();
});

test('signup', async ({ pages: { login, relier } }) => {
const customEventDetail = createCustomEventDetail(
FirefoxCommand.FxAStatus,
{
capabilities: {
choose_what_to_sync: true,
engines: ['bookmarks', 'history'],
},
signedInUser: null,
}
);
const email = login.createEmail();

await relier.goto('context=oauth_webchannel_v1&automatedBrowser=true');
await relier.clickEmailFirst();

await login.respondToWebChannelMessage(customEventDetail);

await login.setEmail(email);
await login.submit();

// the CWTS form is on the same signup page
await login.waitForCWTSHeader();
await login.waitForCWTSEngineBookmarks();
await login.waitForCWTSEngineHistory();

await login.fillOutFirstSignUp(email, PASSWORD, true, false);
await login.checkWebChannelMessage(FirefoxCommand.OAuthLogin);
});

test('signin', async ({ pages: { login, relier, page }, credentials }) => {
const customEventDetail = createCustomEventDetail(
FirefoxCommand.FxAStatus,
{
capabilities: {
engines: ['bookmarks', 'history'],
},
signedInUser: null,
}
);

await relier.goto('context=oauth_webchannel_v1&automatedBrowser=true');
await relier.clickEmailFirst();

await login.respondToWebChannelMessage(customEventDetail);

const { searchParams } = new URL(page.url());
expect(searchParams.has('client_id')).toBe(true);
expect(searchParams.has('redirect_uri')).toBe(true);
expect(searchParams.has('state')).toBe(true);
expect(searchParams.has('context')).toBe(true);

await login.login(credentials.email, credentials.password);

await login.checkWebChannelMessage('fxaccounts:oauth_login');
});
});
2 changes: 0 additions & 2 deletions packages/fxa-content-server/tests/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

const testsSettings = require('./functional_settings');
module.exports = testsSettings.concat([
'tests/functional/oauth_webchannel.js',

// new and flaky tests above here',
'tests/functional/email_opt_in.js',
'tests/functional/fx_desktop_handshake.js',
Expand Down
135 changes: 0 additions & 135 deletions packages/fxa-content-server/tests/functional/oauth_webchannel.js

This file was deleted.

23 changes: 0 additions & 23 deletions packages/fxa-content-server/tests/functional/robots_txt.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/fxa-content-server/tests/functional_regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = testsSettings.concat([
'tests/functional/bounced_email.js',
'tests/functional/email_opt_in.js',
'tests/functional/fx_desktop_handshake.js',
'tests/functional/oauth_webchannel.js',
'tests/functional/pages.js',
'tests/functional/sign_in.js',
'tests/functional/sign_in_blocked.js',
Expand Down

0 comments on commit 16454ce

Please sign in to comment.