tor-browser

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

browser_styleeditor_bug_740541_iframes.js (2776B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that sheets inside iframes are shown in the editor.
      6 
      7 add_task(async function () {
      8  function makeStylesheet(selector) {
      9    return (
     10      "data:text/css;charset=UTF-8," + encodeURIComponent(selector + " { }")
     11    );
     12  }
     13 
     14  function makeDocument(stylesheets, framedDocuments) {
     15    stylesheets = stylesheets || [];
     16    framedDocuments = framedDocuments || [];
     17    return (
     18      "data:text/html;charset=UTF-8," +
     19      encodeURIComponent(
     20        Array.prototype.concat
     21          .call(
     22            [
     23              "<!DOCTYPE html>",
     24              "<html>",
     25              "<head>",
     26              "<title>Bug 740541</title>",
     27            ],
     28            stylesheets.map(function (sheet) {
     29              return (
     30                '<link rel="stylesheet" type="text/css" href="' + sheet + '">'
     31              );
     32            }),
     33            ["</head>", "<body>"],
     34            framedDocuments.map(function (doc) {
     35              return '<iframe src="' + doc + '"></iframe>';
     36            }),
     37            ["</body>", "</html>"]
     38          )
     39          .join("\n")
     40      )
     41    );
     42  }
     43 
     44  const DOCUMENT_WITH_INLINE_STYLE =
     45    "data:text/html;charset=UTF-8," +
     46    encodeURIComponent(
     47      [
     48        "<!DOCTYPE html>",
     49        "<html>",
     50        " <head>",
     51        "  <title>Bug 740541</title>",
     52        '  <style type="text/css">',
     53        "    .something {",
     54        "    }",
     55        "  </style>",
     56        " </head>",
     57        " <body>",
     58        " </body>",
     59        " </html>",
     60      ].join("\n")
     61    );
     62 
     63  const FOUR = TEST_BASE_HTTP + "four.html";
     64 
     65  const SIMPLE = TEST_BASE_HTTP + "simple.css";
     66 
     67  const SIMPLE_DOCUMENT = TEST_BASE_HTTP + "simple.html";
     68 
     69  const TESTCASE_URI = makeDocument(
     70    [makeStylesheet(".a")],
     71    [
     72      makeDocument([], [FOUR, DOCUMENT_WITH_INLINE_STYLE]),
     73      makeDocument(
     74        [makeStylesheet(".b"), SIMPLE],
     75        [makeDocument([makeStylesheet(".c")], [])]
     76      ),
     77      makeDocument([SIMPLE], []),
     78      SIMPLE_DOCUMENT,
     79    ]
     80  );
     81 
     82  const EXPECTED_STYLE_SHEET_COUNT = 12;
     83 
     84  const { ui } = await openStyleEditorForURL(TESTCASE_URI);
     85 
     86  is(
     87    ui.editors.length,
     88    EXPECTED_STYLE_SHEET_COUNT,
     89    "Got the expected number of style sheets."
     90  );
     91 
     92  // Verify that stylesheets are removed when their related target is destroyed
     93  info("Remove all iframes");
     94  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
     95    const iframes = content.document.querySelectorAll("iframe");
     96    for (const iframe of iframes) {
     97      iframe.remove();
     98    }
     99  });
    100 
    101  await waitFor(
    102    () => ui.editors.length == 1,
    103    "Wait until all iframe stylesheets are removed and we only have the top document one"
    104  );
    105 });