tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_nested_iframe.js (5017B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from ../../mochitest/role.js */
      8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      9 
     10 const NESTED_IFRAME_DOC_BODY_ID = "nested-iframe-body";
     11 const NESTED_IFRAME_ID = "nested-iframe";
     12 // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     13 const nestedURL = new URL(`http://example.com/document-builder.sjs`);
     14 nestedURL.searchParams.append(
     15  "html",
     16  `<html>
     17      <head>
     18        <meta charset="utf-8"/>
     19        <title>Accessibility Nested Iframe Frame Test</title>
     20      </head>
     21      <body id="${NESTED_IFRAME_DOC_BODY_ID}">
     22        <table id="table">
     23          <tr>
     24            <td>cell1</td>
     25            <td>cell2</td>
     26          </tr>
     27        </table>
     28        <ul id="ul">
     29          <li id="li">item1</li>
     30        </ul>
     31      </body>
     32    </html>`
     33 );
     34 
     35 function getOsPid(browsingContext) {
     36  return browsingContext.currentWindowGlobal.osPid;
     37 }
     38 
     39 addAccessibleTask(
     40  `<iframe id="${NESTED_IFRAME_ID}" src="${nestedURL.href}"/>`,
     41  async function (browser, iframeDocAcc, contentDocAcc) {
     42    ok(iframeDocAcc, "IFRAME document accessible is present");
     43    let nestedDocAcc = findAccessibleChildByID(
     44      iframeDocAcc,
     45      NESTED_IFRAME_DOC_BODY_ID
     46    );
     47    let waitForNestedDocLoad = false;
     48    if (nestedDocAcc) {
     49      const state = {};
     50      nestedDocAcc.getState(state, {});
     51      if (state.value & STATE_BUSY) {
     52        info("Nested IFRAME document accessible is present but busy");
     53        waitForNestedDocLoad = true;
     54      } else {
     55        ok(true, "Nested IFRAME document accessible is present and ready");
     56      }
     57    } else {
     58      info("Nested IFRAME document accessible is not present yet");
     59      waitForNestedDocLoad = true;
     60    }
     61    if (waitForNestedDocLoad) {
     62      info("Waiting for doc load complete on nested iframe document");
     63      nestedDocAcc = (
     64        await waitForEvent(
     65          EVENT_DOCUMENT_LOAD_COMPLETE,
     66          NESTED_IFRAME_DOC_BODY_ID
     67        )
     68      ).accessible;
     69    }
     70 
     71    if (gIsRemoteIframe) {
     72      isnot(
     73        getOsPid(browser.browsingContext),
     74        getOsPid(browser.browsingContext.children[0]),
     75        `Content and IFRAME documents are in separate processes.`
     76      );
     77      isnot(
     78        getOsPid(browser.browsingContext),
     79        getOsPid(browser.browsingContext.children[0].children[0]),
     80        `Content and nested IFRAME documents are in separate processes.`
     81      );
     82      isnot(
     83        getOsPid(browser.browsingContext.children[0]),
     84        getOsPid(browser.browsingContext.children[0].children[0]),
     85        `IFRAME and nested IFRAME documents are in separate processes.`
     86      );
     87    } else {
     88      is(
     89        getOsPid(browser.browsingContext),
     90        getOsPid(browser.browsingContext.children[0]),
     91        `Content and IFRAME documents are in same processes.`
     92      );
     93      if (gFissionBrowser) {
     94        isnot(
     95          getOsPid(browser.browsingContext.children[0]),
     96          getOsPid(browser.browsingContext.children[0].children[0]),
     97          `IFRAME and nested IFRAME documents are in separate processes.`
     98        );
     99      } else {
    100        is(
    101          getOsPid(browser.browsingContext),
    102          getOsPid(browser.browsingContext.children[0].children[0]),
    103          `Content and nested IFRAME documents are in same processes.`
    104        );
    105      }
    106    }
    107 
    108    const tree = {
    109      DOCUMENT: [
    110        {
    111          INTERNAL_FRAME: [
    112            {
    113              DOCUMENT: [
    114                {
    115                  INTERNAL_FRAME: [
    116                    {
    117                      DOCUMENT: [
    118                        {
    119                          TABLE: [
    120                            {
    121                              ROW: [
    122                                { CELL: [{ TEXT_LEAF: [] }] },
    123                                { CELL: [{ TEXT_LEAF: [] }] },
    124                              ],
    125                            },
    126                          ],
    127                        },
    128                        {
    129                          LIST: [
    130                            {
    131                              LISTITEM: [
    132                                { LISTITEM_MARKER: [] },
    133                                { TEXT_LEAF: [] },
    134                              ],
    135                            },
    136                          ],
    137                        },
    138                      ],
    139                    },
    140                  ],
    141                },
    142              ],
    143            },
    144          ],
    145        },
    146      ],
    147    };
    148    testAccessibleTree(contentDocAcc, tree);
    149 
    150    const nestedIframeAcc = iframeDocAcc.getChildAt(0);
    151    is(
    152      nestedIframeAcc.getChildAt(0),
    153      nestedDocAcc,
    154      "Document for nested IFRAME matches."
    155    );
    156 
    157    is(
    158      nestedDocAcc.parent,
    159      nestedIframeAcc,
    160      "Nested IFRAME document's parent matches the nested IFRAME."
    161    );
    162  },
    163  { topLevel: false, iframe: true, remoteIframe: true }
    164 );