Bug 871323 - Remove enablePrivilege from offline tests. r?mayhemer draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 26 Jan 2017 23:32:19 +0900
changeset 466920 307f2ecc0b7dc050252b9aee1045b9047bc31aef
parent 466730 a338e596b1d9f37186aaeddcfaa572ae043e578d
child 543567 c151a971f7a6f6a7ff1bea3cd10b19dc15661184
push id43049
push userVYV03354@nifty.ne.jp
push dateThu, 26 Jan 2017 22:14:05 +0000
reviewersmayhemer
bugs871323
milestone54.0a1
Bug 871323 - Remove enablePrivilege from offline tests. r?mayhemer MozReview-Commit-ID: 7vshwGVAi6h
dom/tests/mochitest/ajax/offline/offlineTests.js
dom/tests/mochitest/ajax/offline/test_fallback.html
dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html
dom/tests/mochitest/ajax/offline/test_updateCheck.html
--- a/dom/tests/mochitest/ajax/offline/offlineTests.js
+++ b/dom/tests/mochitest/ajax/offline/offlineTests.js
@@ -47,17 +47,18 @@ fetch: function(callback)
     callback(this.contents);
     return;
   }
 
   var url = this.urls.shift();
   var self = this;
 
   var cacheStorage = OfflineTest.getActiveStorage();
-  cacheStorage.asyncOpenURI(CommonUtils.makeURI(url), "", Ci.nsICacheStorage.OPEN_READONLY, this);
+  cacheStorage.asyncOpenURI(CommonUtils.makeURI(url), "", Ci.nsICacheStorage.OPEN_READONLY,
+                            SpecialPowers.wrapCallbackObject(this));
 }
 };
 
 var OfflineTest = {
 
 _allowedByDefault: false,
 
 _hasSlave: false,
@@ -91,18 +92,16 @@ setupChild: function()
  * Setup the tests.  This will reload the current page in a new window
  * if necessary.
  *
  * @return boolean Whether this window is the slave window
  *                 to actually run the test in.
  */
 setup: function()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   try {
     this._allowedByDefault = SpecialPowers.getBoolPref("offline-apps.allow_by_default");
   } catch (e) {}
 
   if (this._allowedByDefault) {
     this._masterWindow = window;
 
     return true;
@@ -251,33 +250,33 @@ failEvent: function(e)
 },
 
 // The offline API as specified has no way to watch the load of a resource
 // added with applicationCache.mozAdd().
 waitForAdd: function(url, onFinished) {
   // Check every half second for ten seconds.
   var numChecks = 20;
 
-  var waitForAddListener = {
+  var waitForAddListener = SpecialPowers.wrapCallbackObject({
     onCacheEntryCheck: function() { return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; },
     onCacheEntryAvailable: function(entry, isnew, applicationCache, status) {
       if (entry) {
         entry.close();
         onFinished();
         return;
       }
 
       if (--numChecks == 0) {
         onFinished();
         return;
       }
 
       setTimeout(OfflineTest.priv(waitFunc), 500);
     }
-  };
+  });
 
   var waitFunc = function() {
     var cacheStorage = OfflineTest.getActiveStorage();
     cacheStorage.asyncOpenURI(CommonUtils.makeURI(url), "", Ci.nsICacheStorage.OPEN_READONLY, waitForAddListener);
   }
 
   setTimeout(this.priv(waitFunc), 500);
 },
@@ -375,17 +374,17 @@ checkCache: function(url, expectEntry, c
       this.ok(false, url + " should exist in the offline cache (no session)");
     } else {
       this.ok(true, url + " should not exist in the offline cache (no session)");
     }
     if (callback) setTimeout(this.priv(callback), 0);
     return;
   }
 
-  var _checkCacheListener = {
+  var _checkCacheListener = SpecialPowers.wrapCallbackObject({
     onCacheEntryCheck: function() { return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; },
     onCacheEntryAvailable: function(entry, isnew, applicationCache, status) {
       if (entry) {
         if (expectEntry) {
           OfflineTest.ok(true, url + " should exist in the offline cache");
         } else {
           OfflineTest.ok(false, url + " should not exist in the offline cache");
         }
@@ -405,17 +404,17 @@ checkCache: function(url, expectEntry, c
             OfflineTest.ok(mustBeValid, url + " should not exist in the offline cache");
           }
         } else {
           OfflineTest.ok(false, "got invalid error for " + url);
         }
       }
       if (callback) setTimeout(OfflineTest.priv(callback), 0);
     }
-  };
+  });
 
   cacheStorage.asyncOpenURI(CommonUtils.makeURI(url), "", Ci.nsICacheStorage.OPEN_READONLY, _checkCacheListener);
 },
 
 setSJSState: function(sjsPath, stateQuery)
 {
   var client = new XMLHttpRequest();
   client.open("GET", sjsPath + "?state=" + stateQuery, false);
--- a/dom/tests/mochitest/ajax/offline/test_fallback.html
+++ b/dom/tests/mochitest/ajax/offline/test_fallback.html
@@ -96,18 +96,16 @@ function onFallbackLoad(fallbackIdentifi
 
 function finishTest()
 {
   OfflineTest.teardownAndFinish();
 }
 
 function finalize()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var entries = [
     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub-non-existing.html", false],
     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html", false],
     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html", false],
     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace2/non-existing.html", false]
   ];
   OfflineTest.checkCacheEntries(entries, finishTest);
 }
--- a/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html
+++ b/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html
@@ -35,17 +35,17 @@ function finish() {
   obs.notifyObservers(updateService, "disk-space-watcher", "free");
 
   OfflineTest.teardownAndFinish();
 }
 
 if (OfflineTest.setup()) {
   obs.notifyObservers(updateService, "disk-space-watcher", "full");
 
-  var updateObserver = {
+  var updateObserver = SpecialPowers.wrapCallbackObject({
     updateStateChanged: function (aUpdate, aState) {
       switch(aState) {
         case Ci.nsIOfflineCacheUpdateObserver.STATE_ERROR:
           errorReceived = true;
           OfflineTest.ok(true, "Expected error. Update canceled");
         break;
         case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED:
           aUpdate.removeObserver(this);
@@ -63,17 +63,17 @@ if (OfflineTest.setup()) {
         case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS:
           aUpdate.removeObserver(this);
           OfflineTest.ok(false, "The update was supposed to be canceled");
           finish();
           break;
       }
     },
     applicationCacheAvailable: function() {}
-  };
+  });
 
   var manifest = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest";
   var ioService = Cc["@mozilla.org/network/io-service;1"]
                   .getService(Ci.nsIIOService);
   var manifestURI = ioService.newURI(manifest, null, null);
   var documentURI = ioService.newURI(document.documentURI, null, null);
   var update = updateService.scheduleUpdate(manifestURI, documentURI, systemPrincipal, window);
   update.addObserver(updateObserver, false);
--- a/dom/tests/mochitest/ajax/offline/test_updateCheck.html
+++ b/dom/tests/mochitest/ajax/offline/test_updateCheck.html
@@ -29,55 +29,55 @@ var manifestURI = Cc["@mozilla.org/netwo
 var updateService = Cc['@mozilla.org/offlinecacheupdate-service;1']
                     .getService(Ci.nsIOfflineCacheUpdateService);
 
 var systemPrincipal = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
 
 function manifestCached()
 {
   // Run first check for an update
-  updateService.checkForUpdate(manifestURI, systemPrincipal, {
+  updateService.checkForUpdate(manifestURI, systemPrincipal, SpecialPowers.wrapCallbackObject({
     observe: function(subject, topic, data) {
       OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail");
 
       // Change the manifest content
       OfflineTest.setSJSState(manifest, "second");
 
       // Check we now get notification on update ready
-      updateService.checkForUpdate(manifestURI, systemPrincipal, {
+      updateService.checkForUpdate(manifestURI, systemPrincipal, SpecialPowers.wrapCallbackObject({
         observe: function(subject, topic, data) {
           OfflineTest.is(topic, "offline-cache-update-available", "Update avail (1)");
 
           // Do the check again.  We must get the same result.  Double check is here
           // to make sure we don't overwrite any data in the cache by the check it self.
-          updateService.checkForUpdate(manifestURI, systemPrincipal, {
+          updateService.checkForUpdate(manifestURI, systemPrincipal, SpecialPowers.wrapCallbackObject({
             observe: function(subject, topic, data) {
               OfflineTest.is(topic, "offline-cache-update-available", "Update avail (2)");
 
               // Update the manifest, invokes manifestUpdated()
               applicationCache.onupdateready = OfflineTest.priv(manifestUpdated);
               applicationCache.update();
             }
-          });
+          }));
         }
-      });
+      }));
     }
-  });
+  }));
 }
 
 function manifestUpdated()
 {
   // Check for an update after manifest has been updated
-  updateService.checkForUpdate(manifestURI, systemPrincipal, {
+  updateService.checkForUpdate(manifestURI, systemPrincipal, SpecialPowers.wrapCallbackObject({
     observe: function(subject, topic, data) {
       OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail (2)");
 
       OfflineTest.teardownAndFinish();
     }
-  });
+  }));
 }
 
 if (OfflineTest.setup()) {
   applicationCache.onerror = OfflineTest.failEvent;
   applicationCache.oncached = OfflineTest.priv(manifestCached);
 }
 
 </script>