summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/unifiedtoolbar/test/unit/test_customizationState.js
blob: 048b5c5cde3765343ef52de3b553a35bd54c35d9 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { TestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TestUtils.sys.mjs"
);
const { storeState, getState } = ChromeUtils.importESModule(
  "resource:///modules/CustomizationState.mjs"
);

add_setup(function () {
  // Ensure xulStore has a profile to refer to.
  do_get_profile();
});

add_task(function test_getState_empty() {
  const state = getState();
  Assert.equal(typeof state, "object", "State should be an object");
  Assert.deepEqual(state, {}, "Empty state should be an empty object");
});

add_task(async function test_storeState_observer() {
  const stateChangeObserved = TestUtils.topicObserved(
    "unified-toolbar-state-change"
  );
  storeState({
    mail: ["write-message", "spacer", "search-bar", "spacer"],
  });
  await stateChangeObserved;
});

add_task(function test_storeState_getState() {
  const state = {
    mail: ["write-message", "spacer", "search-bar", "spacer"],
    calendar: [],
  };
  const previousState = getState();
  Assert.notDeepEqual(
    previousState,
    state,
    "Current state should be different from the state to write"
  );
  storeState(state);
  const newState = getState();
  Assert.deepEqual(
    newState,
    state,
    "State loaded should matche the stored state"
  );
  Assert.notStrictEqual(
    newState,
    state,
    "State loaded should not be the same object as what was saved"
  );
});

registerCleanupFunction(() => {
  Services.xulStore.removeValue(
    "chrome://messenger/content/messenger.xhtml",
    "unifiedToolbar",
    "state"
  );
});