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