michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); michael@0: openScratchpad(runTests); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,

test run() and display() in Scratchpad"; michael@0: } michael@0: michael@0: michael@0: function runTests() michael@0: { michael@0: let sp = gScratchpadWindow.Scratchpad; michael@0: let tests = [{ michael@0: method: "run", michael@0: prepare: function() { michael@0: content.wrappedJSObject.foobarBug636725 = 1; michael@0: sp.editor.setText("++window.foobarBug636725"); michael@0: }, michael@0: then: function([code, , result]) { michael@0: is(code, sp.getText(), "code is correct"); michael@0: is(result, content.wrappedJSObject.foobarBug636725, michael@0: "result is correct"); michael@0: michael@0: is(sp.getText(), "++window.foobarBug636725", michael@0: "run() does not change the editor content"); michael@0: michael@0: is(content.wrappedJSObject.foobarBug636725, 2, michael@0: "run() updated window.foobarBug636725"); michael@0: } michael@0: }, michael@0: { michael@0: method: "display", michael@0: prepare: function() {}, michael@0: then: function() { michael@0: is(content.wrappedJSObject.foobarBug636725, 3, michael@0: "display() updated window.foobarBug636725"); michael@0: michael@0: is(sp.getText(), "++window.foobarBug636725\n/*\n3\n*/", michael@0: "display() shows evaluation result in the textbox"); michael@0: michael@0: is(sp.editor.getSelection(), "\n/*\n3\n*/", "getSelection is correct"); michael@0: } michael@0: }, michael@0: { michael@0: method: "run", michael@0: prepare: function() { michael@0: sp.editor.setText("window.foobarBug636725 = 'a';\n" + michael@0: "window.foobarBug636725 = 'b';"); michael@0: sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 29 }); michael@0: }, michael@0: then: function([code, , result]) { michael@0: is(code, "window.foobarBug636725 = 'a';", "code is correct"); michael@0: is(result, "a", "result is correct"); michael@0: michael@0: is(sp.getText(), "window.foobarBug636725 = 'a';\n" + michael@0: "window.foobarBug636725 = 'b';", michael@0: "run() does not change the textbox value"); michael@0: michael@0: is(content.wrappedJSObject.foobarBug636725, "a", michael@0: "run() worked for the selected range"); michael@0: } michael@0: }, michael@0: { michael@0: method: "display", michael@0: prepare: function() { michael@0: sp.editor.setText("window.foobarBug636725 = 'c';\n" + michael@0: "window.foobarBug636725 = 'b';"); michael@0: sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 22 }); michael@0: }, michael@0: then: function() { michael@0: is(content.wrappedJSObject.foobarBug636725, "a", michael@0: "display() worked for the selected range"); michael@0: michael@0: is(sp.getText(), "window.foobarBug636725" + michael@0: "\n/*\na\n*/" + michael@0: " = 'c';\n" + michael@0: "window.foobarBug636725 = 'b';", michael@0: "display() shows evaluation result in the textbox"); michael@0: michael@0: is(sp.editor.getSelection(), "\n/*\na\n*/", "getSelection is correct"); michael@0: } michael@0: }]; michael@0: michael@0: runAsyncCallbackTests(sp, tests).then(function() { michael@0: ok(sp.editor.somethingSelected(), "something is selected"); michael@0: sp.editor.dropSelection(); michael@0: ok(!sp.editor.somethingSelected(), "something is no longer selected"); michael@0: ok(!sp.editor.getSelection(), "getSelection is empty"); michael@0: michael@0: // Test undo/redo. michael@0: sp.editor.setText("foo1"); michael@0: sp.editor.setText("foo2"); michael@0: is(sp.getText(), "foo2", "editor content updated"); michael@0: sp.undo(); michael@0: is(sp.getText(), "foo1", "undo() works"); michael@0: sp.redo(); michael@0: is(sp.getText(), "foo2", "redo() works"); michael@0: michael@0: finish(); michael@0: }); michael@0: }