michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test computed view key bindings michael@0: michael@0: let test = asyncTest(function*() { michael@0: yield addTab("data:text/html,default styles test"); michael@0: michael@0: info("Adding content to the test page"); michael@0: content.document.body.innerHTML = '' + michael@0: 'Some styled text' + michael@0: ''; michael@0: michael@0: let {toolbox, inspector, view} = yield openComputedView(); michael@0: michael@0: info("Selecting the test node"); michael@0: yield selectNode(".matches", inspector); michael@0: michael@0: let propView = getFirstVisiblePropertyView(view); michael@0: let rulesTable = propView.matchedSelectorsContainer; michael@0: let matchedExpander = propView.element; michael@0: michael@0: info("Focusing the property"); michael@0: let onMatchedExpanderFocus = once(matchedExpander, "focus", true); michael@0: EventUtils.synthesizeMouseAtCenter(matchedExpander, {}, view.styleWindow); michael@0: yield onMatchedExpanderFocus; michael@0: michael@0: yield checkToggleKeyBinding(view.styleWindow, "VK_SPACE", rulesTable, inspector); michael@0: yield checkToggleKeyBinding(view.styleWindow, "VK_RETURN", rulesTable, inspector); michael@0: yield checkHelpLinkKeybinding(view); michael@0: }); michael@0: michael@0: function getFirstVisiblePropertyView(view) { michael@0: let propView = null; michael@0: view.propertyViews.some(p => { michael@0: if (p.visible) { michael@0: propView = p; michael@0: return true; michael@0: } michael@0: return false; michael@0: }); michael@0: michael@0: return propView; michael@0: } michael@0: michael@0: function* checkToggleKeyBinding(win, key, rulesTable, inspector) { michael@0: info("Pressing " + key + " key a couple of times to check that the property gets expanded/collapsed"); michael@0: michael@0: let onExpand = inspector.once("computed-view-property-expanded"); michael@0: let onCollapse = inspector.once("computed-view-property-collapsed"); michael@0: michael@0: info("Expanding the property"); michael@0: EventUtils.synthesizeKey(key, {}, win); michael@0: yield onExpand; michael@0: isnot(rulesTable.innerHTML, "", "The property has been expanded"); michael@0: michael@0: info("Collapsing the property"); michael@0: EventUtils.synthesizeKey(key, {}, win); michael@0: yield onCollapse; michael@0: is(rulesTable.innerHTML, "", "The property has been collapsed"); michael@0: } michael@0: michael@0: function checkHelpLinkKeybinding(view) { michael@0: info("Check that MDN link is opened on \"F1\""); michael@0: let def = promise.defer(); michael@0: michael@0: let propView = getFirstVisiblePropertyView(view); michael@0: propView.mdnLinkClick = function(aEvent) { michael@0: ok(true, "Pressing F1 opened the MDN link"); michael@0: def.resolve(); michael@0: }; michael@0: michael@0: EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow); michael@0: return def.promise; michael@0: }