Bug 1171678 - Use pushPermissions instead of setPermissions in contacts tests. r=felash
authorReuben Morais <reuben.morais@gmail.com>
Thu, 06 Aug 2015 17:10:00 -0400
changeset 288440 3326bade9e594199030c6271e66ab995220c335b
parent 288439 bee58bfd8bcf532df396fc270456950a87621cab
child 288441 4e1afd96d6747083ccd23afadeced7161755d363
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelash
bugs1171678
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1171678 - Use pushPermissions instead of setPermissions in contacts tests. r=felash CLOSED TREE
dom/contacts/tests/shared.js
--- a/dom/contacts/tests/shared.js
+++ b/dom/contacts/tests/shared.js
@@ -1,27 +1,28 @@
 "use strict";
 
 // Fix the environment to run Contacts tests
 if (SpecialPowers.isMainProcess()) {
   SpecialPowers.Cu.import("resource://gre/modules/ContactService.jsm");
 }
 
-SpecialPowers.addPermission("contacts-write", true, document);
-SpecialPowers.addPermission("contacts-read", true, document);
-SpecialPowers.addPermission("contacts-create", true, document);
-
 // Some helpful global vars
 var isAndroid = (navigator.userAgent.indexOf("Android") !== -1);
 
 var defaultOptions = {
   sortBy: "givenName",
 };
 
-var mozContacts = navigator.mozContacts;
+// Make sure we only touch |navigator.mozContacts| after we have the necessary
+// permissions, or we'll race when checking the listen permission needed for the 
+// oncontactchange event. This is only needed for tests because at first we have
+// the permission set to UNKNOWN_ACTION. That should never happen for real apps,
+// see dom/apps/PermissionsTable.jsm.
+var mozContacts;
 
 // To test sorting
 var c1 = {
   name: ["a a"],
   familyName: ["a"],
   givenName: ["a"],
 };
 
@@ -490,14 +491,21 @@ function next() {
 SimpleTest.waitForExplicitFinish();
 
 function start_tests() {
   // Skip tests on Android < 4.0 due to test failures on tbpl (see bugs 897924 & 888891)
   let androidVersion = SpecialPowers.Cc['@mozilla.org/system-info;1']
                                     .getService(SpecialPowers.Ci.nsIPropertyBag2)
                                     .getProperty('version');
   if (!isAndroid || androidVersion >= 14) {
-    next();
+    SpecialPowers.pushPermissions([
+      {type: "contacts-write", allow: 1, context: document},
+      {type: "contacts-read", allow: 1, context: document},
+      {type: "contacts-create", allow: 1, context: document},
+    ], function() {
+      mozContacts = navigator.mozContacts;
+      next();
+    });
   } else {
     ok(true, "Skip tests on Android < 4.0 (bugs 897924 & 888891");
     SimpleTest.finish();
   }
 }