Commit b5206977 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Add tests for canvas tainting from video.

R=horo

Bug: 780435
Change-Id: Ie8ae9cf8dca55f122a7b4a984ca0a96035b0099f
Reviewed-on: https://chromium-review.googlesource.com/892683Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532814}
parent ffc086c7
......@@ -681,8 +681,10 @@ crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-wo
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/sandboxed-iframe-fetch-event.https.html [ Timeout ]
# Failing tests in dictionary order.
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting-cache.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting-image-cache.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting-image.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting-video-cache.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-canvas-tainting-video.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-event-referrer-policy.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-request-html-imports.https.html [ Failure ]
crbug.com/736308 virtual/outofblink-cors/external/wpt/service-workers/service-worker/fetch-request-xhr.https.html [ Failure ]
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: canvas tainting of the fetched image using cached responses</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: canvas tainting of the fetched image</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: canvas tainting of the fetched video using cache responses</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script src="resources/fetch-canvas-tainting-tests.js"></script>
<body>
<script>
do_canvas_tainting_tests({
resource_path: base_path() + 'resources/fetch-access-control.py?VIDEO',
cache: true
});
</script>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: canvas tainting of the fetched video</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script src="resources/fetch-canvas-tainting-tests.js"></script>
<body>
<script>
do_canvas_tainting_tests({
resource_path: base_path() + 'resources/fetch-access-control.py?VIDEO',
cache: false
});
</script>
</body>
import base64
import json
import os
import sys
def main(request, response):
headers = []
......@@ -31,6 +33,10 @@ def main(request, response):
"jBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=")
return headers, body
if "VIDEO" in request.GET:
headers.append(("Content-Type", "video/webm"))
body = open(os.path.join(request.doc_root, "media", "movie_5.ogv"), "rb").read()
return headers, body
username = request.auth.username if request.auth.username else "undefined"
password = request.auth.password if request.auth.username else "undefined"
......
......@@ -5,34 +5,65 @@ const NOT_TAINTED = 'NOT_TAINTED';
const TAINTED = 'TAINTED';
const LOAD_ERROR = 'LOAD_ERROR';
// Creates an image element with src=|url| and an optional |cross_origin|
// attibute. Tries to read from the image using a canvas element. Returns
// NOT_TAINTED if the could be read, TAINTED if it could not be read, and
// LOAD_ERROR if loading the image failed.
// Creates an image/video element with src=|url| and an optional |cross_origin|
// attibute. Tries to read from the image/video using a canvas element. Returns
// NOT_TAINTED if it could be read, TAINTED if it could not be read, and
// LOAD_ERROR if loading the image/video failed.
function create_test_case_promise(url, cross_origin) {
return new Promise(resolve => {
const img = document.createElement('img');
if (cross_origin != '') {
img.crossOrigin = cross_origin;
if (url.indexOf('PNGIMAGE') != -1) {
const img = document.createElement('img');
if (cross_origin != '') {
img.crossOrigin = cross_origin;
}
img.onload = function() {
try {
const canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
context.getImageData(0, 0, 100, 100);
resolve(NOT_TAINTED);
} catch (e) {
resolve(TAINTED);
}
};
img.onerror = function() {
resolve(LOAD_ERROR);
}
img.src = url;
return;
}
img.onload = function() {
try {
const canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
context.getImageData(0, 0, 100, 100);
resolve(NOT_TAINTED);
} catch (e) {
resolve(TAINTED);
if (url.indexOf('VIDEO') != -1) {
const video = document.createElement('video');
video.autoplay = true;
if (cross_origin != '') {
video.crossOrigin = cross_origin;
}
};
img.onerror = function() {
resolve(LOAD_ERROR);
video.onplay = function() {
try {
const canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0);
context.getImageData(0, 0, 100, 100);
resolve(NOT_TAINTED);
} catch (e) {
resolve(TAINTED);
}
};
video.onerror = function() {
resolve(LOAD_ERROR);
}
video.src = url;
return;
}
img.src = url;
});
resolve('unknown resource type');
});
}
</script>
</html>
......@@ -18,7 +18,7 @@ function canvas_taint_test(url, cross_origin, expected_result) {
// Runs all the tests. The given |params| has these properties:
// * |resource_path|: the relative path to the (image) resource to test.
// * |resource_path|: the relative path to the (image/video) resource to test.
// * |cache|: when true, the service worker bounces responses into
// Cache Storage and back out before responding with them.
function do_canvas_tainting_tests(params) {
......
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