Bug 1358384 - Test the persistent-storage permission based on the pref-on/off state, r=johannh draft
authorFischer.json <fischer.json@gmail.com>
Fri, 21 Apr 2017 00:04:53 +0800
changeset 571905 13843962607ef9f6b67efd64c80a0c85b68d3588
parent 569138 0b77ed3f26c5335503bc16e85b8c067382e7bb1e
child 626907 a251322ec628d785aecf48626b579cee9bf63f92
push id56948
push userbmo:fliu@mozilla.com
push dateWed, 03 May 2017 13:28:50 +0000
reviewersjohannh
bugs1358384
milestone55.0a1
Bug 1358384 - Test the persistent-storage permission based on the pref-on/off state, r=johannh The persistent-storage permission is still only pref-on on Nightly so this patch would test it only when it is pref-on. MozReview-Commit-ID: Ei64cpJslgU
browser/modules/test/unit/test_SitePermissions.js
--- a/browser/modules/test/unit/test_SitePermissions.js
+++ b/browser/modules/test/unit/test_SitePermissions.js
@@ -1,20 +1,28 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 "use strict";
 
 Components.utils.import("resource:///modules/SitePermissions.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+const STORAGE_MANAGER_ENABLED = Services.prefs.getBoolPref("browser.storageManager.enabled");
+
 add_task(function* testPermissionsListing() {
-  Assert.deepEqual(SitePermissions.listPermissions().sort(),
-    ["camera", "cookie", "desktop-notification", "focus-tab-by-prompt", "geo", "image",
-     "indexedDB", "install", "microphone", "persistent-storage", "popup", "screen"],
+  let expectedPermissions = ["camera", "cookie", "desktop-notification", "focus-tab-by-prompt",
+     "geo", "image", "indexedDB", "install", "microphone", "popup", "screen"];
+  if (STORAGE_MANAGER_ENABLED) {
+    // The persistent-storage permission is still only pref-on on Nightly
+    // so we add it only when it's pref-on.
+    // Should remove this checking and add it as default after it is fully pref-on.
+    expectedPermissions.push("persistent-storage");
+  }
+  Assert.deepEqual(SitePermissions.listPermissions().sort(), expectedPermissions.sort(),
     "Correct list of all permissions");
 });
 
 add_task(function* testGetAllByURI() {
   // check that it returns an empty array on an invalid URI
   // like a file URI, which doesn't support site permissions
   let wrongURI = Services.io.newURI("file:///example.js")
   Assert.deepEqual(SitePermissions.getAllByURI(wrongURI), []);
@@ -68,17 +76,23 @@ add_task(function* testGetAvailableState
                      SitePermissions.BLOCK ]);
 });
 
 add_task(function* testExactHostMatch() {
   let uri = Services.io.newURI("https://example.com");
   let subUri = Services.io.newURI("https://test1.example.com");
 
   let exactHostMatched = ["desktop-notification", "focus-tab-by-prompt", "camera",
-                          "microphone", "screen", "geo", "persistent-storage"];
+                          "microphone", "screen", "geo"];
+  if (STORAGE_MANAGER_ENABLED) {
+    // The persistent-storage permission is still only pref-on on Nightly
+    // so we add it only when it's pref-on.
+    // Should remove this checking and add it as default after it is fully pref-on.
+    exactHostMatched.push("persistent-storage");
+  }
   let nonExactHostMatched = ["image", "cookie", "popup", "install", "indexedDB"];
 
   let permissions = SitePermissions.listPermissions();
   for (let permission of permissions) {
     SitePermissions.set(uri, permission, SitePermissions.ALLOW);
 
     if (exactHostMatched.includes(permission)) {
       // Check that the sub-origin does not inherit the permission from its parent.