tor-browser

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

browser_contentTheme_in_process_tab.js (2541B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests that tabs running in the parent process can hear about updates
      8 * to lightweight themes via contentTheme.js.
      9 *
     10 * The test loads the History Sidebar document in a tab to avoid having
     11 * to create a special parent-process page for the LightweightTheme
     12 * JSWindow actors.
     13 */
     14 add_task(async function test_in_process_tab() {
     15  let win = await BrowserTestUtils.openNewBrowserWindow();
     16  const IN_PROCESS_URI = "chrome://browser/content/places/historySidebar.xhtml";
     17  const SIDEBAR_BGCOLOR = "rgb(255, 0, 0)";
     18  // contentTheme.js will always convert the sidebar text color to rgba, so
     19  // we need to compare against that.
     20  const SIDEBAR_TEXT_COLOR = "rgba(0, 255, 0, 1)";
     21 
     22  await BrowserTestUtils.withNewTab(
     23    {
     24      gBrowser: win.gBrowser,
     25      url: IN_PROCESS_URI,
     26    },
     27    async browser => {
     28      await SpecialPowers.spawn(
     29        browser,
     30        [SIDEBAR_BGCOLOR, SIDEBAR_TEXT_COLOR],
     31        async (bgColor, textColor) => {
     32          let style = content.document.documentElement.style;
     33          Assert.notEqual(
     34            style.getPropertyValue("--sidebar-background-color"),
     35            bgColor
     36          );
     37          Assert.notEqual(
     38            style.getPropertyValue("--sidebar-text-color"),
     39            textColor
     40          );
     41        }
     42      );
     43 
     44      // Now cobble together a very simple theme that sets the sidebar background
     45      // and text color.
     46      let lwtData = {
     47        theme: {
     48          sidebar: SIDEBAR_BGCOLOR,
     49          sidebar_text: SIDEBAR_TEXT_COLOR,
     50        },
     51        darkTheme: null,
     52        window: win.docShell.outerWindowID,
     53      };
     54 
     55      Services.obs.notifyObservers(lwtData, "lightweight-theme-styling-update");
     56 
     57      await SpecialPowers.spawn(
     58        browser,
     59        [SIDEBAR_BGCOLOR, SIDEBAR_TEXT_COLOR],
     60        async (bgColor, textColor) => {
     61          let style = content.document.documentElement.style;
     62          Assert.equal(
     63            style.getPropertyValue("--sidebar-background-color"),
     64            bgColor,
     65            "The sidebar background text color should have been set by " +
     66              "contentTheme.js"
     67          );
     68          Assert.equal(
     69            style.getPropertyValue("--sidebar-text-color"),
     70            textColor,
     71            "The sidebar background text color should have been set by " +
     72              "contentTheme.js"
     73          );
     74        }
     75      );
     76    }
     77  );
     78 
     79  await BrowserTestUtils.closeWindow(win);
     80 });