|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const kTestWidget1 = "test-customize-mode-create-destroy1"; |
|
8 const kTestWidget2 = "test-customize-mode-create-destroy2"; |
|
9 |
|
10 // Creating and destroying a widget should correctly wrap/unwrap stuff |
|
11 add_task(function testWrapUnwrap() { |
|
12 yield startCustomizing(); |
|
13 CustomizableUI.createWidget({id: kTestWidget1, label: 'Pretty label', tooltiptext: 'Pretty tooltip'}); |
|
14 let elem = document.getElementById(kTestWidget1); |
|
15 let wrapper = document.getElementById("wrapper-" + kTestWidget1); |
|
16 ok(elem, "There should be an item"); |
|
17 ok(wrapper, "There should be a wrapper"); |
|
18 is(wrapper.firstChild.id, kTestWidget1, "Wrapper should have test widget"); |
|
19 is(wrapper.parentNode.id, "customization-palette", "Wrapper should be in palette"); |
|
20 CustomizableUI.destroyWidget(kTestWidget1); |
|
21 wrapper = document.getElementById("wrapper-" + kTestWidget1); |
|
22 ok(!wrapper, "There should be a wrapper"); |
|
23 let item = document.getElementById(kTestWidget1); |
|
24 ok(!item, "There should no longer be an item"); |
|
25 }); |
|
26 |
|
27 // Creating and destroying a widget should correctly deal with panel placeholders |
|
28 add_task(function testPanelPlaceholders() { |
|
29 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
30 is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 1 : 2, "The number of placeholders should be correct."); |
|
31 CustomizableUI.createWidget({id: kTestWidget2, label: 'Pretty label', tooltiptext: 'Pretty tooltip', defaultArea: CustomizableUI.AREA_PANEL}); |
|
32 let elem = document.getElementById(kTestWidget2); |
|
33 let wrapper = document.getElementById("wrapper-" + kTestWidget2); |
|
34 ok(elem, "There should be an item"); |
|
35 ok(wrapper, "There should be a wrapper"); |
|
36 is(wrapper.firstChild.id, kTestWidget2, "Wrapper should have test widget"); |
|
37 is(wrapper.parentNode, panel, "Wrapper should be in panel"); |
|
38 is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 3 : 1, "The number of placeholders should be correct."); |
|
39 CustomizableUI.destroyWidget(kTestWidget2); |
|
40 wrapper = document.getElementById("wrapper-" + kTestWidget2); |
|
41 ok(!wrapper, "There should be a wrapper"); |
|
42 let item = document.getElementById(kTestWidget2); |
|
43 ok(!item, "There should no longer be an item"); |
|
44 yield endCustomizing(); |
|
45 }); |
|
46 |
|
47 add_task(function asyncCleanup() { |
|
48 yield endCustomizing(); |
|
49 try { |
|
50 CustomizableUI.destroyWidget(kTestWidget1); |
|
51 } catch (ex) {} |
|
52 try { |
|
53 CustomizableUI.destroyWidget(kTestWidget2); |
|
54 } catch (ex) {} |
|
55 yield resetCustomization(); |
|
56 }); |