1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_876944_customize_mode_create_destroy.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const kTestWidget1 = "test-customize-mode-create-destroy1"; 1.11 +const kTestWidget2 = "test-customize-mode-create-destroy2"; 1.12 + 1.13 +// Creating and destroying a widget should correctly wrap/unwrap stuff 1.14 +add_task(function testWrapUnwrap() { 1.15 + yield startCustomizing(); 1.16 + CustomizableUI.createWidget({id: kTestWidget1, label: 'Pretty label', tooltiptext: 'Pretty tooltip'}); 1.17 + let elem = document.getElementById(kTestWidget1); 1.18 + let wrapper = document.getElementById("wrapper-" + kTestWidget1); 1.19 + ok(elem, "There should be an item"); 1.20 + ok(wrapper, "There should be a wrapper"); 1.21 + is(wrapper.firstChild.id, kTestWidget1, "Wrapper should have test widget"); 1.22 + is(wrapper.parentNode.id, "customization-palette", "Wrapper should be in palette"); 1.23 + CustomizableUI.destroyWidget(kTestWidget1); 1.24 + wrapper = document.getElementById("wrapper-" + kTestWidget1); 1.25 + ok(!wrapper, "There should be a wrapper"); 1.26 + let item = document.getElementById(kTestWidget1); 1.27 + ok(!item, "There should no longer be an item"); 1.28 +}); 1.29 + 1.30 +// Creating and destroying a widget should correctly deal with panel placeholders 1.31 +add_task(function testPanelPlaceholders() { 1.32 + let panel = document.getElementById(CustomizableUI.AREA_PANEL); 1.33 + is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 1 : 2, "The number of placeholders should be correct."); 1.34 + CustomizableUI.createWidget({id: kTestWidget2, label: 'Pretty label', tooltiptext: 'Pretty tooltip', defaultArea: CustomizableUI.AREA_PANEL}); 1.35 + let elem = document.getElementById(kTestWidget2); 1.36 + let wrapper = document.getElementById("wrapper-" + kTestWidget2); 1.37 + ok(elem, "There should be an item"); 1.38 + ok(wrapper, "There should be a wrapper"); 1.39 + is(wrapper.firstChild.id, kTestWidget2, "Wrapper should have test widget"); 1.40 + is(wrapper.parentNode, panel, "Wrapper should be in panel"); 1.41 + is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 3 : 1, "The number of placeholders should be correct."); 1.42 + CustomizableUI.destroyWidget(kTestWidget2); 1.43 + wrapper = document.getElementById("wrapper-" + kTestWidget2); 1.44 + ok(!wrapper, "There should be a wrapper"); 1.45 + let item = document.getElementById(kTestWidget2); 1.46 + ok(!item, "There should no longer be an item"); 1.47 + yield endCustomizing(); 1.48 +}); 1.49 + 1.50 +add_task(function asyncCleanup() { 1.51 + yield endCustomizing(); 1.52 + try { 1.53 + CustomizableUI.destroyWidget(kTestWidget1); 1.54 + } catch (ex) {} 1.55 + try { 1.56 + CustomizableUI.destroyWidget(kTestWidget2); 1.57 + } catch (ex) {} 1.58 + yield resetCustomization(); 1.59 +});