From 466e0c173209391c4631d4216e934d69d068361a Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Thu, 12 Jan 2012 12:14:02 +0000
Subject: [PATCH] Fixing the Safari/PhantomJS crash bug and other headless
 errors.

* Remove the set_password controller, which was never used.
* Remove the set_password test suite.
* Remove the set_password HTML with the autofocus element, which caused some versions of WebKit to wig out.
* In storage.js, make sure when we do JSON.parse, there is something to parse.

close #851
close #889
---
 .../static/dialog/controllers/set_password.js |  64 -----------
 .../static/dialog/views/set_password.ejs      |  44 --------
 resources/static/shared/storage.js            |   5 +-
 resources/static/test/index.html              |   2 -
 resources/static/test/phantomrunner.js        |   2 +-
 .../controllers/set_password_unit_test.js     | 106 ------------------
 scripts/compress.sh                           |   2 +-
 7 files changed, 4 insertions(+), 221 deletions(-)
 delete mode 100644 resources/static/dialog/controllers/set_password.js
 delete mode 100644 resources/static/dialog/views/set_password.ejs
 delete mode 100644 resources/static/test/qunit/controllers/set_password_unit_test.js

diff --git a/resources/static/dialog/controllers/set_password.js b/resources/static/dialog/controllers/set_password.js
deleted file mode 100644
index 44d58d86c..000000000
--- a/resources/static/dialog/controllers/set_password.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */
-/*global _: true, BrowserID: true, PageController: true */
-/* 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/. */
-BrowserID.Modules.SetPassword = (function() {
-  "use strict";
-
-  var bid = BrowserID,
-      user = bid.User,
-      errors = bid.Errors,
-      helpers = bid.Helpers,
-      dom = bid.DOM,
-      sc;
-
-
-  function setPassword(oncomplete) {
-    function complete(status) {
-      if(oncomplete) oncomplete(status);
-    }
-
-    var self = this,
-        pass = dom.getInner("#password"),
-        vpass = dom.getInner("#vpassword"),
-        valid = bid.Validation.passwordAndValidationPassword(pass, vpass);
-
-    if(valid) {
-      user.setPassword(
-        pass,
-        function(status) {
-          self.publish("password_set");
-          complete(true);
-        },
-        self.getErrorDialog(errors.setPassword, complete)
-      );
-    }
-    else {
-      complete(false);
-    }
-  }
-
-  var Module = bid.Modules.PageModule.extend({
-    start: function(options) {
-      var self=this;
-      sc.start.call(self, options);
-
-      self.renderDialog("set_password", options);
-    },
-
-    submit: setPassword
-
-    // BEGIN TESTING API
-    ,
-
-    setPassword: setPassword
-    // END TESTING API
-  });
-
-  sc = Module.sc;
-
-  return Module;
-
-}());
-
diff --git a/resources/static/dialog/views/set_password.ejs b/resources/static/dialog/views/set_password.ejs
deleted file mode 100644
index 2819c9770..000000000
--- a/resources/static/dialog/views/set_password.ejs
+++ /dev/null
@@ -1,44 +0,0 @@
-<!-- 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/. -->
-
-  <strong>
-    Sign in using
-  </strong>
-
-  <div class="form_section" id="set_password">
-      <ul class="inputs">
-          <li>
-              <label for="password" class="serif">Password</label>
-              <input class="sans" id="password" placeholder="Enter a Password" type="password" autofocus maxlength=80>
-
-              <div class="tooltip" id="password_required" for="password">
-                Password is required.
-              </div>
-
-              <div class="tooltip" id="password_too_short" for="password">
-                Password must be at least 8 characters long.
-              </div>
-          <li>
-
-          <li>
-              <label for="vpassword" class="serif">Verify Password</label>
-              <input class="sans" id="vpassword" placeholder="Repeat Password" type="password" maxlength=80>
-
-              <div class="tooltip" id="vpassword_required" for="vpassword">
-                Verification password is required.
-              </div>
-
-              <div class="tooltip" id="passwords_no_match" for="vpassword">
-                Passwords do not match.
-              </div>
-          <li>
-
-
-      </ul>
-
-      <div class="submit cf">
-          <button tabindex="1">Reset Password</button>
-          <!--button id="cancel_set_password" tabindex="2">Cancel</button-->
-      </div>
-  </div>
diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js
index 56b820a55..40288033a 100644
--- a/resources/static/shared/storage.js
+++ b/resources/static/shared/storage.js
@@ -27,7 +27,7 @@ BrowserID.Storage = (function() {
 
   function getEmails() {
     try {
-      var emails = JSON.parse(storage.emails);
+      var emails = JSON.parse(storage.emails || "{}");
       if (emails !== null)
         return emails;
     } catch(e) {
@@ -91,7 +91,7 @@ BrowserID.Storage = (function() {
   }
 
   function retrieveTemporaryKeypair() {
-    var raw_kp = JSON.parse(storage.tempKeypair);
+    var raw_kp = JSON.parse(storage.tempKeypair || "");
     storage.tempKeypair = null;
     if (raw_kp) {
       prepareDeps();
@@ -123,7 +123,6 @@ BrowserID.Storage = (function() {
         origin = staged.origin;
       }
     } catch (x) {
-      console.log(x);
       storage.removeItem("stagedOnBehalfOf");
     }
 
diff --git a/resources/static/test/index.html b/resources/static/test/index.html
index fe81479ff..9f5ea5b2c 100644
--- a/resources/static/test/index.html
+++ b/resources/static/test/index.html
@@ -110,7 +110,6 @@
     <script type="text/javascript" src="/dialog/controllers/email_chosen.js"></script>
     <script type="text/javascript" src="/dialog/controllers/provision_primary_user.js"></script>
     <script type="text/javascript" src="/dialog/controllers/primary_user_provisioned.js"></script>
-    <script type="text/javascript" src="/dialog/controllers/set_password.js"></script>
 
     <script type="text/javascript" src="/pages/page_helpers.js"></script>
     <script type="text/javascript" src="/pages/add_email_address.js"></script>
@@ -161,7 +160,6 @@
     <script type="text/javascript" src="qunit/controllers/email_chosen_unit_test.js"></script>
     <script type="text/javascript" src="qunit/controllers/provision_primary_user_unit_test.js"></script>
     <script type="text/javascript" src="qunit/controllers/primary_user_provisioned_unit_test.js"></script>
-    <script type="text/javascript" src="qunit/controllers/set_password_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>
diff --git a/resources/static/test/phantomrunner.js b/resources/static/test/phantomrunner.js
index aa56a1c22..174fdeec0 100644
--- a/resources/static/test/phantomrunner.js
+++ b/resources/static/test/phantomrunner.js
@@ -83,6 +83,6 @@ page.open(phantom.args[0], function(status){
                 return 10000;
             });
             phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
-        }, 60*1000);
+        }, 90*1000);
     }
 });
