2012-08-14 18:51:48 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
// Tests that the jsb command works as it should
|
|
|
|
|
2015-09-21 20:07:31 +03:00
|
|
|
const TEST_URI = "http://example.com/browser/devtools/client/commandline/" +
|
2012-08-14 18:51:48 +04:00
|
|
|
"test/browser_cmd_jsb_script.jsi";
|
|
|
|
|
|
|
|
function test() {
|
2013-09-03 15:20:27 +04:00
|
|
|
return Task.spawn(testTask).then(finish, helpers.handleError);
|
2012-08-14 18:51:48 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
function* testTask() {
|
2013-09-03 15:20:27 +04:00
|
|
|
let options = yield helpers.openTab("about:blank");
|
|
|
|
yield helpers.openToolbar(options);
|
|
|
|
|
2014-06-09 18:16:26 +04:00
|
|
|
let notifyPromise = wwNotifyOnce();
|
2013-03-13 08:51:30 +04:00
|
|
|
|
|
|
|
helpers.audit(options, [
|
|
|
|
{
|
|
|
|
setup: 'jsb',
|
|
|
|
check: {
|
|
|
|
input: 'jsb',
|
|
|
|
hints: ' <url> [options]',
|
|
|
|
markup: 'VVV',
|
|
|
|
status: 'ERROR'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
setup: 'jsb ' + TEST_URI,
|
2014-06-09 18:16:26 +04:00
|
|
|
// Should result in a new scratchpad window
|
2015-04-23 12:24:49 +03:00
|
|
|
exec: {
|
|
|
|
output: '',
|
|
|
|
error: false
|
|
|
|
}
|
2013-03-13 08:51:30 +04:00
|
|
|
}
|
|
|
|
]);
|
2012-10-03 22:10:07 +04:00
|
|
|
|
2014-06-09 18:16:26 +04:00
|
|
|
let { subject } = yield notifyPromise;
|
|
|
|
let scratchpadWin = subject.QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
yield helpers.listenOnce(scratchpadWin, "load");
|
|
|
|
|
|
|
|
let scratchpad = scratchpadWin.Scratchpad;
|
|
|
|
|
|
|
|
yield observeOnce(scratchpad);
|
|
|
|
|
|
|
|
let result = scratchpad.getText();
|
|
|
|
result = result.replace(/[\r\n]]*/g, "\n");
|
|
|
|
let correct = "function somefunc() {\n" +
|
|
|
|
" if (true) // Some comment\n" +
|
2014-07-14 17:25:22 +04:00
|
|
|
" doSomething();\n" +
|
2014-06-09 18:16:26 +04:00
|
|
|
" for (let n = 0; n < 500; n++) {\n" +
|
|
|
|
" if (n % 2 == 1) {\n" +
|
|
|
|
" console.log(n);\n" +
|
|
|
|
" console.log(n + 1);\n" +
|
|
|
|
" }\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}";
|
|
|
|
is(result, correct, "JS has been correctly prettified");
|
|
|
|
|
|
|
|
if (scratchpadWin) {
|
|
|
|
scratchpadWin.close();
|
|
|
|
scratchpadWin = null;
|
|
|
|
}
|
2013-09-03 15:20:27 +04:00
|
|
|
|
|
|
|
yield helpers.closeToolbar(options);
|
|
|
|
yield helpers.closeTab(options);
|
|
|
|
}
|
2014-06-09 18:16:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for calling Services.ww.[un]registerNotification using promises.
|
|
|
|
* @return a promise that resolves when the notification service first notifies
|
|
|
|
* with topic == "domwindowopened".
|
|
|
|
* The value of the promise is { subject: subject, topic: topic, data: data }
|
|
|
|
*/
|
|
|
|
function wwNotifyOnce() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let onNotify = (subject, topic, data) => {
|
|
|
|
if (topic == "domwindowopened") {
|
|
|
|
Services.ww.unregisterNotification(onNotify);
|
|
|
|
resolve({ subject: subject, topic: topic, data: data });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Services.ww.registerNotification(onNotify);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* YET ANOTHER WRAPPER for a place where we are using events as poor-man's
|
|
|
|
* promises. Perhaps this should be promoted to scratchpad?
|
|
|
|
*/
|
|
|
|
function observeOnce(scratchpad) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let observer = {
|
|
|
|
onReady: function() {
|
|
|
|
scratchpad.removeObserver(observer);
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
scratchpad.addObserver(observer);
|
|
|
|
});
|
|
|
|
}
|