browser_cmd_settings.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Any copyright is dedicated to the Public Domain.
  2. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // Tests that the pref commands work
  4. var prefBranch = Cc["@mozilla.org/preferences-service;1"]
  5. .getService(Ci.nsIPrefService).getBranch(null)
  6. .QueryInterface(Ci.nsIPrefBranch2);
  7. var supportsString = Cc["@mozilla.org/supports-string;1"]
  8. .createInstance(Ci.nsISupportsString);
  9. const TEST_URI = "data:text/html;charset=utf-8,gcli-settings";
  10. function test() {
  11. return Task.spawn(spawnTest).then(finish, helpers.handleError);
  12. }
  13. function* spawnTest() {
  14. // Setup
  15. let options = yield helpers.openTab(TEST_URI);
  16. const { createSystem } = require("gcli/system");
  17. const system = createSystem({ location: "server" });
  18. const gcliInit = require("devtools/shared/gcli/commands/index");
  19. gcliInit.addAllItemsByModule(system);
  20. yield system.load();
  21. let settings = system.settings;
  22. let hideIntroEnabled = settings.get("devtools.gcli.hideIntro");
  23. let tabSize = settings.get("devtools.editor.tabsize");
  24. let remoteHost = settings.get("devtools.debugger.remote-host");
  25. let hideIntroOrig = prefBranch.getBoolPref("devtools.gcli.hideIntro");
  26. let tabSizeOrig = prefBranch.getIntPref("devtools.editor.tabsize");
  27. let remoteHostOrig = prefBranch.getComplexValue(
  28. "devtools.debugger.remote-host",
  29. Components.interfaces.nsISupportsString).data;
  30. info("originally: devtools.gcli.hideIntro = " + hideIntroOrig);
  31. info("originally: devtools.editor.tabsize = " + tabSizeOrig);
  32. info("originally: devtools.debugger.remote-host = " + remoteHostOrig);
  33. // Actual tests
  34. is(hideIntroEnabled.value, hideIntroOrig, "hideIntroEnabled default");
  35. is(tabSize.value, tabSizeOrig, "tabSize default");
  36. is(remoteHost.value, remoteHostOrig, "remoteHost default");
  37. hideIntroEnabled.setDefault();
  38. tabSize.setDefault();
  39. remoteHost.setDefault();
  40. let hideIntroEnabledDefault = hideIntroEnabled.value;
  41. let tabSizeDefault = tabSize.value;
  42. let remoteHostDefault = remoteHost.value;
  43. hideIntroEnabled.value = false;
  44. tabSize.value = 42;
  45. remoteHost.value = "example.com";
  46. is(hideIntroEnabled.value, false, "hideIntroEnabled basic");
  47. is(tabSize.value, 42, "tabSize basic");
  48. is(remoteHost.value, "example.com", "remoteHost basic");
  49. function hideIntroEnabledCheck(ev) {
  50. is(ev.setting, hideIntroEnabled, "hideIntroEnabled event setting");
  51. is(ev.value, true, "hideIntroEnabled event value");
  52. is(ev.setting.value, true, "hideIntroEnabled event setting value");
  53. }
  54. hideIntroEnabled.onChange.add(hideIntroEnabledCheck);
  55. hideIntroEnabled.value = true;
  56. is(hideIntroEnabled.value, true, "hideIntroEnabled change");
  57. function tabSizeCheck(ev) {
  58. is(ev.setting, tabSize, "tabSize event setting");
  59. is(ev.value, 1, "tabSize event value");
  60. is(ev.setting.value, 1, "tabSize event setting value");
  61. }
  62. tabSize.onChange.add(tabSizeCheck);
  63. tabSize.value = 1;
  64. is(tabSize.value, 1, "tabSize change");
  65. function remoteHostCheck(ev) {
  66. is(ev.setting, remoteHost, "remoteHost event setting");
  67. is(ev.value, "y.com", "remoteHost event value");
  68. is(ev.setting.value, "y.com", "remoteHost event setting value");
  69. }
  70. remoteHost.onChange.add(remoteHostCheck);
  71. remoteHost.value = "y.com";
  72. is(remoteHost.value, "y.com", "remoteHost change");
  73. hideIntroEnabled.onChange.remove(hideIntroEnabledCheck);
  74. tabSize.onChange.remove(tabSizeCheck);
  75. remoteHost.onChange.remove(remoteHostCheck);
  76. function remoteHostReCheck(ev) {
  77. is(ev.setting, remoteHost, "remoteHost event reset");
  78. is(ev.value, null, "remoteHost event revalue");
  79. is(ev.setting.value, null, "remoteHost event setting revalue");
  80. }
  81. remoteHost.onChange.add(remoteHostReCheck);
  82. hideIntroEnabled.setDefault();
  83. tabSize.setDefault();
  84. remoteHost.setDefault();
  85. remoteHost.onChange.remove(remoteHostReCheck);
  86. is(hideIntroEnabled.value, hideIntroEnabledDefault, "hideIntroEnabled reset");
  87. is(tabSize.value, tabSizeDefault, "tabSize reset");
  88. is(remoteHost.value, remoteHostDefault, "remoteHost reset");
  89. // Cleanup
  90. prefBranch.setBoolPref("devtools.gcli.hideIntro", hideIntroOrig);
  91. prefBranch.setIntPref("devtools.editor.tabsize", tabSizeOrig);
  92. supportsString.data = remoteHostOrig;
  93. prefBranch.setComplexValue("devtools.debugger.remote-host",
  94. Components.interfaces.nsISupportsString,
  95. supportsString);
  96. yield helpers.closeTab(options);
  97. }