summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/name/test_browserui.xhtml
blob: d7834eb3c0baaf9e07f0c4da010a504ea52ce255 (plain)
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
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Accessibility Name Calculating Test.">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../promisified-events.js"></script>

  <script type="application/javascript">
  <![CDATA[
    const { BrowserTestUtils } = ChromeUtils.importESModule(
      "resource://testing-common/BrowserTestUtils.sys.mjs");
    const ABOUT_MOZILLA_URL = "about:mozilla";
    const ABOUT_LICENSE_URL = "about:license";

    SimpleTest.waitForExplicitFinish();

    (async () => {
      info("Opening a new browser window.");
      const win = await BrowserTestUtils.openNewBrowserWindow({
        remote: false,
        fission: false,
      });
      const winFocused = SimpleTest.promiseFocus(win);
      const loaded = BrowserTestUtils.browserLoaded(
        win.gBrowser.selectedBrowser);
      let docLoaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, event =>
        event.accessible.QueryInterface(nsIAccessibleDocument).URL === ABOUT_LICENSE_URL,
        `Loaded tab: ${ABOUT_LICENSE_URL}`);
      BrowserTestUtils.startLoadingURIString(win.gBrowser.selectedBrowser,
        "about:license");
      await loaded;
      await docLoaded;
      await winFocused;

      info(`Loading a new tab: ${ABOUT_MOZILLA_URL}.`);
      docLoaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, event =>
        event.accessible.QueryInterface(nsIAccessibleDocument).URL === ABOUT_MOZILLA_URL,
        `Added tab: ${ABOUT_MOZILLA_URL}`);
      const tab = win.gBrowser.addTrustedTab(ABOUT_MOZILLA_URL);
      await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
      await docLoaded;

      info("Focusing on the newly opened tab.");
      const focused = waitForEvent(EVENT_FOCUS, event =>
        event.DOMNode === win.gBrowser.getBrowserAtIndex(1).contentDocument);
      await BrowserTestUtils.synthesizeKey("VK_TAB", { ctrlKey: true },
        win.gBrowser.selectedBrowser);
      const focusEvent = await focused;

      const title = getAccessible(win.document).name;
      const accName = focusEvent.accessible.name;
      isnot(title.indexOf(accName), -1,
        `Window title contains the name of active tab document (Is "${accName}" in "${title}"?)`);

      await BrowserTestUtils.closeWindow(win);
      SimpleTest.finish();
    })();
  ]]>
  </script>

  <vbox flex="1" style="overflow: auto;">
  <body xmlns="http://www.w3.org/1999/xhtml">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=507382"
       title="focus is fired earlier than root accessible name is changed when switching between tabs">
      Mozilla Bug
    </a>
    <p id="display"></p>
    <div id="content" style="display: none">
    </div>
    <pre id="test">
    </pre>
  </body>

  <vbox id="eventdump"></vbox>
  </vbox>
</window>