File: test_bug629172.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (105 lines) | stat: -rw-r--r-- 3,950 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=629172
-->
<head>
  <title>Test for Bug 629172</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629172">Mozilla Bug 629172</a>
<p id="display"></p>
<div id="content">
<textarea id="ltr-ref">test.</textarea>
<textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea>
</div>
<pre id="test">
<script>

/** Test for Bug 629172 */
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async function() {
  await SpecialPowers.pushPrefEnv({
    set: [["test.events.async.enabled", true]],
  });

  let LTRRef = document.getElementById("ltr-ref");
  let RTLRef = document.getElementById("rtl-ref");
  let ReferenceScreenshots = {};

  // generate the reference screenshots
  document.body.clientWidth;
  ReferenceScreenshots.ltr = snapshotWindow(window);
  LTRRef.remove();
  RTLRef.style.display = "";
  document.body.clientWidth;
  ReferenceScreenshots.rtl = snapshotWindow(window);
  RTLRef.remove();

  async function testDirection(initialDir) {
    function revertDir(aDir) {
      return aDir == "rtl" ? "ltr" : "rtl";
    }

    function promiseFormatSetBlockTextDirectionInputEvent(aElement) {
      return new Promise(resolve => {
        function handler(aEvent) {
          if (aEvent.inputType !== "formatSetBlockTextDirection") {
            ok(false, `Unexpected input event received: inputType="${aEvent.inputType}"`);
          } else {
            aElement.removeEventListener("input", handler, true);
            SimpleTest.executeSoon(resolve);
          }
        }
        aElement.addEventListener("input", handler, true);
      });
    }

    let textarea = document.createElement("textarea");
    textarea.setAttribute("dir", initialDir);
    textarea.value = "test.";
    document.getElementById("content").appendChild(textarea);
    document.body.clientWidth;
    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[initialDir],
                    /* expectEqual = */ true, /* fuzz = */ null,
                    `<textarea dir="${initialDir}"> before Accel+Shift+X`,
                    `<textarea dir="${initialDir}">`);
    textarea.focus();
    let waitForInputEvent = promiseFormatSetBlockTextDirectionInputEvent(textarea);
    synthesizeKey("X", {accelKey: true, shiftKey: true});
    await waitForInputEvent;
    is(textarea.getAttribute("dir"), revertDir(initialDir),
       "The dir attribute must be correctly updated with first Accel+Shift+X");
    textarea.blur();
    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[revertDir(initialDir)],
                    /* expectEqual = */ true, /* fuzz = */ null,
                    `<textarea dir="${initialDir}"> after first Accel+Shift+X`,
                    `<textarea dir="${revertDir(initialDir)}">`);
    textarea.focus();
    waitForInputEvent = promiseFormatSetBlockTextDirectionInputEvent(textarea);
    synthesizeKey("X", {accelKey: true, shiftKey: true});
    await waitForInputEvent;
    is(textarea.getAttribute("dir"), initialDir,
       "The dir attribute must be correctly recovered with second Accel+Shift+X");
    textarea.blur();
    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[initialDir],
                    /* expectEqual = */ true, /* fuzz = */ null,
                    `<textarea dir="${initialDir}"> after second Accel+Shift+X`,
                    `<textarea dir="${initialDir}">`);
    textarea.remove();
  }

  await testDirection("ltr");
  await testDirection("rtl");

  SimpleTest.finish();
});

</script>
</pre>
</body>
</html>