Commit 26540116 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Add more WPT tests for mixed-content check in workers/worklets (1/2)

This CL adds test code for more worker/worklet-related cases
to mixed-content/ WPT tests:
- module-worker-top-level (outsideSettings of https: module script)
- module-data-worker-import (outsideSettings of data: worker)
- classic-data-worker-fetch (insideSettings of data: worker)
- worklet-*-top-level (outsideSettings of https: worklets)
- worklet-*-data-import (outsideSettings of data: worklets)

Actual generated tests is added in a separate CL
https://chromium-review.googlesource.com/1212746
for easier code review.

These tests are for
https://chromium-review.googlesource.com/1208390.

Bug: 880986, 880023, 880015
Change-Id: I07eb96cffec889103bf437813180127644466af8
Reviewed-on: https://chromium-review.googlesource.com/1212744
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590239}
parent c7731a29
......@@ -184,17 +184,29 @@ function requestViaFetch(url) {
return fetch(url);
}
function dedicatedWorkerUrlThatFetches(url) {
return `data:text/javascript,
fetch('${url}')
.then(() => postMessage(''),
() => postMessage(''));`;
}
function workerUrlThatImports(url) {
return `data:text/javascript,import '${url}';`;
}
/**
* Creates a new Worker, binds message and error events wrapping them into.
* {@code worker.eventPromise} and posts an empty string message to start
* the worker.
* @param {string} url The endpoint URL for the worker script.
* @param {object} options The options for Worker constructor.
* @return {Promise} The promise for success/error events.
*/
function requestViaWorker(url) {
function requestViaDedicatedWorker(url, options) {
var worker;
try {
worker = new Worker(url);
worker = new Worker(url, options);
} catch (e) {
return Promise.reject(e);
}
......@@ -204,6 +216,29 @@ function requestViaWorker(url) {
return worker.eventPromise;
}
// Returns a reference to a worklet object corresponding to a given type.
function get_worklet(type) {
if (type == 'animation')
return CSS.animationWorklet;
if (type == 'layout')
return CSS.layoutWorklet;
if (type == 'paint')
return CSS.paintWorklet;
if (type == 'audio')
return new OfflineAudioContext(2,44100*40,44100).audioWorklet;
assert_unreached('unknown worklet type is passed.');
return undefined;
}
function requestViaWorklet(type, url) {
try {
return get_worklet(type).addModule(url);
} catch (e) {
return Promise.reject(e);
}
}
/**
* Sets the href attribute on a navigable DOM element and performs a navigation
* by clicking it. To avoid navigating away from the current execution
......
......@@ -65,7 +65,14 @@ function MixedContentTestCase(scenario, description, sanityChecker) {
"iframe-tag": requestViaIframe,
"img-tag": requestViaImage,
"script-tag": requestViaScript,
"worker-request": requestViaWorker,
"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,
......@@ -76,8 +83,6 @@ function MixedContentTestCase(scenario, description, sanityChecker) {
"websocket-request": requestViaWebSocket
};
sanityChecker.checkScenario(scenario, resourceMap);
// Mapping all expected MIME types to the scenario.
var contentType = {
"a-tag": "text/html",
......@@ -88,7 +93,12 @@ function MixedContentTestCase(scenario, description, sanityChecker) {
"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",
......@@ -99,6 +109,20 @@ function MixedContentTestCase(scenario, description, sanityChecker) {
"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() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment