Bug 1022181 - Mobile ID Tests. Part 1: DOM Tests. r=sicking
authorFernando Jiménez <ferjmoreno@gmail.com>
Tue, 08 Jul 2014 19:57:44 +0200
changeset 192910 2edd10045963bc75b01da46842277984f843e88a
parent 192909 3bc782198bd7759291ca1b04e73d632ee2a364f6
child 192911 05e7b540b5c1d31be38c23c8388f959dec34c789
push id7663
push userkwierso@gmail.com
push dateWed, 09 Jul 2014 03:08:08 +0000
treeherderfx-team@48de6f4f82af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1022181
milestone33.0a1
Bug 1022181 - Mobile ID Tests. Part 1: DOM Tests. r=sicking
dom/mobileid/moz.build
dom/mobileid/test/mochitest.ini
dom/mobileid/test/moz.build
dom/mobileid/test/test_mobileid_basics.html
dom/mobileid/test/test_mobileid_no_permission.html
--- a/dom/mobileid/moz.build
+++ b/dom/mobileid/moz.build
@@ -1,7 +1,9 @@
 # -*- 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/.
 
 PARALLEL_DIRS += ['interfaces', 'src']
+
+TEST_DIRS += ['test']
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/test/mochitest.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+skip-if = (buildapp != 'b2g')
+
+[test_mobileid_basics.html]
+[test_mobileid_no_permission.html]
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/test/moz.build
@@ -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']
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/test/test_mobileid_basics.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/dom/mobileid/test/test_mobileid_no_permission.html
@@ -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>