From 5ba6b5e7be5b6f9abd4cc3692bd2b714edf901b5 Mon Sep 17 00:00:00 2001 From: Jed Parsons Date: Thu, 10 Jan 2013 10:28:45 -0800 Subject: [PATCH] Bug 829110 - add tests for navigator.mozId.request oncancel() callback --- test_apps/uitest/index.html | 2 +- test_apps/uitest/js/identity.js | 152 +++++++++++++++------------ test_apps/uitest/tests/identity.html | 2 +- 3 files changed, 86 insertions(+), 70 deletions(-) diff --git a/test_apps/uitest/index.html b/test_apps/uitest/index.html index a01bd09db864..e4872fd37fcd 100644 --- a/test_apps/uitest/index.html +++ b/test_apps/uitest/index.html @@ -35,7 +35,7 @@
  • navigator.mozPay tests
  • text inputmode tests
  • audio tag tests
  • -
  • navigator.id tests
  • +
  • navigator.mozId tests
  • diff --git a/test_apps/uitest/js/identity.js b/test_apps/uitest/js/identity.js index ec5ed2fbaa90..b1c42c5b6a05 100644 --- a/test_apps/uitest/js/identity.js +++ b/test_apps/uitest/js/identity.js @@ -1,6 +1,8 @@ /** * The IdentityTests are meant to be exercised from marionette as part of the * gaia-ui-tests suites. + * + * In these tests, we exercise the native navigator.mozId directly. */ function getUnverifiedOk() { @@ -20,46 +22,17 @@ function unpackAssertion(assertion) { }; } -var testElementHandlers = { - 't-request': function() { - navigator.id.request(); - }, - - 't-request-allowUnverified': function() { - navigator.id.request({ - allowUnverified: getUnverifiedOk() - }); - }, - - 't-request-forceIssuer': function() { - navigator.id.request({ - forceIssuer: getIssuerName() - }); - }, - - 't-request-forceIssuer-allowUnverified': function() { - navigator.id.request({ - allowUnverified: getUnverifiedOk(), - forceIssuer: getIssuerName() - }); - }, - - 't-logout': function() { - navigator.id.logout(); - } -}; - -var IdentityTests = { - _eventNum: 1, +function IdentityTests() { /** - * make a note in the event stream + * recordEvent: make a note in the event stream * * message is the main text of the note * cklass is the css class to apply to the enclosing li * params is an optional dictionary of strings to append as divs */ - recordEvent: function id_recordEvent(message, cklass, params) { + this._eventNum = 1; + this.recordEvent = function id_recordEvent(message, cklass, params) { var li = document.createElement('li'); if (cklass) { li.classList.add(cklass); @@ -78,47 +51,90 @@ var IdentityTests = { li.innerHTML = html; events.appendChild(li); this._eventNum += 1; - }, + }; + + this._setupCallbacks = function id__setupCallbacks() { + if (this._running) return; + var self = this; + try { + navigator.mozId.watch({ + loggedInUser: null, + + onlogin: function(assertion) { + var unpacked = JSON.stringify(unpackAssertion(assertion), null, 2); + self.recordEvent("login", 'login', {assertion: assertion, unpacked: unpacked}); + }, - init: function id_init() { + onlogout: function() { + self.recordEvent("logout", 'logout'); + }, + + onready: function() { + self.recordEvent("ready", 'ready'); + } + + }); + } catch (err) { + this.recordEvent("Error: " + err, 'error'); + } + }; + + /** + * Bind UI components + */ + this._bindEvents = function id__bindEvents() { + if (this._running) return; var self = this; - window.addEventListener("DOMContentLoaded", function() { - // Set up identity calbacks - try { - navigator.id.watch({ - loggedInUser: null, - - onlogin: function(assertion) { - var unpacked = JSON.stringify(unpackAssertion(assertion), null, 2); - self.recordEvent("login", 'login', {assertion: assertion, unpacked: unpacked}); - }, - - onlogout: function() { - self.recordEvent("logout", 'logout'); - }, - - onready: function() { - self.recordEvent("ready", 'ready'); - }, - - oncancel: function() { - self.recordEvent("cancel", 'cancel'); - } + var testElementHandlers = { + 't-request': function() { + navigator.mozId.request(); + }, + + 't-request-withOnCancel': function() { + navigator.mozId.request({oncancel: function() { self.recordEvent("cancel", 'cancel') }}); + }, + + 't-request-allowUnverified': function() { + navigator.mozId.request({ + allowUnverified: getUnverifiedOk() }); - } catch (err) { - self.recordEvent("Error: " + err, 'error'); - } + }, - // Bind selectors and onclick callbacks - Object.keys(testElementHandlers).forEach(function(selector) { - document.getElementById(selector).addEventListener( - 'click', testElementHandlers[selector]); - }); + 't-request-forceIssuer': function() { + navigator.mozId.request({ + forceIssuer: getIssuerName() + }); + }, - self.recordEvent("Ready to rock"); + 't-request-forceIssuer-allowUnverified': function() { + navigator.mozId.request({ + allowUnverified: getUnverifiedOk(), + forceIssuer: getIssuerName() + }); + }, + + 't-logout': function() { + navigator.mozId.logout(); + } + }; + + Object.keys(testElementHandlers).forEach(function(selector) { + document.getElementById(selector).addEventListener( + 'click', testElementHandlers[selector]); }); + }; + + this.init = function id_init() { + this._setupCallbacks(); + this._bindEvents(); + this._running = true; + + this.recordEvent("Ready to rock"); } -}; +} -IdentityTests.init(); +window.addEventListener('DOMContentLoaded', function() { + var identityTests = new IdentityTests(); + identityTests.init(); +}, false); diff --git a/test_apps/uitest/tests/identity.html b/test_apps/uitest/tests/identity.html index 32390eb7c4f0..a19d5227d339 100644 --- a/test_apps/uitest/tests/identity.html +++ b/test_apps/uitest/tests/identity.html @@ -20,6 +20,7 @@

    Tests

    -