tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_982656_restore_defaults_builtin_widgets.js (2490B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // Restoring default should not place addon widgets back in the toolbar
      8 add_task(async function () {
      9  ok(CustomizableUI.inDefaultState, "Default state to begin");
     10 
     11  const kWidgetId =
     12    "bug982656-add-on-widget-should-not-restore-to-default-area";
     13  let widgetSpec = {
     14    id: kWidgetId,
     15    defaultArea: CustomizableUI.AREA_NAVBAR,
     16  };
     17  CustomizableUI.createWidget(widgetSpec);
     18 
     19  ok(!CustomizableUI.inDefaultState, "Not in default state after widget added");
     20  is(
     21    CustomizableUI.getPlacementOfWidget(kWidgetId).area,
     22    CustomizableUI.AREA_NAVBAR,
     23    "Widget should be in navbar"
     24  );
     25 
     26  await resetCustomization();
     27 
     28  ok(CustomizableUI.inDefaultState, "Back in default state after reset");
     29  is(
     30    CustomizableUI.getPlacementOfWidget(kWidgetId),
     31    null,
     32    "Widget now in palette"
     33  );
     34  CustomizableUI.destroyWidget(kWidgetId);
     35 });
     36 
     37 // resetCustomization shouldn't move 3rd party widgets out of custom toolbars
     38 add_task(async function () {
     39  const kToolbarId = "bug982656-toolbar-with-defaultset";
     40  const kWidgetId =
     41    "bug982656-add-on-widget-should-restore-to-default-area-when-area-is-not-builtin";
     42  ok(
     43    CustomizableUI.inDefaultState,
     44    "Everything should be in its default state."
     45  );
     46  let toolbar = createToolbarWithPlacements(kToolbarId);
     47  ok(CustomizableUI.areas.includes(kToolbarId), "Toolbar has been registered.");
     48  is(
     49    CustomizableUI.getAreaType(kToolbarId),
     50    CustomizableUI.TYPE_TOOLBAR,
     51    "Area should be registered as toolbar"
     52  );
     53 
     54  let widgetSpec = {
     55    id: kWidgetId,
     56    defaultArea: kToolbarId,
     57  };
     58  CustomizableUI.createWidget(widgetSpec);
     59 
     60  ok(
     61    !CustomizableUI.inDefaultState,
     62    "No longer in default state after toolbar is registered and visible."
     63  );
     64  is(
     65    CustomizableUI.getPlacementOfWidget(kWidgetId).area,
     66    kToolbarId,
     67    "Widget should be in custom toolbar"
     68  );
     69 
     70  await resetCustomization();
     71  ok(CustomizableUI.inDefaultState, "Back in default state after reset");
     72  is(
     73    CustomizableUI.getPlacementOfWidget(kWidgetId).area,
     74    kToolbarId,
     75    "Widget still in custom toolbar"
     76  );
     77  ok(toolbar.collapsed, "Custom toolbar should be collapsed after reset");
     78 
     79  toolbar.remove();
     80  CustomizableUI.destroyWidget(kWidgetId);
     81  CustomizableUI.unregisterArea(kToolbarId);
     82 });