michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const kTestWidget1 = "test-customize-mode-create-destroy1"; michael@0: const kTestWidget2 = "test-customize-mode-create-destroy2"; michael@0: michael@0: // Creating and destroying a widget should correctly wrap/unwrap stuff michael@0: add_task(function testWrapUnwrap() { michael@0: yield startCustomizing(); michael@0: CustomizableUI.createWidget({id: kTestWidget1, label: 'Pretty label', tooltiptext: 'Pretty tooltip'}); michael@0: let elem = document.getElementById(kTestWidget1); michael@0: let wrapper = document.getElementById("wrapper-" + kTestWidget1); michael@0: ok(elem, "There should be an item"); michael@0: ok(wrapper, "There should be a wrapper"); michael@0: is(wrapper.firstChild.id, kTestWidget1, "Wrapper should have test widget"); michael@0: is(wrapper.parentNode.id, "customization-palette", "Wrapper should be in palette"); michael@0: CustomizableUI.destroyWidget(kTestWidget1); michael@0: wrapper = document.getElementById("wrapper-" + kTestWidget1); michael@0: ok(!wrapper, "There should be a wrapper"); michael@0: let item = document.getElementById(kTestWidget1); michael@0: ok(!item, "There should no longer be an item"); michael@0: }); michael@0: michael@0: // Creating and destroying a widget should correctly deal with panel placeholders michael@0: add_task(function testPanelPlaceholders() { michael@0: let panel = document.getElementById(CustomizableUI.AREA_PANEL); michael@0: is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 1 : 2, "The number of placeholders should be correct."); michael@0: CustomizableUI.createWidget({id: kTestWidget2, label: 'Pretty label', tooltiptext: 'Pretty tooltip', defaultArea: CustomizableUI.AREA_PANEL}); michael@0: let elem = document.getElementById(kTestWidget2); michael@0: let wrapper = document.getElementById("wrapper-" + kTestWidget2); michael@0: ok(elem, "There should be an item"); michael@0: ok(wrapper, "There should be a wrapper"); michael@0: is(wrapper.firstChild.id, kTestWidget2, "Wrapper should have test widget"); michael@0: is(wrapper.parentNode, panel, "Wrapper should be in panel"); michael@0: is(panel.querySelectorAll(".panel-customization-placeholder").length, isInWin8() ? 3 : 1, "The number of placeholders should be correct."); michael@0: CustomizableUI.destroyWidget(kTestWidget2); michael@0: wrapper = document.getElementById("wrapper-" + kTestWidget2); michael@0: ok(!wrapper, "There should be a wrapper"); michael@0: let item = document.getElementById(kTestWidget2); michael@0: ok(!item, "There should no longer be an item"); michael@0: yield endCustomizing(); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield endCustomizing(); michael@0: try { michael@0: CustomizableUI.destroyWidget(kTestWidget1); michael@0: } catch (ex) {} michael@0: try { michael@0: CustomizableUI.destroyWidget(kTestWidget2); michael@0: } catch (ex) {} michael@0: yield resetCustomization(); michael@0: });