зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1508310 - Implement Report-to header support - part 9 - cleanup tests, r=smaug
This commit is contained in:
Родитель
f759361b23
Коммит
3adbdc9ee7
|
@ -44,5 +44,6 @@ with Files('**'):
|
|||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
|
||||
BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
|
||||
|
||||
TEST_DIRS += [ 'tests/gtest' ]
|
||||
|
|
|
@ -3,5 +3,10 @@
|
|||
module.exports = {
|
||||
"extends": [
|
||||
"plugin:mozilla/mochitest-test",
|
||||
"plugin:mozilla/browser-test",
|
||||
],
|
||||
|
||||
"rules": {
|
||||
"no-unused-vars": ["error", {"args": "none", "varsIgnorePattern": "^end_test$"}],
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
delivering.sjs
|
||||
empty.html
|
||||
|
||||
[browser_cleanup.js]
|
|
@ -0,0 +1,173 @@
|
|||
const TEST_HOST = "example.org";
|
||||
const TEST_DOMAIN = "https://" + TEST_HOST;
|
||||
const TEST_PATH = "/browser/dom/reporting/tests/";
|
||||
const TEST_TOP_PAGE = TEST_DOMAIN + TEST_PATH + "empty.html";
|
||||
const TEST_SJS = TEST_DOMAIN + TEST_PATH + "delivering.sjs";
|
||||
|
||||
async function storeReportingHeader(browser, extraParams = "") {
|
||||
await ContentTask.spawn(browser, { url: TEST_SJS, extraParams }, async obj => {
|
||||
await content.fetch(obj.url + "?task=header" + (obj.extraParams.length ? "&" + obj.extraParams : ""))
|
||||
.then(r => r.text())
|
||||
.then(text => {
|
||||
is(text, "OK", "Report-to header sent");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
await SpecialPowers.flushPrefEnv();
|
||||
await SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.reporting.enabled", true],
|
||||
["dom.reporting.header.enabled", true],
|
||||
["dom.reporting.testing.enabled", true],
|
||||
["dom.reporting.delivering.timeout", 1],
|
||||
["privacy.userContext.enabled", true],
|
||||
]});
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Testing a total cleanup");
|
||||
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
|
||||
|
||||
await storeReportingHeader(browser);
|
||||
ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
|
||||
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
|
||||
});
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a full cleanup");
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Testing a total QuotaManager cleanup");
|
||||
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
|
||||
|
||||
await storeReportingHeader(browser);
|
||||
ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
|
||||
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_DOM_QUOTA, value => resolve());
|
||||
});
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a quota cleanup");
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Testing a QuotaManager host cleanup");
|
||||
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
|
||||
|
||||
await storeReportingHeader(browser);
|
||||
ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
|
||||
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteDataFromHost(TEST_HOST, true, Ci.nsIClearDataService.CLEAR_DOM_QUOTA, value => resolve());
|
||||
});
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before a quota cleanup");
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Testing a 410 endpoint status");
|
||||
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
|
||||
|
||||
await storeReportingHeader(browser, "410=true");
|
||||
ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We have data");
|
||||
|
||||
await ContentTask.spawn(browser, null, async _ => {
|
||||
let testingInterface = new content.TestingDeprecatedInterface();
|
||||
ok(!!testingInterface, "Created a deprecated interface");
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
let count = 0;
|
||||
let id = setInterval(_ => {
|
||||
++count;
|
||||
if (count > 10) {
|
||||
ok(false, "Something went wrong.");
|
||||
clearInterval(id);
|
||||
reject();
|
||||
}
|
||||
|
||||
if (!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN)) {
|
||||
ok(true, "No data after a 410!");
|
||||
clearInterval(id);
|
||||
resolve();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Creating a new container");
|
||||
|
||||
let identity = ContextualIdentityService.create("Report-To-Test", "fingerprint", "orange");
|
||||
|
||||
info("Creating a new container tab");
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE, {userContextId: identity.userContextId});
|
||||
is(tab.getAttribute("usercontextid"), identity.userContextId, "New tab has the right UCI");
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "No data before the test");
|
||||
|
||||
await storeReportingHeader(browser);
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN), "We don't have data for the origin");
|
||||
ok(ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN + "^userContextId=" + identity.userContextId), "We have data for the origin + userContextId");
|
||||
|
||||
info("Removing the tab");
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
|
||||
ContextualIdentityService.remove(identity.userContextId);
|
||||
|
||||
ok(!ChromeUtils.hasReportingHeaderForOrigin(TEST_DOMAIN + "^userContextId=" + identity.userContextId), "No more data after a container removal");
|
||||
});
|
||||
|
||||
add_task(async function() {
|
||||
info("Cleaning up.");
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
|
||||
});
|
||||
});
|
|
@ -0,0 +1,69 @@
|
|||
const CC = Components.Constructor;
|
||||
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
"setInputStream");
|
||||
|
||||
Components.utils.importGlobalProperties(["URLSearchParams"]);
|
||||
|
||||
function handleRequest(aRequest, aResponse) {
|
||||
var params = new URLSearchParams(aRequest.queryString);
|
||||
|
||||
// Report-to setter
|
||||
if (aRequest.method == "GET" && params.get("task") == "header") {
|
||||
let extraParams = [];
|
||||
|
||||
if (params.has("410")) {
|
||||
extraParams.push("410=true");
|
||||
}
|
||||
|
||||
let body = {
|
||||
max_age: 100000,
|
||||
endpoints: [{
|
||||
url: "https://example.org/tests/dom/reporting/tests/delivering.sjs" +
|
||||
(extraParams.length ? "?" + extraParams.join("&") : ""),
|
||||
priority: 1,
|
||||
weight: 1,
|
||||
}]
|
||||
};
|
||||
|
||||
aResponse.setStatusLine(aRequest.httpVersion, 200, "OK");
|
||||
aResponse.setHeader("Report-to", JSON.stringify(body), false);
|
||||
aResponse.write("OK");
|
||||
return;
|
||||
}
|
||||
|
||||
// Report check
|
||||
if (aRequest.method == "GET" && params.get("task") == "check") {
|
||||
aResponse.setStatusLine(aRequest.httpVersion, 200, "OK");
|
||||
aResponse.write(getState("report"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (aRequest.method == "POST") {
|
||||
var body = new BinaryInputStream(aRequest.bodyInputStream);
|
||||
|
||||
var avail;
|
||||
var bytes = [];
|
||||
while ((avail = body.available()) > 0) {
|
||||
Array.prototype.push.apply(bytes, body.readByteArray(avail));
|
||||
}
|
||||
|
||||
let data = {
|
||||
contentType: aRequest.getHeader("content-type"),
|
||||
origin: aRequest.getHeader("origin"),
|
||||
body: JSON.parse(String.fromCharCode.apply(null, bytes)),
|
||||
}
|
||||
|
||||
setState("report", JSON.stringify(data));
|
||||
|
||||
if (params.has("410")) {
|
||||
aResponse.setStatusLine(aRequest.httpVersion, 410, "Gone");
|
||||
} else {
|
||||
aResponse.setStatusLine(aRequest.httpVersion, 200, "OK");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
aResponse.setStatusLine(aRequest.httpVersion, 500, "Internal error");
|
||||
aResponse.write("Invalid request");
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Hello world!
|
Загрузка…
Ссылка в новой задаче