diff --git a/resources/static/test/qunit/controllers/set_password_unit_test.js b/resources/static/test/qunit/controllers/set_password_unit_test.js
deleted file mode 100644
index b8910f686..000000000
--- a/resources/static/test/qunit/controllers/set_password_unit_test.js
+++ /dev/null
@@ -1,106 +0,0 @@
-/*jshint browsers:true, forin: true, laxbreak: true */
-/*global test: true, start: true, stop: true, module: true, ok: true, equal: true, BrowserID:true */
-/* 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/. */
-(function() {
-  "use strict";
-
-  var controller,
-      bid = BrowserID,
-      storage = bid.Storage,
-      testHelpers = bid.TestHelpers,
-      xhr = bid.Mocks.xhr,
-      register = bid.TestHelpers.register;
-
-  module("controllers/set_password", {
-    setup: function() {
-      testHelpers.setup();
-      createController();
-      $("#password").val("");
-      $("#vpassword").val("");
-    },
-
-    teardown: function() {
-      if (controller) {
-        try {
-          controller.destroy();
-          controller = null;
-        } catch(e) {
-          // could already be destroyed from the close
-        }
-      }
-      testHelpers.setup();
-    }
-  });
-
-
-  function createController(options) {
-    controller = bid.Modules.SetPassword.create();
-    controller.start(options);
-  }
-
-  function testInvalidInput() {
-    controller.setPassword(function(status) {
-      equal(false, status, "status is false");
-      testHelpers.testTooltipVisible();
-      start();
-    });
-  }
-
-  test("create displays the correct template", function() {
-    equal($("#set_password").length, 1, "the correct template is displayed");
-  });
-
-  asyncTest("setPassword with no password", function() {
-    $("#password").val("");
-    $("#vpassword").val("password");
-    testInvalidInput();
-  });
-
-  asyncTest("setPassword with no verification password", function() {
-    $("#password").val("password");
-    $("#vpassword").val("");
-    testInvalidInput();
-  });
-
-  asyncTest("setPassword with too short of a password", function() {
-    $("#password").val("pass");
-    $("#vpassword").val("pass");
-    testInvalidInput();
-  });
-
-  asyncTest("setPassword with mismatched passwords", function() {
-    $("#password").val("passwords");
-    $("#vpassword").val("password");
-    testInvalidInput();
-  });
-
-  asyncTest("setPassword with XHR error", function() {
-    $("#password").val("password");
-    $("#vpassword").val("password");
-    xhr.useResult("ajaxError");
-
-    controller.setPassword(function(status) {
-      equal(status, false, "correct status");
-      testHelpers.testErrorVisible();
-      start();
-    });
-  });
-
-  asyncTest("setPassword happy case", function() {
-    $("#password").val("password");
-    $("#vpassword").val("password");
-
-
-    register("password_set", function(msg, info) {
-      ok(true, msg + " message received");
-      start();
-    });
-
-    controller.setPassword(function(status) {
-      equal(status, true, "correct status");
-    });
-  });
-}());
-
diff --git a/scripts/compress.sh b/scripts/compress.sh
index 75d633bba..433a8c6db 100755
--- a/scripts/compress.sh
+++ b/scripts/compress.sh
@@ -58,7 +58,7 @@ cp templates.js $BUILD_PATH/templates.js
 cd ../..
 
 # produce the dialog js
-cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/code_check.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgot_password.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/set_password.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/dialog.uncompressed.js
+cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/code_check.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgot_password.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/dialog.uncompressed.js
 
 # produce the dialog css
 cat css/common.css dialog/css/popup.css dialog/css/m.css > $BUILD_PATH/dialog.uncompressed.css
-- 
GitLab