summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/browser/browser_browserLoaded_content_loaded.js
blob: fa29e03d2318810017a7a50eefa8716de7be3c59 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

function isDOMLoaded(browser) {
  return SpecialPowers.spawn(browser, [], async function () {
    Assert.equal(
      content.document.readyState,
      "complete",
      "Browser should be loaded."
    );
  });
}

// It checks if calling BrowserTestUtils.browserLoaded() yields
// browser object.
add_task(async function () {
  let tab = BrowserTestUtils.addTab(gBrowser, "http://example.com");
  let browser = tab.linkedBrowser;
  await BrowserTestUtils.browserLoaded(browser);
  await isDOMLoaded(browser);
  gBrowser.removeTab(tab);
});

// It checks that BrowserTestUtils.browserLoaded() works well with
// promise.all().
add_task(async function () {
  let tabURLs = [
    `http://example.org`,
    `http://mochi.test:8888`,
    `http://test:80`,
  ];
  // Add tabs, get the respective browsers
  let browsers = tabURLs.map(
    u => BrowserTestUtils.addTab(gBrowser, u).linkedBrowser
  );

  // wait for promises to settle
  await Promise.all(
    (function* () {
      for (let b of browsers) {
        yield BrowserTestUtils.browserLoaded(b);
      }
    })()
  );
  for (const browser of browsers) {
    await isDOMLoaded(browser);
  }
  // cleanup
  browsers
    .map(browser => gBrowser.getTabForBrowser(browser))
    .forEach(tab => gBrowser.removeTab(tab));
});