browser_prefs-02.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that preference helpers work properly with custom types of Float and Json.
  5. const { PrefsHelper } = require("devtools/client/shared/prefs");
  6. function test() {
  7. let originalJson = Services.prefs.getCharPref(
  8. "devtools.performance.timeline.hidden-markers");
  9. let originalFloat = Services.prefs.getCharPref(
  10. "devtools.performance.memory.sample-probability");
  11. let Prefs = new PrefsHelper("devtools.performance", {
  12. "float": ["Float", "memory.sample-probability"],
  13. "json": ["Json", "timeline.hidden-markers"]
  14. });
  15. Prefs.registerObserver();
  16. // Float
  17. Services.prefs.setCharPref("devtools.performance.timeline.hidden-markers", "{\"a\":1}");
  18. is(Prefs.json.a, 1, "The JSON pref value is correctly casted on get.");
  19. Prefs.json = { b: 2 };
  20. is(Prefs.json.a, undefined, "The JSON pref value is correctly casted on set (1).");
  21. is(Prefs.json.b, 2, "The JSON pref value is correctly casted on set (2).");
  22. // Float
  23. Services.prefs.setCharPref("devtools.performance.memory.sample-probability", "3.14");
  24. is(Prefs.float, 3.14, "The float pref value is correctly casted on get.");
  25. Prefs.float = 6.28;
  26. is(Prefs.float, 6.28, "The float pref value is correctly casted on set.");
  27. Prefs.unregisterObserver();
  28. Services.prefs.setCharPref("devtools.performance.timeline.hidden-markers",
  29. originalJson);
  30. Services.prefs.setCharPref("devtools.performance.memory.sample-probability",
  31. originalFloat);
  32. finish();
  33. }