browser/devtools/tilt/test/browser_tilt_utils01.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2aa369e76873
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3 "use strict";
4
5 function test() {
6 let prefs = TiltUtils.Preferences;
7 ok(prefs, "The TiltUtils.Preferences wasn't found.");
8
9 prefs.create("test-pref-bool", "boolean", true);
10 prefs.create("test-pref-int", "integer", 42);
11 prefs.create("test-pref-string", "string", "hello world!");
12
13 is(prefs.get("test-pref-bool", "boolean"), true,
14 "The boolean test preference wasn't initially set correctly.");
15 is(prefs.get("test-pref-int", "integer"), 42,
16 "The integer test preference wasn't initially set correctly.");
17 is(prefs.get("test-pref-string", "string"), "hello world!",
18 "The string test preference wasn't initially set correctly.");
19
20
21 prefs.set("test-pref-bool", "boolean", false);
22 prefs.set("test-pref-int", "integer", 24);
23 prefs.set("test-pref-string", "string", "!dlrow olleh");
24
25 is(prefs.get("test-pref-bool", "boolean"), false,
26 "The boolean test preference wasn't changed correctly.");
27 is(prefs.get("test-pref-int", "integer"), 24,
28 "The integer test preference wasn't changed correctly.");
29 is(prefs.get("test-pref-string", "string"), "!dlrow olleh",
30 "The string test preference wasn't changed correctly.");
31
32
33 is(typeof prefs.get("unknown-pref", "boolean"), "undefined",
34 "Inexisted boolean prefs should be handled as undefined.");
35 is(typeof prefs.get("unknown-pref", "integer"), "undefined",
36 "Inexisted integer prefs should be handled as undefined.");
37 is(typeof prefs.get("unknown-pref", "string"), "undefined",
38 "Inexisted string prefs should be handled as undefined.");
39
40
41 is(prefs.get("test-pref-bool", "integer"), null,
42 "The get() boolean function didn't handle incorrect types as it should.");
43 is(prefs.get("test-pref-bool", "string"), null,
44 "The get() boolean function didn't handle incorrect types as it should.");
45 is(prefs.get("test-pref-int", "boolean"), null,
46 "The get() integer function didn't handle incorrect types as it should.");
47 is(prefs.get("test-pref-int", "string"), null,
48 "The get() integer function didn't handle incorrect types as it should.");
49 is(prefs.get("test-pref-string", "boolean"), null,
50 "The get() string function didn't handle incorrect types as it should.");
51 is(prefs.get("test-pref-string", "integer"), null,
52 "The get() string function didn't handle incorrect types as it should.");
53
54
55 is(typeof prefs.get(), "undefined",
56 "The get() function should not work if not enough params are passed.");
57 is(typeof prefs.set(), "undefined",
58 "The set() function should not work if not enough params are passed.");
59 is(typeof prefs.create(), "undefined",
60 "The create() function should not work if not enough params are passed.");
61
62
63 is(prefs.get("test-pref-wrong-type", "wrong-type", 1), null,
64 "The get() function should expect only correct pref types.");
65 is(prefs.set("test-pref-wrong-type", "wrong-type", 1), false,
66 "The set() function should expect only correct pref types.");
67 is(prefs.create("test-pref-wrong-type", "wrong-type", 1), false,
68 "The create() function should expect only correct pref types.");
69 }

mercurial