Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#7523 from jedp/829110-test-oncancel
Browse files Browse the repository at this point in the history
Bug 829110 - add tests for navigator.mozId.request oncancel() callback; r=ferjm
  • Loading branch information
ferjm committed Jan 10, 2013
2 parents 6dad649 + 5ba6b5e commit d6796d0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 70 deletions.
2 changes: 1 addition & 1 deletion test_apps/uitest/index.html
Expand Up @@ -35,7 +35,7 @@
<li><a href="#test=pay">navigator.mozPay tests</a></li>
<li><a href="#test=inputmode">text inputmode tests</a></li>
<li><a href="#test=audiotag">audio tag tests</a></li>
<li><a href="#test=identity">navigator.id tests</a></li>
<li><a href="#test=identity">navigator.mozId tests</a></li>
</ul>
</div>
<div id="test-panel" class="panel">
Expand Down
152 changes: 84 additions & 68 deletions 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() {
Expand All @@ -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);
Expand All @@ -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);

2 changes: 1 addition & 1 deletion test_apps/uitest/tests/identity.html
Expand Up @@ -20,6 +20,7 @@
<p>Tests</p>
<ul>
<li><button id="t-request">Request</button> (Standard, verified email)</li>
<li><button id="t-request-withOnCancel">Request</button> (With <code>oncancel</code> handler)</li>
<li><button id="t-request-allowUnverified">Request</button> (Unverified)</li>
<li><button id="t-request-forceIssuer">Request</button> (Force issuer)</li>
<li><button id="t-request-forceIssuer-allowUnverified">Request</button> (Force issuer; unverified)</li>
Expand All @@ -35,7 +36,6 @@
</div>

<script type="text/javascript" src="../js/identity.js"></script>
<script src="https://notoriousb2g.personatest.org/include.js"></script>
</body>

</html>

0 comments on commit d6796d0

Please sign in to comment.