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 | // Tests that the jsb command works as it should |
michael@0 | 5 | |
michael@0 | 6 | const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" + |
michael@0 | 7 | "test/browser_cmd_jsb_script.jsi"; |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | return Task.spawn(testTask).then(finish, helpers.handleError); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | function testTask() { |
michael@0 | 14 | let options = yield helpers.openTab("about:blank"); |
michael@0 | 15 | yield helpers.openToolbar(options); |
michael@0 | 16 | |
michael@0 | 17 | let deferred = promise.defer(); |
michael@0 | 18 | let scratchpadWin = null; |
michael@0 | 19 | let scratchpad = null; |
michael@0 | 20 | |
michael@0 | 21 | let observer = { |
michael@0 | 22 | onReady: function() { |
michael@0 | 23 | scratchpad.removeObserver(observer); |
michael@0 | 24 | |
michael@0 | 25 | let result = scratchpad.getText(); |
michael@0 | 26 | result = result.replace(/[\r\n]]*/g, "\n"); |
michael@0 | 27 | let correct = "function somefunc() {\n" + |
michael@0 | 28 | " if (true) // Some comment\n" + |
michael@0 | 29 | " doSomething();\n" + |
michael@0 | 30 | " for (let n = 0; n < 500; n++) {\n" + |
michael@0 | 31 | " if (n % 2 == 1) {\n" + |
michael@0 | 32 | " console.log(n);\n" + |
michael@0 | 33 | " console.log(n + 1);\n" + |
michael@0 | 34 | " }\n" + |
michael@0 | 35 | " }\n" + |
michael@0 | 36 | "}"; |
michael@0 | 37 | is(result, correct, "JS has been correctly prettified"); |
michael@0 | 38 | |
michael@0 | 39 | if (scratchpadWin) { |
michael@0 | 40 | scratchpadWin.close(); |
michael@0 | 41 | scratchpadWin = null; |
michael@0 | 42 | } |
michael@0 | 43 | deferred.resolve(); |
michael@0 | 44 | }, |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | let onLoad = function GDT_onLoad() { |
michael@0 | 48 | scratchpadWin.removeEventListener("load", onLoad, false); |
michael@0 | 49 | scratchpad = scratchpadWin.Scratchpad; |
michael@0 | 50 | |
michael@0 | 51 | scratchpad.addObserver(observer); |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | let onNotify = function(subject, topic, data) { |
michael@0 | 55 | if (topic == "domwindowopened") { |
michael@0 | 56 | Services.ww.unregisterNotification(onNotify); |
michael@0 | 57 | |
michael@0 | 58 | scratchpadWin = subject.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 59 | scratchpadWin.addEventListener("load", onLoad, false); |
michael@0 | 60 | } |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | Services.ww.registerNotification(onNotify); |
michael@0 | 64 | |
michael@0 | 65 | helpers.audit(options, [ |
michael@0 | 66 | { |
michael@0 | 67 | setup: 'jsb', |
michael@0 | 68 | check: { |
michael@0 | 69 | input: 'jsb', |
michael@0 | 70 | hints: ' <url> [options]', |
michael@0 | 71 | markup: 'VVV', |
michael@0 | 72 | status: 'ERROR' |
michael@0 | 73 | } |
michael@0 | 74 | }, |
michael@0 | 75 | { |
michael@0 | 76 | setup: 'jsb ' + TEST_URI, |
michael@0 | 77 | // Should result in a new window, which should fire onReady (eventually) |
michael@0 | 78 | exec: { |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | ]); |
michael@0 | 82 | |
michael@0 | 83 | yield deferred.promise; |
michael@0 | 84 | |
michael@0 | 85 | yield helpers.closeToolbar(options); |
michael@0 | 86 | yield helpers.closeTab(options); |
michael@0 | 87 | } |