summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/fission/browser_nested_iframe.js
blob: d6600a2d5e075bba16bff7214e3079ed16ee27ff (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/role.js */
loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });

const NESTED_IFRAME_DOC_BODY_ID = "nested-iframe-body";
const NESTED_IFRAME_ID = "nested-iframe";
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
const nestedURL = new URL(`http://example.com/document-builder.sjs`);
nestedURL.searchParams.append(
  "html",
  `<html>
      <head>
        <meta charset="utf-8"/>
        <title>Accessibility Nested Iframe Frame Test</title>
      </head>
      <body id="${NESTED_IFRAME_DOC_BODY_ID}">
        <table id="table">
          <tr>
            <td>cell1</td>
            <td>cell2</td>
          </tr>
        </table>
        <ul id="ul">
          <li id="li">item1</li>
        </ul>
      </body>
    </html>`
);

function getOsPid(browsingContext) {
  return browsingContext.currentWindowGlobal.osPid;
}

addAccessibleTask(
  `<iframe id="${NESTED_IFRAME_ID}" src="${nestedURL.href}"/>`,
  async function (browser, iframeDocAcc, contentDocAcc) {
    ok(iframeDocAcc, "IFRAME document accessible is present");
    let nestedDocAcc = findAccessibleChildByID(
      iframeDocAcc,
      NESTED_IFRAME_DOC_BODY_ID
    );
    let waitForNestedDocLoad = false;
    if (nestedDocAcc) {
      const state = {};
      nestedDocAcc.getState(state, {});
      if (state.value & STATE_BUSY) {
        info("Nested IFRAME document accessible is present but busy");
        waitForNestedDocLoad = true;
      } else {
        ok(true, "Nested IFRAME document accessible is present and ready");
      }
    } else {
      info("Nested IFRAME document accessible is not present yet");
      waitForNestedDocLoad = true;
    }
    if (waitForNestedDocLoad) {
      info("Waiting for doc load complete on nested iframe document");
      nestedDocAcc = (
        await waitForEvent(
          EVENT_DOCUMENT_LOAD_COMPLETE,
          NESTED_IFRAME_DOC_BODY_ID
        )
      ).accessible;
    }

    if (gIsRemoteIframe) {
      isnot(
        getOsPid(browser.browsingContext),
        getOsPid(browser.browsingContext.children[0]),
        `Content and IFRAME documents are in separate processes.`
      );
      isnot(
        getOsPid(browser.browsingContext),
        getOsPid(browser.browsingContext.children[0].children[0]),
        `Content and nested IFRAME documents are in separate processes.`
      );
      isnot(
        getOsPid(browser.browsingContext.children[0]),
        getOsPid(browser.browsingContext.children[0].children[0]),
        `IFRAME and nested IFRAME documents are in separate processes.`
      );
    } else {
      is(
        getOsPid(browser.browsingContext),
        getOsPid(browser.browsingContext.children[0]),
        `Content and IFRAME documents are in same processes.`
      );
      if (gFissionBrowser) {
        isnot(
          getOsPid(browser.browsingContext.children[0]),
          getOsPid(browser.browsingContext.children[0].children[0]),
          `IFRAME and nested IFRAME documents are in separate processes.`
        );
      } else {
        is(
          getOsPid(browser.browsingContext),
          getOsPid(browser.browsingContext.children[0].children[0]),
          `Content and nested IFRAME documents are in same processes.`
        );
      }
    }

    const tree = {
      DOCUMENT: [
        {
          INTERNAL_FRAME: [
            {
              DOCUMENT: [
                {
                  INTERNAL_FRAME: [
                    {
                      DOCUMENT: [
                        {
                          TABLE: [
                            {
                              ROW: [
                                { CELL: [{ TEXT_LEAF: [] }] },
                                { CELL: [{ TEXT_LEAF: [] }] },
                              ],
                            },
                          ],
                        },
                        {
                          LIST: [
                            {
                              LISTITEM: [
                                { LISTITEM_MARKER: [] },
                                { TEXT_LEAF: [] },
                              ],
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    };
    testAccessibleTree(contentDocAcc, tree);

    const nestedIframeAcc = iframeDocAcc.getChildAt(0);
    is(
      nestedIframeAcc.getChildAt(0),
      nestedDocAcc,
      "Document for nested IFRAME matches."
    );

    is(
      nestedDocAcc.parent,
      nestedIframeAcc,
      "Nested IFRAME document's parent matches the nested IFRAME."
    );
  },
  { topLevel: false, iframe: true, remoteIframe: true }
);