tor-browser

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

browser_resources_stylesheets_import.js (1762B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test the ResourceCommand API for imported STYLESHEET + iframe.
      7 
      8 const styleSheetText = `
      9 @import "${URL_ROOT_ORG_SSL}/style_document.css";
     10 body { background-color: tomato; }`;
     11 
     12 const IFRAME_URL = `https://example.org/document-builder.sjs?html=${encodeURIComponent(`
     13  <style>${styleSheetText}</style>
     14  <h1>iframe</h1>
     15 `)}`;
     16 
     17 const TEST_URL = `https://example.org/document-builder.sjs?html=
     18  <h1>import stylesheet test</h1>
     19  <iframe src="${encodeURIComponent(IFRAME_URL)}"></iframe>`;
     20 
     21 add_task(async function () {
     22  info("Check resource available feature of the ResourceCommand");
     23 
     24  const tab = await addTab(TEST_URL);
     25 
     26  const { client, resourceCommand, targetCommand } =
     27    await initResourceCommand(tab);
     28 
     29  info("Check whether ResourceCommand gets existing stylesheet");
     30  const availableResources = [];
     31  await resourceCommand.watchResources([resourceCommand.TYPES.STYLESHEET], {
     32    onAvailable: resources => availableResources.push(...resources),
     33  });
     34 
     35  await waitFor(() => availableResources.length === 2);
     36  ok(true, "We're getting the expected stylesheets");
     37 
     38  const styleNodeStyleSheet = availableResources.find(
     39    resource => resource.nodeHref
     40  );
     41  const importedStyleSheet = availableResources.find(
     42    resource => resource !== styleNodeStyleSheet
     43  );
     44 
     45  is(
     46    await getStyleSheetResourceText(styleNodeStyleSheet),
     47    styleSheetText,
     48    "Got expected text for the <style> stylesheet"
     49  );
     50 
     51  is(
     52    (await getStyleSheetResourceText(importedStyleSheet)).trim(),
     53    `body { margin: 1px; }`,
     54    "Got expected text for the imported stylesheet"
     55  );
     56 
     57  targetCommand.destroy();
     58  await client.close();
     59 });