browser_scratchpad_tab.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /* Bug 660560 */
  4. function test()
  5. {
  6. waitForExplicitFinish();
  7. gBrowser.selectedTab = gBrowser.addTab();
  8. gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
  9. gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
  10. Services.prefs.setIntPref("devtools.editor.tabsize", 5);
  11. openScratchpad(runTests);
  12. }, true);
  13. content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560";
  14. }
  15. function runTests()
  16. {
  17. let sp = gScratchpadWindow.Scratchpad;
  18. ok(sp, "Scratchpad object exists in new window");
  19. ok(sp.editor.hasFocus(), "the editor has focus");
  20. sp.setText("window.foo;");
  21. sp.editor.setCursor({ line: 0, ch: 0 });
  22. EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
  23. is(sp.getText(), " window.foo;", "Tab key added 5 spaces");
  24. is(sp.editor.getCursor().line, 0, "line is correct");
  25. is(sp.editor.getCursor().ch, 5, "character is correct");
  26. sp.editor.setCursor({ line: 0, ch: 6 });
  27. EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
  28. is(sp.getText(), " w indow.foo;",
  29. "Tab key added 4 spaces");
  30. is(sp.editor.getCursor().line, 0, "line is correct");
  31. is(sp.editor.getCursor().ch, 10, "character is correct");
  32. gScratchpadWindow.close();
  33. Services.prefs.setIntPref("devtools.editor.tabsize", 6);
  34. Services.prefs.setBoolPref("devtools.editor.expandtab", false);
  35. openScratchpad(runTests2);
  36. }
  37. function runTests2()
  38. {
  39. let sp = gScratchpadWindow.Scratchpad;
  40. sp.setText("window.foo;");
  41. sp.editor.setCursor({ line: 0, ch: 0 });
  42. EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow);
  43. is(sp.getText(), "\twindow.foo;", "Tab key added the tab character");
  44. is(sp.editor.getCursor().line, 0, "line is correct");
  45. is(sp.editor.getCursor().ch, 1, "character is correct");
  46. Services.prefs.clearUserPref("devtools.editor.tabsize");
  47. Services.prefs.clearUserPref("devtools.editor.expandtab");
  48. finish();
  49. }