browser_scratchpad_pprint-02.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. function test()
  4. {
  5. waitForExplicitFinish();
  6. gBrowser.selectedTab = gBrowser.addTab();
  7. gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
  8. gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
  9. openScratchpad(runTests);
  10. }, true);
  11. content.location = "data:text/html;charset=utf8,test Scratchpad pretty print.";
  12. }
  13. var gTabsize;
  14. function runTests(sw)
  15. {
  16. gTabsize = Services.prefs.getIntPref("devtools.editor.tabsize");
  17. Services.prefs.setIntPref("devtools.editor.tabsize", 6);
  18. const space = " ".repeat(6);
  19. const sp = sw.Scratchpad;
  20. sp.setText("function main() { console.log(5); }");
  21. sp.prettyPrint().then(() => {
  22. const prettyText = sp.getText();
  23. ok(prettyText.includes(space));
  24. finish();
  25. }).then(null, error => {
  26. ok(false, error);
  27. });
  28. }
  29. registerCleanupFunction(function () {
  30. Services.prefs.setIntPref("devtools.editor.tabsize", gTabsize);
  31. gTabsize = null;
  32. });