summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/target-configuration/tests/browser_target_configuration_command.js
blob: 47dab1baa9291720100ef5d2155b413a304fdc1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test the watcher's target-configuration actor API.

add_task(async function () {
  info("Setup the test page with workers of all types");
  const tab = await addTab("data:text/html;charset=utf-8,Configuration actor");

  info("Create a target list for a tab target");
  const commands = await CommandsFactory.forTab(tab);

  const targetConfigurationCommand = commands.targetConfigurationCommand;
  const targetCommand = commands.targetCommand;
  await targetCommand.startListening();

  compareOptions(
    targetConfigurationCommand.configuration,
    {},
    "Initial configuration is empty"
  );

  await targetConfigurationCommand.updateConfiguration({
    cacheDisabled: true,
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    { cacheDisabled: true },
    "Option cacheDisabled was set"
  );

  await targetConfigurationCommand.updateConfiguration({
    javascriptEnabled: false,
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    { cacheDisabled: true, javascriptEnabled: false },
    "Option javascriptEnabled was set"
  );

  await targetConfigurationCommand.updateConfiguration({
    cacheDisabled: false,
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    { cacheDisabled: false, javascriptEnabled: false },
    "Option cacheDisabled was updated"
  );

  await targetConfigurationCommand.updateConfiguration({
    colorSchemeSimulation: "dark",
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    {
      cacheDisabled: false,
      colorSchemeSimulation: "dark",
      javascriptEnabled: false,
    },
    "Option colorSchemeSimulation was set, with a string value"
  );

  await targetConfigurationCommand.updateConfiguration({
    setTabOffline: true,
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    {
      cacheDisabled: false,
      colorSchemeSimulation: "dark",
      javascriptEnabled: false,
      setTabOffline: true,
    },
    "Option setTabOffline was set on"
  );

  await targetConfigurationCommand.updateConfiguration({
    setTabOffline: false,
  });
  compareOptions(
    targetConfigurationCommand.configuration,
    {
      setTabOffline: false,
      cacheDisabled: false,
      colorSchemeSimulation: "dark",
      javascriptEnabled: false,
    },
    "Option setTabOffline was set off"
  );

  targetCommand.destroy();
  await commands.destroy();
});

function compareOptions(options, expected, message) {
  is(
    Object.keys(options).length,
    Object.keys(expected).length,
    message + " (wrong number of options)"
  );

  for (const key of Object.keys(expected)) {
    is(options[key], expected[key], message + ` (wrong value for ${key})`);
  }
}