Bug 1498369 - Ensure the promise returned from Document.hasStorageAccess() will propagate user activation r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 17 Oct 2018 17:51:45 +0000
changeset 490151 a58c07d9a7fa325c65fb00b7a6b2b8cc25a7af1d
parent 490150 c29585c36177f6c1fa00049c519f89b12bd779e3
child 490152 4868fc98a7b612a705d306b60f4c89707791f714
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbaku
bugs1498369
milestone64.0a1
Bug 1498369 - Ensure the promise returned from Document.hasStorageAccess() will propagate user activation r=baku Differential Revision: https://phabricator.services.mozilla.com/D9011
dom/base/nsDocument.cpp
toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -13648,17 +13648,18 @@ already_AddRefed<mozilla::dom::Promise>
 nsIDocument::HasStorageAccess(mozilla::ErrorResult& aRv)
 {
   nsIGlobalObject* global = GetScopeObject();
   if (!global) {
     aRv.Throw(NS_ERROR_NOT_AVAILABLE);
     return nullptr;
   }
 
-  RefPtr<Promise> promise = Promise::Create(global, aRv);
+  RefPtr<Promise> promise = Promise::Create(global, aRv,
+                                            Promise::ePropagateUserInteraction);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   if (NodePrincipal()->GetIsNullPrincipal()) {
     promise->MaybeResolve(false);
     return promise.forget();
   }
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
@@ -5,16 +5,30 @@ AntiTracking.runTest("Storage Access API
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     let [threw, rejected] = await callRequestStorageAccess(dwu => {
       ok(dwu.isHandlingUserInput,
          "Promise handler must run as if we're handling user input");
     });
     ok(!threw, "requestStorageAccess should not throw");
     ok(!rejected, "requestStorageAccess should be available");
+
+    let dwu = SpecialPowers.getDOMWindowUtils(window);
+    let helper = dwu.setHandlingUserInput(true);
+
+    let promise;
+    try {
+      promise = document.hasStorageAccess();
+    } finally {
+      helper.destruct();
+    }
+    await promise.then(_ => {
+      ok(dwu.isHandlingUserInput,
+         "Promise handler must run as if we're handling user input");
+    });
   },
 
   null, // non-blocking callback
   // cleanup function
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });