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 kWidgetId = "some-widget"; michael@0: michael@0: function assertWidgetExists(aWindow, aExists) { michael@0: if (aExists) { michael@0: ok(aWindow.document.getElementById(kWidgetId), michael@0: "Should have found test widget in the window"); michael@0: } else { michael@0: is(aWindow.document.getElementById(kWidgetId), null, michael@0: "Should not have found test widget in the window"); michael@0: } michael@0: } michael@0: michael@0: // A widget that is created with showInPrivateBrowsing undefined should michael@0: // have that value default to true. michael@0: add_task(function() { michael@0: let wrapper = CustomizableUI.createWidget({ michael@0: id: kWidgetId michael@0: }); michael@0: ok(wrapper.showInPrivateBrowsing, michael@0: "showInPrivateBrowsing should have defaulted to true."); michael@0: CustomizableUI.destroyWidget(kWidgetId); michael@0: }); michael@0: michael@0: // Add a widget via the API with showInPrivateBrowsing set to false michael@0: // and ensure it does not appear in pre-existing or newly created michael@0: // private windows. michael@0: add_task(function() { michael@0: let plain1 = yield openAndLoadWindow(); michael@0: let private1 = yield openAndLoadWindow({private: true}); michael@0: CustomizableUI.createWidget({ michael@0: id: kWidgetId, michael@0: removable: true, michael@0: showInPrivateBrowsing: false michael@0: }); michael@0: CustomizableUI.addWidgetToArea(kWidgetId, michael@0: CustomizableUI.AREA_NAVBAR); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(private1, false); michael@0: michael@0: // Now open up some new windows. The widget should exist in the new michael@0: // plain window, but not the new private window. michael@0: let plain2 = yield openAndLoadWindow(); michael@0: let private2 = yield openAndLoadWindow({private: true}); michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private2, false); michael@0: michael@0: // Try moving the widget around and make sure it doesn't get added michael@0: // to the private windows. We'll start by appending it to the tabstrip. michael@0: CustomizableUI.addWidgetToArea(kWidgetId, michael@0: CustomizableUI.AREA_TABSTRIP); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private1, false); michael@0: assertWidgetExists(private2, false); michael@0: michael@0: // And then move it to the beginning of the tabstrip. michael@0: CustomizableUI.moveWidgetWithinArea(kWidgetId, 0); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private1, false); michael@0: assertWidgetExists(private2, false); michael@0: michael@0: CustomizableUI.removeWidgetFromArea("some-widget"); michael@0: assertWidgetExists(plain1, false); michael@0: assertWidgetExists(plain2, false); michael@0: assertWidgetExists(private1, false); michael@0: assertWidgetExists(private2, false); michael@0: michael@0: yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed)); michael@0: michael@0: CustomizableUI.destroyWidget("some-widget"); michael@0: }); michael@0: michael@0: // Add a widget via the API with showInPrivateBrowsing set to true, michael@0: // and ensure that it appears in pre-existing or newly created michael@0: // private browsing windows. michael@0: add_task(function() { michael@0: let plain1 = yield openAndLoadWindow(); michael@0: let private1 = yield openAndLoadWindow({private: true}); michael@0: michael@0: CustomizableUI.createWidget({ michael@0: id: kWidgetId, michael@0: removable: true, michael@0: showInPrivateBrowsing: true michael@0: }); michael@0: CustomizableUI.addWidgetToArea(kWidgetId, michael@0: CustomizableUI.AREA_NAVBAR); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(private1, true); michael@0: michael@0: // Now open up some new windows. The widget should exist in the new michael@0: // plain window, but not the new private window. michael@0: let plain2 = yield openAndLoadWindow(); michael@0: let private2 = yield openAndLoadWindow({private: true}); michael@0: michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private2, true); michael@0: michael@0: // Try moving the widget around and make sure it doesn't get added michael@0: // to the private windows. We'll start by appending it to the tabstrip. michael@0: CustomizableUI.addWidgetToArea(kWidgetId, michael@0: CustomizableUI.AREA_TABSTRIP); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private1, true); michael@0: assertWidgetExists(private2, true); michael@0: michael@0: // And then move it to the beginning of the tabstrip. michael@0: CustomizableUI.moveWidgetWithinArea(kWidgetId, 0); michael@0: assertWidgetExists(plain1, true); michael@0: assertWidgetExists(plain2, true); michael@0: assertWidgetExists(private1, true); michael@0: assertWidgetExists(private2, true); michael@0: michael@0: CustomizableUI.removeWidgetFromArea("some-widget"); michael@0: assertWidgetExists(plain1, false); michael@0: assertWidgetExists(plain2, false); michael@0: assertWidgetExists(private1, false); michael@0: assertWidgetExists(private2, false); michael@0: michael@0: yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed)); michael@0: michael@0: CustomizableUI.destroyWidget("some-widget"); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield resetCustomization(); michael@0: });