browser/devtools/scratchpad/test/browser_scratchpad_tab.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_tab.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +/* Bug 660560 */
     1.8 +
     1.9 +function test()
    1.10 +{
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  gBrowser.selectedTab = gBrowser.addTab();
    1.14 +  gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
    1.15 +    gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
    1.16 +
    1.17 +    ok(window.Scratchpad, "Scratchpad variable exists");
    1.18 +
    1.19 +    Services.prefs.setIntPref("devtools.editor.tabsize", 5);
    1.20 +
    1.21 +    openScratchpad(runTests);
    1.22 +  }, true);
    1.23 +
    1.24 +  content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560";
    1.25 +}
    1.26 +
    1.27 +function runTests()
    1.28 +{
    1.29 +  let sp = gScratchpadWindow.Scratchpad;
    1.30 +  ok(sp, "Scratchpad object exists in new window");
    1.31 +
    1.32 +  ok(sp.editor.hasFocus(), "the editor has focus");
    1.33 +
    1.34 +  sp.setText("window.foo;");
    1.35 +  sp.editor.setCursor({ line: 0, ch: 0 });
    1.36 +
    1.37 +  EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
    1.38 +
    1.39 +  is(sp.getText(), "     window.foo;", "Tab key added 5 spaces");
    1.40 +
    1.41 +  is(sp.editor.getCursor().line, 0, "line is correct");
    1.42 +  is(sp.editor.getCursor().ch, 5, "character is correct");
    1.43 +
    1.44 +  sp.editor.setCursor({ line: 0, ch: 6 });
    1.45 +
    1.46 +  EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
    1.47 +
    1.48 +  is(sp.getText(), "     w    indow.foo;",
    1.49 +     "Tab key added 4 spaces");
    1.50 +
    1.51 +  is(sp.editor.getCursor().line, 0, "line is correct");
    1.52 +  is(sp.editor.getCursor().ch, 10, "character is correct");
    1.53 +
    1.54 +  gScratchpadWindow.close();
    1.55 +
    1.56 +  Services.prefs.setIntPref("devtools.editor.tabsize", 6);
    1.57 +  Services.prefs.setBoolPref("devtools.editor.expandtab", false);
    1.58 +
    1.59 +  openScratchpad(runTests2);
    1.60 +}
    1.61 +
    1.62 +function runTests2()
    1.63 +{
    1.64 +  let sp = gScratchpadWindow.Scratchpad;
    1.65 +
    1.66 +  sp.setText("window.foo;");
    1.67 +  sp.editor.setCursor({ line: 0, ch: 0 });
    1.68 +
    1.69 +  EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
    1.70 +
    1.71 +  is(sp.getText(), "\twindow.foo;", "Tab key added the tab character");
    1.72 +
    1.73 +  is(sp.editor.getCursor().line, 0, "line is correct");
    1.74 +  is(sp.editor.getCursor().ch, 1, "character is correct");
    1.75 +
    1.76 +  Services.prefs.clearUserPref("devtools.editor.tabsize");
    1.77 +  Services.prefs.clearUserPref("devtools.editor.expandtab");
    1.78 +
    1.79 +  finish();
    1.80 +}

mercurial