tor-browser

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

browser_inspector_pane-toggle-05.js (3138B)


      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 // Tests whether the initial selected tab is displayed when switched from 3 pane to 2 pane
      8 // and back to 3 pane when no other tab is selected explicitly. Rule view is displayed
      9 // immediately on toggling to 2 pane.
     10 add_task(async function () {
     11  info(
     12    "Switch to 2 pane inspector and back to 3 pane to test whether the selected tab is used"
     13  );
     14  await pushPref("devtools.inspector.three-pane-enabled", true);
     15 
     16  const { inspector } = await openInspectorForURL("about:blank");
     17 
     18  inspector.sidebar.select("changesview");
     19 
     20  is(
     21    inspector.sidebar.getCurrentTabID(),
     22    "changesview",
     23    "Changes view should be the active sidebar"
     24  );
     25 
     26  info("Click on the toggle button to toggle OFF 3 pane inspector");
     27  await toggleSidebar(inspector);
     28 
     29  is(
     30    inspector.sidebar.getCurrentTabID(),
     31    "ruleview",
     32    "Rules view should be the active sidebar on toggle to 2 pane"
     33  );
     34 
     35  info("Click on the toggle button to toggle ON 3 pane inspector");
     36  await toggleSidebar(inspector);
     37 
     38  is(
     39    inspector.sidebar.getCurrentTabID(),
     40    "changesview",
     41    "Changes view should be the active sidebar again"
     42  );
     43 });
     44 
     45 // Tests whether the selected pane in 2 pane view is also used after toggling to 3 pane view.
     46 add_task(async function () {
     47  info("Switch to 3 pane to test whether the selected pane is preserved");
     48  await pushPref("devtools.inspector.three-pane-enabled", false);
     49 
     50  const { inspector } = await openInspectorForURL("about:blank");
     51 
     52  inspector.sidebar.select("changesview");
     53 
     54  is(
     55    inspector.sidebar.getCurrentTabID(),
     56    "changesview",
     57    "Changes view should be the active sidebar"
     58  );
     59 
     60  info("Click on the toggle button to toggle ON 3 pane inspector");
     61  await toggleSidebar(inspector);
     62 
     63  is(
     64    inspector.sidebar.getCurrentTabID(),
     65    "changesview",
     66    "Changes view should still be the active sidebar"
     67  );
     68 });
     69 
     70 // Tests whether the selected pane is layout view, if rule view is selected before toggling to 3 pane.
     71 add_task(async function () {
     72  info("Switch to 3 pane to test whether the selected pane is layout view");
     73  await pushPref("devtools.inspector.three-pane-enabled", false);
     74 
     75  const { inspector } = await openInspectorForURL("about:blank");
     76 
     77  inspector.sidebar.select("ruleview");
     78 
     79  is(
     80    inspector.sidebar.getCurrentTabID(),
     81    "ruleview",
     82    "Rules view should be the active sidebar in 2 pane"
     83  );
     84 
     85  info("Click on the toggle button to toggle ON 3 pane inspector");
     86  await toggleSidebar(inspector);
     87 
     88  is(
     89    inspector.sidebar.getCurrentTabID(),
     90    "layoutview",
     91    "Layout view should be the active sidebar in 3 pane"
     92  );
     93 });
     94 
     95 const toggleSidebar = async inspector => {
     96  const { panelDoc: doc } = inspector;
     97  const button = doc.querySelector(".sidebar-toggle");
     98 
     99  const onRuleViewAdded = inspector.once("ruleview-added");
    100  EventUtils.synthesizeMouseAtCenter(
    101    button,
    102    {},
    103    inspector.panelDoc.defaultView
    104  );
    105  await onRuleViewAdded;
    106 };