mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 06:08:24 +02:00
Automatic update from web-platform-tests
[WPT] Merge wpt/{referrer-policy,mixed-content}/generic/common.js
To merge wpt/{referrer-policy,mixed-content} test frameworks,
this CL merges their common.js.
The new common.js is based on mixed-content's common.js,
with some aspects imported from referrer-policy's common.js:
- Passes results from subresource payloads to resolved promises,
converting if necessary using wrapResult().
This is for referrer-policy tests that rely on subresource
payload to get referrer request headers, while
mixed-content tests don't use the payload information at all.
- Accepts `additionalAttributes` arguments (to be used to set
referrer-policy-related attributes to elements).
- Extends bindEvents() to clean up event listeners on completion
(which is done for some request types in
referrer-policy's common.js).
- Imports queryImage() (with renaming to
requestViaImageForReferrerPolicy) from referrer-policy's common.js
(this should be merged with mixed-content version of
image requests, but not now).
On mixed-content side:
- expect.py's response for script requests is modified
because postMessage() is required by referrer-policy's common.js.
On referrer-policy side:
- Move referrer-policy-specific code from common.js
to referrer-policy-test-case.js, including wrapResult().
- All tests (except for two [1][2]) are converted to promise-based,
to handle errors correctly.
- Bugs in the remaining two tests [1][2] are fixed.
[1] referrer-policy/generic/iframe-inheritance.html
[2] referrer-policy/generic/sandboxed-iframe-with-opaque-origin.html
Then now
wpt/{referrer-policy,mixed-content}/generic/common.js
are the same.
They are duplicated (i.e. not moved/merged to a single file)
just to avoid mass modification of a large number of
generated files for each step of refactoring,
as these file names are hard-coded there.
Bug: 906850
Change-Id: I39f19d08d658c1a898fc453b621d82a2faaaaf6b
Reviewed-on: https://chromium-review.googlesource.com/c/1455745
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633917}
--
wpt-commits: 767f361425c20ded79c35630f709fc7addf7f80a
wpt-pr: 15262
176 lines
7 KiB
JavaScript
176 lines
7 KiB
JavaScript
/**
|
|
* @fileoverview Test case for mixed-content in Web Platform Tests.
|
|
* @author burnik@google.com (Kristijan Burnik)
|
|
*/
|
|
|
|
function wrapResult(server_data) {
|
|
// Currently the returned value is not used in mixed-content tests.
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* MixedContentTestCase exercises all the tests for checking browser behavior
|
|
* when resources regarded as mixed-content are requested. A single run covers
|
|
* only a single scenario.
|
|
* @param {object} scenario A JSON describing the test arrangement and
|
|
* expectation(s). Refer to /mixed-content/spec.src.json for details.
|
|
* @param {string} description The test scenario verbose description.
|
|
* @param {SanityChecker} sanityChecker Instance of an object used to check the
|
|
* running scenario. Useful in debug mode. See ./sanity-checker.js.
|
|
* Run {@code ./tools/generate.py -h} for info on test generating modes.
|
|
* @return {object} Object wrapping the start method used to run the test.
|
|
*/
|
|
function MixedContentTestCase(scenario, description, sanityChecker) {
|
|
var httpProtocol = "http";
|
|
var httpsProtocol = "https";
|
|
var wsProtocol = "ws";
|
|
var wssProtocol = "wss";
|
|
|
|
var sameOriginHost = location.hostname;
|
|
var crossOriginHost = "{{domains[www1]}}";
|
|
|
|
// These values can evaluate to either empty strings or a ":port" string.
|
|
var httpPort = getNormalizedPort(parseInt("{{ports[http][0]}}", 10));
|
|
var httpsPort = getNormalizedPort(parseInt("{{ports[https][0]}}", 10));
|
|
var wsPort = getNormalizedPort(parseInt("{{ports[ws][0]}}", 10));
|
|
var wssPort = getNormalizedPort(parseInt("{{ports[wss][0]}}", 10));
|
|
|
|
var resourcePath = "/mixed-content/generic/expect.py";
|
|
var wsResourcePath = "/stash_responder";
|
|
|
|
// Map all endpoints to scenario for use in the test.
|
|
var endpoint = {
|
|
"same-origin":
|
|
location.origin + resourcePath,
|
|
"same-host-https":
|
|
httpsProtocol + "://" + sameOriginHost + httpsPort + resourcePath,
|
|
"same-host-http":
|
|
httpProtocol + "://" + sameOriginHost + httpPort + resourcePath,
|
|
"cross-origin-https":
|
|
httpsProtocol + "://" + crossOriginHost + httpsPort + resourcePath,
|
|
"cross-origin-http":
|
|
httpProtocol + "://" + crossOriginHost + httpPort + resourcePath,
|
|
"same-host-wss":
|
|
wssProtocol + "://" + sameOriginHost + wssPort + wsResourcePath,
|
|
"same-host-ws":
|
|
wsProtocol + "://" + sameOriginHost + wsPort + wsResourcePath,
|
|
"cross-origin-wss":
|
|
wssProtocol + "://" + crossOriginHost + wssPort + wsResourcePath,
|
|
"cross-origin-ws":
|
|
wsProtocol + "://" + crossOriginHost + wsPort + wsResourcePath
|
|
};
|
|
|
|
// Mapping all the resource requesting methods to the scenario.
|
|
var resourceMap = {
|
|
"a-tag": requestViaAnchor,
|
|
"area-tag": requestViaArea,
|
|
"beacon-request": requestViaSendBeacon,
|
|
"fetch-request": requestViaFetch,
|
|
"form-tag": requestViaForm,
|
|
"iframe-tag": requestViaIframe,
|
|
"img-tag": requestViaImage,
|
|
"script-tag": requestViaScript,
|
|
"worker-request":
|
|
url => requestViaDedicatedWorker(url),
|
|
"module-worker-top-level":
|
|
url => requestViaDedicatedWorker(url, {type: "module"}),
|
|
"module-data-worker-import":
|
|
url => requestViaDedicatedWorker(workerUrlThatImports(url), {type: "module"}),
|
|
"classic-data-worker-fetch":
|
|
url => requestViaDedicatedWorker(dedicatedWorkerUrlThatFetches(url), {}),
|
|
"xhr-request": requestViaXhr,
|
|
"audio-tag": requestViaAudio,
|
|
"video-tag": requestViaVideo,
|
|
"picture-tag": requestViaPicture,
|
|
"object-tag": requestViaObject,
|
|
"link-css-tag": requestViaLinkStylesheet,
|
|
"link-prefetch-tag": requestViaLinkPrefetch,
|
|
"websocket-request": requestViaWebSocket
|
|
};
|
|
|
|
// Mapping all expected MIME types to the scenario.
|
|
var contentType = {
|
|
"a-tag": "text/html",
|
|
"area-tag": "text/html",
|
|
"beacon-request": "text/plain",
|
|
"fetch-request": "application/json",
|
|
"form-tag": "text/html",
|
|
"iframe-tag": "text/html",
|
|
"img-tag": "image/png",
|
|
"script-tag": "text/javascript",
|
|
|
|
"worker-request": "application/javascript",
|
|
"module-worker-top-level": "application/javascript",
|
|
"module-data-worker-import": "application/javascript",
|
|
"classic-data-worker-fetch": "application/javascript",
|
|
|
|
"xhr-request": "application/json",
|
|
"audio-tag": "audio/wav",
|
|
"video-tag": "video/ogg",
|
|
"picture-tag": "image/png",
|
|
"object-tag": "text/html",
|
|
"link-css-tag": "text/css",
|
|
"link-prefetch-tag": "text/html",
|
|
"websocket-request": "application/json"
|
|
};
|
|
|
|
for (const workletType of ['animation', 'audio', 'layout', 'paint']) {
|
|
resourceMap[`worklet-${workletType}-top-level`] =
|
|
url => requestViaWorklet(workletType, url);
|
|
contentType[`worklet-${workletType}-top-level`] =
|
|
"application/javascript";
|
|
|
|
resourceMap[`worklet-${workletType}-data-import`] =
|
|
url => requestViaWorklet(workletType, workerUrlThatImports(url));
|
|
contentType[`worklet-${workletType}-data-import`] =
|
|
"application/javascript";
|
|
}
|
|
|
|
sanityChecker.checkScenario(scenario, resourceMap);
|
|
|
|
var mixed_content_test = async_test(description);
|
|
|
|
function runTest() {
|
|
sanityChecker.setFailTimeout(mixed_content_test);
|
|
|
|
var key = guid();
|
|
var value = guid();
|
|
// We use the same path for both HTTP/S and WS/S stash requests.
|
|
var stash_path = encodeURIComponent("/mixed-content");
|
|
var announceResourceRequestUrl = endpoint['same-origin'] +
|
|
"?action=put&key=" + key +
|
|
"&value=" + value +
|
|
"&path=" + stash_path;
|
|
var assertResourceRequestUrl = endpoint['same-origin'] +
|
|
"?action=take&key=" + key +
|
|
"&path=" + stash_path;
|
|
var resourceRequestUrl = endpoint[scenario.origin] + "?redirection=" +
|
|
scenario.redirection + "&action=purge&key=" + key +
|
|
"&path=" + stash_path + "&content_type=" +
|
|
contentType[scenario.subresource];
|
|
|
|
xhrRequest(announceResourceRequestUrl)
|
|
.then(mixed_content_test.step_func(_ => {
|
|
// Send out the real resource request.
|
|
// This should tear down the key if it's not blocked.
|
|
return resourceMap[scenario.subresource](resourceRequestUrl);
|
|
}))
|
|
.then(mixed_content_test.step_func(_ => {
|
|
// Send request to check if the key has been torn down.
|
|
return xhrRequest(assertResourceRequestUrl);
|
|
}))
|
|
.catch(mixed_content_test.step_func(e => {
|
|
// When requestResource fails, we also check the key state.
|
|
return xhrRequest(assertResourceRequestUrl);
|
|
}))
|
|
.then(mixed_content_test.step_func_done(response => {
|
|
// Now check if the value has been torn down. If it's still there,
|
|
// we have blocked the request to mixed-content.
|
|
assert_equals(response.status, scenario.expectation,
|
|
"The resource request should be '" + scenario.expectation + "'.");
|
|
}));
|
|
|
|
} // runTest
|
|
|
|
return {start: mixed_content_test.step_func(runTest) };
|
|
} // MixedContentTestCase
|