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
|
/* 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/. */
"use strict";
const BUTTONID = "test-widget-saved-earlier";
const AREAID = "test-area-saved-earlier";
var hadSavedState;
function test() {
// Hack our way into the module to fake a saved state that isn't there...
let backstagePass = ChromeUtils.import(
"resource:///modules/CustomizableUI.jsm",
null
);
hadSavedState = backstagePass.gSavedState != null;
if (!hadSavedState) {
backstagePass.gSavedState = { placements: {} };
}
backstagePass.gSavedState.placements[AREAID] = [BUTTONID];
// Put bogus stuff in the saved state for the nav-bar, so as to check the current placements
// override this one...
backstagePass.gSavedState.placements[CustomizableUI.AREA_NAVBAR] = [
"bogus-navbar-item",
];
backstagePass.gDirty = true;
backstagePass.CustomizableUIInternal.saveState();
let newSavedState = JSON.parse(
Services.prefs.getCharPref("browser.uiCustomization.state")
);
let savedArea = Array.isArray(newSavedState.placements[AREAID]);
ok(
savedArea,
"Should have re-saved the state, even though the area isn't registered"
);
if (savedArea) {
placementArraysEqual(AREAID, newSavedState.placements[AREAID], [BUTTONID]);
}
ok(
!backstagePass.gPlacements.has(AREAID),
"Placements map shouldn't have been affected"
);
let savedNavbar = Array.isArray(
newSavedState.placements[CustomizableUI.AREA_NAVBAR]
);
ok(savedNavbar, "Should have saved nav-bar contents");
if (savedNavbar) {
placementArraysEqual(
CustomizableUI.AREA_NAVBAR,
newSavedState.placements[CustomizableUI.AREA_NAVBAR],
CustomizableUI.getWidgetIdsInArea(CustomizableUI.AREA_NAVBAR)
);
}
}
registerCleanupFunction(function() {
let backstagePass = ChromeUtils.import(
"resource:///modules/CustomizableUI.jsm",
null
);
if (!hadSavedState) {
backstagePass.gSavedState = null;
} else {
let savedPlacements = backstagePass.gSavedState.placements;
delete savedPlacements[AREAID];
let realNavBarPlacements = CustomizableUI.getWidgetIdsInArea(
CustomizableUI.AREA_NAVBAR
);
savedPlacements[CustomizableUI.AREA_NAVBAR] = realNavBarPlacements;
}
backstagePass.gDirty = true;
backstagePass.CustomizableUIInternal.saveState();
});
|