Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(test): Add functional test for web channel flow when user signs …
Browse files Browse the repository at this point in the history
…up, closes original tab, and opens the verification link in the same browser.

This is to add additional coverage to prepare for the add-a-broker branch.

Additional work:
* Reduce duplication in the web channel tests by calling the fillOutSignUp and fillOutSignIn FunctionalHelpers.
  • Loading branch information
Shane Tomlinson committed Oct 31, 2014
1 parent 310bd7d commit c2b51b9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 106 deletions.
18 changes: 14 additions & 4 deletions app/scripts/views/ready.js
Expand Up @@ -60,14 +60,24 @@ function (_, BaseView, Template, Session, Xss, Strings,
afterRender: function () {
var graphic = this.$el.find('.graphic');
graphic.addClass('pulse');
// Finish the WebChannel flow
if (this.isOAuthSameBrowser() && this.relier.get('webChannelId')) {
this.submit();
}

return this._createMarketingSnippet();
},

afterVisible: function () {
// Finish the WebChannel flow
var self = this;
return p()
.then(function () {
if (self.isOAuthSameBrowser() && self.relier.get('webChannelId')) {
// The delay is to give the functional tests time to bind an event
// handler to listen for the `oauth_complete` message on the
// web channel.
return p().delay(100).then(_.bind(self.submit, self));
}
});
},

_createMarketingSnippet: function () {
var marketingSnippet = new MarketingSnippet({
type: this.type,
Expand Down
6 changes: 5 additions & 1 deletion app/tests/spec/views/ready.js
Expand Up @@ -102,6 +102,10 @@ function (chai, sinon, View, Session, FxaClient, p, FxDesktopRelier,
});
});

});


