Skip to content

Commit

Permalink
Offscreen canvas: make worker tests catch errors
Browse files Browse the repository at this point in the history
Part of #11269.
  • Loading branch information
zcorpan committed Jun 11, 2018
1 parent 32f74fe commit 8b2d92a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@
</script>

<script>
function makeWorker(script)
{
var blob = new Blob([script]);
return new Worker(URL.createObjectURL(blob));
function makeWorker(test) {
var blob = new Blob([document.getElementById("myWorker").textContent]);
var worker = new Worker(URL.createObjectURL(blob));
worker.onerror = test.unreached_func("error");
return worker;
}

function drawCanvas(ctx)
Expand Down Expand Up @@ -190,103 +191,103 @@
}

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "empty", "empty", msg.data);
}));
worker.postMessage('test1');
}, "Test that convertToBlob with default arguments produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "empty", 1.0, msg.data);
}));
worker.postMessage('test2');
}, "Test that convertToBlob with default type/1.0 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "empty", 0.2, msg.data);
}));
worker.postMessage('test3');
}, "Test that convertToBlob with default type/0.2 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/png", "empty", msg.data);
}));
worker.postMessage('test4');
}, "Test that convertToBlob with png/default quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/png", 1.0, msg.data);
}));
worker.postMessage('test5');
}, "Test that convertToBlob with png/1.0 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/png", 0.2, msg.data);
}));
worker.postMessage('test6');
}, "Test that convertToBlob with png/0.2 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/jpeg", "empty", msg.data);
}));
worker.postMessage('test7');
}, "Test that convertToBlob with jpeg/default quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/jpeg", 1.0, msg.data);
}));
worker.postMessage('test8');
}, "Test that convertToBlob with jpeg/1.0 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/jpeg", 0.2, msg.data);
}));
worker.postMessage('test9');
}, "Test that convertToBlob with jpeg/0.2 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/webp", "empty", msg.data);
}));
worker.postMessage('test10');
}, "Test that convertToBlob with webp/default quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/webp", 1.0, msg.data);
}));
worker.postMessage('test11');
}, "Test that convertToBlob with webp/1.0 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func(function(msg) {
compareWithToBlob(t, "image/webp", 0.2, msg.data);
}));
worker.postMessage('test12');
}, "Test that convertToBlob with webp/0.2 quality produces correct result in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand All @@ -295,7 +296,7 @@
}, "Test that call convertToBlob on a detached OffscreenCanvas throws exception in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@
_assertPixel(canvas, 5,5, 0,255,0,255, "5,5", "0,255,0,255");
}

function makeWorker(script) {
var blob = new Blob([script]);
return new Worker(URL.createObjectURL(blob));
function makeWorker(test) {
var blob = new Blob([document.getElementById("myWorker").textContent]);
var worker = new Worker(URL.createObjectURL(blob));
worker.onerror = test.unreached_func("error");
return worker;
}

async_test(function(t) {
var placeholder = document.createElement('canvas');
placeholder.width = placeholder.height = 10;
var offscreenCanvas = placeholder.transferControlToOffscreen();
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
verifyPlaceholder(placeholder);
Expand All @@ -67,7 +69,7 @@
}, "Test that calling OffscreenCanvas's commit pushes its contents to its placeholder.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@
</script>

<script>
function makeWorker(script)
{
var blob = new Blob([script]);
return new Worker(URL.createObjectURL(blob));
function makeWorker(test) {
var blob = new Blob([document.getElementById("myWorker").textContent]);
var worker = new Worker(URL.createObjectURL(blob));
worker.onerror = test.unreached_func("error");
return worker;
}

function drawImageBitmap(image, x, y)
Expand All @@ -126,15 +127,15 @@
}

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker();
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
worker.postMessage('test1');
}, "Test that transferToImageBitmap returns an ImageBitmap with correct width and height in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
var clr = drawImageBitmap(msg.data, 50, 25);
assert_array_equals(clr, [0, 255, 0, 255]);
Expand All @@ -143,7 +144,7 @@
}, "Test that transferToImageBitmap returns an ImageBitmap with correct color in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
var clr = drawImageBitmap(msg.data, 50, 25);
assert_array_equals(clr, [0, 0, 0, 0]);
Expand All @@ -152,7 +153,7 @@
}, "Test that call transferToImageBitmap twice returns an ImageBitmap with correct color in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
var clr = drawImageBitmap(msg.data, 50, 25);
assert_array_equals(clr, [0, 0, 0, 255]);
Expand All @@ -161,15 +162,15 @@
}, "Test that call transferToImageBitmap twice on a alpha-disabled context returns an ImageBitmap with correct color in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
worker.postMessage('test5');
}, "Test that transferToImageBitmap won't change context's property in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
var clr1 = drawImageBitmap(msg.data, 23, 25);
assert_array_equals(clr1, [0, 255, 0, 255]);
Expand All @@ -180,7 +181,7 @@
}, "Test that call transferToImageBitmap preserves transform in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand All @@ -189,7 +190,7 @@
}, "Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception in a worker");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
</script>

<script>
function makeWorker(script)
{
var blob = new Blob([script]);
return new Worker(URL.createObjectURL(blob));
function makeWorker(test) {
var blob = new Blob([document.getElementById("myWorker").textContent]);
var worker = new Worker(URL.createObjectURL(blob));
worker.onerror = test.unreached_func("error");
return worker;
}

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_equals(msg.data.width, 10);
assert_equals(msg.data.height, 10);
Expand All @@ -95,23 +96,23 @@
}, "Test that OffscreenCanvas's size is correct after being transferred from a worker.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
worker.postMessage('test2');
}, "Test that transfer an OffscreenCanvas that has a 2d context throws exception in a worker.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
assert_true(msg.data);
}));
worker.postMessage('test3');
}, "Test that transfer an OffscreenCanvas that has a webgl context throws exception in a worker.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand All @@ -120,7 +121,7 @@
}, "Test that transfer an OffscreenCanvas twice throws exception in a worker.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand All @@ -129,7 +130,7 @@
}, "Test that calling getContext('2d') on a detached OffscreenCanvas throws exception in a worker.");

async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var worker = makeWorker(t);
worker.addEventListener('message', t.step_func_done(function(msg) {
if (msg.data == true || msg.data == false)
assert_true(msg.data);
Expand Down

0 comments on commit 8b2d92a

Please sign in to comment.