mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1270338 - Add a mochitest to ensure Sanitizer clears data for all containers. r=baku,tanvi
--HG-- extra : rebase_source : fde0d706abf24766d868004f192398a0b6a2f31e
This commit is contained in:
parent
b16067d16c
commit
4acdd5c525
@ -70,3 +70,4 @@ support-files =
|
||||
[browser_clientAuth.js]
|
||||
[browser_cacheAPI.js]
|
||||
[browser_permissions.js]
|
||||
[browser_sanitize.js]
|
||||
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Bug 1270338 - Add a mochitest to ensure Sanitizer clears data for all containers
|
||||
*/
|
||||
|
||||
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {});
|
||||
|
||||
const TEST_DOMAIN = "http://example.net/";
|
||||
|
||||
let tempScope = {};
|
||||
Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js",
|
||||
tempScope);
|
||||
let Sanitizer = tempScope.Sanitizer;
|
||||
|
||||
function setCookies(aBrowser) {
|
||||
ContentTask.spawn(aBrowser, null, function() {
|
||||
content.document.cookie = "key=value";
|
||||
});
|
||||
}
|
||||
|
||||
function cacheDataForContext(loadContextInfo) {
|
||||
return new Promise(resolve => {
|
||||
let cachedURIs = [];
|
||||
let cacheVisitor = {
|
||||
onCacheStorageInfo(num, consumption) {},
|
||||
onCacheEntryInfo(uri, idEnhance) {
|
||||
cachedURIs.push(uri.asciiSpec);
|
||||
},
|
||||
onCacheEntryVisitCompleted() {
|
||||
resolve(cachedURIs);
|
||||
},
|
||||
QueryInterface(iid) {
|
||||
if (iid.equals(Ci.nsICacheStorageVisitor))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
// Visiting the disk cache also visits memory storage so we do not
|
||||
// need to use Services.cache2.memoryCacheStorage() here.
|
||||
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
|
||||
storage.asyncVisitStorage(cacheVisitor, true);
|
||||
});
|
||||
}
|
||||
|
||||
function checkCookiesSanitized(aBrowser) {
|
||||
ContentTask.spawn(aBrowser, null, function() {
|
||||
is(content.document.cookie, "",
|
||||
"Cookies of all origin attributes should be cleared.");
|
||||
});
|
||||
}
|
||||
|
||||
function checkCacheExists(aShouldExist) {
|
||||
return function* () {
|
||||
let loadContextInfos = [
|
||||
LoadContextInfo.default,
|
||||
LoadContextInfo.custom(false, { userContextId: 1 }),
|
||||
LoadContextInfo.custom(false, { userContextId: 2 }),
|
||||
LoadContextInfo.custom(false, { firstPartyDomain: "example.com" }),
|
||||
LoadContextInfo.custom(false, { firstPartyDomain: "example.org" }),
|
||||
];
|
||||
let i = 0;
|
||||
for (let loadContextInfo of loadContextInfos) {
|
||||
let cacheURIs = yield cacheDataForContext(loadContextInfo);
|
||||
is(cacheURIs.includes(TEST_DOMAIN), aShouldExist, TEST_DOMAIN + " should "
|
||||
+ (aShouldExist ? "not " : "") + "be cached for all origin attributes." + i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_task(function* setup() {
|
||||
let networkCache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
|
||||
.getService(Ci.nsICacheStorageService);
|
||||
networkCache.clear();
|
||||
});
|
||||
|
||||
// This will set the cookies and the cache.
|
||||
IsolationTestTools.runTests(TEST_DOMAIN, setCookies, () => true);
|
||||
|
||||
add_task(checkCacheExists(true));
|
||||
|
||||
add_task(function* sanitize() {
|
||||
let sanitizer = new Sanitizer();
|
||||
yield sanitizer.sanitize(["cookies", "cache"]);
|
||||
});
|
||||
|
||||
add_task(checkCacheExists(false));
|
||||
IsolationTestTools.runTests(TEST_DOMAIN, checkCookiesSanitized, () => true);
|
@ -173,30 +173,28 @@ this.IsolationTestTools = {
|
||||
* The testing task which will be run in different settings.
|
||||
*/
|
||||
_add_task(aTask) {
|
||||
add_task(function* addTaskForIsolationTests() {
|
||||
let testSettings = [
|
||||
{ mode: TEST_MODE_FIRSTPARTY,
|
||||
skip: false,
|
||||
prefs: [["privacy.firstparty.isolate", true]]
|
||||
},
|
||||
{ mode: TEST_MODE_NO_ISOLATION,
|
||||
skip: false,
|
||||
prefs: [["privacy.firstparty.isolate", false]]
|
||||
},
|
||||
{ mode: TEST_MODE_CONTAINERS,
|
||||
skip: false,
|
||||
prefs: [["privacy.userContext.enabled", true]]
|
||||
},
|
||||
];
|
||||
let testSettings = [
|
||||
{ mode: TEST_MODE_FIRSTPARTY,
|
||||
skip: false,
|
||||
prefs: [["privacy.firstparty.isolate", true]]
|
||||
},
|
||||
{ mode: TEST_MODE_NO_ISOLATION,
|
||||
skip: false,
|
||||
prefs: [["privacy.firstparty.isolate", false]]
|
||||
},
|
||||
{ mode: TEST_MODE_CONTAINERS,
|
||||
skip: false,
|
||||
prefs: [["privacy.userContext.enabled", true]]
|
||||
},
|
||||
];
|
||||
|
||||
// Add test tasks.
|
||||
for (let testSetting of testSettings) {
|
||||
IsolationTestTools._addTaskForMode(testSetting.mode,
|
||||
testSetting.prefs,
|
||||
testSetting.skip,
|
||||
aTask);
|
||||
}
|
||||
});
|
||||
// Add test tasks.
|
||||
for (let testSetting of testSettings) {
|
||||
IsolationTestTools._addTaskForMode(testSetting.mode,
|
||||
testSetting.prefs,
|
||||
testSetting.skip,
|
||||
aTask);
|
||||
}
|
||||
},
|
||||
|
||||
_addTaskForMode(aMode, aPref, aSkip, aTask) {
|
||||
|
Loading…
Reference in New Issue
Block a user