Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test computed view key bindings |
michael@0 | 8 | |
michael@0 | 9 | let test = asyncTest(function*() { |
michael@0 | 10 | yield addTab("data:text/html,default styles test"); |
michael@0 | 11 | |
michael@0 | 12 | info("Adding content to the test page"); |
michael@0 | 13 | content.document.body.innerHTML = '<style type="text/css"> ' + |
michael@0 | 14 | '.matches {color: #F00;}</style>' + |
michael@0 | 15 | '<span class="matches">Some styled text</span>' + |
michael@0 | 16 | '</div>'; |
michael@0 | 17 | |
michael@0 | 18 | let {toolbox, inspector, view} = yield openComputedView(); |
michael@0 | 19 | |
michael@0 | 20 | info("Selecting the test node"); |
michael@0 | 21 | yield selectNode(".matches", inspector); |
michael@0 | 22 | |
michael@0 | 23 | let propView = getFirstVisiblePropertyView(view); |
michael@0 | 24 | let rulesTable = propView.matchedSelectorsContainer; |
michael@0 | 25 | let matchedExpander = propView.element; |
michael@0 | 26 | |
michael@0 | 27 | info("Focusing the property"); |
michael@0 | 28 | let onMatchedExpanderFocus = once(matchedExpander, "focus", true); |
michael@0 | 29 | EventUtils.synthesizeMouseAtCenter(matchedExpander, {}, view.styleWindow); |
michael@0 | 30 | yield onMatchedExpanderFocus; |
michael@0 | 31 | |
michael@0 | 32 | yield checkToggleKeyBinding(view.styleWindow, "VK_SPACE", rulesTable, inspector); |
michael@0 | 33 | yield checkToggleKeyBinding(view.styleWindow, "VK_RETURN", rulesTable, inspector); |
michael@0 | 34 | yield checkHelpLinkKeybinding(view); |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | function getFirstVisiblePropertyView(view) { |
michael@0 | 38 | let propView = null; |
michael@0 | 39 | view.propertyViews.some(p => { |
michael@0 | 40 | if (p.visible) { |
michael@0 | 41 | propView = p; |
michael@0 | 42 | return true; |
michael@0 | 43 | } |
michael@0 | 44 | return false; |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | return propView; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function* checkToggleKeyBinding(win, key, rulesTable, inspector) { |
michael@0 | 51 | info("Pressing " + key + " key a couple of times to check that the property gets expanded/collapsed"); |
michael@0 | 52 | |
michael@0 | 53 | let onExpand = inspector.once("computed-view-property-expanded"); |
michael@0 | 54 | let onCollapse = inspector.once("computed-view-property-collapsed"); |
michael@0 | 55 | |
michael@0 | 56 | info("Expanding the property"); |
michael@0 | 57 | EventUtils.synthesizeKey(key, {}, win); |
michael@0 | 58 | yield onExpand; |
michael@0 | 59 | isnot(rulesTable.innerHTML, "", "The property has been expanded"); |
michael@0 | 60 | |
michael@0 | 61 | info("Collapsing the property"); |
michael@0 | 62 | EventUtils.synthesizeKey(key, {}, win); |
michael@0 | 63 | yield onCollapse; |
michael@0 | 64 | is(rulesTable.innerHTML, "", "The property has been collapsed"); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function checkHelpLinkKeybinding(view) { |
michael@0 | 68 | info("Check that MDN link is opened on \"F1\""); |
michael@0 | 69 | let def = promise.defer(); |
michael@0 | 70 | |
michael@0 | 71 | let propView = getFirstVisiblePropertyView(view); |
michael@0 | 72 | propView.mdnLinkClick = function(aEvent) { |
michael@0 | 73 | ok(true, "Pressing F1 opened the MDN link"); |
michael@0 | 74 | def.resolve(); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow); |
michael@0 | 78 | return def.promise; |
michael@0 | 79 | } |