tor-browser

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

browser_source_map-late-script.js (1433B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that you can subscribe to notifications on a source before it has loaded.
      5 
      6 "use strict";
      7 
      8 const PAGE_URL = `${URL_ROOT_SSL}doc_empty-tab-01.html`;
      9 const JS_URL = URL_ROOT_SSL + "code_bundle_late_script.js";
     10 
     11 const ORIGINAL_URL = "webpack:///code_late_script.js";
     12 
     13 const GENERATED_LINE = 107;
     14 const ORIGINAL_LINE = 11;
     15 
     16 add_task(async function () {
     17  // Start with the empty page, then navigate, so that we can properly
     18  // listen for new sources arriving.
     19  const toolbox = await openNewTabAndToolbox(PAGE_URL, "webconsole");
     20  const service = toolbox.sourceMapURLService;
     21 
     22  const scriptMapped = new Promise(resolve => {
     23    let count = 0;
     24    service.subscribeByURL(
     25      JS_URL,
     26      GENERATED_LINE,
     27      undefined,
     28      originalLocation => {
     29        if (count === 0) {
     30          resolve(originalLocation);
     31        }
     32        count += 1;
     33 
     34        return () => {};
     35      }
     36    );
     37  });
     38 
     39  // Inject JS script
     40  const sourceSeen = waitForSourceLoad(toolbox, JS_URL);
     41  await createScript(JS_URL);
     42  await sourceSeen;
     43 
     44  // Ensure that the URL service fired an event about the location loading.
     45  const { url, line } = await scriptMapped;
     46  is(url, ORIGINAL_URL, "check mapped URL");
     47  is(line, ORIGINAL_LINE, "check mapped line number");
     48 
     49  await toolbox.destroy();
     50  gBrowser.removeCurrentTab();
     51  finish();
     52 });