summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/browser/browser_as_load_location.js
blob: f11b6cf503fc602e1bff0aef8e7e961e4e254c1d (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
"use strict";

/**
 * Helper to test that a newtab page loads its html document.
 *
 * @param selector {String} CSS selector to find an element in newtab content
 * @param message {String} Description of the test printed with the assertion
 */
async function checkNewtabLoads(selector, message) {
  // simulate a newtab open as a user would
  BrowserOpenTab();

  // wait until the browser loads
  let browser = gBrowser.selectedBrowser;
  await waitForPreloaded(browser);

  // check what the content task thinks has been loaded.
  let found = await ContentTask.spawn(
    browser,
    selector,
    arg => content.document.querySelector(arg) !== null
  );
  ok(found, message);

  // avoid leakage
  BrowserTestUtils.removeTab(gBrowser.selectedTab);
}

// Test with activity stream on
async function checkActivityStreamLoads() {
  await checkNewtabLoads(
    "body.activity-stream",
    "Got <body class='activity-stream'> Element"
  );
}

// Run a first time not from a preloaded browser
add_task(async function checkActivityStreamNotPreloadedLoad() {
  NewTabPagePreloading.removePreloadedBrowser(window);
  await checkActivityStreamLoads();
});

// Run a second time from a preloaded browser
add_task(checkActivityStreamLoads);