summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/webgl/array-setters.html
blob: 648a63faeda142a79b4cbb7a4c768f250e38a1c8 (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
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/webgl-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>

<script>
description("Test all permutations of WebGLArray setters to make sure values don't get truncated");

debug('Regression test for <a href="https://bugs.webkit.org/show_bug.cgi?id=33350">https://bugs.webkit.org/show_bug.cgi?id=33350</a> : <code>WebGLArray subclasses do the wrong conversion in indexSetter</code>');

var webGLArray = null;
var array = null;

function testSetters(typeName, low, high) {
    var type = window[typeName];
    webGLArray = new type(2);
    array = [low, high];
    debug("Testing " + typeName);
    webGLArray.set(array);
    shouldBe("webGLArray", "array");
    shouldBe("webGLArray[0]", "array[0]");
    shouldBe("webGLArray[1]", "array[1]");
    webGLArray[0] = 0;
    webGLArray[1] = 0;
    shouldBe("webGLArray[0]", "0");
    shouldBe("webGLArray[1]", "0");
    webGLArray[0] = array[0];
    shouldBe("webGLArray[0]", "array[0]");
    webGLArray[1] = array[1];
    shouldBe("webGLArray[1]", "array[1]");

    // Verify set() behaves correctly with shared underlying buffer. 
    array = [0, 1, 2, 3, 4, 5];
    webGLArray = new type(6);
    webGLArray.set(array);
    array = webGLArray.subarray(2, 4);
    array[0] = 88;
    array[1] = 99;
    shouldBe("webGLArray[2]", "88");
    shouldBe("webGLArray[3]", "99");
    // pre-overlap
    webGLArray.set(array, 1);
    shouldBe("webGLArray[1]", "88");
    shouldBe("webGLArray[2]", "99");
    shouldBe("array[0]", "99");
    shouldBe("array[1]", "99");
    array[1] = 77;
    // post-overlap
    webGLArray.set(array, 3);
    shouldBe("webGLArray[3]", "99");
    shouldBe("webGLArray[4]", "77");
    shouldBe("array[0]", "99");
    shouldBe("array[1]", "99");
}

testSetters("Int8Array", -128, 127);
testSetters("Uint8Array", 0, 255);
testSetters("Int16Array", -32768, 32767);
testSetters("Uint16Array", 0, 65535);
testSetters("Int32Array", -2147483648, 2147483647);
testSetters("Uint32Array", 0, 4294967295);
testSetters("Float32Array", -2.5, 3.5);
</script>

</body>
</html>