tor-browser

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

browser_caching_large_update.js (2086B)


      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 /**
      8 * Test a large update which adds many thousands of Accessibles with a
      9 * lot of content in each.
     10 */
     11 addAccessibleTask(`<main id="main" hidden></main>`, async function (browser) {
     12  let shown = waitForEvent(EVENT_SHOW, "main");
     13  await invokeContentTask(browser, [], () => {
     14    // Make a long string.
     15    let text = "";
     16    for (let i = 0; i < 100; ++i) {
     17      text += "a";
     18    }
     19    // Create lots of nodes which include the long string.
     20    const contMain = content.document.getElementById("main");
     21    // 15000 children of main.
     22    for (let w = 0; w < 15000; ++w) {
     23      // Each of those goes 9 deep.
     24      let parent = contMain;
     25      for (let d = 0; d < 10; ++d) {
     26        const div = content.document.createElement("div");
     27        div.setAttribute("aria-label", `${w} ${d} ${text}`);
     28        parent.append(div);
     29        parent = div;
     30      }
     31    }
     32    contMain.hidden = false;
     33  });
     34  const main = (await shown).accessible;
     35  is(main.childCount, 15000, "main has correct number of children");
     36 
     37  // We don't want to output passes for every check, since that would output
     38  // hundreds of thousands of lines, which slows the test to a crawl. Instead,
     39  // output any failures and keep track of overall success/failure.
     40  let treeOk = true;
     41  function check(val, msg) {
     42    if (!val) {
     43      ok(false, msg);
     44      treeOk = false;
     45    }
     46  }
     47 
     48  info("Checking tree");
     49  for (let w = 0; w < 15000; ++w) {
     50    let acc = main.getChildAt(w);
     51    let parent = main;
     52    for (let d = 0; d < 10; ++d) {
     53      check(acc, `Got child ${w} depth ${d}`);
     54      const name = `${w} ${d}`;
     55      check(acc.name.startsWith(name + " "), `${name}: correct name`);
     56      check(acc.parent == parent, `${name}: correct parent`);
     57      parent = acc;
     58      acc = acc.firstChild;
     59    }
     60  }
     61  // check() sets treeOk to false for any failure.
     62  ok(treeOk, "Tree is correct");
     63 });