tor-browser

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

browser_target_configuration_command.js (2835B)


      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 watcher's target-configuration actor API.
      7 
      8 add_task(async function () {
      9  info("Setup the test page with workers of all types");
     10  const tab = await addTab("data:text/html;charset=utf-8,Configuration actor");
     11 
     12  info("Create a target list for a tab target");
     13  const commands = await CommandsFactory.forTab(tab);
     14 
     15  const targetConfigurationCommand = commands.targetConfigurationCommand;
     16  const targetCommand = commands.targetCommand;
     17  await targetCommand.startListening();
     18 
     19  compareOptions(
     20    targetConfigurationCommand.configuration,
     21    {},
     22    "Initial configuration is empty"
     23  );
     24 
     25  await targetConfigurationCommand.updateConfiguration({
     26    cacheDisabled: true,
     27  });
     28  compareOptions(
     29    targetConfigurationCommand.configuration,
     30    { cacheDisabled: true },
     31    "Option cacheDisabled was set"
     32  );
     33 
     34  await targetConfigurationCommand.updateConfiguration({
     35    javascriptEnabled: false,
     36  });
     37  compareOptions(
     38    targetConfigurationCommand.configuration,
     39    { cacheDisabled: true, javascriptEnabled: false },
     40    "Option javascriptEnabled was set"
     41  );
     42 
     43  await targetConfigurationCommand.updateConfiguration({
     44    cacheDisabled: false,
     45  });
     46  compareOptions(
     47    targetConfigurationCommand.configuration,
     48    { cacheDisabled: false, javascriptEnabled: false },
     49    "Option cacheDisabled was updated"
     50  );
     51 
     52  await targetConfigurationCommand.updateConfiguration({
     53    colorSchemeSimulation: "dark",
     54  });
     55  compareOptions(
     56    targetConfigurationCommand.configuration,
     57    {
     58      cacheDisabled: false,
     59      colorSchemeSimulation: "dark",
     60      javascriptEnabled: false,
     61    },
     62    "Option colorSchemeSimulation was set, with a string value"
     63  );
     64 
     65  await targetConfigurationCommand.updateConfiguration({
     66    setTabOffline: true,
     67  });
     68  compareOptions(
     69    targetConfigurationCommand.configuration,
     70    {
     71      cacheDisabled: false,
     72      colorSchemeSimulation: "dark",
     73      javascriptEnabled: false,
     74      setTabOffline: true,
     75    },
     76    "Option setTabOffline was set on"
     77  );
     78 
     79  await targetConfigurationCommand.updateConfiguration({
     80    setTabOffline: false,
     81  });
     82  compareOptions(
     83    targetConfigurationCommand.configuration,
     84    {
     85      setTabOffline: false,
     86      cacheDisabled: false,
     87      colorSchemeSimulation: "dark",
     88      javascriptEnabled: false,
     89    },
     90    "Option setTabOffline was set off"
     91  );
     92 
     93  targetCommand.destroy();
     94  await commands.destroy();
     95 });
     96 
     97 function compareOptions(options, expected, message) {
     98  is(
     99    Object.keys(options).length,
    100    Object.keys(expected).length,
    101    message + " (wrong number of options)"
    102  );
    103 
    104  for (const key of Object.keys(expected)) {
    105    is(options[key], expected[key], message + ` (wrong value for ${key})`);
    106  }
    107 }