tor-browser

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

browser_styleeditor_sourcemaps_inline.js (2353B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // https rather than chrome to improve coverage
      7 const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps-inline.html";
      8 const PREF = "devtools.source-map.client-service.enabled";
      9 
     10 const sassContent = `body {
     11  background-color: black;
     12  & > h1 {
     13    color: white;
     14  }
     15 }
     16 `;
     17 
     18 const cssContent =
     19  `body {
     20  background-color: black;
     21 }
     22 body > h1 {
     23  color: white;
     24 }
     25 ` +
     26  "/*# sourceMappingURL=data:application/json;base64,ewoidmVyc2lvbiI6IDMsCiJtY" +
     27  "XBwaW5ncyI6ICJBQUFBLElBQUs7RUFDSCxnQkFBZ0IsRUFBRSxLQUFLO0VBQ3ZCLFNBQU87SUFD" +
     28  "TCxLQUFLLEVBQUUsS0FBSyIsCiJzb3VyY2VzIjogWyJ0ZXN0LnNjc3MiXSwKInNvdXJjZXNDb25" +
     29  "0ZW50IjogWyJib2R5IHtcbiAgYmFja2dyb3VuZC1jb2xvcjogYmxhY2s7XG4gICYgPiBoMSB7XG" +
     30  "4gICAgY29sb3I6IHdoaXRlO1xuICB9XG59XG4iXSwKIm5hbWVzIjogW10sCiJmaWxlIjogInRlc" +
     31  "3QuY3NzIgp9Cg== */";
     32 
     33 add_task(async function () {
     34  const { ui } = await openStyleEditorForURL(TESTCASE_URI);
     35 
     36  is(
     37    ui.editors.length,
     38    1,
     39    "correct number of editors with source maps enabled"
     40  );
     41 
     42  await testEditor(ui.editors[0], "test.scss", sassContent);
     43 
     44  // Test disabling original sources
     45  await togglePref(ui);
     46 
     47  is(ui.editors.length, 1, "correct number of editors after pref toggled");
     48 
     49  // Test CSS editors
     50  await testEditor(ui.editors[0], "<inline style sheet #1>", cssContent);
     51 
     52  Services.prefs.clearUserPref(PREF);
     53 });
     54 
     55 async function testEditor(editor, expectedName, expectedText) {
     56  const name = getStylesheetNameFor(editor);
     57  is(expectedName, name, name + " editor name is correct");
     58 
     59  await openEditor(editor);
     60  const text = editor.sourceEditor.getText();
     61  is(text, expectedText, name + " editor contains expected text");
     62 }
     63 
     64 /* Helpers */
     65 
     66 function togglePref(UI) {
     67  const editorsPromise = UI.once("stylesheets-refreshed");
     68  const selectedPromise = UI.once("editor-selected");
     69 
     70  Services.prefs.setBoolPref(PREF, false);
     71 
     72  return Promise.all([editorsPromise, selectedPromise]);
     73 }
     74 
     75 function openEditor(editor) {
     76  getLinkFor(editor).click();
     77 
     78  return editor.getSourceEditor();
     79 }
     80 
     81 function getLinkFor(editor) {
     82  return editor.summary.querySelector(".stylesheet-name");
     83 }
     84 
     85 function getStylesheetNameFor(editor) {
     86  return editor.summary
     87    .querySelector(".stylesheet-name > label")
     88    .getAttribute("value");
     89 }