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

Commit

Permalink
Merge pull request #22481 from ferjm/bug1044060.mobileiduitest
Browse files Browse the repository at this point in the history
Bug 1044060 - [MobileID] Add Mobile ID test to Gaia UI test app. r=timdream
  • Loading branch information
ferjm committed Aug 14, 2014
2 parents 6c88fd8 + d2c0922 commit d6c7edf
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev_apps/uitest-privileged/index.html
Expand Up @@ -27,6 +27,7 @@
<li><a href="#test=API/devicestorage">Device Storage</a></li>
<li><a href="#test=API/geolocation">Geolocation</a></li>
<li><a href="#test=API/getusermedia">getUserMedia</a></li>
<li><a href="#test=API/mobileid">MobileIdentity</a></li>
</ul>
</div>
<div id="tabs" class="tabs">
Expand Down
68 changes: 68 additions & 0 deletions dev_apps/uitest-privileged/js/API/mobileid.js
@@ -0,0 +1,68 @@
'use strict';

var MobileId = {
init: function() {
this.clearButton = document.getElementById('clear-button');
this.clearButton.classList.add('hidden');
this.clearButton.addEventListener('click', this.onClear.bind(this));

this.getAssertionButton = document.getElementById('get-assertion-button');
this.getAssertionButton.addEventListener('click', (function() {
navigator.getMobileIdAssertion().then(
this.onAssertion.bind(this),
this.onError.bind(this)
);
}).bind(this));

this.forceSelectionButton = document.getElementById('force-selection-button');
this.forceSelectionButton.addEventListener('click', (function() {
navigator.getMobileIdAssertion({
forceSelection: true
}).then(
this.onAssertion.bind(this),
this.onError.bind(this)
);
}).bind(this));

this.assertionPlaceholder = document.getElementById('assertion-placeholder');
this.assertionContainer = document.getElementById('assertion-container');

this.errorPlaceholder = document.getElementById('error-placeholder');
this.errorContainer = document.getElementById('error-container');
},

onAssertion: function(aAssertion) {
var segments = aAssertion.split('.');

var decoded = JSON.parse(atob(segments[1].replace(/-/g, '+')
.replace(/_/g, '/')));
if (!decoded || !decoded.verifiedMSISDN) {
this.onError('Invalid assertion :(');
return;
}
this.assertionContainer.classList.remove('hidden');
this.assertionPlaceholder.textContent = 'Verified phone number ' +
decoded.verifiedMSISDN;
this.clearButton.classList.remove('hidden');
},

onError: function(aError) {
console.error('ERROR ' + aError.name || aError);
this.errorContainer.classList.remove('hidden');
this.errorPlaceholder.textContent = aError.name;
this.clearButton.classList.remove('hidden');
},

onClear: function() {
this.assertionPlaceholder.textContent = '';
this.assertionContainer.classList.add('hidden');
this.errorPlaceholder.textContent = '';
this.errorContainer.classList.add('hidden');
this.clearButton.classList.add('hidden');
},
};

window.addEventListener('DOMContentLoaded', function onload() {
window.removeEventListener('DOMContentLoaded', onload);
MobileId.init();
});
3 changes: 2 additions & 1 deletion dev_apps/uitest-privileged/manifest.webapp
Expand Up @@ -21,6 +21,7 @@
"device-storage:pictures":{ "access": "readwrite" },
"device-storage:sdcard":{ "access": "readwrite" },
"device-storage:videos":{ "access": "readwrite" },
"geolocation":{}
"geolocation":{},
"mobileid": {}
}
}
28 changes: 28 additions & 0 deletions dev_apps/uitest-privileged/tests_html/API/mobileid.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<meta charset="utf-8">
<title>Mobile Identity test</title>
<script defer src="../../js/API/mobileid.js"></script>
<link rel="stylesheet" type="text/css" href="../../style/API.css">
</head>
<body>
<h1>Mobile ID Tester</h1>
<div class="main-form">
<section id="action-buttons">
<button id="get-assertion-button">Get Assertion</button>
<button id="force-selection-button">Force selection</button>
<button id="clear-button">Clear</button>
</section>
<section id="results">
<div id="assertion-container">
<p id="assertion-placeholder"></p>
</div>
<div id="error-container">
<p id="error-placeholder" class="error"></p>
</div>
</section>
<div>
</body>
</html>

0 comments on commit d6c7edf

Please sign in to comment.