summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/filters/tentative/idl-conversions/canvas-filter-sequence-conversion.html
blob: d48627867e3996873da95c2826622fdb7350760d (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
<!DOCTYPE html>
<title>Canvas test: canvas-filter-sequence-conversion</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>canvas-filter-sequence-conversion</h1>
<p class="desc">Test converting types into sequences</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>

<ul id="d"></ul>
<script>
var t = async_test("Test pixels on CanvasFilter() various inputs to tableValues (which is a sequence)");
_addTest(function(canvas, ctx) {

  // Inputs to parameters that are expecting sequence<long>. Results are either the value of the
  // red pixel drawing using the resultant filter or that we expect this input to throw an error.
  const testCases = [
    {input: [], result: 0},
    {input: [0.5], result: 127},
    {input: ["0.5"], result: 127},
    {input: 1, result: "throws"},
    {input: {}, result: "throws"},
    {input: false, result: "throws"},
    {input: true, result: "throws"},
    {input: NaN, result: "throws"},
    {input: { valueOf() { return [1]; }}, result: "throws"},
  ];

  // A simple filter that just overrides the red channel if successful.
  function makeFilter(value) {
    return new CanvasFilter({
      name: "componentTransfer",
      funcR: {type: "table", tableValues: value}
    });
  }

  for (const tc of testCases) {
    if (tc.result === "throws") {
      assert_throws_js(TypeError, function(){ makeFilter(tc.input) });
    } else {
      ctx.reset();
      ctx.filter = makeFilter(tc.input);
      ctx.fillRect(0, 0, 100, 100);
      _assertPixelApprox(canvas, 5, 5, tc.result,0,0,255, 2);
    }
  }
  t.done();
});
</script>