tor-browser

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

browser_computed_original-source-link.js (2191B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests that the computed view shows the original source link when source maps
      7 // are enabled.
      8 
      9 const TESTCASE_URI = URL_ROOT_SSL + "doc_sourcemaps.html";
     10 const PREF = "devtools.source-map.client-service.enabled";
     11 const SCSS_LOC = "doc_sourcemaps.scss:4";
     12 const CSS_LOC = "doc_sourcemaps.css:1";
     13 
     14 add_task(async function () {
     15  info("Turning the pref " + PREF + " on");
     16  Services.prefs.setBoolPref(PREF, true);
     17 
     18  await addTab(TESTCASE_URI);
     19  const { toolbox, inspector, view } = await openComputedView();
     20  let onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
     21  await selectNode("div", inspector);
     22 
     23  info("Expanding the first property");
     24  await expandComputedViewPropertyByIndex(view, 0);
     25 
     26  info("Verifying the link text");
     27  await onLinksUpdated;
     28  verifyLinkText(view, SCSS_LOC);
     29 
     30  info("Toggling the pref");
     31  onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
     32  Services.prefs.setBoolPref(PREF, false);
     33  await onLinksUpdated;
     34 
     35  info("Verifying that the link text has changed after the pref change");
     36  await verifyLinkText(view, CSS_LOC);
     37 
     38  info("Toggling the pref again");
     39  onLinksUpdated = inspector.once("computed-view-sourcelinks-updated");
     40  Services.prefs.setBoolPref(PREF, true);
     41  await onLinksUpdated;
     42 
     43  info("Testing that clicking on the link works");
     44  await testClickingLink(toolbox, view);
     45 
     46  info("Turning the pref " + PREF + " off");
     47  Services.prefs.clearUserPref(PREF);
     48 });
     49 
     50 async function testClickingLink(toolbox, view) {
     51  const onEditor = waitForStyleEditor(toolbox, "doc_sourcemaps.scss");
     52 
     53  info("Clicking the computedview stylesheet link");
     54  const link = getComputedViewLinkByIndex(view, 0);
     55  link.scrollIntoView();
     56  link.click();
     57 
     58  const editor = await onEditor;
     59 
     60  const { line } = editor.sourceEditor.getCursor();
     61  is(line, 3, "cursor is at correct line number in original source");
     62 }
     63 
     64 function verifyLinkText(view, text) {
     65  const link = getComputedViewLinkByIndex(view, 0);
     66  is(
     67    link.textContent,
     68    text,
     69    "Linked text changed to display the correct location"
     70  );
     71 }