tor-browser

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

browser_987177_xul_wrapper_updating.js (4390B)


      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 const BUTTONID = "test-XUL-wrapper-widget";
      8 add_task(function () {
      9  let btn = createDummyXULButton(BUTTONID, "XUL btn");
     10  gNavToolbox.palette.appendChild(btn);
     11  let groupWrapper = CustomizableUI.getWidget(BUTTONID);
     12  ok(groupWrapper, "Should get a group wrapper");
     13  let singleWrapper = groupWrapper.forWindow(window);
     14  ok(singleWrapper, "Should get a single wrapper");
     15  is(singleWrapper.node, btn, "Node should be in the wrapper");
     16  is(
     17    groupWrapper.instances.length,
     18    1,
     19    "There should be 1 instance on the group wrapper"
     20  );
     21  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
     22 
     23  CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR);
     24 
     25  let otherSingleWrapper = groupWrapper.forWindow(window);
     26  is(
     27    singleWrapper,
     28    otherSingleWrapper,
     29    "Should get the same wrapper after adding the node to the navbar."
     30  );
     31  is(singleWrapper.node, btn, "Node should be in the wrapper");
     32  is(
     33    groupWrapper.instances.length,
     34    1,
     35    "There should be 1 instance on the group wrapper"
     36  );
     37  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
     38 
     39  CustomizableUI.removeWidgetFromArea(BUTTONID);
     40 
     41  otherSingleWrapper = groupWrapper.forWindow(window);
     42  isnot(
     43    singleWrapper,
     44    otherSingleWrapper,
     45    "Shouldn't get the same wrapper after removing it from the navbar."
     46  );
     47  singleWrapper = otherSingleWrapper;
     48  is(singleWrapper.node, btn, "Node should be in the wrapper");
     49  is(
     50    groupWrapper.instances.length,
     51    1,
     52    "There should be 1 instance on the group wrapper"
     53  );
     54  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
     55 
     56  btn.remove();
     57  otherSingleWrapper = groupWrapper.forWindow(window);
     58  is(
     59    singleWrapper,
     60    otherSingleWrapper,
     61    "Should get the same wrapper after physically removing the node."
     62  );
     63  is(
     64    singleWrapper.node,
     65    null,
     66    "Wrapper's node should be null now that it's left the DOM."
     67  );
     68  is(
     69    groupWrapper.instances.length,
     70    1,
     71    "There should be 1 instance on the group wrapper"
     72  );
     73  is(groupWrapper.instances[0].node, null, "That instance should be null.");
     74 
     75  btn = createDummyXULButton(BUTTONID, "XUL btn");
     76  gNavToolbox.palette.appendChild(btn);
     77  otherSingleWrapper = groupWrapper.forWindow(window);
     78  is(
     79    singleWrapper,
     80    otherSingleWrapper,
     81    "Should get the same wrapper after readding the node."
     82  );
     83  is(singleWrapper.node, btn, "Node should be in the wrapper");
     84  is(
     85    groupWrapper.instances.length,
     86    1,
     87    "There should be 1 instance on the group wrapper"
     88  );
     89  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
     90 
     91  CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR);
     92 
     93  otherSingleWrapper = groupWrapper.forWindow(window);
     94  is(
     95    singleWrapper,
     96    otherSingleWrapper,
     97    "Should get the same wrapper after adding the node to the navbar."
     98  );
     99  is(singleWrapper.node, btn, "Node should be in the wrapper");
    100  is(
    101    groupWrapper.instances.length,
    102    1,
    103    "There should be 1 instance on the group wrapper"
    104  );
    105  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
    106 
    107  CustomizableUI.removeWidgetFromArea(BUTTONID);
    108 
    109  otherSingleWrapper = groupWrapper.forWindow(window);
    110  isnot(
    111    singleWrapper,
    112    otherSingleWrapper,
    113    "Shouldn't get the same wrapper after removing it from the navbar."
    114  );
    115  singleWrapper = otherSingleWrapper;
    116  is(singleWrapper.node, btn, "Node should be in the wrapper");
    117  is(
    118    groupWrapper.instances.length,
    119    1,
    120    "There should be 1 instance on the group wrapper"
    121  );
    122  is(groupWrapper.instances[0].node, btn, "Button should be that instance.");
    123 
    124  btn.remove();
    125  otherSingleWrapper = groupWrapper.forWindow(window);
    126  is(
    127    singleWrapper,
    128    otherSingleWrapper,
    129    "Should get the same wrapper after physically removing the node."
    130  );
    131  is(
    132    singleWrapper.node,
    133    null,
    134    "Wrapper's node should be null now that it's left the DOM."
    135  );
    136  is(
    137    groupWrapper.instances.length,
    138    1,
    139    "There should be 1 instance on the group wrapper"
    140  );
    141  is(groupWrapper.instances[0].node, null, "That instance should be null.");
    142 });