tor-browser

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

browser_stylesheets_getTextEmpty.js (1597B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that StyleSheetsActor.getText handles empty text correctly.
      7 
      8 const CSS_CONTENT = "body { background-color: #f06; }";
      9 const TEST_URI = `data:text/html;charset=utf-8,<style>${encodeURIComponent(
     10  CSS_CONTENT
     11 )}</style>`;
     12 
     13 add_task(async function () {
     14  const tab = await addTab(TEST_URI);
     15 
     16  const commands = await CommandsFactory.forTab(tab);
     17  await commands.targetCommand.startListening();
     18  const target = commands.targetCommand.targetFront;
     19 
     20  const styleSheetsFront = await target.getFront("stylesheets");
     21  ok(styleSheetsFront, "The StyleSheetsFront was created.");
     22 
     23  const sheets = [];
     24  await commands.resourceCommand.watchResources(
     25    [commands.resourceCommand.TYPES.STYLESHEET],
     26    {
     27      onAvailable: resources => sheets.push(...resources),
     28    }
     29  );
     30  is(sheets.length, 1, "watchResources returned the correct number of sheets");
     31 
     32  const { resourceId } = sheets[0];
     33 
     34  is(
     35    await getStyleSheetText(styleSheetsFront, resourceId),
     36    CSS_CONTENT,
     37    "The stylesheet has expected initial text"
     38  );
     39  info("Update stylesheet content via the styleSheetsFront");
     40  await styleSheetsFront.update(resourceId, "", false);
     41  is(
     42    await getStyleSheetText(styleSheetsFront, resourceId),
     43    "",
     44    "Stylesheet is now empty, as expected"
     45  );
     46 
     47  await commands.destroy();
     48 });
     49 
     50 async function getStyleSheetText(styleSheetsFront, resourceId) {
     51  const longStringFront = await styleSheetsFront.getText(resourceId);
     52  return longStringFront.string();
     53 }