tor-browser

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

browser_computed_keybindings_01.js (2438B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests computed view key bindings.
      7 
      8 const TEST_URI = `
      9  <style type="text/css">
     10    .matches {
     11      color: #F00;
     12    }
     13  </style>
     14  <span class="matches">Some styled text</span>
     15 `;
     16 
     17 add_task(async function () {
     18  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     19  const { inspector, view } = await openComputedView();
     20  await selectNode(".matches", inspector);
     21 
     22  const propView = getFirstVisiblePropertyView(view);
     23  const rulesTable = propView.matchedSelectorsContainer;
     24  const matchedExpander = propView.element;
     25 
     26  info("Focusing the property");
     27  matchedExpander.scrollIntoView();
     28  const onMatchedExpanderFocus = once(matchedExpander, "focus", true);
     29  EventUtils.synthesizeMouseAtCenter(matchedExpander, {}, view.styleWindow);
     30  await onMatchedExpanderFocus;
     31 
     32  await checkToggleKeyBinding(
     33    view.styleWindow,
     34    "VK_SPACE",
     35    rulesTable,
     36    inspector
     37  );
     38  await checkToggleKeyBinding(
     39    view.styleWindow,
     40    "VK_RETURN",
     41    rulesTable,
     42    inspector
     43  );
     44  await checkHelpLinkKeybinding(view);
     45 });
     46 
     47 function getFirstVisiblePropertyView(view) {
     48  let propView = null;
     49  view.propertyViews.some(p => {
     50    if (p.visible) {
     51      propView = p;
     52      return true;
     53    }
     54    return false;
     55  });
     56 
     57  return propView;
     58 }
     59 
     60 async function checkToggleKeyBinding(win, key, rulesTable, inspector) {
     61  info(
     62    "Pressing " +
     63      key +
     64      " key a couple of times to check that the " +
     65      "property gets expanded/collapsed"
     66  );
     67 
     68  const onExpand = inspector.once("computed-view-property-expanded");
     69  const onCollapse = inspector.once("computed-view-property-collapsed");
     70 
     71  info("Expanding the property");
     72  EventUtils.synthesizeKey(key, {}, win);
     73  await onExpand;
     74  isnot(rulesTable.innerHTML, "", "The property has been expanded");
     75 
     76  info("Collapsing the property");
     77  EventUtils.synthesizeKey(key, {}, win);
     78  await onCollapse;
     79  is(rulesTable.innerHTML, "", "The property has been collapsed");
     80 }
     81 
     82 function checkHelpLinkKeybinding(view) {
     83  info('Check that MDN link is opened on "F1"');
     84  const propView = getFirstVisiblePropertyView(view);
     85  return new Promise(resolve => {
     86    propView.mdnLinkClick = function () {
     87      ok(true, "Pressing F1 opened the MDN link");
     88      resolve();
     89    };
     90    EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow);
     91  });
     92 }