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 500256 a58c07d9a7fa325c65fb00b7a6b2b8cc25a7af1d
parent 500255 c29585c36177f6c1fa00049c519f89b12bd779e3
child 500257 4868fc98a7b612a705d306b60f4c89707791f714
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1498369
milestone64.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 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());
     });