|
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/ */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 // Test computed view key bindings |
|
8 |
|
9 let test = asyncTest(function*() { |
|
10 yield addTab("data:text/html,default styles test"); |
|
11 |
|
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>'; |
|
17 |
|
18 let {toolbox, inspector, view} = yield openComputedView(); |
|
19 |
|
20 info("Selecting the test node"); |
|
21 yield selectNode(".matches", inspector); |
|
22 |
|
23 let propView = getFirstVisiblePropertyView(view); |
|
24 let rulesTable = propView.matchedSelectorsContainer; |
|
25 let matchedExpander = propView.element; |
|
26 |
|
27 info("Focusing the property"); |
|
28 let onMatchedExpanderFocus = once(matchedExpander, "focus", true); |
|
29 EventUtils.synthesizeMouseAtCenter(matchedExpander, {}, view.styleWindow); |
|
30 yield onMatchedExpanderFocus; |
|
31 |
|
32 yield checkToggleKeyBinding(view.styleWindow, "VK_SPACE", rulesTable, inspector); |
|
33 yield checkToggleKeyBinding(view.styleWindow, "VK_RETURN", rulesTable, inspector); |
|
34 yield checkHelpLinkKeybinding(view); |
|
35 }); |
|
36 |
|
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 }); |
|
46 |
|
47 return propView; |
|
48 } |
|
49 |
|
50 function* checkToggleKeyBinding(win, key, rulesTable, inspector) { |
|
51 info("Pressing " + key + " key a couple of times to check that the property gets expanded/collapsed"); |
|
52 |
|
53 let onExpand = inspector.once("computed-view-property-expanded"); |
|
54 let onCollapse = inspector.once("computed-view-property-collapsed"); |
|
55 |
|
56 info("Expanding the property"); |
|
57 EventUtils.synthesizeKey(key, {}, win); |
|
58 yield onExpand; |
|
59 isnot(rulesTable.innerHTML, "", "The property has been expanded"); |
|
60 |
|
61 info("Collapsing the property"); |
|
62 EventUtils.synthesizeKey(key, {}, win); |
|
63 yield onCollapse; |
|
64 is(rulesTable.innerHTML, "", "The property has been collapsed"); |
|
65 } |
|
66 |
|
67 function checkHelpLinkKeybinding(view) { |
|
68 info("Check that MDN link is opened on \"F1\""); |
|
69 let def = promise.defer(); |
|
70 |
|
71 let propView = getFirstVisiblePropertyView(view); |
|
72 propView.mdnLinkClick = function(aEvent) { |
|
73 ok(true, "Pressing F1 opened the MDN link"); |
|
74 def.resolve(); |
|
75 }; |
|
76 |
|
77 EventUtils.synthesizeKey("VK_F1", {}, view.styleWindow); |
|
78 return def.promise; |
|
79 } |