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: /* Bug 660560 */ 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: michael@0: ok(window.Scratchpad, "Scratchpad variable exists"); michael@0: michael@0: Services.prefs.setIntPref("devtools.editor.tabsize", 5); michael@0: michael@0: openScratchpad(runTests); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560"; michael@0: } michael@0: michael@0: function runTests() michael@0: { michael@0: let sp = gScratchpadWindow.Scratchpad; michael@0: ok(sp, "Scratchpad object exists in new window"); michael@0: michael@0: ok(sp.editor.hasFocus(), "the editor has focus"); michael@0: michael@0: sp.setText("window.foo;"); michael@0: sp.editor.setCursor({ line: 0, ch: 0 }); michael@0: michael@0: EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); michael@0: michael@0: is(sp.getText(), " window.foo;", "Tab key added 5 spaces"); michael@0: michael@0: is(sp.editor.getCursor().line, 0, "line is correct"); michael@0: is(sp.editor.getCursor().ch, 5, "character is correct"); michael@0: michael@0: sp.editor.setCursor({ line: 0, ch: 6 }); michael@0: michael@0: EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); michael@0: michael@0: is(sp.getText(), " w indow.foo;", michael@0: "Tab key added 4 spaces"); michael@0: michael@0: is(sp.editor.getCursor().line, 0, "line is correct"); michael@0: is(sp.editor.getCursor().ch, 10, "character is correct"); michael@0: michael@0: gScratchpadWindow.close(); michael@0: michael@0: Services.prefs.setIntPref("devtools.editor.tabsize", 6); michael@0: Services.prefs.setBoolPref("devtools.editor.expandtab", false); michael@0: michael@0: openScratchpad(runTests2); michael@0: } michael@0: michael@0: function runTests2() michael@0: { michael@0: let sp = gScratchpadWindow.Scratchpad; michael@0: michael@0: sp.setText("window.foo;"); michael@0: sp.editor.setCursor({ line: 0, ch: 0 }); michael@0: michael@0: EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); michael@0: michael@0: is(sp.getText(), "\twindow.foo;", "Tab key added the tab character"); michael@0: michael@0: is(sp.editor.getCursor().line, 0, "line is correct"); michael@0: is(sp.editor.getCursor().ch, 1, "character is correct"); michael@0: michael@0: Services.prefs.clearUserPref("devtools.editor.tabsize"); michael@0: Services.prefs.clearUserPref("devtools.editor.expandtab"); michael@0: michael@0: finish(); michael@0: }