зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1732919 - Update tests for new Storage Access API user activation behavior. r=anti-tracking-reviewers,timhuang
Differential Revision: https://phabricator.services.mozilla.com/D127152
This commit is contained in:
Родитель
6abcdb4407
Коммит
2bebfa93be
|
@ -16,7 +16,7 @@ const button = document.getElementById("button")
|
|||
button.addEventListener("click", () => {
|
||||
is(domWindowUtils.isHandlingUserInput, true, "handling user input");
|
||||
|
||||
document.requestStorageAccess().then(() => {
|
||||
document.hasStorageAccess().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.requestStorageAccess().then(() => {
|
||||
content.document.hasStorageAccess().then(() => {
|
||||
is(DOMWindowUtils.isHandlingUserInput, true,
|
||||
"still handling user input");
|
||||
Promise.resolve().then(() => {
|
||||
|
|
|
@ -37,8 +37,7 @@ AntiTracking._createTask({
|
|||
ok(document.cookie != "", "Nothing is blocked");
|
||||
|
||||
// requestStorageAccess should resolve
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
await document
|
||||
.requestStorageAccess()
|
||||
.then(() => {
|
||||
|
@ -47,7 +46,7 @@ AntiTracking._createTask({
|
|||
.catch(() => {
|
||||
ok(false, "Should grant storage access");
|
||||
});
|
||||
helper.destruct();
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
},
|
||||
extraPrefs: null,
|
||||
expectedBlockingNotifications: 0,
|
||||
|
|
|
@ -37,8 +37,7 @@ AntiTracking._createTask({
|
|||
ok(document.cookie == "", "All is blocked");
|
||||
|
||||
// requestStorageAccess should reject
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
await document
|
||||
.requestStorageAccess()
|
||||
.then(() => {
|
||||
|
@ -47,7 +46,7 @@ AntiTracking._createTask({
|
|||
.catch(() => {
|
||||
ok(true, "Should not grant storage access");
|
||||
});
|
||||
helper.destruct();
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
},
|
||||
extraPrefs: null,
|
||||
expectedBlockingNotifications:
|
||||
|
|
|
@ -177,10 +177,9 @@ add_task(async function test_privilege_api_with_reject_tracker() {
|
|||
|
||||
// Call the privilege API.
|
||||
await SpecialPowers.spawn(browser, [], async _ => {
|
||||
// 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);
|
||||
// The privilege API requires user activation. So, we set the user
|
||||
// activation flag before we call the API.
|
||||
content.document.notifyUserGestureActivation();
|
||||
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin(
|
||||
|
@ -190,7 +189,7 @@ add_task(async function test_privilege_api_with_reject_tracker() {
|
|||
ok(false, "The API shouldn't throw.");
|
||||
}
|
||||
|
||||
helper.destruct();
|
||||
content.document.clearUserGestureActivation();
|
||||
});
|
||||
|
||||
// Verify if the storage access permission is set correctly.
|
||||
|
@ -274,8 +273,7 @@ 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.
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
content.document.notifyUserGestureActivation();
|
||||
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin(
|
||||
|
@ -285,7 +283,7 @@ add_task(async function test_privilege_api_with_dFPI() {
|
|||
ok(false, "The API shouldn't throw.");
|
||||
}
|
||||
|
||||
helper.destruct();
|
||||
content.document.clearUserGestureActivation();
|
||||
});
|
||||
|
||||
// Verify if the storage access permission is set correctly.
|
||||
|
@ -365,8 +363,7 @@ 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.
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
content.document.notifyUserGestureActivation();
|
||||
let isThrown = false;
|
||||
|
||||
try {
|
||||
|
@ -379,7 +376,7 @@ add_task(async function test_prompt() {
|
|||
|
||||
is(isThrown, !allow, `The API ${allow ? "shouldn't" : "should"} throw.`);
|
||||
|
||||
helper.destruct();
|
||||
content.document.clearUserGestureActivation();
|
||||
});
|
||||
|
||||
await shownPromise;
|
||||
|
@ -447,9 +444,7 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw without user gesture.");
|
||||
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(content);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
|
||||
content.document.notifyUserGestureActivation();
|
||||
isThrown = false;
|
||||
try {
|
||||
await content.document.requestStorageAccessForOrigin();
|
||||
|
@ -458,6 +453,7 @@ 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("");
|
||||
|
@ -467,6 +463,7 @@ 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");
|
||||
|
@ -476,7 +473,7 @@ add_task(async function test_invalid_input() {
|
|||
}
|
||||
ok(isThrown, "The API should throw with invalid url.");
|
||||
|
||||
helper.destruct();
|
||||
content.document.clearUserGestureActivation();
|
||||
});
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/* import-globals-from antitracking_head.js */
|
||||
|
||||
AntiTracking.runTest(
|
||||
"Storage Access API returns promises that maintain user activation for calling its reject handler",
|
||||
"Storage Access API returns promises that do not maintain user activation for calling its reject handler",
|
||||
// blocking callback
|
||||
async _ => {
|
||||
/* import-globals-from storageAccessAPIHelpers.js */
|
||||
let [threw, rejected] = await callRequestStorageAccess(dwu => {
|
||||
let [threw, rejected] = await callRequestStorageAccess(() => {
|
||||
ok(
|
||||
dwu.isHandlingUserInput,
|
||||
"Promise reject handler must run as if we're handling user input"
|
||||
!SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
"Promise reject handler must not have user activation"
|
||||
);
|
||||
}, true);
|
||||
ok(!threw, "requestStorageAccess should not throw");
|
||||
|
|
|
@ -5,30 +5,23 @@ AntiTracking.runTest(
|
|||
// blocking callback
|
||||
async _ => {
|
||||
/* import-globals-from storageAccessAPIHelpers.js */
|
||||
let [threw, rejected] = await callRequestStorageAccess(dwu => {
|
||||
let [threw, rejected] = await callRequestStorageAccess(() => {
|
||||
ok(
|
||||
dwu.isHandlingUserInput,
|
||||
SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
"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);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
|
||||
await document.hasStorageAccess();
|
||||
|
||||
let promise;
|
||||
try {
|
||||
promise = document.hasStorageAccess();
|
||||
} finally {
|
||||
helper.destruct();
|
||||
}
|
||||
await promise.then(_ => {
|
||||
ok(
|
||||
dwu.isHandlingUserInput,
|
||||
SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
"Promise handler must run as if we're handling user input"
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
null, // non-blocking callback
|
||||
|
|
|
@ -16,8 +16,7 @@ async function stillNoStorageAccess() {
|
|||
}
|
||||
|
||||
async function callRequestStorageAccess(callback, expectFail) {
|
||||
let dwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
let helper = dwu.setHandlingUserInput(true);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
|
||||
let origin = new URL(location.href).origin;
|
||||
|
||||
|
@ -47,23 +46,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(dwu));
|
||||
await p.catch(_ => callback());
|
||||
success = false;
|
||||
} else {
|
||||
await p.then(_ => callback(dwu));
|
||||
await p.then(_ => callback());
|
||||
}
|
||||
} else {
|
||||
await p;
|
||||
}
|
||||
} catch (e) {
|
||||
success = false;
|
||||
} finally {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
}
|
||||
ok(!success, "Should not have worked without user interaction");
|
||||
|
||||
|
@ -71,7 +70,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
|
||||
await interactWithTracker();
|
||||
|
||||
helper = dwu.setHandlingUserInput(true);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
}
|
||||
if (
|
||||
effectiveCookieBehavior ==
|
||||
|
@ -81,10 +80,10 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
try {
|
||||
if (callback) {
|
||||
if (expectFail) {
|
||||
await document.requestStorageAccess().catch(_ => callback(dwu));
|
||||
await document.requestStorageAccess().catch(_ => callback());
|
||||
success = false;
|
||||
} else {
|
||||
await document.requestStorageAccess().then(_ => callback(dwu));
|
||||
await document.requestStorageAccess().then(_ => callback());
|
||||
}
|
||||
} else {
|
||||
await document.requestStorageAccess();
|
||||
|
@ -92,7 +91,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
} catch (e) {
|
||||
success = false;
|
||||
} finally {
|
||||
helper.destruct();
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
}
|
||||
ok(success, "Should not have thrown");
|
||||
|
||||
|
@ -100,7 +99,7 @@ async function callRequestStorageAccess(callback, expectFail) {
|
|||
|
||||
await interactWithTracker();
|
||||
|
||||
helper = dwu.setHandlingUserInput(true);
|
||||
SpecialPowers.wrap(document).notifyUserGestureActivation();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,23 +109,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(dwu));
|
||||
await p.catch(_ => callback());
|
||||
rejected = true;
|
||||
} else {
|
||||
await p.then(_ => callback(dwu));
|
||||
await p.then(_ => callback());
|
||||
}
|
||||
} else {
|
||||
await p;
|
||||
}
|
||||
} catch (e) {
|
||||
rejected = true;
|
||||
} finally {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
}
|
||||
|
||||
success = !threw && !rejected;
|
||||
|
|
Загрузка…
Ссылка в новой задаче