browser/components/customizableui/test/browser_885530_showInPrivateBrowsing.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_885530_showInPrivateBrowsing.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     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 kWidgetId = "some-widget";
    1.11 +
    1.12 +function assertWidgetExists(aWindow, aExists) {
    1.13 +  if (aExists) {
    1.14 +    ok(aWindow.document.getElementById(kWidgetId),
    1.15 +       "Should have found test widget in the window");
    1.16 +  } else {
    1.17 +    is(aWindow.document.getElementById(kWidgetId), null,
    1.18 +       "Should not have found test widget in the window");
    1.19 +  }
    1.20 +}
    1.21 +
    1.22 +// A widget that is created with showInPrivateBrowsing undefined should
    1.23 +// have that value default to true.
    1.24 +add_task(function() {
    1.25 +  let wrapper = CustomizableUI.createWidget({
    1.26 +    id: kWidgetId
    1.27 +  });
    1.28 +  ok(wrapper.showInPrivateBrowsing,
    1.29 +     "showInPrivateBrowsing should have defaulted to true.");
    1.30 +  CustomizableUI.destroyWidget(kWidgetId);
    1.31 +});
    1.32 +
    1.33 +// Add a widget via the API with showInPrivateBrowsing set to false
    1.34 +// and ensure it does not appear in pre-existing or newly created
    1.35 +// private windows.
    1.36 +add_task(function() {
    1.37 +  let plain1 = yield openAndLoadWindow();
    1.38 +  let private1 = yield openAndLoadWindow({private: true});
    1.39 +  CustomizableUI.createWidget({
    1.40 +    id: kWidgetId,
    1.41 +    removable: true,
    1.42 +    showInPrivateBrowsing: false
    1.43 +  });
    1.44 +  CustomizableUI.addWidgetToArea(kWidgetId,
    1.45 +                                 CustomizableUI.AREA_NAVBAR);
    1.46 +  assertWidgetExists(plain1, true);
    1.47 +  assertWidgetExists(private1, false);
    1.48 +
    1.49 +  // Now open up some new windows. The widget should exist in the new
    1.50 +  // plain window, but not the new private window.
    1.51 +  let plain2 = yield openAndLoadWindow();
    1.52 +  let private2 = yield openAndLoadWindow({private: true});
    1.53 +  assertWidgetExists(plain2, true);
    1.54 +  assertWidgetExists(private2, false);
    1.55 +
    1.56 +  // Try moving the widget around and make sure it doesn't get added
    1.57 +  // to the private windows. We'll start by appending it to the tabstrip.
    1.58 +  CustomizableUI.addWidgetToArea(kWidgetId,
    1.59 +                                 CustomizableUI.AREA_TABSTRIP);
    1.60 +  assertWidgetExists(plain1, true);
    1.61 +  assertWidgetExists(plain2, true);
    1.62 +  assertWidgetExists(private1, false);
    1.63 +  assertWidgetExists(private2, false);
    1.64 +
    1.65 +  // And then move it to the beginning of the tabstrip.
    1.66 +  CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
    1.67 +  assertWidgetExists(plain1, true);
    1.68 +  assertWidgetExists(plain2, true);
    1.69 +  assertWidgetExists(private1, false);
    1.70 +  assertWidgetExists(private2, false);
    1.71 +
    1.72 +  CustomizableUI.removeWidgetFromArea("some-widget");
    1.73 +  assertWidgetExists(plain1, false);
    1.74 +  assertWidgetExists(plain2, false);
    1.75 +  assertWidgetExists(private1, false);
    1.76 +  assertWidgetExists(private2, false);
    1.77 +
    1.78 +  yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
    1.79 +
    1.80 +  CustomizableUI.destroyWidget("some-widget");
    1.81 +});
    1.82 +
    1.83 +// Add a widget via the API with showInPrivateBrowsing set to true,
    1.84 +// and ensure that it appears in pre-existing or newly created
    1.85 +// private browsing windows.
    1.86 +add_task(function() {
    1.87 +  let plain1 = yield openAndLoadWindow();
    1.88 +  let private1 = yield openAndLoadWindow({private: true});
    1.89 +
    1.90 +  CustomizableUI.createWidget({
    1.91 +    id: kWidgetId,
    1.92 +    removable: true,
    1.93 +    showInPrivateBrowsing: true
    1.94 +  });
    1.95 +  CustomizableUI.addWidgetToArea(kWidgetId,
    1.96 +                                 CustomizableUI.AREA_NAVBAR);
    1.97 +  assertWidgetExists(plain1, true);
    1.98 +  assertWidgetExists(private1, true);
    1.99 +
   1.100 +  // Now open up some new windows. The widget should exist in the new
   1.101 +  // plain window, but not the new private window.
   1.102 +  let plain2 = yield openAndLoadWindow();
   1.103 +  let private2 = yield openAndLoadWindow({private: true});
   1.104 +
   1.105 +  assertWidgetExists(plain2, true);
   1.106 +  assertWidgetExists(private2, true);
   1.107 +
   1.108 +  // Try moving the widget around and make sure it doesn't get added
   1.109 +  // to the private windows. We'll start by appending it to the tabstrip.
   1.110 +  CustomizableUI.addWidgetToArea(kWidgetId,
   1.111 +                                 CustomizableUI.AREA_TABSTRIP);
   1.112 +  assertWidgetExists(plain1, true);
   1.113 +  assertWidgetExists(plain2, true);
   1.114 +  assertWidgetExists(private1, true);
   1.115 +  assertWidgetExists(private2, true);
   1.116 +
   1.117 +  // And then move it to the beginning of the tabstrip.
   1.118 +  CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
   1.119 +  assertWidgetExists(plain1, true);
   1.120 +  assertWidgetExists(plain2, true);
   1.121 +  assertWidgetExists(private1, true);
   1.122 +  assertWidgetExists(private2, true);
   1.123 +
   1.124 +  CustomizableUI.removeWidgetFromArea("some-widget");
   1.125 +  assertWidgetExists(plain1, false);
   1.126 +  assertWidgetExists(plain2, false);
   1.127 +  assertWidgetExists(private1, false);
   1.128 +  assertWidgetExists(private2, false);
   1.129 +
   1.130 +  yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
   1.131 +
   1.132 +  CustomizableUI.destroyWidget("some-widget");
   1.133 +});
   1.134 +
   1.135 +add_task(function asyncCleanup() {
   1.136 +  yield resetCustomization();
   1.137 +});

mercurial