browser/devtools/styleinspector/test/browser_computedview_keybindings_01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleinspector/test/browser_computedview_keybindings_01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +// Test computed view key bindings
    1.11 +
    1.12 +let test = asyncTest(function*() {
    1.13 +  yield addTab("data:text/html,default styles test");
    1.14 +
    1.15 +  info("Adding content to the test page");
    1.16 +  content.document.body.innerHTML = '<style type="text/css"> ' +
    1.17 +    '.matches {color: #F00;}</style>' +
    1.18 +    '<span class="matches">Some styled text</span>' +
    1.19 +    '</div>';
    1.20 +
    1.21 +  let {toolbox, inspector, view} = yield openComputedView();
    1.22 +
    1.23 +  info("Selecting the test node");
    1.24 +  yield selectNode(".matches", inspector);
    1.25 +
    1.26 +  let propView = getFirstVisiblePropertyView(view);
    1.27 +  let rulesTable = propView.matchedSelectorsContainer;
    1.28 +  let matchedExpander = propView.element;
    1.29 +
    1.30 +  info("Focusing the property");
    1.31 +  let onMatchedExpanderFocus = once(matchedExpander, "focus", true);
    1.32 +  EventUtils.synthesizeMouseAtCenter(matchedExpander, {}, view.styleWindow);
    1.33 +  yield onMatchedExpanderFocus;
    1.34 +
    1.35 +  yield checkToggleKeyBinding(view.styleWindow, "VK_SPACE", rulesTable, inspector);
    1.36 +  yield checkToggleKeyBinding(view.styleWindow, "VK_RETURN", rulesTable, inspector);
    1.37 +  yield checkHelpLinkKeybinding(view);
    1.38 +});
    1.39 +
    1.40 +function getFirstVisiblePropertyView(view) {
    1.41 +  let propView = null;
    1.42 +  view.propertyViews.some(p => {
    1.43 +    if (p.visible) {
    1.44 +      propView = p;
    1.45 +      return true;
    1.46 +    }
    1.47 +    return false;
    1.48 +  });
    1.49 +
    1.50 +  return propView;
    1.51 +}
    1.52 +
    1.53 +function* checkToggleKeyBinding(win, key, rulesTable, inspector) {
    1.54 +  info("Pressing " + key + " key a couple of times to check that the property gets expanded/collapsed");
    1.55 +
    1.56 +  let onExpand = inspector.once("computed-view-property-expanded");
    1.57 +  let onCollapse = inspector.once("computed-view-property-collapsed");
    1.58 +
    1.59 +  info("Expanding the property");
    1.60 +  EventUtils.synthesizeKey(key, {}, win);
    1.61 +  yield onExpand;
    1.62 +  isnot(rulesTable.innerHTML, "", "The property has been expanded");
    1.63 +
    1.64 +  info("Collapsing the property");
    1.65 +  EventUtils.synthesizeKey(key, {}, win);
    1.66 +  yield onCollapse;
    1.67 +  is(rulesTable.innerHTML, "", "The property has been collapsed");
    1.68 +}
    1.69 +
    1.70 +function checkHelpLinkKeybinding(view) {
    1.71 +  info("Check that MDN link is opened on \"F1\"");
    1.72 +  let def = promise.defer();
    1.73 +
    1.74 +  let propView = getFirstVisiblePropertyView(view);
    1.75 +  propView.mdnLinkClick = function(aEvent) {
    1.76 +    ok(true, "Pressing F1 opened the MDN link");
    1.77 +    def.resolve();
    1.78 +  };
    1.79 +
    1.80 +  EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow);
    1.81 +  return def.promise;
    1.82 +}

mercurial