2011-04-19 13:40:30 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
// Reference to the Scratchpad chrome window object.
|
|
|
|
let gScratchpadWindow;
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
function test()
|
|
|
|
{
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
gBrowser.selectedBrowser.addEventListener("load", function() {
|
|
|
|
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
gScratchpadWindow = Scratchpad.openScratchpad();
|
|
|
|
gScratchpadWindow.addEventListener("load", runTests, false);
|
2011-04-19 13:40:30 -07:00
|
|
|
}, true);
|
|
|
|
|
2011-05-21 04:59:23 -07:00
|
|
|
content.location = "data:text/html,<p>test run() and display() in Scratchpad";
|
2011-04-19 13:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTests()
|
|
|
|
{
|
2011-05-09 07:51:52 -07:00
|
|
|
gScratchpadWindow.removeEventListener("load", arguments.callee, false);
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
let sp = gScratchpadWindow.Scratchpad;
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
content.wrappedJSObject.foobarBug636725 = 1;
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
ok(sp.textbox, "textbox exists");
|
|
|
|
sp.textbox.value = "++window.foobarBug636725";
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-21 04:59:23 -07:00
|
|
|
let exec = sp.run();
|
2011-05-09 07:51:52 -07:00
|
|
|
is(exec[0], sp.textbox.value, "execute()[0] is correct");
|
2011-04-19 13:40:30 -07:00
|
|
|
is(exec[1], content.wrappedJSObject.foobarBug636725,
|
|
|
|
"execute()[1] is correct");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.value, "++window.foobarBug636725",
|
2011-04-19 13:40:30 -07:00
|
|
|
"execute() does not change the textbox value");
|
|
|
|
|
|
|
|
is(content.wrappedJSObject.foobarBug636725, 2,
|
|
|
|
"execute() updated window.foobarBug636725");
|
|
|
|
|
2011-05-21 04:59:23 -07:00
|
|
|
sp.display();
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
is(content.wrappedJSObject.foobarBug636725, 3,
|
|
|
|
"print() updated window.foobarBug636725");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.value, "++window.foobarBug636725/*\n3\n*/",
|
2011-04-19 13:40:30 -07:00
|
|
|
"print() shows evaluation result in the textbox");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.selectedText, "/*\n3\n*/", "selectedText is correct");
|
|
|
|
is(sp.textbox.selectionStart, 24, "selectionStart is correct");
|
|
|
|
is(sp.textbox.selectionEnd, 31, "selectionEnd is correct");
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
// Test selection execute() and print().
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.textbox.value = "window.foobarBug636725 = 'a';\n" +
|
2011-04-19 13:40:30 -07:00
|
|
|
"window.foobarBug636725 = 'b';";
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.selectRange(1, 2);
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.selectionStart, 1, "selectionStart is 1");
|
|
|
|
is(sp.textbox.selectionEnd, 2, "selectionEnd is 2");
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.selectRange(0, 29);
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.selectionStart, 0, "selectionStart is 0");
|
|
|
|
is(sp.textbox.selectionEnd, 29, "selectionEnd is 29");
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-21 04:59:23 -07:00
|
|
|
exec = sp.run();
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
is(exec[0], "window.foobarBug636725 = 'a';",
|
|
|
|
"execute()[0] is correct");
|
|
|
|
is(exec[1], "a",
|
|
|
|
"execute()[1] is correct");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.value, "window.foobarBug636725 = 'a';\n" +
|
2011-04-19 13:40:30 -07:00
|
|
|
"window.foobarBug636725 = 'b';",
|
|
|
|
"execute() does not change the textbox value");
|
|
|
|
|
|
|
|
is(content.wrappedJSObject.foobarBug636725, "a",
|
|
|
|
"execute() worked for the selected range");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.textbox.value = "window.foobarBug636725 = 'c';\n" +
|
2011-04-19 13:40:30 -07:00
|
|
|
"window.foobarBug636725 = 'b';";
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.selectRange(0, 22);
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-21 04:59:23 -07:00
|
|
|
sp.display();
|
2011-04-19 13:40:30 -07:00
|
|
|
|
|
|
|
is(content.wrappedJSObject.foobarBug636725, "a",
|
|
|
|
"print() worked for the selected range");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.textbox.value, "window.foobarBug636725" +
|
2011-04-19 13:40:30 -07:00
|
|
|
"/*\na\n*/" +
|
|
|
|
" = 'c';\n" +
|
|
|
|
"window.foobarBug636725 = 'b';",
|
|
|
|
"print() shows evaluation result in the textbox");
|
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
is(sp.selectedText, "/*\na\n*/", "selectedText is correct");
|
|
|
|
is(sp.textbox.selectionStart, 22, "selectionStart is correct");
|
|
|
|
is(sp.textbox.selectionEnd, 29, "selectionEnd is correct");
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
sp.deselect();
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
ok(!sp.selectedText, "selectedText is empty");
|
|
|
|
is(sp.textbox.selectionStart, sp.textbox.selectionEnd, "deselect() works");
|
2011-04-19 13:40:30 -07:00
|
|
|
|
2011-05-09 07:51:52 -07:00
|
|
|
gScratchpadWindow.close();
|
|
|
|
gScratchpadWindow = null;
|
2011-04-19 13:40:30 -07:00
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
finish();
|
|
|
|
}
|