Bug 1490811 - Part 2: Add a test for the basic functionality of the storage access prompt r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Nov 2018 21:23:18 +0000
changeset 507343 f2bf86926c655278bd1d0319b70eef55450bcee5
parent 507342 8e3bf28192dff3eea2e163c4dbf56bc02da86430
child 507344 0c537d7bf40a6dff095bf73dfa1a7455ef02956f
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1490811
milestone65.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 1490811 - Part 2: Add a test for the basic functionality of the storage access prompt r=johannh Depends on D12467 Differential Revision: https://phabricator.services.mozilla.com/D12507
browser/modules/test/browser/browser_PermissionUI_prompts.js
browser/modules/test/browser/head.js
--- a/browser/modules/test/browser/browser_PermissionUI_prompts.js
+++ b/browser/modules/test/browser/browser_PermissionUI_prompts.js
@@ -32,67 +32,82 @@ add_task(async function test_midi_permis
 
 // Tests that AutoplayPermissionPrompt works as expected
 add_task(async function test_autoplay_permission_prompt() {
   Services.prefs.setIntPref("media.autoplay.default", Ci.nsIAutoplay.PROMPT);
   await testPrompt(PermissionUI.AutoplayPermissionPrompt);
   Services.prefs.clearUserPref("media.autoplay.default");
 });
 
+// Tests that AutoplayPermissionPrompt works as expected
+add_task(async function test_storage_access_permission_prompt() {
+  await testPrompt(PermissionUI.StorageAccessPermissionPrompt);
+});
+
 async function testPrompt(Prompt) {
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: "http://example.com",
   }, async function(browser) {
     let mockRequest = makeMockPermissionRequest(browser);
     let principal = mockRequest.principal;
     let TestPrompt = new Prompt(mockRequest);
     let permissionKey = TestPrompt.usePermissionManager &&
                         TestPrompt.permissionKey;
 
     registerCleanupFunction(function() {
-      SitePermissions.remove(principal.URI, permissionKey);
+      if (permissionKey) {
+        SitePermissions.remove(principal.URI, permissionKey);
+      }
     });
 
     let shownPromise =
       BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
     TestPrompt.prompt();
     await shownPromise;
     let notification =
       PopupNotifications.getNotification(TestPrompt.notificationID, browser);
     Assert.ok(notification, "Should have gotten the notification");
 
-    let curPerm = SitePermissions.get(principal.URI, permissionKey, browser);
-    Assert.equal(curPerm.state, SitePermissions.UNKNOWN,
-                 "Should be no permission set to begin with.");
+    let curPerm;
+    if (permissionKey) {
+      curPerm = SitePermissions.get(principal.URI, permissionKey, browser);
+      Assert.equal(curPerm.state, SitePermissions.UNKNOWN,
+                   "Should be no permission set to begin with.");
+    }
 
     // First test denying the permission request without the checkbox checked.
     let popupNotification = getPopupNotificationNode();
     popupNotification.checkbox.checked = false;
 
     let isNotificationPrompt = Prompt == PermissionUI.DesktopNotificationPermissionPrompt;
     let isPersistentStoragePrompt = Prompt == PermissionUI.PersistentStoragePermissionPrompt;
+    let isStorageAccessPrompt = Prompt == PermissionUI.StorageAccessPermissionPrompt;
 
-    let expectedSecondaryActionsCount = isNotificationPrompt || isPersistentStoragePrompt ? 2 : 1;
+    let expectedSecondaryActionsCount = isNotificationPrompt ||
+                                        isPersistentStoragePrompt ||
+                                        isStorageAccessPrompt ? 2 : 1;
     Assert.equal(notification.secondaryActions.length, expectedSecondaryActionsCount,
                  "There should only be " + expectedSecondaryActionsCount + " secondary action(s)");
     await clickSecondaryAction();
-    curPerm = SitePermissions.get(principal.URI, permissionKey, browser);
-    Assert.deepEqual(curPerm, {
-                       state: SitePermissions.BLOCK,
-                       scope: SitePermissions.SCOPE_TEMPORARY,
-                     }, "Should have denied the action temporarily");
+    if (permissionKey) {
+      curPerm = SitePermissions.get(principal.URI, permissionKey, browser);
+      Assert.deepEqual(curPerm, {
+                         state: SitePermissions.BLOCK,
+                         scope: SitePermissions.SCOPE_TEMPORARY,
+                       }, "Should have denied the action temporarily");
 
-    Assert.ok(mockRequest._cancelled,
-              "The request should have been cancelled");
-    Assert.ok(!mockRequest._allowed,
-              "The request should not have been allowed");
+      Assert.ok(mockRequest._cancelled,
+                "The request should have been cancelled");
+      Assert.ok(!mockRequest._allowed,
+                "The request should not have been allowed");
 
-    SitePermissions.remove(principal.URI, permissionKey, browser);
-    mockRequest._cancelled = false;
+      SitePermissions.remove(principal.URI, permissionKey, browser);
+      mockRequest._cancelled = false;
+    }
 
     // Bring the PopupNotification back up now...
     shownPromise =
       BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
     TestPrompt.prompt();
     await shownPromise;
 
     // Test denying the permission request with the checkbox checked (for geolocation)
@@ -103,44 +118,50 @@ async function testPrompt(Prompt) {
       secondaryActionToClickIndex = 1;
     } else {
       popupNotification.checkbox.checked = true;
     }
 
     Assert.equal(notification.secondaryActions.length, expectedSecondaryActionsCount,
                  "There should only be " + expectedSecondaryActionsCount + " secondary action(s)");
     await clickSecondaryAction(secondaryActionToClickIndex);
-    curPerm = SitePermissions.get(principal.URI, permissionKey);
-    Assert.deepEqual(curPerm, {
-                       state: SitePermissions.BLOCK,
-                       scope: SitePermissions.SCOPE_PERSISTENT,
-                     }, "Should have denied the action permanently");
-    Assert.ok(mockRequest._cancelled,
-              "The request should have been cancelled");
-    Assert.ok(!mockRequest._allowed,
-              "The request should not have been allowed");
+    if (permissionKey) {
+      curPerm = SitePermissions.get(principal.URI, permissionKey);
+      Assert.deepEqual(curPerm, {
+                         state: SitePermissions.BLOCK,
+                         scope: SitePermissions.SCOPE_PERSISTENT,
+                       }, "Should have denied the action permanently");
+      Assert.ok(mockRequest._cancelled,
+                "The request should have been cancelled");
+      Assert.ok(!mockRequest._allowed,
+                "The request should not have been allowed");
+    }
 
-    SitePermissions.remove(principal.URI, permissionKey);
-    mockRequest._cancelled = false;
+    if (permissionKey) {
+      SitePermissions.remove(principal.URI, permissionKey);
+      mockRequest._cancelled = false;
+    }
 
     // Bring the PopupNotification back up now...
     shownPromise =
       BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
     TestPrompt.prompt();
     await shownPromise;
 
     // Test allowing the permission request with the checkbox checked.
     popupNotification = getPopupNotificationNode();
     popupNotification.checkbox.checked = true;
 
     await clickMainAction();
-    curPerm = SitePermissions.get(principal.URI, permissionKey);
-    Assert.deepEqual(curPerm, {
-                       state: SitePermissions.ALLOW,
-                       scope: SitePermissions.SCOPE_PERSISTENT,
-                     }, "Should have allowed the action permanently");
-    Assert.ok(!mockRequest._cancelled,
-              "The request should not have been cancelled");
-    Assert.ok(mockRequest._allowed,
-              "The request should have been allowed");
+    if (permissionKey) {
+      curPerm = SitePermissions.get(principal.URI, permissionKey);
+      Assert.deepEqual(curPerm, {
+                         state: SitePermissions.ALLOW,
+                         scope: SitePermissions.SCOPE_PERSISTENT,
+                       }, "Should have allowed the action permanently");
+      Assert.ok(!mockRequest._cancelled,
+                "The request should not have been cancelled");
+      Assert.ok(mockRequest._allowed,
+                "The request should have been allowed");
+    }
   });
 }
 
--- a/browser/modules/test/browser/head.js
+++ b/browser/modules/test/browser/head.js
@@ -176,16 +176,17 @@ function makeMockPermissionRequest(brows
     options: Cc["@mozilla.org/array;1"].createInstance(Ci.nsIArray),
     QueryInterface: ChromeUtils.generateQI([Ci.nsIContentPermissionType]),
   };
   let types = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
   types.appendElement(type);
   let result = {
     types,
     principal: browser.contentPrincipal,
+    topLevelPrincipal: browser.contentPrincipal,
     requester: null,
     _cancelled: false,
     cancel() {
       this._cancelled = true;
     },
     _allowed: false,
     allow() {
       this._allowed = true;