1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_utils01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +function test() { 1.9 + let prefs = TiltUtils.Preferences; 1.10 + ok(prefs, "The TiltUtils.Preferences wasn't found."); 1.11 + 1.12 + prefs.create("test-pref-bool", "boolean", true); 1.13 + prefs.create("test-pref-int", "integer", 42); 1.14 + prefs.create("test-pref-string", "string", "hello world!"); 1.15 + 1.16 + is(prefs.get("test-pref-bool", "boolean"), true, 1.17 + "The boolean test preference wasn't initially set correctly."); 1.18 + is(prefs.get("test-pref-int", "integer"), 42, 1.19 + "The integer test preference wasn't initially set correctly."); 1.20 + is(prefs.get("test-pref-string", "string"), "hello world!", 1.21 + "The string test preference wasn't initially set correctly."); 1.22 + 1.23 + 1.24 + prefs.set("test-pref-bool", "boolean", false); 1.25 + prefs.set("test-pref-int", "integer", 24); 1.26 + prefs.set("test-pref-string", "string", "!dlrow olleh"); 1.27 + 1.28 + is(prefs.get("test-pref-bool", "boolean"), false, 1.29 + "The boolean test preference wasn't changed correctly."); 1.30 + is(prefs.get("test-pref-int", "integer"), 24, 1.31 + "The integer test preference wasn't changed correctly."); 1.32 + is(prefs.get("test-pref-string", "string"), "!dlrow olleh", 1.33 + "The string test preference wasn't changed correctly."); 1.34 + 1.35 + 1.36 + is(typeof prefs.get("unknown-pref", "boolean"), "undefined", 1.37 + "Inexisted boolean prefs should be handled as undefined."); 1.38 + is(typeof prefs.get("unknown-pref", "integer"), "undefined", 1.39 + "Inexisted integer prefs should be handled as undefined."); 1.40 + is(typeof prefs.get("unknown-pref", "string"), "undefined", 1.41 + "Inexisted string prefs should be handled as undefined."); 1.42 + 1.43 + 1.44 + is(prefs.get("test-pref-bool", "integer"), null, 1.45 + "The get() boolean function didn't handle incorrect types as it should."); 1.46 + is(prefs.get("test-pref-bool", "string"), null, 1.47 + "The get() boolean function didn't handle incorrect types as it should."); 1.48 + is(prefs.get("test-pref-int", "boolean"), null, 1.49 + "The get() integer function didn't handle incorrect types as it should."); 1.50 + is(prefs.get("test-pref-int", "string"), null, 1.51 + "The get() integer function didn't handle incorrect types as it should."); 1.52 + is(prefs.get("test-pref-string", "boolean"), null, 1.53 + "The get() string function didn't handle incorrect types as it should."); 1.54 + is(prefs.get("test-pref-string", "integer"), null, 1.55 + "The get() string function didn't handle incorrect types as it should."); 1.56 + 1.57 + 1.58 + is(typeof prefs.get(), "undefined", 1.59 + "The get() function should not work if not enough params are passed."); 1.60 + is(typeof prefs.set(), "undefined", 1.61 + "The set() function should not work if not enough params are passed."); 1.62 + is(typeof prefs.create(), "undefined", 1.63 + "The create() function should not work if not enough params are passed."); 1.64 + 1.65 + 1.66 + is(prefs.get("test-pref-wrong-type", "wrong-type", 1), null, 1.67 + "The get() function should expect only correct pref types."); 1.68 + is(prefs.set("test-pref-wrong-type", "wrong-type", 1), false, 1.69 + "The set() function should expect only correct pref types."); 1.70 + is(prefs.create("test-pref-wrong-type", "wrong-type", 1), false, 1.71 + "The create() function should expect only correct pref types."); 1.72 +}