зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1683131 - Add a test for telemetry r=necko-reviewers,dragana
Depends on D103028 Differential Revision: https://phabricator.services.mozilla.com/D104507
This commit is contained in:
Родитель
4316bedcd3
Коммит
56cd237cb3
|
@ -5,6 +5,22 @@ support-files =
|
|||
redirect.sjs
|
||||
auth_post.sjs
|
||||
post.html
|
||||
res.css
|
||||
res.css^headers^
|
||||
res.csv
|
||||
res.csv^headers^
|
||||
res_206.html
|
||||
res_206.html^headers^
|
||||
res_nosniff.html
|
||||
res_nosniff.html^headers^
|
||||
res_img.png
|
||||
res_nosniff2.html
|
||||
res_nosniff2.html^headers^
|
||||
res_not_ok.html
|
||||
res_not_ok.html^headers^
|
||||
res.unknown
|
||||
res_img_unknown.png
|
||||
res.mp3
|
||||
|
||||
[browser_about_cache.js]
|
||||
[browser_bug1535877.js]
|
||||
|
@ -13,6 +29,7 @@ support-files =
|
|||
skip-if = !crashreporter
|
||||
(e10s && debug && os == "linux" && bits == 64)
|
||||
debug # Bug 1370783
|
||||
[browser_opaque_response_blocking_telemetry.js]
|
||||
[browser_post_file.js]
|
||||
[browser_nsIFormPOSTActionChannel.js]
|
||||
skip-if = e10s # protocol handler and channel does not work in content process
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const DIRPATH = getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content/",
|
||||
""
|
||||
);
|
||||
|
||||
const ORIGIN1 = "https://example.com";
|
||||
const URL = `${ORIGIN1}/${DIRPATH}dummy.html`;
|
||||
|
||||
// Cross origin urls.
|
||||
const ORIGIN2 = "https://example.org";
|
||||
const SAFE_LISTED_URL = `${ORIGIN2}/${DIRPATH}res.css`;
|
||||
const BLOCKED_LISTED_NEVER_SNIFFED_URL = `${ORIGIN2}/${DIRPATH}res.csv`;
|
||||
const BLOCKED_LISTED_206_URL = `${ORIGIN2}/${DIRPATH}res_206.html`;
|
||||
const BLOCKED_LISTED_NOSNIFF_URL = `${ORIGIN2}/${DIRPATH}res_nosniff.html`;
|
||||
const IMAGE_URL = `${ORIGIN2}/${DIRPATH}res_img.png`;
|
||||
const NOSNIFF_URL = `${ORIGIN2}/${DIRPATH}res_nosniff2.html`;
|
||||
const NOT_OK_URL = `${ORIGIN2}/${DIRPATH}res_not_ok.html`;
|
||||
const UNKNOWN_URL = `${ORIGIN2}/${DIRPATH}res.unknown`;
|
||||
const IMAGE_UNKNOWN_URL = `${ORIGIN2}/${DIRPATH}res_img_unknown.png`;
|
||||
|
||||
add_task(async function() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.opaqueResponseBlocking", true]],
|
||||
});
|
||||
let histogram = Services.telemetry.getKeyedHistogramById(
|
||||
"OPAQUE_RESPONSE_BLOCKING"
|
||||
);
|
||||
const testcases = [
|
||||
{
|
||||
url: SAFE_LISTED_URL,
|
||||
key: "Allowed_SafeListed",
|
||||
},
|
||||
{
|
||||
url: BLOCKED_LISTED_NEVER_SNIFFED_URL,
|
||||
key: "Blocked_BlockListedNeverSniffed",
|
||||
},
|
||||
{
|
||||
url: BLOCKED_LISTED_206_URL,
|
||||
key: "Blocked_206AndBlockListed",
|
||||
},
|
||||
{
|
||||
url: BLOCKED_LISTED_NOSNIFF_URL,
|
||||
key: "Blocked_NosniffAndEitherBlockListedOrTextPlain",
|
||||
},
|
||||
{
|
||||
url: IMAGE_URL,
|
||||
key: "Allowed_SniffAsImageOrAudioOrVideo",
|
||||
},
|
||||
{
|
||||
url: NOSNIFF_URL,
|
||||
key: "Blocked_NoSniffHeaderAfterSniff",
|
||||
},
|
||||
{
|
||||
url: NOT_OK_URL,
|
||||
key: "Blocked_ResponseNotOk",
|
||||
},
|
||||
{
|
||||
url: UNKNOWN_URL,
|
||||
key: "Allowed_FailtoGetMIMEType",
|
||||
},
|
||||
{
|
||||
url: IMAGE_UNKNOWN_URL,
|
||||
key: "Blocked_ContentTypeBeginsWithImageOrVideoOrAudio",
|
||||
},
|
||||
];
|
||||
|
||||
for (let testcase of testcases) {
|
||||
histogram.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(URL, async function(browser) {
|
||||
BrowserTestUtils.loadURI(browser, URL);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
info(`Fetching cross-origin url: ${testcase.url}.`);
|
||||
|
||||
await SpecialPowers.spawn(
|
||||
browser,
|
||||
[testcase.url, testcase.media],
|
||||
async (url, media) => {
|
||||
try {
|
||||
await content.window.fetch(url);
|
||||
} catch (e) {
|
||||
/* Ignore result */
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
info(`Validating if the telemetry probe has been reported.`);
|
||||
|
||||
let snapshot = histogram.snapshot();
|
||||
let keys = testcase.keys;
|
||||
if (!keys) {
|
||||
keys = [testcase.key];
|
||||
}
|
||||
for (let key of keys) {
|
||||
ok(snapshot.hasOwnProperty(key), `Should have recorded key ${key}`);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
/* François was here. */
|
||||
#purple-text {
|
||||
color: purple;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Content-Type: text/css; charset=utf-8
|
|
@ -0,0 +1 @@
|
|||
1,2,3
|
|
|
@ -0,0 +1 @@
|
|||
Content-Type: text/csv;
|
Двоичный файл не отображается.
|
@ -0,0 +1 @@
|
|||
unknown
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Dummy Page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,2 @@
|
|||
HTTP 206
|
||||
Content-Type: text/html;
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 126 KiB |
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Dummy Page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Dummy Page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,2 @@
|
|||
X-Content-Type-Options: nosniff
|
||||
Content-Type: text/html;
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Dummy Page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,2 @@
|
|||
X-Content-Type-Options: nosniff
|
||||
Content-Type: text/test
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Dummy Page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
HTTP 302 Found
|
Загрузка…
Ссылка в новой задаче