summaryrefslogtreecommitdiffstats
path: root/modules/libpref/test/unit/test_warnings.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /modules/libpref/test/unit/test_warnings.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'modules/libpref/test/unit/test_warnings.js')
-rw-r--r--modules/libpref/test/unit/test_warnings.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/modules/libpref/test/unit/test_warnings.js b/modules/libpref/test/unit/test_warnings.js
new file mode 100644
index 000000000..856e117b7
--- /dev/null
+++ b/modules/libpref/test/unit/test_warnings.js
@@ -0,0 +1,69 @@
+/* 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/. */
+
+Cu.import("resource://gre/modules/Promise.jsm");
+
+var cs = Cc["@mozilla.org/consoleservice;1"].
+ getService(Ci.nsIConsoleService);
+var ps = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService);
+
+function makeBuffer(length) {
+ return new Array(length + 1).join('x');
+}
+
+/**
+ * @resolves |true| if execution proceeded without warning,
+ * |false| if there was a warning.
+ */
+function checkWarning(pref, buffer) {
+ let deferred = Promise.defer();
+ let complete = false;
+ let listener = {
+ observe: function(event) {
+ let message = event.message;
+ if (!(message.startsWith("Warning: attempting to write")
+ && message.includes(pref))) {
+ return;
+ }
+ if (complete) {
+ return;
+ }
+ complete = true;
+ do_print("Warning while setting " + pref);
+ cs.unregisterListener(listener);
+ deferred.resolve(true);
+ }
+ };
+ do_timeout(1000, function() {
+ if (complete) {
+ return;
+ }
+ complete = true;
+ do_print("No warning while setting " + pref);
+ cs.unregisterListener(listener);
+ deferred.resolve(false);
+ });
+ cs.registerListener(listener);
+ ps.setCharPref(pref, buffer);
+ return deferred.promise;
+}
+
+function run_test() {
+ run_next_test();
+}
+
+add_task(function() {
+ // Simple change, shouldn't cause a warning
+ do_print("Checking that a simple change doesn't cause a warning");
+ let buf = makeBuffer(100);
+ let warned = yield checkWarning("string.accept", buf);
+ do_check_false(warned);
+
+ // Large change, should cause a warning
+ do_print("Checking that a large change causes a warning");
+ buf = makeBuffer(32 * 1024);
+ warned = yield checkWarning("string.warn", buf);
+ do_check_true(warned);
+});