Bug 1349990 - Update host matching for webrtc prompts. r=Paolo, a=gchang
authorJohann Hofmann <jhofmann@mozilla.com>
Fri, 24 Mar 2017 13:13:18 +0100
changeset 377052 67a86746e6f1ab170c9fa6b1abb0e5d5a8f10258
parent 377051 b20ed8d1b4d6d47ae9acff9bb370b6f5631d9149
child 377053 38fce2379faf57f70099f00bb0d26ab9e3ff7aee
push id7121
push userryanvm@gmail.com
push dateWed, 29 Mar 2017 15:12:09 +0000
treeherdermozilla-beta@79bb8c332fd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaolo, gchang
bugs1349990
milestone53.0
Bug 1349990 - Update host matching for webrtc prompts. r=Paolo, a=gchang MozReview-Commit-ID: IIuHvVTy2G7
browser/modules/SitePermissions.jsm
browser/modules/test/xpcshell/test_SitePermissions.js
--- a/browser/modules/SitePermissions.jsm
+++ b/browser/modules/SitePermissions.jsm
@@ -572,19 +572,26 @@ var gPermissionObject = {
     }
   },
 
   "desktop-notification": {
     exactHostMatch: true,
     labelID: "desktop-notification2",
   },
 
-  "camera": {},
-  "microphone": {},
+  "camera": {
+    exactHostMatch: true,
+  },
+
+  "microphone": {
+    exactHostMatch: true,
+  },
+
   "screen": {
+    exactHostMatch: true,
     states: [ SitePermissions.UNKNOWN, SitePermissions.BLOCK ],
   },
 
   "popup": {
     getDefault() {
       return Services.prefs.getBoolPref("dom.disable_open_during_load") ?
                SitePermissions.BLOCK : SitePermissions.ALLOW;
     }
--- a/browser/modules/test/xpcshell/test_SitePermissions.js
+++ b/browser/modules/test/xpcshell/test_SitePermissions.js
@@ -62,8 +62,40 @@ add_task(function* testGetAvailableState
                    [ SitePermissions.ALLOW,
                      SitePermissions.ALLOW_COOKIES_FOR_SESSION,
                      SitePermissions.BLOCK ]);
 
   Assert.deepEqual(SitePermissions.getAvailableStates("popup"),
                    [ SitePermissions.ALLOW,
                      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", "camera", "microphone", "screen", "geo"];
+  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.
+      Assert.equal(SitePermissions.get(subUri, permission).state, SitePermissions.UNKNOWN);
+    } else if (nonExactHostMatched.includes(permission)) {
+      // Check that the sub-origin does inherit the permission from its parent.
+      Assert.equal(SitePermissions.get(subUri, permission).state, SitePermissions.ALLOW);
+    } else {
+      Assert.ok(false, `Found an unknown permission ${permission} in exact host match test.` +
+                       "Please add new permissions from SitePermissions.jsm to this test.");
+    }
+
+    // Check that the permission can be made specific to the sub-origin.
+    SitePermissions.set(subUri, permission, SitePermissions.BLOCK);
+    Assert.equal(SitePermissions.get(subUri, permission).state, SitePermissions.BLOCK);
+    Assert.equal(SitePermissions.get(uri, permission).state, SitePermissions.ALLOW);
+
+    SitePermissions.remove(subUri, permission);
+    SitePermissions.remove(uri, permission);
+  }
+});