File: test_canvas_focusring.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (79 lines) | stat: -rw-r--r-- 2,332 bytes parent folder | download | duplicates (23)
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
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML>
<title>Canvas Tests</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<script>
SimpleTest.waitForExplicitFinish();
</script>

<p>Canvas test: drawFocusIfNeeded</p>
<canvas id="c689" class="output" width="50" height="25">
    <input id="button3" type="range" min="1" max="12"></input>
    <input id="button4" type="range" min="1" max="12"></input>
</canvas>
<script type="text/javascript">
function isEmptyCanvas(ctx, w, h) {
  var imgdata = ctx.getImageData(0, 0, w, h);
  for(var x = 0; x < w*h*4; x++)
    if(imgdata.data[x] != 0)
      return false;
  return true;
}

var b1 = document.getElementById('button3');
var b2 = document.getElementById('button4');

function test_drawFocusIfNeeded_canvas() {
  var c = document.getElementById("c689");
  var ctx = c.getContext("2d");
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  ctx.beginPath();
  ctx.rect(10, 10, 30, 30);
  ctx.drawFocusIfNeeded(b1);
  ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 1 is drawn");

  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  ctx.beginPath();
  ctx.rect(50, 10, 30, 30);
  ctx.drawFocusIfNeeded(b2);
  ctx.rect(50, 10, 30, 30);
  ctx.drawFocusIfNeeded(b2);
  ok(isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height), "focus of button 2 is drawn");

  b1.focus();
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  ctx.beginPath();
  ctx.rect(10, 10, 30, 30);
  ctx.drawFocusIfNeeded(b1);
  ok(!isEmptyCanvas(ctx, ctx.canvas.width, ctx.canvas.height) , "focus of button 1 is not drawn");
}
</script>


<script>

async function runTests() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["canvas.focusring.enabled", true],
      ["browser.display.always_show_rings_after_key_focus", true],
    ]
  });
  await SimpleTest.promiseFocus();
  synthesizeKey("KEY_Tab"); // Trigger keyboard navigation so outlines are shown.
  synthesizeKey("KEY_Tab", { shiftKey: true }); // And now undo the focus move.
  try {
    test_drawFocusIfNeeded_canvas();
  } catch(e) {
    ok(false, "unexpected exception thrown in: test_drawFocusIfNeeded_canvas");
    throw e;
  }

 SimpleTest.finish();
}

addLoadEvent(runTests);

</script>