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