browser_as_load_location.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. /**
  3. * Helper to test that a newtab page loads its html document.
  4. *
  5. * @param selector {String} CSS selector to find an element in newtab content
  6. * @param message {String} Description of the test printed with the assertion
  7. */
  8. async function checkNewtabLoads(selector, message) {
  9. // simulate a newtab open as a user would
  10. BrowserOpenTab();
  11. // wait until the browser loads
  12. let browser = gBrowser.selectedBrowser;
  13. await waitForPreloaded(browser);
  14. // check what the content task thinks has been loaded.
  15. let found = await ContentTask.spawn(browser, selector, arg =>
  16. content.document.querySelector(arg) !== null);
  17. ok(found, message);
  18. // avoid leakage
  19. BrowserTestUtils.removeTab(gBrowser.selectedTab);
  20. }
  21. // Test with activity stream on
  22. async function checkActivityStreamLoads() {
  23. await checkNewtabLoads("body.activity-stream", "Got <body class='activity-stream'> Element");
  24. }
  25. // Run a first time not from a preloaded browser
  26. add_task(async function checkActivityStreamNotPreloadedLoad() {
  27. NewTabPagePreloading.removePreloadedBrowser(window);
  28. await checkActivityStreamLoads();
  29. });
  30. // Run a second time from a preloaded browser
  31. add_task(checkActivityStreamLoads);