tor-browser

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

browser_newtab_button_customizemode.js (5467B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests in this file check that user customizations to the tabstrip show
      8 * the correct type of new tab button while the tabstrip isn't overflowing.
      9 */
     10 
     11 const kGlobalNewTabButton = document.getElementById("new-tab-button");
     12 const kInnerNewTabButton = gBrowser.tabContainer.newTabButton;
     13 
     14 function assertNewTabButton(which) {
     15  if (which == "global") {
     16    isnot(
     17      kGlobalNewTabButton.getBoundingClientRect().width,
     18      0,
     19      "main new tab button should be visible"
     20    );
     21    is(
     22      kInnerNewTabButton.getBoundingClientRect().width,
     23      0,
     24      "inner new tab button should be hidden"
     25    );
     26  } else if (which == "inner") {
     27    is(
     28      kGlobalNewTabButton.getBoundingClientRect().width,
     29      0,
     30      "main new tab button should be hidden"
     31    );
     32    isnot(
     33      kInnerNewTabButton.getBoundingClientRect().width,
     34      0,
     35      "inner new tab button should be visible"
     36    );
     37  } else {
     38    ok(false, "Unexpected button: " + which);
     39  }
     40 }
     41 
     42 /**
     43 * Add and remove items *after* the new tab button in customize mode.
     44 */
     45 add_task(async function addremove_after_newtab_customizemode() {
     46  await startCustomizing();
     47  await waitForElementShown(kGlobalNewTabButton);
     48  simulateItemDrag(
     49    document.getElementById("stop-reload-button"),
     50    kGlobalNewTabButton,
     51    "end"
     52  );
     53  ok(
     54    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
     55    "tabs should have the adjacent newtab attribute"
     56  );
     57  await endCustomizing();
     58  assertNewTabButton("inner");
     59 
     60  await startCustomizing();
     61  let dropTarget = document.getElementById("forward-button");
     62  await waitForElementShown(dropTarget);
     63  simulateItemDrag(
     64    document.getElementById("stop-reload-button"),
     65    dropTarget,
     66    "end"
     67  );
     68  ok(
     69    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
     70    "tabs should still have the adjacent newtab attribute"
     71  );
     72  await endCustomizing();
     73  assertNewTabButton("inner");
     74  ok(CustomizableUI.inDefaultState, "Should be in default state");
     75 });
     76 
     77 /**
     78 * Add and remove items *before* the new tab button in customize mode.
     79 */
     80 add_task(async function addremove_before_newtab_customizemode() {
     81  await startCustomizing();
     82  await waitForElementShown(kGlobalNewTabButton);
     83  simulateItemDrag(
     84    document.getElementById("stop-reload-button"),
     85    kGlobalNewTabButton,
     86    "start"
     87  );
     88  ok(
     89    !gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
     90    "tabs should no longer have the adjacent newtab attribute"
     91  );
     92  await endCustomizing();
     93  assertNewTabButton("global");
     94  await startCustomizing();
     95  let dropTarget = document.getElementById("forward-button");
     96  await waitForElementShown(dropTarget);
     97  simulateItemDrag(
     98    document.getElementById("stop-reload-button"),
     99    dropTarget,
    100    "end"
    101  );
    102  ok(
    103    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    104    "tabs should have the adjacent newtab attribute again"
    105  );
    106  await endCustomizing();
    107  assertNewTabButton("inner");
    108  ok(CustomizableUI.inDefaultState, "Should be in default state");
    109 });
    110 
    111 /**
    112 * Add and remove items *after* the new tab button outside of customize mode.
    113 */
    114 add_task(async function addremove_after_newtab_api() {
    115  CustomizableUI.addWidgetToArea("stop-reload-button", "TabsToolbar");
    116  ok(
    117    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    118    "tabs should have the adjacent newtab attribute"
    119  );
    120  assertNewTabButton("inner");
    121 
    122  CustomizableUI.reset();
    123  ok(
    124    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    125    "tabs should still have the adjacent newtab attribute"
    126  );
    127  assertNewTabButton("inner");
    128  ok(CustomizableUI.inDefaultState, "Should be in default state");
    129 });
    130 
    131 /**
    132 * Add and remove items *before* the new tab button outside of customize mode.
    133 */
    134 add_task(async function addremove_before_newtab_api() {
    135  let index =
    136    CustomizableUI.getWidgetIdsInArea("TabsToolbar").indexOf("new-tab-button");
    137  CustomizableUI.addWidgetToArea("stop-reload-button", "TabsToolbar", index);
    138  ok(
    139    !gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    140    "tabs should no longer have the adjacent newtab attribute"
    141  );
    142  assertNewTabButton("global");
    143 
    144  CustomizableUI.removeWidgetFromArea("stop-reload-button");
    145  ok(
    146    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    147    "tabs should have the adjacent newtab attribute again"
    148  );
    149  assertNewTabButton("inner");
    150 
    151  CustomizableUI.reset();
    152  ok(CustomizableUI.inDefaultState, "Should be in default state");
    153 });
    154 
    155 /**
    156 * Reset to defaults in customize mode to see if that doesn't break things.
    157 */
    158 add_task(async function reset_before_newtab_customizemode() {
    159  await startCustomizing();
    160  await waitForElementShown(kGlobalNewTabButton);
    161  simulateItemDrag(
    162    document.getElementById("stop-reload-button"),
    163    kGlobalNewTabButton,
    164    "start"
    165  );
    166  ok(
    167    !gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    168    "tabs should no longer have the adjacent newtab attribute"
    169  );
    170  await endCustomizing();
    171  assertNewTabButton("global");
    172  await startCustomizing();
    173  await gCustomizeMode.reset();
    174  ok(
    175    gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
    176    "tabs should have the adjacent newtab attribute again"
    177  );
    178  await endCustomizing();
    179  assertNewTabButton("inner");
    180  ok(CustomizableUI.inDefaultState, "Should be in default state");
    181 });