gecko-dev/dom/mobileid/test/test_mobileid_basics.html

79 lines
2.5 KiB
HTML

<!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>