summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/e10s/browser_caching_large_update.js
blob: ccf8a86921c511b2381abf0fbfb849f89ae7e460 (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
/* 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";

/**
 * Test a large update which adds many thousands of Accessibles with a
 * lot of content in each.
 */
addAccessibleTask(
  `<main id="main" hidden></main>`,
  async function (browser, docAcc) {
    let shown = waitForEvent(EVENT_SHOW, "main");
    await invokeContentTask(browser, [], () => {
      // Make a long string.
      let text = "";
      for (let i = 0; i < 100; ++i) {
        text += "a";
      }
      // Create lots of nodes which include the long string.
      const contMain = content.document.getElementById("main");
      // 15000 children of main.
      for (let w = 0; w < 15000; ++w) {
        // Each of those goes 9 deep.
        let parent = contMain;
        for (let d = 0; d < 10; ++d) {
          const div = content.document.createElement("div");
          div.setAttribute("aria-label", `${w} ${d} ${text}`);
          parent.append(div);
          parent = div;
        }
      }
      contMain.hidden = false;
    });
    const main = (await shown).accessible;
    is(main.childCount, 15000, "main has correct number of children");

    // We don't want to output passes for every check, since that would output
    // hundreds of thousands of lines, which slows the test to a crawl. Instead,
    // output any failures and keep track of overall success/failure.
    let treeOk = true;
    function check(val, msg) {
      if (!val) {
        ok(false, msg);
        treeOk = false;
      }
    }

    info("Checking tree");
    for (let w = 0; w < 15000; ++w) {
      let acc = main.getChildAt(w);
      let parent = main;
      for (let d = 0; d < 10; ++d) {
        check(acc, `Got child ${w} depth ${d}`);
        const name = `${w} ${d}`;
        check(acc.name.startsWith(name + " "), `${name}: correct name`);
        check(acc.parent == parent, `${name}: correct parent`);
        parent = acc;
        acc = acc.firstChild;
      }
    }
    // check() sets treeOk to false for any failure.
    ok(treeOk, "Tree is correct");
  }
);