content/canvas/test/test_canvas_focusring.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial