Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <title>Canvas Tests</title>
3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
5 <body>
6 <script>
8 SimpleTest.waitForExplicitFinish();
9 const Cc = SpecialPowers.Cc;
10 const Cr = SpecialPowers.Cr;
11 SpecialPowers.setBoolPref("canvas.focusring.enabled", true);
12 SpecialPowers.setBoolPref("canvas.customfocusring.enabled", true);
13 </script>
15 <p>Canvas test: drawCustomFocusRing</p>
16 <canvas id="c688" class="output" width="100" height="50">+
17 <input id="button1" type="range" min="1" max="12"></input>
18 <input id="button2" type="range" min="1" max="12"></input>
19 </canvas>
20 <script type="text/javascript">
21 function test_drawCustomFocusRing_canvas() {
22 var c = document.getElementById("c688");
23 var ctx = c.getContext("2d");
24 ctx.beginPath();
25 var b1 = document.getElementById('button1');
26 var b2 = document.getElementById('button2');
27 ok(!ctx.drawCustomFocusRing(b1), "button 1 is focused");
28 ok(!ctx.drawCustomFocusRing(b2), "button 2 is focused");
29 b1.focus();
30 ok(ctx.drawCustomFocusRing(b1), "button 1 should not be focused");
31 }
32 </script>
34 <p>Canvas test: drawFocusIfNeeded</p>
35 <canvas id="c689" class="output" width="50" height="25">
36 <input id="button3" type="range" min="1" max="12"></input>
37 <input id="button4" type="range" min="1" max="12"></input>
38 </canvas>
39 <script type="text/javascript">
40 function isEmptyCanvas(ctx, w, h) {
41 var imgdata = ctx.getImageData(0, 0, w, h);
42 for(var x = 0; x < w*h*4; x++)
43 if(imgdata.data[x] != 0)
44 return false;
45 return true;
46 }
48 function test_drawFocusIfNeeded_canvas() {
49 var c = document.getElementById("c689");
50 var ctx = c.getContext("2d");
51 var b1 = document.getElementById('button3');
52 var b2 = document.getElementById('button4');
53 ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
54 ctx.beginPath();
55 ctx.rect(10, 10, 30, 30);
56 ctx.drawFocusIfNeeded(b1);
57 ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 1 is drawn");
59 ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
60 ctx.beginPath();
61 ctx.rect(50, 10, 30, 30);
62 ctx.drawFocusIfNeeded(b2);
63 ctx.rect(50, 10, 30, 30);
64 ctx.drawFocusIfNeeded(b2);
65 ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 2 is drawn");
67 b1.focus();
68 ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
69 ctx.beginPath();
70 ctx.rect(10, 10, 30, 30);
71 ctx.drawFocusIfNeeded(b1);
72 ok(!isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height) , "focus of button 1 is not drawn");
73 }
74 </script>
77 <script>
79 function runTests() {
80 try {
81 test_drawCustomFocusRing_canvas();
82 } catch(e) {
83 throw e;
84 ok(false, "unexpected exception thrown in: test_drawCustomFocusRing_canvas");
85 }
86 try {
87 test_drawFocusIfNeeded_canvas();
88 } catch(e) {
89 throw e;
90 ok(false, "unexpected exception thrown in: test_drawFocusIfNeeded_canvas");
91 }
93 SpecialPowers.setBoolPref("canvas.focusring.enabled", false);
94 SpecialPowers.setBoolPref("canvas.customfocusring.enabled", false);
95 SimpleTest.finish();
96 }
98 addLoadEvent(runTests);
100 </script>