Skip to content
Permalink
Browse files

refactor(test): Hook up default WebChannel responses if none specified

This simplifies developer lives by hooking up default WebChannel
responses in applicable environments if none are specified.
  • Loading branch information
shane-tomlinson authored and vbudhram committed Dec 2, 2019
1 parent bfdf0cb commit 06f2708653eb1c83b954bc786a09f5e43bedfd10
@@ -48,17 +48,7 @@ registerSuite('signup with an email that bounces', {
// ensure a fresh signup page is loaded. If this suite is
// run after a Sync suite, these tests try to use a Sync broker
// which results in a channel timeout.
.then(
openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER))
);
},

@@ -121,14 +111,7 @@ const setUpBouncedSignIn = thenify(function(email) {
return this.parent
.then(clearBrowserState({ force: true }))
.then(createUser(email, PASSWORD, { preVerified: true }))
.then(
openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': { capabilities: null, signedInUser: null },
},
})
)
.then(openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER))
.then(fillOutEmailFirstSignIn(email, PASSWORD))
.then(testElementExists(selectors.SIGNIN_TOKEN_CODE.HEADER))
.then(testIsBrowserNotified('fxaccounts:can_link_account'))
@@ -25,8 +25,6 @@ const CONNECT_ANOTHER_DEVICE_URL = `${config.fxaContentRoot}connect_another_devi
const CONNECT_ANOTHER_DEVICE_SMS_ENABLED_URL = `${config.fxaContentRoot}connect_another_device?forceExperiment=sendSms&forceExperimentGroup=signinCodes`;
const ENTER_EMAIL_URL = `${config.fxaContentRoot}?context=fx_desktop_v3&service=sync&action=email`;

const CHANNEL_COMMAND_CAN_LINK_ACCOUNT = 'fxaccounts:can_link_account';

const {
clearBrowserState,
createEmail,
@@ -55,11 +53,6 @@ registerSuite('connect_another_device', {
.then(
openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER, {
query: { forceUA },
webChannelResponses: {
[CHANNEL_COMMAND_CAN_LINK_ACCOUNT]: {
ok: true,
},
},
})
)
.then(fillOutEmailFirstSignUp(email, PASSWORD))
@@ -99,11 +92,6 @@ registerSuite('connect_another_device', {
.then(
openPage(ENTER_EMAIL_URL, selectors.ENTER_EMAIL.HEADER, {
query: { forceUA },
webChannelResponses: {
[CHANNEL_COMMAND_CAN_LINK_ACCOUNT]: {
ok: true,
},
},
})
)
.then(fillOutEmailFirstSignUp(email, PASSWORD))
@@ -52,7 +52,6 @@ registerSuite('Firefox Desktop non-sync', {
forceUA: uaStrings['desktop_firefox_71'],
},
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
signedInUser: null,
clientId: FIREFOX_CLIENT_ID,
@@ -85,7 +84,6 @@ registerSuite('Firefox Desktop non-sync', {
forceUA: uaStrings['desktop_firefox_71'],
},
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
signedInUser: null,
clientId: FIREFOX_CLIENT_ID,
@@ -115,7 +113,6 @@ registerSuite('Firefox Desktop non-sync', {
forceUA: uaStrings['desktop_firefox_71'],
},
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
signedInUser: null,
clientId: FIREFOX_CLIENT_ID,
@@ -154,7 +151,6 @@ registerSuite('Firefox Desktop non-sync', {
forceUA: uaStrings['desktop_firefox_71'],
},
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
signedInUser: null,
clientId: FIREFOX_CLIENT_ID,
@@ -248,45 +248,22 @@ registerSuite('Firefox desktop user info handshake', {

'Sync - no user signed into browser, no user signed in locally': function() {
return this.remote
.then(
openPage(SYNC_ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
)
.then(openPage(SYNC_ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER))
.then(testElementValueEquals(selectors.ENTER_EMAIL.EMAIL, ''));
},

'Sync - no user signed into browser, user signed in locally': function() {
return (
this.remote
// First, sign in the user to populate localStorage
.then(
openPage(ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
)
.then(openPage(ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER))
.then(fillOutEmailFirstSignIn(otherEmail, PASSWORD))
.then(testElementExists(selectors.SETTINGS.HEADER))

.then(
openPage(
SYNC_ENTER_EMAIL_PAGE_URL,
selectors.SIGNIN_PASSWORD.HEADER,
{
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
}
selectors.SIGNIN_PASSWORD.HEADER
)
)

@@ -388,51 +365,23 @@ registerSuite('Firefox desktop user info handshake', {

'Sync settings page - no user signed into browser': function() {
return this.remote.then(
openPage(SYNC_SETTINGS_PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
openPage(SYNC_SETTINGS_PAGE_URL, selectors.ENTER_EMAIL.HEADER)
);
},

'Non-Sync settings page - no user signed into browser, no user signed in locally': function() {
return this.remote.then(
openPage(SETTINGS_PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
openPage(SETTINGS_PAGE_URL, selectors.ENTER_EMAIL.HEADER)
);
},

'Non-Sync settings page - no user signed into browser, user signed in locally': function() {
return this.remote
.then(
openPage(ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
)
.then(openPage(ENTER_EMAIL_PAGE_URL, selectors.ENTER_EMAIL.HEADER))
.then(fillOutEmailFirstSignIn(otherEmail, PASSWORD))
.then(testElementExists(selectors.SETTINGS.HEADER))

.then(
openPage(SETTINGS_PAGE_URL, selectors.SETTINGS.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
signedInUser: null,
},
},
})
)
.then(openPage(SETTINGS_PAGE_URL, selectors.SETTINGS.HEADER))

.then(
testElementTextEquals(selectors.SETTINGS.PROFILE_HEADER, otherEmail)
@@ -14,6 +14,7 @@ const Querystring = require('querystring');
const restmail = require('../../lib/restmail');
const selectors = require('./selectors');
const TestHelpers = require('../../lib/helpers');
const UAParser = require('ua-parser-js');
const Url = require('url');

// Default options for TOTP
@@ -115,6 +116,7 @@ const takeScreenshot = function() {
`Screenshot saved at: ${screenCaptureHost}${res.headers.location}`
);
},
//eslint-disable-next-line handle-callback-err
err => {
console.error('Capturing base64 screenshot:');
console.error(`data:image/png;base64,${buffer.toString('base64')}`);
@@ -1372,13 +1374,54 @@ const openSignUpInNewTab = thenify(function() {
* @returns {Promise} - resolves when complete
*/
const openPage = thenify(function(url, readySelector, options = {}) {
url = addQueryParamsToLink(url, options.query || {});

function isWebChannelSync() {
return (
/context=fx_desktop_v3/.test(url) || /context=fx_fennec_v1/.test(url)
);
}

function isUAWithWebChannelSupport() {
const forceUARegExp = /forceUA=([^&]+)/;
const matches = forceUARegExp.exec(url);
if (matches) {
const uap = UAParser(decodeURIComponent(matches[1]));

return (
uap.browser.name === 'Firefox' &&
uap.os.name !== 'iOS' &&
parseInt(uap.browser.major, 10) > 40
);
}
return false;
}

if (isWebChannelSync() || isUAWithWebChannelSupport()) {
if (!options.webChannelResponses) {
options.webChannelResponses = {};
}

if (!options.webChannelResponses['fxaccounts:can_link_account']) {
options.webChannelResponses['fxaccounts:can_link_account'] = { ok: true };
}

if (!options.webChannelResponses['fxaccounts:fxa_status']) {
options.webChannelResponses['fxaccounts:fxa_status'] = {
capabilities: null,
signedInUser: null,
};
}
}
if (options.webChannelResponses) {
options.query = options.query || {};
// If there are webChannelResponses, the automatedBrowser
// query param introduces a short delay so that the web
// channel response listeners can be hooked up before FxA
// sends the fxaccounts:fxa_status message.
options.query.automatedBrowser = true;
options.query = {
automatedBrowser: true,
...options.query,
};
}

url = addQueryParamsToLink(url, options.query);
@@ -53,17 +53,7 @@ registerSuite('signin with OAuth after Sync', {
return (
this.remote
.then(createUser(email, PASSWORD, { preVerified: true }))
.then(
openPage(SYNC_EMAIL_FIRST_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(SYNC_EMAIL_FIRST_URL, selectors.ENTER_EMAIL.HEADER))

.then(fillOutEmailFirstSignIn(email, PASSWORD))
.then(testElementExists(selectors.SIGNIN_TOKEN_CODE.HEADER))
@@ -143,17 +133,7 @@ registerSuite('signin to Sync after OAuth', {
.then(fillOutEmailFirstSignIn(email, PASSWORD))
.then(testElementTextEquals(selectors['123DONE'].AUTHENTICATED, email))

.then(
openPage(SYNC_EMAIL_FIRST_URL, selectors.SIGNIN_PASSWORD.HEADER, {
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(SYNC_EMAIL_FIRST_URL, selectors.SIGNIN_PASSWORD.HEADER))
.then(
testElementTextEquals(
selectors.SIGNIN_PASSWORD.EMAIL_NOT_EDITABLE,
@@ -28,13 +28,7 @@ registerSuite('password strength balloon', {

return this.remote
.then(clearBrowserState({ force: true }))
.then(
openPage(PAGE_URL, selectors.ENTER_EMAIL.HEADER, {
webChannelResponses: {
'fxaccounts:can_link_account': { ok: true },
},
})
)
.then(openPage(PAGE_URL, selectors.ENTER_EMAIL.HEADER))
.then(type(selectors.ENTER_EMAIL.EMAIL, email))
.then(
click(selectors.ENTER_EMAIL.SUBMIT, selectors.SIGNUP_PASSWORD.HEADER)
@@ -95,16 +95,7 @@ registerSuite('Recovery key', {
'can reset password with recovery key': function() {
return (
this.remote
.then(
openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER))
.then(fillOutResetPassword(email))
.then(testElementExists(selectors.CONFIRM_RESET_PASSWORD.HEADER))
.then(openVerificationLinkInSameTab(email, 2))
@@ -143,16 +134,7 @@ registerSuite('Recovery key', {
'can reset password when forgot recovery key': function() {
return (
this.remote
.then(
openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER))
.then(fillOutResetPassword(email))
.then(testElementExists(selectors.CONFIRM_RESET_PASSWORD.HEADER))
.then(openVerificationLinkInSameTab(email, 2))
@@ -183,16 +165,7 @@ registerSuite('Recovery key', {
'can not re-use recovery key': function() {
return (
this.remote
.then(
openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER, {
webChannelResponses: {
'fxaccounts:fxa_status': {
capabilities: null,
signedInUser: null,
},
},
})
)
.then(openPage(RESET_PASSWORD_URL, selectors.RESET_PASSWORD.HEADER))
.then(fillOutResetPassword(email))
.then(testElementExists(selectors.CONFIRM_RESET_PASSWORD.HEADER))
.then(openVerificationLinkInSameTab(email, 2))

0 comments on commit 06f2708

Please sign in to comment.
You can’t perform that action at this time.