From 144925e4b5dd3ba365308194d163f01ba59cdb11 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Tue, 20 Dec 2011 16:58:33 +0000 Subject: [PATCH] Starting to add loads of stuff for verify_user - controllers, actions, state machine stuff. --- .../static/dialog/controllers/actions.js | 11 +++- .../dialog/controllers/verify_primary_user.js | 60 +++++++++++++++++ resources/static/dialog/resources/helpers.js | 4 +- .../static/dialog/resources/state_machine.js | 8 +++ resources/static/dialog/start.js | 1 + resources/static/test/index.html | 3 + .../qunit/controllers/actions_unit_test.js | 22 +++++++ .../verify_primary_user_unit_test.js | 65 +++++++++++++++++++ .../test/qunit/resources/helpers_unit_test.js | 2 +- .../resources/state_machine_unit_test.js | 20 ++++++ resources/views/dialog_layout.ejs | 1 + 11 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 resources/static/dialog/controllers/verify_primary_user.js create mode 100644 resources/static/test/qunit/controllers/verify_primary_user_unit_test.js diff --git a/resources/static/dialog/controllers/actions.js b/resources/static/dialog/controllers/actions.js index 9e253e9ae..bd2725383 100644 --- a/resources/static/dialog/controllers/actions.js +++ b/resources/static/dialog/controllers/actions.js @@ -1,4 +1,4 @@ -/*jshint brgwser:true, jQuery: true, forin: true, laxbreak:true */ +/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */ /*global _: true, BrowserID: true, PageController: true */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -168,8 +168,15 @@ BrowserID.Modules.Actions = (function() { authenticated: authenticated }); }, self.getErrorDialog(errors.checkAuthentication)); - } + }, + doVerifyPrimaryUser: function(info) { + startService("verify_primary_user", info); + }, + + doPrimaryUserVerified: function() { + // XXX we've gotta do something here too. + } }); sc = Module.sc; diff --git a/resources/static/dialog/controllers/verify_primary_user.js b/resources/static/dialog/controllers/verify_primary_user.js new file mode 100644 index 000000000..272584945 --- /dev/null +++ b/resources/static/dialog/controllers/verify_primary_user.js @@ -0,0 +1,60 @@ +/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */ +/*global _: true, BrowserID: true, PageController: true */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla BrowserID. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +BrowserID.Modules.VerifyPrimaryUser = (function() { + "use strict"; + + var bid = BrowserID, + sc; + + var Module = bid.Modules.PageModule.extend({ + start: function(data) { + var self=this; + + data = data || {}; + + // XXX YEEHA! We've gotta set some variables and redirect off to the + // IdPs page. + sc.start.call(this, data); + } + + }); + + sc = Module.sc; + + return Module; +}()); + diff --git a/resources/static/dialog/resources/helpers.js b/resources/static/dialog/resources/helpers.js index 697146bb8..4449bc518 100644 --- a/resources/static/dialog/resources/helpers.js +++ b/resources/static/dialog/resources/helpers.js @@ -118,13 +118,13 @@ // XXX Is this status possible? break; case "primary.verified": - self.close("primay_user_verified", { + self.close("primary_user_verified", { email: email }); complete(true); break; case "primary.verify": - self.close("primay_user_verified", { + self.close("primary_verify_user", { email: email }); complete(true); diff --git a/resources/static/dialog/resources/state_machine.js b/resources/static/dialog/resources/state_machine.js index e611a76ca..00f401da5 100644 --- a/resources/static/dialog/resources/state_machine.js +++ b/resources/static/dialog/resources/state_machine.js @@ -146,6 +146,14 @@ gotoState("doEmailConfirmed"); }); + subscribe("primary_user_verified", function(msg, info) { + gotoState("doPrimaryUserVerified", info); + }); + + subscribe("primary_verify_user", function(msg, info) { + gotoState("doVerifyPrimaryUser", info); + }); + subscribe("authenticate_with_required_email", function(msg, info) { gotoState("doAuthenticateWithRequiredEmail", info); }); diff --git a/resources/static/dialog/start.js b/resources/static/dialog/start.js index a6787584a..944649ef0 100644 --- a/resources/static/dialog/start.js +++ b/resources/static/dialog/start.js @@ -18,6 +18,7 @@ moduleManager.register("forgot_password", modules.ForgotPassword); moduleManager.register("pick_email", modules.PickEmail); moduleManager.register("required_email", modules.RequiredEmail); + moduleManager.register("verify_primary_user", modules.VerifyPrimaryUser); moduleManager.start("dialog"); } diff --git a/resources/static/test/index.html b/resources/static/test/index.html index b3400342e..50386e33e 100644 --- a/resources/static/test/index.html +++ b/resources/static/test/index.html @@ -121,6 +121,7 @@ <script type="text/javascript" src="/dialog/controllers/authenticate.js"></script> <script type="text/javascript" src="/dialog/controllers/forgotpassword.js"></script> <script type="text/javascript" src="/dialog/controllers/required_email.js"></script> + <script type="text/javascript" src="/dialog/controllers/verify_primary_user.js"></script> <script type="text/javascript" src="/pages/page_helpers.js"></script> <script type="text/javascript" src="/pages/add_email_address.js"></script> @@ -167,6 +168,8 @@ <script type="text/javascript" src="qunit/controllers/authenticate_unit_test.js"></script> <script type="text/javascript" src="qunit/controllers/forgotpassword_unit_test.js"></script> <script type="text/javascript" src="qunit/controllers/required_email_unit_test.js"></script> + <script type="text/javascript" src="qunit/controllers/verify_primary_user_unit_test.js"></script> + <!-- must go last or all other tests will fail. --> <script type="text/javascript" src="qunit/controllers/dialog_unit_test.js"></script> </body> diff --git a/resources/static/test/qunit/controllers/actions_unit_test.js b/resources/static/test/qunit/controllers/actions_unit_test.js index 340c91498..5e6aee990 100644 --- a/resources/static/test/qunit/controllers/actions_unit_test.js +++ b/resources/static/test/qunit/controllers/actions_unit_test.js @@ -95,5 +95,27 @@ }); }); + /* + asyncTest("doVerifyPrimaryUser does something", function() { + createController({ + ready: function() { + controller.doVerifyPrimaryUser(); + // XXX test something + start(); + } + }); + }); + + asyncTest("doPrimaryUserVerified does something", function() { + createController({ + ready: function() { + controller.doPrimaryUserVerified(); + // XXX test something + start(); + } + }); + }); +*/ + }()); diff --git a/resources/static/test/qunit/controllers/verify_primary_user_unit_test.js b/resources/static/test/qunit/controllers/verify_primary_user_unit_test.js new file mode 100644 index 000000000..1a9390b05 --- /dev/null +++ b/resources/static/test/qunit/controllers/verify_primary_user_unit_test.js @@ -0,0 +1,65 @@ +/*jshint browsers:true, forin: true, laxbreak: true */ +/*global test: true, start: true, stop: true, module: true, ok: true, equal: true, BrowserID:true */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla BrowserID. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +(function() { + "use strict"; + + var bid = BrowserID, + controller, + el, + testHelpers = bid.TestHelpers; + + function createController(config) { + controller = BrowserID.Modules.VerifyPrimaryUser.create(); + controller.start(config); + } + + module("controllers/verify_primary_user", { + setup: function() { + testHelpers.setup(); + }, + + teardown: function() { + if(controller) { + controller.destroy(); + } + testHelpers.teardown(); + } + }); + + // XXX Do some tests! +}()); + diff --git a/resources/static/test/qunit/resources/helpers_unit_test.js b/resources/static/test/qunit/resources/helpers_unit_test.js index 8fd762395..666138477 100644 --- a/resources/static/test/qunit/resources/helpers_unit_test.js +++ b/resources/static/test/qunit/resources/helpers_unit_test.js @@ -65,7 +65,7 @@ function expectedClose(message, field, value) { return function(m, info) { - ok(m, message, "correct message: " + message); + equal(m, message, "correct message: " + message); if(value) { equal(info[field], value, field + " has correct value of " + value); diff --git a/resources/static/test/qunit/resources/state_machine_unit_test.js b/resources/static/test/qunit/resources/state_machine_unit_test.js index e988f9351..9453ffb7c 100644 --- a/resources/static/test/qunit/resources/state_machine_unit_test.js +++ b/resources/static/test/qunit/resources/state_machine_unit_test.js @@ -102,6 +102,14 @@ doError: function() { this.error = true; + }, + + doPrimaryUserVerified: function() { + this.primaryUserVerified = true; + }, + + doVerifyPrimaryUser: function() { + this.verifyPrimaryUser = true; } }; @@ -154,6 +162,18 @@ ok(controllerMock.emailConfirmed, "user was confirmed"); }); + // XXX make these and the messages for secondary match up so there is consistency. + test("primary_user_verified calls doPrimaryUserVerified", function() { + mediator.publish("primary_user_verified"); + + ok(controllerMock.primaryUserVerified, "doPrimaryUserVerified called"); + }); + + test("primary_verify_user calls doVerifyPrimaryUser", function() { + mediator.publish("primary_verify_user"); + ok(controllerMock.verifyPrimaryUser, "doVerifyPrimaryUser called"); + }); + test("authenticated", function() { mediator.publish("authenticated"); diff --git a/resources/views/dialog_layout.ejs b/resources/views/dialog_layout.ejs index fb7412ef1..52fa963ec 100644 --- a/resources/views/dialog_layout.ejs +++ b/resources/views/dialog_layout.ejs @@ -91,6 +91,7 @@ <script type="text/javascript" src="/dialog/controllers/pickemail.js"></script> <script type="text/javascript" src="/dialog/controllers/addemail.js"></script> <script type="text/javascript" src="/dialog/controllers/required_email.js"></script> + <script type="text/javascript" src="/dialog/controllers/verify_primary_user.js"></script> <script type="text/javascript" src="/dialog/start.js"></script> <% } %> <% } %> -- GitLab