|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that screenshot command works properly |
|
5 const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" + |
|
6 "test/browser_cmd_screenshot.html"; |
|
7 |
|
8 let FileUtils = (Cu.import("resource://gre/modules/FileUtils.jsm", {})).FileUtils; |
|
9 |
|
10 function test() { |
|
11 return Task.spawn(spawnTest).then(finish, helpers.handleError); |
|
12 } |
|
13 |
|
14 function spawnTest() { |
|
15 waitForExplicitFinish(); |
|
16 |
|
17 info("RUN TEST: non-private window"); |
|
18 let normWin = yield addWindow({ private: false }); |
|
19 yield addTabWithToolbarRunTests(normWin); |
|
20 normWin.close(); |
|
21 |
|
22 info("RUN TEST: private window"); |
|
23 let pbWin = yield addWindow({ private: true }); |
|
24 yield addTabWithToolbarRunTests(pbWin); |
|
25 pbWin.close(); |
|
26 } |
|
27 |
|
28 function addTabWithToolbarRunTests(win) { |
|
29 let options = yield helpers.openTab(TEST_URI, { chromeWindow: win }); |
|
30 yield helpers.openToolbar(options); |
|
31 |
|
32 // Test input status |
|
33 yield helpers.audit(options, [ |
|
34 { |
|
35 setup: 'screenshot', |
|
36 check: { |
|
37 input: 'screenshot', |
|
38 markup: 'VVVVVVVVVV', |
|
39 status: 'VALID', |
|
40 args: { |
|
41 } |
|
42 }, |
|
43 }, |
|
44 { |
|
45 setup: 'screenshot abc.png', |
|
46 check: { |
|
47 input: 'screenshot abc.png', |
|
48 markup: 'VVVVVVVVVVVVVVVVVV', |
|
49 status: 'VALID', |
|
50 args: { |
|
51 filename: { value: "abc.png"}, |
|
52 } |
|
53 }, |
|
54 }, |
|
55 { |
|
56 setup: 'screenshot --fullpage', |
|
57 check: { |
|
58 input: 'screenshot --fullpage', |
|
59 markup: 'VVVVVVVVVVVVVVVVVVVVV', |
|
60 status: 'VALID', |
|
61 args: { |
|
62 fullpage: { value: true}, |
|
63 } |
|
64 }, |
|
65 }, |
|
66 { |
|
67 setup: 'screenshot abc --delay 5', |
|
68 check: { |
|
69 input: 'screenshot abc --delay 5', |
|
70 markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', |
|
71 status: 'VALID', |
|
72 args: { |
|
73 filename: { value: "abc"}, |
|
74 delay: { value: 5 }, |
|
75 } |
|
76 }, |
|
77 }, |
|
78 { |
|
79 setup: 'screenshot --selector img#testImage', |
|
80 check: { |
|
81 input: 'screenshot --selector img#testImage', |
|
82 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
83 status: 'VALID', |
|
84 args: { |
|
85 selector: { |
|
86 value: options.window.document.getElementById("testImage") |
|
87 }, |
|
88 } |
|
89 }, |
|
90 }, |
|
91 ]); |
|
92 |
|
93 // Test capture to file |
|
94 let file = FileUtils.getFile("TmpD", [ "TestScreenshotFile.png" ]); |
|
95 |
|
96 yield helpers.audit(options, [ |
|
97 { |
|
98 setup: 'screenshot ' + file.path, |
|
99 check: { |
|
100 args: { |
|
101 filename: { value: "" + file.path }, |
|
102 fullpage: { value: false }, |
|
103 clipboard: { value: false }, |
|
104 chrome: { value: false }, |
|
105 }, |
|
106 }, |
|
107 exec: { |
|
108 output: new RegExp("^Saved to "), |
|
109 }, |
|
110 post: function() { |
|
111 // Bug 849168: screenshot command tests fail in try but not locally |
|
112 // ok(file.exists(), "Screenshot file exists"); |
|
113 |
|
114 if (file.exists()) { |
|
115 file.remove(false); |
|
116 } |
|
117 } |
|
118 }, |
|
119 ]); |
|
120 |
|
121 // Test capture to clipboard |
|
122 let clipid = Ci.nsIClipboard; |
|
123 let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(clipid); |
|
124 let trans = Cc["@mozilla.org/widget/transferable;1"] |
|
125 .createInstance(Ci.nsITransferable); |
|
126 trans.init(null); |
|
127 trans.addDataFlavor("image/png"); |
|
128 |
|
129 yield helpers.audit(options, [ |
|
130 { |
|
131 setup: 'screenshot --fullpage --clipboard', |
|
132 check: { |
|
133 args: { |
|
134 fullpage: { value: true }, |
|
135 clipboard: { value: true }, |
|
136 chrome: { value: false }, |
|
137 }, |
|
138 }, |
|
139 exec: { |
|
140 output: new RegExp("^Copied to clipboard.$"), |
|
141 }, |
|
142 post: function() { |
|
143 try { |
|
144 clip.getData(trans, clipid.kGlobalClipboard); |
|
145 let str = new Object(); |
|
146 let strLength = new Object(); |
|
147 trans.getTransferData("image/png", str, strLength); |
|
148 |
|
149 ok(str.value, "screenshot exists"); |
|
150 ok(strLength.value > 0, "screenshot has length"); |
|
151 } |
|
152 finally { |
|
153 Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); |
|
154 |
|
155 // Recent PB changes to the test I'm modifying removed the 'pb' |
|
156 // variable, but left this line in tact. This seems so obviously |
|
157 // wrong that I'm leaving this in in case the analysis is wrong |
|
158 // pb.privateBrowsingEnabled = true; |
|
159 } |
|
160 } |
|
161 }, |
|
162 ]); |
|
163 |
|
164 yield helpers.closeToolbar(options); |
|
165 yield helpers.closeTab(options); |
|
166 } |
|
167 |
|
168 function addWindow(windowOptions) { |
|
169 let deferred = promise.defer(); |
|
170 |
|
171 let win = OpenBrowserWindow(windowOptions); |
|
172 |
|
173 // This feels hacky, we should refactor it |
|
174 whenDelayedStartupFinished(win, function() { |
|
175 // Would like to get rid of this executeSoon, but without it the url |
|
176 // (TEST_URI) provided in addTabWithToolbarRunTests hasn't loaded |
|
177 executeSoon(function() { |
|
178 deferred.resolve(win); |
|
179 }); |
|
180 }); |
|
181 |
|
182 return deferred.promise; |
|
183 } |