michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that the jsb command works as it should michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" + michael@0: "test/browser_cmd_jsb_script.jsi"; michael@0: michael@0: function test() { michael@0: return Task.spawn(testTask).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: function testTask() { michael@0: let options = yield helpers.openTab("about:blank"); michael@0: yield helpers.openToolbar(options); michael@0: michael@0: let deferred = promise.defer(); michael@0: let scratchpadWin = null; michael@0: let scratchpad = null; michael@0: michael@0: let observer = { michael@0: onReady: function() { michael@0: scratchpad.removeObserver(observer); michael@0: michael@0: let result = scratchpad.getText(); michael@0: result = result.replace(/[\r\n]]*/g, "\n"); michael@0: let correct = "function somefunc() {\n" + michael@0: " if (true) // Some comment\n" + michael@0: " doSomething();\n" + michael@0: " for (let n = 0; n < 500; n++) {\n" + michael@0: " if (n % 2 == 1) {\n" + michael@0: " console.log(n);\n" + michael@0: " console.log(n + 1);\n" + michael@0: " }\n" + michael@0: " }\n" + michael@0: "}"; michael@0: is(result, correct, "JS has been correctly prettified"); michael@0: michael@0: if (scratchpadWin) { michael@0: scratchpadWin.close(); michael@0: scratchpadWin = null; michael@0: } michael@0: deferred.resolve(); michael@0: }, michael@0: }; michael@0: michael@0: let onLoad = function GDT_onLoad() { michael@0: scratchpadWin.removeEventListener("load", onLoad, false); michael@0: scratchpad = scratchpadWin.Scratchpad; michael@0: michael@0: scratchpad.addObserver(observer); michael@0: }; michael@0: michael@0: let onNotify = function(subject, topic, data) { michael@0: if (topic == "domwindowopened") { michael@0: Services.ww.unregisterNotification(onNotify); michael@0: michael@0: scratchpadWin = subject.QueryInterface(Ci.nsIDOMWindow); michael@0: scratchpadWin.addEventListener("load", onLoad, false); michael@0: } michael@0: }; michael@0: michael@0: Services.ww.registerNotification(onNotify); michael@0: michael@0: helpers.audit(options, [ michael@0: { michael@0: setup: 'jsb', michael@0: check: { michael@0: input: 'jsb', michael@0: hints: ' [options]', michael@0: markup: 'VVV', michael@0: status: 'ERROR' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'jsb ' + TEST_URI, michael@0: // Should result in a new window, which should fire onReady (eventually) michael@0: exec: { michael@0: } michael@0: } michael@0: ]); michael@0: michael@0: yield deferred.promise; michael@0: michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }