Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const kWidgetId = "some-widget";
9 function assertWidgetExists(aWindow, aExists) {
10 if (aExists) {
11 ok(aWindow.document.getElementById(kWidgetId),
12 "Should have found test widget in the window");
13 } else {
14 is(aWindow.document.getElementById(kWidgetId), null,
15 "Should not have found test widget in the window");
16 }
17 }
19 // A widget that is created with showInPrivateBrowsing undefined should
20 // have that value default to true.
21 add_task(function() {
22 let wrapper = CustomizableUI.createWidget({
23 id: kWidgetId
24 });
25 ok(wrapper.showInPrivateBrowsing,
26 "showInPrivateBrowsing should have defaulted to true.");
27 CustomizableUI.destroyWidget(kWidgetId);
28 });
30 // Add a widget via the API with showInPrivateBrowsing set to false
31 // and ensure it does not appear in pre-existing or newly created
32 // private windows.
33 add_task(function() {
34 let plain1 = yield openAndLoadWindow();
35 let private1 = yield openAndLoadWindow({private: true});
36 CustomizableUI.createWidget({
37 id: kWidgetId,
38 removable: true,
39 showInPrivateBrowsing: false
40 });
41 CustomizableUI.addWidgetToArea(kWidgetId,
42 CustomizableUI.AREA_NAVBAR);
43 assertWidgetExists(plain1, true);
44 assertWidgetExists(private1, false);
46 // Now open up some new windows. The widget should exist in the new
47 // plain window, but not the new private window.
48 let plain2 = yield openAndLoadWindow();
49 let private2 = yield openAndLoadWindow({private: true});
50 assertWidgetExists(plain2, true);
51 assertWidgetExists(private2, false);
53 // Try moving the widget around and make sure it doesn't get added
54 // to the private windows. We'll start by appending it to the tabstrip.
55 CustomizableUI.addWidgetToArea(kWidgetId,
56 CustomizableUI.AREA_TABSTRIP);
57 assertWidgetExists(plain1, true);
58 assertWidgetExists(plain2, true);
59 assertWidgetExists(private1, false);
60 assertWidgetExists(private2, false);
62 // And then move it to the beginning of the tabstrip.
63 CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
64 assertWidgetExists(plain1, true);
65 assertWidgetExists(plain2, true);
66 assertWidgetExists(private1, false);
67 assertWidgetExists(private2, false);
69 CustomizableUI.removeWidgetFromArea("some-widget");
70 assertWidgetExists(plain1, false);
71 assertWidgetExists(plain2, false);
72 assertWidgetExists(private1, false);
73 assertWidgetExists(private2, false);
75 yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
77 CustomizableUI.destroyWidget("some-widget");
78 });
80 // Add a widget via the API with showInPrivateBrowsing set to true,
81 // and ensure that it appears in pre-existing or newly created
82 // private browsing windows.
83 add_task(function() {
84 let plain1 = yield openAndLoadWindow();
85 let private1 = yield openAndLoadWindow({private: true});
87 CustomizableUI.createWidget({
88 id: kWidgetId,
89 removable: true,
90 showInPrivateBrowsing: true
91 });
92 CustomizableUI.addWidgetToArea(kWidgetId,
93 CustomizableUI.AREA_NAVBAR);
94 assertWidgetExists(plain1, true);
95 assertWidgetExists(private1, true);
97 // Now open up some new windows. The widget should exist in the new
98 // plain window, but not the new private window.
99 let plain2 = yield openAndLoadWindow();
100 let private2 = yield openAndLoadWindow({private: true});
102 assertWidgetExists(plain2, true);
103 assertWidgetExists(private2, true);
105 // Try moving the widget around and make sure it doesn't get added
106 // to the private windows. We'll start by appending it to the tabstrip.
107 CustomizableUI.addWidgetToArea(kWidgetId,
108 CustomizableUI.AREA_TABSTRIP);
109 assertWidgetExists(plain1, true);
110 assertWidgetExists(plain2, true);
111 assertWidgetExists(private1, true);
112 assertWidgetExists(private2, true);
114 // And then move it to the beginning of the tabstrip.
115 CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
116 assertWidgetExists(plain1, true);
117 assertWidgetExists(plain2, true);
118 assertWidgetExists(private1, true);
119 assertWidgetExists(private2, true);
121 CustomizableUI.removeWidgetFromArea("some-widget");
122 assertWidgetExists(plain1, false);
123 assertWidgetExists(plain2, false);
124 assertWidgetExists(private1, false);
125 assertWidgetExists(private2, false);
127 yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
129 CustomizableUI.destroyWidget("some-widget");
130 });
132 add_task(function asyncCleanup() {
133 yield resetCustomization();
134 });