tor-browser

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

browser_996364_registerArea_different_properties.js (3758B)


      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 // Calling CustomizableUI.registerArea twice with no
      8 // properties should not throw an exception.
      9 add_task(function () {
     10  try {
     11    CustomizableUI.registerArea("area-996364", {});
     12    CustomizableUI.registerArea("area-996364", {});
     13  } catch (ex) {
     14    ok(false, ex.message);
     15  }
     16 
     17  CustomizableUI.unregisterArea("area-996364", true);
     18 });
     19 
     20 add_task(function () {
     21  let exceptionThrown = false;
     22  try {
     23    CustomizableUI.registerArea("area-996364-2", {
     24      type: CustomizableUI.TYPE_TOOLBAR,
     25      defaultCollapsed: "false",
     26    });
     27  } catch (ex) {
     28    exceptionThrown = true;
     29  }
     30  ok(
     31    exceptionThrown,
     32    "defaultCollapsed is not allowed as an external property"
     33  );
     34 
     35  // No need to unregister the area because registration fails.
     36 });
     37 
     38 add_task(function () {
     39  let exceptionThrown;
     40  try {
     41    CustomizableUI.registerArea("area-996364-3", {
     42      type: CustomizableUI.TYPE_TOOLBAR,
     43    });
     44    CustomizableUI.registerArea("area-996364-3", {
     45      type: CustomizableUI.TYPE_PANEL,
     46    });
     47  } catch (ex) {
     48    exceptionThrown = ex;
     49  }
     50  ok(
     51    exceptionThrown,
     52    "Exception expected, an area cannot change types: " +
     53      (exceptionThrown ? exceptionThrown : "[no exception]")
     54  );
     55 
     56  CustomizableUI.unregisterArea("area-996364-3", true);
     57 });
     58 
     59 add_task(function () {
     60  let exceptionThrown;
     61  try {
     62    CustomizableUI.registerArea("area-996364-4", {
     63      type: CustomizableUI.TYPE_PANEL,
     64    });
     65    CustomizableUI.registerArea("area-996364-4", {
     66      type: CustomizableUI.TYPE_TOOLBAR,
     67    });
     68  } catch (ex) {
     69    exceptionThrown = ex;
     70  }
     71  ok(
     72    exceptionThrown,
     73    "Exception expected, an area cannot change types: " +
     74      (exceptionThrown ? exceptionThrown : "[no exception]")
     75  );
     76 
     77  CustomizableUI.unregisterArea("area-996364-4", true);
     78 });
     79 
     80 add_task(function () {
     81  let exceptionThrown;
     82  try {
     83    CustomizableUI.registerArea("area-996899-1", {
     84      anchor: "PanelUI-menu-button",
     85      type: CustomizableUI.TYPE_PANEL,
     86      defaultPlacements: [],
     87    });
     88    CustomizableUI.registerArea("area-996899-1", {
     89      anchor: "home-button",
     90      type: CustomizableUI.TYPE_PANEL,
     91      defaultPlacements: [],
     92    });
     93  } catch (ex) {
     94    exceptionThrown = ex;
     95  }
     96  ok(
     97    !exceptionThrown,
     98    "Changing anchors shouldn't throw an exception: " +
     99      (exceptionThrown ? exceptionThrown : "[no exception]")
    100  );
    101  CustomizableUI.unregisterArea("area-996899-1", true);
    102 });
    103 
    104 add_task(function () {
    105  let exceptionThrown;
    106  try {
    107    CustomizableUI.registerArea("area-996899-2", {
    108      anchor: "PanelUI-menu-button",
    109      type: CustomizableUI.TYPE_PANEL,
    110      defaultPlacements: [],
    111    });
    112    CustomizableUI.registerArea("area-996899-2", {
    113      anchor: "PanelUI-menu-button",
    114      type: CustomizableUI.TYPE_PANEL,
    115      defaultPlacements: ["new-window-button"],
    116    });
    117  } catch (ex) {
    118    exceptionThrown = ex;
    119  }
    120  ok(
    121    !exceptionThrown,
    122    "Changing defaultPlacements shouldn't throw an exception: " +
    123      (exceptionThrown ? exceptionThrown : "[no exception]")
    124  );
    125  CustomizableUI.unregisterArea("area-996899-2", true);
    126 });
    127 
    128 add_task(function () {
    129  let exceptionThrown;
    130  try {
    131    CustomizableUI.registerArea("area-996899-4", { overflowable: true });
    132    CustomizableUI.registerArea("area-996899-4", { overflowable: false });
    133  } catch (ex) {
    134    exceptionThrown = ex;
    135  }
    136  ok(
    137    exceptionThrown,
    138    "Changing 'overflowable' should throw an exception: " +
    139      (exceptionThrown ? exceptionThrown : "[no exception]")
    140  );
    141  CustomizableUI.unregisterArea("area-996899-4", true);
    142 });