describe('afterVisible', function () {
it('auto-completes the OAuth flow if using the WebChannel on the same browser', function () {
relier.set('webChannelId', 'channel_id');
relier.set('clientId', 'fmd');
Expand All @@ -112,7 +116,7 @@ function (chai, sinon, View, Session, FxaClient, p, FxDesktopRelier,
return p(true);
});

return view.render()
return view.afterVisible()
.then(function () {
assert.isTrue(view.finishOAuthFlow.called);
});
Expand Down
23 changes: 19 additions & 4 deletions tests/functional/lib/helpers.js
Expand Up @@ -249,8 +249,16 @@ define([

function fillOutSignIn(context, email, password) {
return context.get('remote')
.get(require.toUrl(SIGNIN_URL))
.setFindTimeout(intern.config.pageLoadTimeout)
.getCurrentUrl()
.then(function (currentUrl) {
// only load the signin page if not already at a signin page.
if (currentUrl.indexOf('signin') === -1) {
return context.get('remote')
.get(require.toUrl(SIGNIN_URL))
.setFindTimeout(intern.config.pageLoadTimeout);
}
})

.findByCssSelector('form input.email')
.click()
.clearValue()
Expand All @@ -270,8 +278,15 @@ define([

function fillOutSignUp(context, email, password, year) {
return context.get('remote')
.get(require.toUrl(SIGNUP_URL))
.setFindTimeout(intern.config.pageLoadTimeout)
.getCurrentUrl()
.then(function (currentUrl) {
// only load the signup page if not already at a signup page.
if (currentUrl.indexOf('signup') === -1) {
return context.get('remote')
.get(require.toUrl(SIGNUP_URL))
.setFindTimeout(intern.config.pageLoadTimeout);
}
})

.findByCssSelector('form input.email')
.click()
Expand Down
136 changes: 39 additions & 97 deletions tests/functional/oauth_webchannel.js
Expand Up @@ -22,6 +22,7 @@ define([

var PASSWORD = 'password';
var TOO_YOUNG_YEAR = new Date().getFullYear() - 13;
var OLD_ENOUGH_YEAR = TOO_YOUNG_YEAR - 1;
var user;
var email;
var client;
Expand Down Expand Up @@ -81,20 +82,9 @@ define([
return client.signUp(email, PASSWORD, { preVerified: false });
})

.findByCssSelector('form input.email')
.clearValue()
.click()
.type(email)
.end()

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.end()

.findByCssSelector('button[type="submit"]')
.click()
.end()
.then(function () {
return FunctionalHelpers.fillOutSignIn(self, email, PASSWORD);
})

// wah wah, user has to verify.
.findByCssSelector('#fxa-confirm-header')
Expand All @@ -114,20 +104,9 @@ define([

.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ])

.findByCssSelector('form input.email')
.clearValue()
.click()
.type(email)
.end()

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.end()

.findByCssSelector('button[type="submit"]')
.click()
.end()
.then(function () {
return FunctionalHelpers.fillOutSignIn(self, email, PASSWORD);
})

// user should be redirected back to 123done

Expand All @@ -141,30 +120,9 @@ define([
return openFxaFromRp(self, 'signup')
.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ])

.findByCssSelector('form input.email')
.clearValue()
.click()
.type(email)
.end()

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.end()

.findByCssSelector('#fxa-age-year')
.click()
.end()

.findById('fxa-' + (TOO_YOUNG_YEAR - 1))
.pressMouseButton()
.releaseMouseButton()
.click()
.end()

.findByCssSelector('button[type="submit"]')
.click()
.end()
.then(function () {
return FunctionalHelpers.fillOutSignUp(self, email, PASSWORD, OLD_ENOUGH_YEAR);
})

.findByCssSelector('#fxa-confirm-header')
.end()
Expand All @@ -186,36 +144,41 @@ define([
.end();
},

'signup, verify different browser - from original tab\'s P.O.V.': function () {
'signup, verify same browser with original tab closed': function () {
var self = this;

return openFxaFromRp(self, 'signup')
.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ])

.findByCssSelector('form input.email')
.clearValue()
.click()
.type(email)
.end()
.then(function () {
return FunctionalHelpers.fillOutSignUp(self, email, PASSWORD, OLD_ENOUGH_YEAR);
})

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.findByCssSelector('#fxa-confirm-header')
.end()

.findByCssSelector('#fxa-age-year')
.click()
.end()
.then(function () {
return FunctionalHelpers.getVerificationLink(email, 0);
})
.then(function (verificationLink) {
return self.get('remote').get(require.toUrl(verificationLink))
.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ]);
})

.findById('fxa-' + (TOO_YOUNG_YEAR - 1))
.pressMouseButton()
.releaseMouseButton()
.click()
.end()
// window should automatically sign in.

.findByCssSelector('button[type="submit"]')
.click()
.end()
.findByCssSelector('#loggedin')
.end();
},

'signup, verify different browser - from original tab\'s P.O.V.': function () {
var self = this;

return openFxaFromRp(self, 'signup')
.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ])

.then(function () {
return FunctionalHelpers.fillOutSignUp(self, email, PASSWORD, OLD_ENOUGH_YEAR);
})

.findByCssSelector('#fxa-confirm-header')
.end()
Expand All @@ -235,30 +198,9 @@ define([
return openFxaFromRp(self, 'signup')
.execute(redirectToRpOnWebChannelMessage, [ OAUTH_APP ])

.findByCssSelector('form input.email')
.clearValue()
.click()
.type(email)
.end()

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.end()

.findByCssSelector('#fxa-age-year')
.click()
.end()

.findById('fxa-' + (TOO_YOUNG_YEAR - 1))
.pressMouseButton()
.releaseMouseButton()
.click()
.end()

.findByCssSelector('button[type="submit"]')
.click()
.end()
.then(function () {
return FunctionalHelpers.fillOutSignUp(self, email, PASSWORD, OLD_ENOUGH_YEAR);
})

.findByCssSelector('#fxa-confirm-header')
.end()
Expand Down

0 comments on commit c2b51b9

Please sign in to comment.