summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/shim/test/test_service_prefs_defaults.html
blob: d8933b74a1bd6b33f6cb2b4e2d07d84694af5e43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1309384
-->
<head>
  <title>Test for Bug 1309384 - Services.prefs replacement defaults handling</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css">

<script type="application/javascript;version=1.8">
"use strict";
var exports = {}
var module = {exports};

// Allow one require("raw!prefs...") to return some defaults, with the
// others being ignored.
var firstTime = true;
function require(something) {
  if (!something.startsWith("raw!prefs!")) {
    throw new Error("whoops");
  }
  if (!firstTime) {
    return "";
  }
  firstTime = false;
  return "pref('pref1', 'pref1default');\n" +
    "pref('pref2', 'pref2default');\n" +
    "pref('pref3', 'pref3default');\n";
}

// Pretend that one of the prefs was modifed by the user in an earlier session.
localStorage.setItem("Services.prefs:pref3", JSON.stringify({
  // string
  type: 32,
  defaultValue: "pref3default",
  hasUserValue: true,
  userValue: "glass winged butterfly"
}));

</script>

  <script type="application/javascript;version=1.8"
	  src="resource://devtools/client/shared/shim/Services.js"></script>
</head>
<body>
<script type="application/javascript;version=1.8">
"use strict";

is(Services.prefs.getCharPref("pref1"), "pref1default", "pref1 value");
is(Services.prefs.getCharPref("pref2"), "pref2default", "pref2 value");
is(Services.prefs.getCharPref("pref3"), "glass winged butterfly", "pref3 value");

// Only pref3 should be in local storage at this point.
is(localStorage.length, 1, "local storage is correct");

Services.prefs.setCharPref("pref2", "pref2override");

// Check that a default pref can be overridden properly

// Workaround to reset the prefs helper and force it to read defaults & overrides again.
Services._prefs = null;
is(Services.prefs.getCharPref("pref2"), "pref2override", "pref2 value overridden");

// Clean up.
localStorage.clear();

</script>
</body>