tor-browser

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

browser_toolbox_highlight.js (3594B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js");
      7 
      8 var toolbox = null;
      9 
     10 function test() {
     11  (async function () {
     12    const URL = "data:text/plain;charset=UTF-8,Nothing to see here, move along";
     13 
     14    const TOOL_ID_1 = "jsdebugger";
     15    const TOOL_ID_2 = "webconsole";
     16    await addTab(URL);
     17 
     18    toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab, {
     19      toolId: TOOL_ID_1,
     20      hostType: Toolbox.HostType.BOTTOM,
     21    });
     22 
     23    // select tool 2
     24    await toolbox.selectTool(TOOL_ID_2);
     25    // and highlight the first one
     26    await highlightTab(TOOL_ID_1);
     27    // to see if it has the proper class.
     28    await checkHighlighted(TOOL_ID_1);
     29    // Now switch back to first tool
     30    await toolbox.selectTool(TOOL_ID_1);
     31    // to check again. But there is no easy way to test if
     32    // it is showing orange or not.
     33    await checkNoHighlightWhenSelected(TOOL_ID_1);
     34    // Switch to tool 2 again
     35    await toolbox.selectTool(TOOL_ID_2);
     36    // and check again.
     37    await checkHighlighted(TOOL_ID_1);
     38    // Highlight another tool
     39    await highlightTab(TOOL_ID_2);
     40    // Check that both tools are highlighted.
     41    await checkHighlighted(TOOL_ID_1);
     42    // Check second tool being both highlighted and selected.
     43    await checkNoHighlightWhenSelected(TOOL_ID_2);
     44    // Select tool 1
     45    await toolbox.selectTool(TOOL_ID_1);
     46    // Check second tool is still highlighted
     47    await checkHighlighted(TOOL_ID_2);
     48    // Unhighlight the second tool
     49    await unhighlightTab(TOOL_ID_2);
     50    // to see the classes gone.
     51    await checkNoHighlight(TOOL_ID_2);
     52    // Now unhighlight the tool
     53    await unhighlightTab(TOOL_ID_1);
     54    // to see the classes gone.
     55    await checkNoHighlight(TOOL_ID_1);
     56 
     57    // Now close the toolbox and exit.
     58    executeSoon(() => {
     59      toolbox.destroy().then(() => {
     60        toolbox = null;
     61        gBrowser.removeCurrentTab();
     62        finish();
     63      });
     64    });
     65  })().catch(() => {
     66    ok(false, "There was an error running the test.");
     67  });
     68 }
     69 
     70 function highlightTab(toolId) {
     71  info(`Highlighting tool ${toolId}'s tab.`);
     72  return toolbox.highlightTool(toolId);
     73 }
     74 
     75 function unhighlightTab(toolId) {
     76  info(`Unhighlighting tool ${toolId}'s tab.`);
     77  return toolbox.unhighlightTool(toolId);
     78 }
     79 
     80 function checkHighlighted(toolId) {
     81  const tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
     82  ok(
     83    toolbox.isHighlighted(toolId),
     84    `Toolbox.isHighlighted reports ${toolId} as highlighted`
     85  );
     86  ok(
     87    tab.classList.contains("highlighted"),
     88    `The highlighted class is present in ${toolId}.`
     89  );
     90  ok(
     91    !tab.classList.contains("selected"),
     92    `The tab is not selected in ${toolId}`
     93  );
     94 }
     95 
     96 function checkNoHighlightWhenSelected(toolId) {
     97  const tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
     98  ok(
     99    toolbox.isHighlighted(toolId),
    100    `Toolbox.isHighlighted reports ${toolId} as highlighted`
    101  );
    102  ok(
    103    tab.classList.contains("highlighted"),
    104    `The highlighted class is present in ${toolId}`
    105  );
    106  ok(
    107    tab.classList.contains("selected"),
    108    `And the tab is selected, so the orange glow will not be present. in ${toolId}`
    109  );
    110 }
    111 
    112 function checkNoHighlight(toolId) {
    113  const tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
    114  ok(
    115    !toolbox.isHighlighted(toolId),
    116    `Toolbox.isHighlighted reports ${toolId} as not highlighted`
    117  );
    118  ok(
    119    !tab.classList.contains("highlighted"),
    120    `The highlighted class is not present in ${toolId}`
    121  );
    122 }