summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/test_offscreencanvas_neuter.html
blob: 2af080c7c1effc91cee4ee28824ab56a05de07d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE HTML>
<html>
<head>
<title>OffscreenCanvas: Test neutering</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<canvas id="c" width="64" height="64"></canvas>
<script>

SimpleTest.waitForExplicitFinish();

function runTest() {

  var htmlCanvas = document.getElementById("c");
  var worker = new Worker("offscreencanvas_neuter.js");

  ok(htmlCanvas, "Should have HTML canvas element");
  ok(worker, "Web worker successfully created");

  ok(htmlCanvas.transferControlToOffscreen, "HTMLCanvasElement has transferControlToOffscreen function");

  var offscreenCanvas = htmlCanvas.transferControlToOffscreen();
  ok(offscreenCanvas, "Expected transferControlToOffscreen to succeed");

  /* check html canvas is neuterd */
  is(htmlCanvas.width, 64, "HTML canvas has correct width");
  SimpleTest.doesThrow(
    function() { htmlCanvas.width = 128; },
    "Can't change html canvas' width after transferControlToOffscreen");

  SimpleTest.doesThrow(
    function() { htmlCanvas.height = 128; },
    "Can't change html canvas' height after transferControlToOffscreen");

  ok(!htmlCanvas.getContext("2d"), "Can't getContext after transferControlToOffscreen");
  ok(!htmlCanvas.getContext("webgl"), "Can't getContext after transferControlToOffscreen");
  ok(!htmlCanvas.getContext("webgl2"), "Can't getContext after transferControlToOffscreen");

  worker.postMessage(offscreenCanvas, [offscreenCanvas]);

  /* check parent offscreencanvas is neutered after being transfered */
  SimpleTest.doesThrow(
    function() { offscreenCanvas.width = 128; },
    "Can't change transfered worker canvas width");

  SimpleTest.doesThrow(
    function() { offscreenCanvas.height = 128; },
    "Can't change transfered worker canvas height");

  SimpleTest.doesThrow(
    function() { offscreenCanvas.getContext("2d") },
    "Can't getContext on transfered worker canvas");

  SimpleTest.doesThrow(
    function() { offscreenCanvas.getContext("webgl") },
    "Can't getContext on transfered worker canvas");

  SimpleTest.doesThrow(
    function() { offscreenCanvas.getContext("webgl2") },
    "Can't getContext on transfered worker canvas");

  // Transfer a neutered offscreencanvas should be ok.
  worker.postMessage(offscreenCanvas, [offscreenCanvas]);

  worker.terminate();
  SimpleTest.finish();
}

SpecialPowers.pushPrefEnv({'set': [
  ['gfx.offscreencanvas.enabled', true],
  ['webgl.force-enabled', true],
]}, runTest);

</script>
</body>
</html>