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";
// NB: This uses some ugly hacks to get into the CUI module from elsewhere...
// don't try this at home, kids.
function test() {
// Customize something to make sure stuff changed:
CustomizableUI.addWidgetToArea("feed-button", CustomizableUI.AREA_NAVBAR);
// Check what version we're on:
let CustomizableUIBSPass = Cu.import("resource:///modules/CustomizableUI.jsm", {});
is(CustomizableUIBSPass.gFuturePlacements.size, 0,
"All future placements should be dealt with by now.");
let {CustomizableUIInternal, gFuturePlacements, gPalette} = CustomizableUIBSPass;
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 0,
"No change to future placements initially.");
let currentVersion = CustomizableUIBSPass.kVersion;
// Add our widget to the defaults:
let testWidgetNew = {
id: "test-messing-with-default-placements-new",
label: "Test messing with default placements - should be inserted",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: currentVersion + 1,
};
let normalizedWidget = CustomizableUIInternal.normalizeWidget(testWidgetNew,
CustomizableUI.SOURCE_BUILTIN);
ok(normalizedWidget, "Widget should be normalizable");
if (!normalizedWidget) {
return;
}
CustomizableUIBSPass.gPalette.set(testWidgetNew.id, normalizedWidget);
let testWidgetOld = {
id: "test-messing-with-default-placements-old",
label: "Test messing with default placements - should NOT be inserted",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: currentVersion,
};
normalizedWidget = CustomizableUIInternal.normalizeWidget(testWidgetOld,
CustomizableUI.SOURCE_BUILTIN);
ok(normalizedWidget, "Widget should be normalizable");
if (!normalizedWidget) {
return;
}
CustomizableUIBSPass.gPalette.set(testWidgetOld.id, normalizedWidget);
// Now increase the version in the module:
CustomizableUIBSPass.kVersion++;
let hadSavedState = !!CustomizableUIBSPass.gSavedState
if (!hadSavedState) {
CustomizableUIBSPass.gSavedState = {currentVersion: CustomizableUIBSPass.kVersion - 1};
}
// Then call the re-init routine so we re-add the builtin widgets
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 1,
"Should have 1 more future placement");
let haveNavbarPlacements = gFuturePlacements.has(CustomizableUI.AREA_NAVBAR);
ok(haveNavbarPlacements, "Should have placements for nav-bar");
if (haveNavbarPlacements) {
let placements = [...gFuturePlacements.get(CustomizableUI.AREA_NAVBAR)];
// Ignore widgets that are placed using the pref facility and not the
// versioned facility. They're independent of kVersion and the saved
// state's current version, so they may be present in the placements.
for (let i = 0; i < placements.length; ) {
if (placements[i] == testWidgetNew.id) {
i++;
continue;
}
let pref = "browser.toolbarbuttons.introduced." + placements[i];
let introduced = false;
try {
introduced = Services.prefs.getBoolPref(pref);
} catch (ex) {}
if (!introduced) {
i++;
continue;
}
placements.splice(i, 1);
}
is(placements.length, 1, "Should have 1 newly placed widget in nav-bar");
is(placements[0], testWidgetNew.id, "Should have our test widget to be placed in nav-bar");
}
gFuturePlacements.delete(CustomizableUI.AREA_NAVBAR);
CustomizableUIBSPass.kVersion--;
gPalette.delete(testWidgetNew.id);
gPalette.delete(testWidgetOld.id);
if (!hadSavedState) {
CustomizableUIBSPass.gSavedState = null;
}
}
|