aboutsummaryrefslogtreecommitdiff
path: root/tools/addon-sdk-1.12/test/test-app-strings.js
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@gmail.com>2013-01-02 15:31:43 -0800
committerGravatar Rogan Creswick <creswick@gmail.com>2013-01-02 15:31:43 -0800
commit91c8d16838b39c7726f6c0a0fb333f5ba38d2494 (patch)
tree136df17525e5e62f3ddc5b7a6dc71ffd31e2aa42 /tools/addon-sdk-1.12/test/test-app-strings.js
parentf7b228c479bac8828e521a2826d7f57f150da877 (diff)
updated addon-sdk to 1.12
Diffstat (limited to 'tools/addon-sdk-1.12/test/test-app-strings.js')
-rw-r--r--tools/addon-sdk-1.12/test/test-app-strings.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/addon-sdk-1.12/test/test-app-strings.js b/tools/addon-sdk-1.12/test/test-app-strings.js
new file mode 100644
index 0000000..faa52fc
--- /dev/null
+++ b/tools/addon-sdk-1.12/test/test-app-strings.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { Cc,Ci } = require("chrome");
+
+let StringBundle = require("sdk/deprecated/app-strings").StringBundle;
+exports.testStringBundle = function(test) {
+ let url = "chrome://global/locale/security/caps.properties";
+
+ let strings = StringBundle(url);
+
+ test.assertEqual(strings.url, url,
+ "'url' property contains correct URL of string bundle");
+
+ let appLocale = Cc["@mozilla.org/intl/nslocaleservice;1"].
+ getService(Ci.nsILocaleService).
+ getApplicationLocale();
+
+ let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
+ getService(Ci.nsIStringBundleService).
+ createBundle(url, appLocale);
+
+ let (name = "Yes") {
+ test.assertEqual(strings.get(name), stringBundle.GetStringFromName(name),
+ "getting a string returns the string");
+ }
+
+ let (name = "ExtensionCapability", args = ["foo"]) {
+ test.assertEqual(strings.get(name, args),
+ stringBundle.formatStringFromName(name, args, args.length),
+ "getting a formatted string returns the formatted string");
+ }
+
+ test.assertRaises(function () strings.get("nonexistentString"),
+ "String 'nonexistentString' could not be retrieved from " +
+ "the bundle due to an unknown error (it doesn't exist?).",
+ "retrieving a nonexistent string throws an exception");
+
+ let a = [], b = [];
+ let enumerator = stringBundle.getSimpleEnumeration();
+ while (enumerator.hasMoreElements()) {
+ let elem = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
+ a.push([elem.key, elem.value]);
+ }
+ for (let key in strings)
+ b.push([ key, strings.get(key) ]);
+
+ // Sort the arrays, because we don't assume enumeration has a set order.
+ // Sort compares [key, val] as string "key,val", which sorts the way we want
+ // it to, so there is no need to provide a custom compare function.
+ a.sort();
+ b.sort();
+
+ test.assertEqual(a.length, b.length,
+ "the iterator returns the correct number of items");
+ for (let i = 0; i < a.length; i++) {
+ test.assertEqual(a[i][0], b[i][0], "the iterated string's name is correct");
+ test.assertEqual(a[i][1], b[i][1],
+ "the iterated string's value is correct");
+ }
+};