Bug 1022181 - Mobile ID Tests. Part 1: DOM Tests. r=sicking

This commit is contained in:
Fernando Jiménez 2014-07-08 19:57:44 +02:00
parent 878f922292
commit e11235db84
5 changed files with 116 additions and 0 deletions

View File

@ -5,3 +5,5 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PARALLEL_DIRS += ['interfaces', 'src']
TEST_DIRS += ['test']

View File

@ -0,0 +1,5 @@
[DEFAULT]
skip-if = (buildapp != 'b2g')
[test_mobileid_basics.html]
[test_mobileid_no_permission.html]

View File

@ -0,0 +1,7 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
MOCHITEST_MANIFESTS += ['mochitest.ini']

View File

@ -0,0 +1,78 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for navigator.getMobileIdAssertion</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
const MOCK_CID = SpecialPowers.wrap(SpecialPowers.Components)
.ID("{4cb9b8b3-bc8c-46c0-a2b6-2eb0b1ffce94}");
const MOBILE_ID_SERVICE_CONTRACT_ID = "@mozilla.org/mobileidentity-service;1";
function finish() {
SpecialPowers.wrap(SpecialPowers.Components).manager
.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar)
.unregisterFactory(MOCK_CID, mockMobileIdService);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
var mockMobileIdService = {
QueryInterface: function(aIID) {
if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIMobileIdentityService)) {
return this;
}
throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
},
createInstance: function(aOuter, aIID) {
if (aOuter != null) {
throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(aIID);
},
getMobileIdAssertion: function(aWindow, aOptions) {
return new Promise(function(resolve, reject) {
resolve(aOptions);
});
}
};
mockMobileIdService = SpecialPowers.wrapCallbackObject(mockMobileIdService);
SpecialPowers.wrap(SpecialPowers.Components).manager
.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar)
.registerFactory(MOCK_CID, "mobileid service",
MOBILE_ID_SERVICE_CONTRACT_ID,
mockMobileIdService);
// Tests
SpecialPowers.pushPermissions([{"type": "mobileid",
"allow": 1,
"context": document}], function() {
ok("getMobileIdAssertion" in navigator,
"navigator.getMobileIdAssertion should exist");
var options = { forceSelection: true };
var promise = navigator.getMobileIdAssertion(options)
.then(function(result) {
ok(promise instanceof Promise, "Should return a Promise");
is(result.forceSelection, options.forceSelection,
"MobileIdentityService should receive correct options");
finish();
});
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for navigator.getMobileIdAssertion - No permission</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
ok(!("getMobileIdAssertion" in navigator),
"navigator.getMobileIdAssertion should NOT exist");
SimpleTest.finish();
</script>
</pre>
</body>
</html>