|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 let modifiers = { |
|
5 accelKey: true |
|
6 }; |
|
7 |
|
8 let toolbox; |
|
9 |
|
10 function test() { |
|
11 waitForExplicitFinish(); |
|
12 |
|
13 addTab("about:blank", function() { |
|
14 openToolbox(); |
|
15 }); |
|
16 } |
|
17 |
|
18 function openToolbox() { |
|
19 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
20 |
|
21 gDevTools.showToolbox(target).then((aToolbox) => { |
|
22 toolbox = aToolbox; |
|
23 toolbox.selectTool("styleeditor").then(testZoom); |
|
24 }); |
|
25 } |
|
26 |
|
27 function testZoom() { |
|
28 info("testing zoom keys"); |
|
29 |
|
30 testZoomLevel("in", 2, 1.2); |
|
31 testZoomLevel("out", 3, 0.9); |
|
32 testZoomLevel("reset", 1, 1); |
|
33 |
|
34 tidyUp(); |
|
35 } |
|
36 |
|
37 function testZoomLevel(type, times, expected) { |
|
38 sendZoomKey("toolbox-zoom-"+ type + "-key", times); |
|
39 |
|
40 let zoom = getCurrentZoom(toolbox); |
|
41 is(zoom.toFixed(2), expected, "zoom level correct after zoom " + type); |
|
42 |
|
43 is(toolbox.zoomValue.toFixed(2), expected, |
|
44 "saved zoom level is correct after zoom " + type); |
|
45 } |
|
46 |
|
47 function sendZoomKey(id, times) { |
|
48 let key = toolbox.doc.getElementById(id).getAttribute("key"); |
|
49 for (let i = 0; i < times; i++) { |
|
50 EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView); |
|
51 } |
|
52 } |
|
53 |
|
54 function getCurrentZoom() { |
|
55 var contViewer = toolbox.frame.docShell.contentViewer; |
|
56 var docViewer = contViewer.QueryInterface(Ci.nsIMarkupDocumentViewer); |
|
57 return docViewer.fullZoom; |
|
58 } |
|
59 |
|
60 function tidyUp() { |
|
61 toolbox.destroy().then(function() { |
|
62 gBrowser.removeCurrentTab(); |
|
63 |
|
64 toolbox = modifiers = null; |
|
65 finish(); |
|
66 }); |
|
67 } |