gecko-dev/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
Andrea Marchesini 3ec4717c70 Bug 1536411 - StoragePrincipal - part 5 - Tests, r=Ehsan
Differential Revision: https://phabricator.services.mozilla.com/D24029

--HG--
rename : toolkit/components/antitracking/test/browser/head.js => toolkit/components/antitracking/test/browser/antitracking_head.js
extra : moz-landing-system : lando
2019-04-12 05:30:56 +00:00

78 lines
2.3 KiB
JavaScript

/* import-globals-from antitracking_head.js */
AntiTracking.runTest("localStorage",
async _ => {
is(window.localStorage, null, "LocalStorage is null");
try {
localStorage.foo = 42;
ok(false, "LocalStorage cannot be used!");
} catch (e) {
ok(true, "LocalStorage cannot be used!");
is(e.name, "TypeError", "We want a type error message.");
}
},
async _ => {
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");
},
async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
});
});
AntiTracking.runTest("localStorage and Storage Access API",
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
is(window.localStorage, null, "LocalStorage is null");
try {
localStorage.foo = 42;
ok(false, "LocalStorage cannot be used!");
} catch (e) {
ok(true, "LocalStorage cannot be used!");
is(e.name, "TypeError", "We want a type error message.");
}
/* import-globals-from storageAccessAPIHelpers.js */
await callRequestStorageAccess();
if (SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT) {
is(window.localStorage, null, "LocalStorage is null");
try {
localStorage.foo = 42;
ok(false, "LocalStorage cannot be used!");
} catch (e) {
ok(true, "LocalStorage cannot be used!");
is(e.name, "TypeError", "We want a type error message.");
}
} else {
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");
}
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");
/* import-globals-from storageAccessAPIHelpers.js */
await callRequestStorageAccess();
// For non-tracking windows, calling the API is a no-op
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");
},
async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
});
},
null, false, false);