tor-browser

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

browser_test_report_missing_child_module.js (1676B)


      1 const TEST_URL =
      2  "https://example.com/browser/dom/tests/browser/page_test_report_missing_child_module.html";
      3 
      4 const EXPECTED_MESSAGE = "Loading failed for the module with source ";
      5 
      6 function waitForError(expectedBadModule) {
      7  return new Promise(resolve => {
      8    const listener = {
      9      QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]),
     10      observe(message) {
     11        if (
     12          message.message.includes(expectedBadModule) &&
     13          message.message.includes(EXPECTED_MESSAGE)
     14        ) {
     15          message.QueryInterface(Ci.nsIScriptError);
     16          Services.console.unregisterListener(listener);
     17          resolve(message);
     18        }
     19      },
     20    };
     21    Services.console.registerListener(listener);
     22  });
     23 }
     24 
     25 add_task(async function () {
     26  // We need the console listeners in place BEFORE we load the test page.
     27  const childLoadPromise = waitForError(
     28    "/intentionally-non-existent-child-module.mjs"
     29  );
     30  const grandchildLoadPromise = waitForError(
     31    "/intentionally-non-existent-grandchild-module.mjs"
     32  );
     33 
     34  await BrowserTestUtils.withNewTab(TEST_URL, async function () {
     35    const childLoadError = await childLoadPromise;
     36    Assert.stringContains(
     37      childLoadError.sourceName,
     38      "file_test_report_missing_child_module_parent.mjs",
     39      "A failure to load a top-level module's child should be attributed to the top-level module"
     40    );
     41 
     42    const grandchildLoadError = await grandchildLoadPromise;
     43    Assert.stringContains(
     44      grandchildLoadError.sourceName,
     45      "file_test_report_missing_child_module_parent_02.mjs",
     46      "A failure to load a non-top-level module A's child B should be attributed to A"
     47    );
     48  });
     49 });