1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_canvas_focusring.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas Tests</title> 1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script> 1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> 1.8 +<body> 1.9 +<script> 1.10 + 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +const Cc = SpecialPowers.Cc; 1.13 +const Cr = SpecialPowers.Cr; 1.14 +SpecialPowers.setBoolPref("canvas.focusring.enabled", true); 1.15 +SpecialPowers.setBoolPref("canvas.customfocusring.enabled", true); 1.16 +</script> 1.17 + 1.18 +<p>Canvas test: drawCustomFocusRing</p> 1.19 +<canvas id="c688" class="output" width="100" height="50">+ 1.20 + <input id="button1" type="range" min="1" max="12"></input> 1.21 + <input id="button2" type="range" min="1" max="12"></input> 1.22 +</canvas> 1.23 +<script type="text/javascript"> 1.24 +function test_drawCustomFocusRing_canvas() { 1.25 + var c = document.getElementById("c688"); 1.26 + var ctx = c.getContext("2d"); 1.27 + ctx.beginPath(); 1.28 + var b1 = document.getElementById('button1'); 1.29 + var b2 = document.getElementById('button2'); 1.30 + ok(!ctx.drawCustomFocusRing(b1), "button 1 is focused"); 1.31 + ok(!ctx.drawCustomFocusRing(b2), "button 2 is focused"); 1.32 + b1.focus(); 1.33 + ok(ctx.drawCustomFocusRing(b1), "button 1 should not be focused"); 1.34 +} 1.35 +</script> 1.36 + 1.37 +<p>Canvas test: drawFocusIfNeeded</p> 1.38 +<canvas id="c689" class="output" width="50" height="25"> 1.39 + <input id="button3" type="range" min="1" max="12"></input> 1.40 + <input id="button4" type="range" min="1" max="12"></input> 1.41 +</canvas> 1.42 +<script type="text/javascript"> 1.43 +function isEmptyCanvas(ctx, w, h) { 1.44 + var imgdata = ctx.getImageData(0, 0, w, h); 1.45 + for(var x = 0; x < w*h*4; x++) 1.46 + if(imgdata.data[x] != 0) 1.47 + return false; 1.48 + return true; 1.49 +} 1.50 + 1.51 +function test_drawFocusIfNeeded_canvas() { 1.52 + var c = document.getElementById("c689"); 1.53 + var ctx = c.getContext("2d"); 1.54 + var b1 = document.getElementById('button3'); 1.55 + var b2 = document.getElementById('button4'); 1.56 + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); 1.57 + ctx.beginPath(); 1.58 + ctx.rect(10, 10, 30, 30); 1.59 + ctx.drawFocusIfNeeded(b1); 1.60 + ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 1 is drawn"); 1.61 + 1.62 + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); 1.63 + ctx.beginPath(); 1.64 + ctx.rect(50, 10, 30, 30); 1.65 + ctx.drawFocusIfNeeded(b2); 1.66 + ctx.rect(50, 10, 30, 30); 1.67 + ctx.drawFocusIfNeeded(b2); 1.68 + ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 2 is drawn"); 1.69 + 1.70 + b1.focus(); 1.71 + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); 1.72 + ctx.beginPath(); 1.73 + ctx.rect(10, 10, 30, 30); 1.74 + ctx.drawFocusIfNeeded(b1); 1.75 + ok(!isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height) , "focus of button 1 is not drawn"); 1.76 +} 1.77 +</script> 1.78 + 1.79 + 1.80 +<script> 1.81 + 1.82 +function runTests() { 1.83 + try { 1.84 + test_drawCustomFocusRing_canvas(); 1.85 + } catch(e) { 1.86 + throw e; 1.87 + ok(false, "unexpected exception thrown in: test_drawCustomFocusRing_canvas"); 1.88 + } 1.89 + try { 1.90 + test_drawFocusIfNeeded_canvas(); 1.91 + } catch(e) { 1.92 + throw e; 1.93 + ok(false, "unexpected exception thrown in: test_drawFocusIfNeeded_canvas"); 1.94 + } 1.95 + 1.96 + SpecialPowers.setBoolPref("canvas.focusring.enabled", false); 1.97 + SpecialPowers.setBoolPref("canvas.customfocusring.enabled", false); 1.98 + SimpleTest.finish(); 1.99 +} 1.100 + 1.101 +addLoadEvent(runTests); 1.102 + 1.103 +</script>