зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1732919) for wpt failures at requestStorageAccess.sub.window.html on a CLOSED TREE
Backed out changeset 00afa32396d0 (bug 1732919) Backed out changeset 887e3b523bf3 (bug 1732919) Backed out changeset 096f7a2f65fe (bug 1732919)
This commit is contained in:
Родитель
893ce2f4de
Коммит
383080bb17
|
@ -129,6 +129,7 @@ support-files =
|
|||
test-message-categories-workers.js
|
||||
test-mixedcontent-securityerrors.html
|
||||
test-navigate-to-parse-error.html
|
||||
test-nested-iframe-storageaccess-errors.html
|
||||
test-network-exceptions.html
|
||||
test-network-request.html
|
||||
test-network.html
|
||||
|
@ -146,6 +147,7 @@ support-files =
|
|||
test-sourcemap.min.js
|
||||
test-sourcemap.min.js.map
|
||||
test-stacktrace-location-debugger-link.html
|
||||
test-storageaccess-errors.html
|
||||
test-subresource-security-error.html
|
||||
test-subresource-security-error.js
|
||||
test-subresource-security-error.js^headers^
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const TEST_URI_FIRST_PARTY = "https://example.com";
|
||||
const TEST_URI_THIRD_PARTY = "https://itisatracker.org";
|
||||
const TEST_URI =
|
||||
"https://example.com/browser/devtools/client/webconsole/test/browser/test-storageaccess-errors.html";
|
||||
const LEARN_MORE_URI =
|
||||
"https://developer.mozilla.org/docs/Web/API/Document/requestStorageAccess" +
|
||||
DOCS_GA_PARAMS;
|
||||
|
@ -18,66 +18,8 @@ registerCleanupFunction(function() {
|
|||
UrlClassifierTestUtils.cleanupTestTrackers();
|
||||
});
|
||||
|
||||
/**
|
||||
* Run document.requestStorageAccess in an iframe.
|
||||
* @param {Object} options - Request / iframe options.
|
||||
* @param {boolean} [options.withUserActivation] - Whether the requesting iframe
|
||||
* should have user activation prior to calling rsA.
|
||||
* @param {string} [options.sandboxAttr] - Iframe sandbox attributes.
|
||||
* @param {boolean} [options.nested] - If the iframe calling rsA should be
|
||||
* nested in another same-origin iframe.
|
||||
*/
|
||||
async function runRequestStorageAccess({
|
||||
withUserActivation = false,
|
||||
sandboxAttr = "",
|
||||
nested = false,
|
||||
}) {
|
||||
let parentBC = gBrowser.selectedBrowser.browsingContext;
|
||||
|
||||
// Spawn the rsA iframe in an iframe.
|
||||
if (nested) {
|
||||
parentBC = await SpecialPowers.spawn(
|
||||
parentBC,
|
||||
[TEST_URI_THIRD_PARTY],
|
||||
async uri => {
|
||||
const frame = content.document.createElement("iframe");
|
||||
frame.setAttribute("src", uri);
|
||||
const loadPromise = ContentTaskUtils.waitForEvent(frame, "load");
|
||||
content.document.body.appendChild(frame);
|
||||
await loadPromise;
|
||||
return frame.browsingContext;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Create an iframe which is a third party to the top level.
|
||||
const frameBC = await SpecialPowers.spawn(
|
||||
parentBC,
|
||||
[TEST_URI_THIRD_PARTY, sandboxAttr],
|
||||
async (uri, sandbox) => {
|
||||
const frame = content.document.createElement("iframe");
|
||||
frame.setAttribute("src", uri);
|
||||
if (sandbox) {
|
||||
frame.setAttribute("sandbox", sandbox);
|
||||
}
|
||||
const loadPromise = ContentTaskUtils.waitForEvent(frame, "load");
|
||||
content.document.body.appendChild(frame);
|
||||
await loadPromise;
|
||||
return frame.browsingContext;
|
||||
}
|
||||
);
|
||||
|
||||
// Call requestStorageAccess in the iframe.
|
||||
await SpecialPowers.spawn(frameBC, [withUserActivation], userActivation => {
|
||||
if (userActivation) {
|
||||
content.document.notifyUserGestureActivation();
|
||||
}
|
||||
content.document.requestStorageAccess();
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI_FIRST_PARTY);
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
|
||||
async function checkErrorMessage(text) {
|
||||
const message = await waitFor(
|
||||
|
@ -115,22 +57,9 @@ add_task(async function() {
|
|||
const sandboxed =
|
||||
"document.requestStorageAccess() may not be called in a sandboxed iframe without allow-storage-access-by-user-activation in its sandbox attribute.";
|
||||
|
||||
await runRequestStorageAccess({ withUserActivation: false });
|
||||
await checkErrorMessage(userGesture);
|
||||
|
||||
await runRequestStorageAccess({ withUserActivation: true, nested: true });
|
||||
await checkErrorMessage(nested);
|
||||
|
||||
await runRequestStorageAccess({
|
||||
withUserActivation: true,
|
||||
sandboxAttr: "allow-scripts",
|
||||
});
|
||||
await checkErrorMessage(nullPrincipal);
|
||||
|
||||
await runRequestStorageAccess({
|
||||
withUserActivation: true,
|
||||
sandboxAttr: "allow-same-origin allow-scripts",
|
||||
});
|
||||
await checkErrorMessage(nested);
|
||||
await checkErrorMessage(sandboxed);
|
||||
|
||||
await closeConsole();
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html dir="ltr" xml:lang="en-US" lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>requestStorageAccess test</title>
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="https://itisatracker.org/browser/devtools/client/webconsole/test/browser/test-storageaccess-errors.html"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html dir="ltr" xml:lang="en-US" lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>requestStorageAccess test</title>
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="ifr1"></iframe>
|
||||
<iframe id="ifr2" sandbox="allow-scripts"></iframe>
|
||||
<iframe id="ifr3" sandbox="allow-same-origin allow-scripts"></iframe>
|
||||
<iframe id="ifr4"></iframe>
|
||||
<script>
|
||||
'use strict';
|
||||
if (window.location.host == "itisatracker.org") {
|
||||
document.requestStorageAccess();
|
||||
} else {
|
||||
document.getElementById("ifr1").setAttribute("src", "https://itisatracker.org/browser/devtools/client/webconsole/test/browser/test-nested-iframe-storageaccess-errors.html");
|
||||
document.getElementById("ifr2").setAttribute("src", "https://itisatracker.org/browser/devtools/client/webconsole/test/browser/test-storageaccess-errors.html");
|
||||
document.getElementById("ifr3").setAttribute("src", "https://itisatracker.org/browser/devtools/client/webconsole/test/browser/test-storageaccess-errors.html");
|
||||
document.getElementById("ifr4").setAttribute("src", "https://itisatracker.org/browser/devtools/client/webconsole/test/browser/test-storageaccess-errors.html");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -16580,24 +16580,15 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
// Propagate user input event handling to the resolve handler
|
||||
RefPtr<Promise> promise =
|
||||
Promise::Create(global, aRv, Promise::ePropagateUserInteraction);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Window doesn't have user activation, reject.
|
||||
if (!this->HasValidTransientUserGestureActivation()) {
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
||||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessUserGesture");
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner = GetInnerWindow();
|
||||
if (!inner) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16606,7 +16597,6 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
RefPtr<nsGlobalWindowOuter> outer =
|
||||
nsGlobalWindowOuter::Cast(inner->GetOuterWindow());
|
||||
if (!outer) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16622,14 +16612,12 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessNullPrincipal");
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
RefPtr<BrowsingContext> bc = GetBrowsingContext();
|
||||
if (!bc) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16652,14 +16640,12 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
if (bc->Top()->IsInProcess()) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> topOuter = bc->Top()->GetDOMWindow();
|
||||
if (!topOuter) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<Document> topLevelDoc = topOuter->GetExtantDoc();
|
||||
if (!topLevelDoc) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16678,7 +16664,6 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::errorFlag, nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES, "RequestStorageAccessSandboxed");
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16689,7 +16674,16 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::errorFlag, nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES, "RequestStorageAccessNested");
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Step 8. If the browser is not processing a user gesture, reject.
|
||||
if (!UserActivation::IsHandlingUserInput()) {
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
||||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessUserGesture");
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16707,7 +16701,6 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
// site, reject.
|
||||
if (antiTrackingRejectedReason ==
|
||||
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16802,23 +16795,17 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
|
|||
|
||||
return p;
|
||||
};
|
||||
|
||||
// Consume user activation before entering the async part of this method.
|
||||
// This prevents usage of other transient activation-gated APIs.
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
|
||||
ContentBlocking::AllowAccessFor(
|
||||
NodePrincipal(), bc, ContentBlockingNotifier::eStorageAccessAPI,
|
||||
performFinalChecks)
|
||||
->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[self, outer, promise] {
|
||||
[outer, promise] {
|
||||
// Step 10. Grant the document access to cookies and store
|
||||
// that fact for
|
||||
// the purposes of future calls to
|
||||
// hasStorageAccess() and requestStorageAccess().
|
||||
outer->SetStorageAccessPermissionGranted(true);
|
||||
self->NotifyUserGestureActivation();
|
||||
promise->MaybeResolveWithUndefined();
|
||||
},
|
||||
[outer, promise] {
|
||||
|
@ -16843,24 +16830,14 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
RefPtr<Promise> promise =
|
||||
Promise::Create(global, aRv, Promise::ePropagateUserInteraction);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Window doesn't have user activation, reject.
|
||||
if (!this->HasValidTransientUserGestureActivation()) {
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
||||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessUserGesture");
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner = GetInnerWindow();
|
||||
if (!inner) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16868,7 +16845,6 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
// We only allow request storage access for third-party origin from the
|
||||
// first-party context.
|
||||
if (AntiTrackingUtils::IsThirdPartyWindow(inner, nullptr)) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16879,7 +16855,6 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessNullPrincipal");
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16904,11 +16879,20 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
}
|
||||
}
|
||||
|
||||
// If the browser is not processing a user gesture, reject.
|
||||
if (!UserActivation::IsHandlingUserInput()) {
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
||||
nsLiteralCString("requestStorageAccess"),
|
||||
this, nsContentUtils::eDOM_PROPERTIES,
|
||||
"RequestStorageAccessUserGesture");
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Check any additional rules that the browser has.
|
||||
if (CookieJarSettings()->GetRejectThirdPartyContexts()) {
|
||||
RefPtr<BrowsingContext> bc = GetBrowsingContext();
|
||||
if (!bc) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
@ -16917,17 +16901,12 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
thirdPartyURI, NodePrincipal()->OriginAttributesRef());
|
||||
|
||||
if (!principal) {
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
promise->MaybeRejectWithUndefined();
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
RefPtr<Document> self(this);
|
||||
|
||||
// Consume user activation before entering the async part of this method.
|
||||
// This prevents usage of other transient activation-gated APIs.
|
||||
this->ConsumeTransientUserGestureActivation();
|
||||
|
||||
auto performFinalChecks = [inner, self, principal]() {
|
||||
RefPtr<ContentBlocking::StorageAccessFinalCheckPromise::Private> p =
|
||||
new ContentBlocking::StorageAccessFinalCheckPromise::Private(
|
||||
|
@ -17047,10 +17026,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
|
|||
})
|
||||
->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[self, promise] {
|
||||
self->NotifyUserGestureActivation();
|
||||
promise->MaybeResolveWithUndefined();
|
||||
},
|
||||
[promise] { promise->MaybeResolveWithUndefined(); },
|
||||
[promise] { promise->MaybeRejectWithUndefined(); });
|
||||
|
||||
return promise.forget();
|
||||
|
|
|
@ -16,7 +16,7 @@ const button = document.getElementById("button")
|
|||
button.addEventListener("click", () => {
|
||||
is(domWindowUtils.isHandlingUserInput, true, "handling user input");
|
||||
|
||||
document.hasStorageAccess().then(() => {
|
||||
document.requestStorageAccess().then(() => {
|
||||
is(domWindowUtils.isHandlingUserInput, true, "still handling user input");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ add_task(async function test_explicit_object_prototype() {
|
|||
|
||||
button.addEventListener("click", () => {
|
||||
is(DOMWindowUtils.isHandlingUserInput, true, "handling user input");
|
||||
content.document.hasStorageAccess().then(() => {
|
||||
content.document.requestStorageAccess().then(() => {
|
||||
is(DOMWindowUtils.isHandlingUserInput, true,
|
||||
"still handling user input");
|
||||
Promise.resolve().then(() => {
|
||||
|
|
|
@ -37,7 +37,8 @@ AntiTracking._createTask({
|
|||
ok(document.cookie != "", "Nothing is blocked");
|
||||
|
||||
// requestStorageAccess should resolve
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
await document
|
||||
.requestStorageAccess()
|
||||
.then(() => {
|
||||
|
@ -46,7 +47,7 @@ AntiTracking._createTask({
|
|||
.catch(() => {
|
||||
ok(false, "Should grant storage access");
|
||||
});
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
},
|
||||
extraPrefs: null,
|
||||
expectedBlockingNotifications: 0,
|
||||
|
|
|
@ -37,7 +37,8 @@ AntiTracking._createTask({
|
|||
ok(document.cookie == "", "All is blocked");
|
||||
|
||||
// requestStorageAccess should reject
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
await document
|
||||
.requestStorageAccess()
|
||||
.then(() => {
|
||||
|
@ -46,7 +47,7 @@ AntiTracking._createTask({
|
|||
.catch(() => {
|
||||
ok(true, "Should not grant storage access");
|
||||
});
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
},
|
||||
extraPrefs: null,
|
||||
expectedBlockingNotifications:
|
||||
|
|
|
@ -177,9 +177,10 @@ add_task(async function test_privilege_api_with_reject_tracker() {
|
|||
|
||||
// Call the privilege API.
|
||||
await SpecialPowers.spawn(browser, [], async _ => {
|
||||
// The privilege API requires user activation. So, we set the user
|
||||
// activation flag before we call the API.
|
||||
content.document.notifyUserGestureActivation();
|
||||
// The privilege API requires a user gesture. So, we set the user handling
|
||||
// flag before we call the API.
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin(
|
||||
|
@ -189,7 +190,7 @@ add_task(async function test_privilege_api_with_reject_tracker() {
|
|||
ok(false, "The API shouldn't throw.");
|
||||
}
|
||||
|
||||
content.document.clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
});
|
||||
|
||||
// Verify if the storage access permission is set correctly.
|
||||
|
@ -273,7 +274,8 @@ add_task(async function test_privilege_api_with_dFPI() {
|
|||
await SpecialPowers.spawn(browser, [], async _ => {
|
||||
// The privilege API requires a user gesture. So, we set the user handling
|
||||
// flag before we call the API.
|
||||
content.document.notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin(
|
||||
|
@ -283,7 +285,7 @@ add_task(async function test_privilege_api_with_dFPI() {
|
|||
ok(false, "The API shouldn't throw.");
|
||||
}
|
||||
|
||||
content.document.clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
});
|
||||
|
||||
// Verify if the storage access permission is set correctly.
|
||||
|
@ -363,7 +365,8 @@ add_task(async function test_prompt() {
|
|||
let callAPIPromise = SpecialPowers.spawn(browser, [allow], async allow => {
|
||||
// The privilege API requires a user gesture. So, we set the user handling
|
||||
// flag before we call the API.
|
||||
content.document.notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
let isThrown = false;
|
||||
|
||||
try {
|
||||
|
@ -376,7 +379,7 @@ add_task(async function test_prompt() {
|
|||
|
||||
is(isThrown, !allow, `The API ${allow ? "shouldn't" : "should"} throw.`);
|
||||
|
||||
content.document.clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
});
|
||||
|
||||
await shownPromise;
|
||||
|
@ -444,7 +447,9 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw without user gesture.");
|
||||
|
||||
content.document.notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
isThrown = false;
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin();
|
||||
|
@ -453,7 +458,6 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw with no input.");
|
||||
|
||||
content.document.notifyUserGestureActivation();
|
||||
isThrown = false;
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin("");
|
||||
|
@ -463,7 +467,6 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw with empty string.");
|
||||
|
||||
content.document.notifyUserGestureActivation();
|
||||
isThrown = false;
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin("invalid url");
|
||||
|
@ -473,7 +476,7 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw with invalid url.");
|
||||
|
||||
content.document.clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
});
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/* import-globals-from antitracking_head.js */
|
||||
|
||||
AntiTracking.runTest(
|
||||
"Storage Access API returns promises that do not maintain user activation for calling its reject handler",
|
||||
"Storage Access API returns promises that maintain user activation for calling its reject handler",
|
||||
// blocking callback
|
||||
async _ => {
|
||||
/* import-globals-from storageAccessAPIHelpers.js */
|
||||
let [threw, rejected] = await callRequestStorageAccess(() => {
|
||||
let [threw, rejected] = await callRequestStorageAccess(dwu => {
|
||||
ok(
|
||||
!SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
"Promise reject handler must not have user activation"
|
||||
dwu.isHandlingUserInput,
|
||||
"Promise reject handler must run as if we're handling user input"
|
||||
);
|
||||
}, true);
|
||||
ok(!threw, "requestStorageAccess should not throw");
|
||||
|
|
|
@ -5,23 +5,30 @@ AntiTracking.runTest(
|
|||
// blocking callback
|
||||
async _ => {
|
||||
/* import-globals-from storageAccessAPIHelpers.js */
|
||||
let [threw, rejected] = await callRequestStorageAccess(() => {
|
||||
let [threw, rejected] = await callRequestStorageAccess(dwu => {
|
||||
ok(
|
||||
SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
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");
|
||||
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
await document.hasStorageAccess();
|
||||
|
||||
ok(
|
||||
SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
"Promise handler must run as if we're handling user input"
|
||||
);
|
||||
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
|
||||
|
|
|
@ -16,7 +16,8 @@ async function stillNoStorageAccess() {
|
|||
}
|
||||
|
||||
async function callRequestStorageAccess(callback, expectFail) {
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
let origin = new URL(location.href).origin;
|
||||
|
||||
|
@ -46,23 +47,23 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
p = document.requestStorageAccess();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
} finally {
|
||||
helper.destruct();
|
||||
}
|
||||
ok(!threw, "requestStorageAccess should not throw");
|
||||
try {
|
||||
if (callback) {
|
||||
if (expectFail) {
|
||||
await p.catch(_ => callback());
|
||||
await p.catch(_ => callback(dwu));
|
||||
success = false;
|
||||
} else {
|
||||
await p.then(_ => callback());
|
||||
await p.then(_ => callback(dwu));
|
||||
}
|
||||
} else {
|
||||
await p;
|
||||
}
|
||||
} catch (e) {
|
||||
success = false;
|
||||
} finally {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
}
|
||||
ok(!success, "Should not have worked without user interaction");
|
||||
|
||||
|
@ -70,7 +71,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
|
||||
await interactWithTracker();
|
||||
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
helper = dwu.setHandlingUserInput(true);
|
||||
}
|
||||
if (
|
||||
effectiveCookieBehavior ==
|
||||
|
@ -80,10 +81,10 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
try {
|
||||
if (callback) {
|
||||
if (expectFail) {
|
||||
await document.requestStorageAccess().catch(_ => callback());
|
||||
await document.requestStorageAccess().catch(_ => callback(dwu));
|
||||
success = false;
|
||||
} else {
|
||||
await document.requestStorageAccess().then(_ => callback());
|
||||
await document.requestStorageAccess().then(_ => callback(dwu));
|
||||
}
|
||||
} else {
|
||||
await document.requestStorageAccess();
|
||||
|
@ -91,7 +92,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
} catch (e) {
|
||||
success = false;
|
||||
} finally {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
helper.destruct();
|
||||
}
|
||||
ok(success, "Should not have thrown");
|
||||
|
||||
|
@ -99,7 +100,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
|
||||
await interactWithTracker();
|
||||
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
helper = dwu.setHandlingUserInput(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,23 +110,23 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
p = document.requestStorageAccess();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
} finally {
|
||||
helper.destruct();
|
||||
}
|
||||
let rejected = false;
|
||||
try {
|
||||
if (callback) {
|
||||
if (expectFail) {
|
||||
await p.catch(_ => callback());
|
||||
await p.catch(_ => callback(dwu));
|
||||
rejected = true;
|
||||
} else {
|
||||
await p.then(_ => callback());
|
||||
await p.then(_ => callback(dwu));
|
||||
}
|
||||
} else {
|
||||
await p;
|
||||
}
|
||||
} catch (e) {
|
||||
rejected = true;
|
||||
} finally {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
}
|
||||
|
||||
success = !threw && !rejected;
|
||||
|
|
Загрузка…
Ссылка в новой задаче