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