tor-browser

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

browser_styleeditor_loading_with_containers.js (1839B)


      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 the stylesheets can be loaded correctly with containers
      7 // (bug 1282660).
      8 
      9 const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
     10 const EXPECTED_SHEETS = [
     11  {
     12    sheetIndex: 0,
     13    name: /^simple.css$/,
     14    rules: 1,
     15    active: true,
     16  },
     17  {
     18    sheetIndex: 1,
     19    name: /^<.*>$/,
     20    rules: 3,
     21    active: false,
     22  },
     23 ];
     24 
     25 add_task(async function () {
     26  // Using the personal container.
     27  const userContextId = 1;
     28  const { tab } = await openTabInUserContext(TESTCASE_URI, userContextId);
     29  const { ui } = await openStyleEditor(tab);
     30 
     31  is(ui.editors.length, 2, "The UI contains two style sheets.");
     32  await checkSheet(ui.editors[0], EXPECTED_SHEETS[0]);
     33  await checkSheet(ui.editors[1], EXPECTED_SHEETS[1]);
     34 });
     35 
     36 async function openTabInUserContext(uri, userContextId) {
     37  // Open the tab in the correct userContextId.
     38  const tab = BrowserTestUtils.addTab(gBrowser, uri, { userContextId });
     39 
     40  // Select tab and make sure its browser is focused.
     41  gBrowser.selectedTab = tab;
     42  tab.ownerDocument.defaultView.focus();
     43 
     44  const browser = gBrowser.getBrowserForTab(tab);
     45  await BrowserTestUtils.browserLoaded(browser);
     46  return { tab, browser };
     47 }
     48 
     49 async function checkSheet(editor, expected) {
     50  is(
     51    editor.styleSheet.styleSheetIndex,
     52    expected.sheetIndex,
     53    "Style sheet has correct index."
     54  );
     55 
     56  const summary = editor.summary;
     57  const name = summary
     58    .querySelector(".stylesheet-name > label")
     59    .getAttribute("value");
     60  ok(expected.name.test(name), "The name '" + name + "' is correct.");
     61 
     62  await assertRuleCount(editor, expected.rules);
     63 
     64  is(
     65    summary.classList.contains("splitview-active"),
     66    expected.active,
     67    "The active status for this sheet is correct."
     68  );
     69 }