Bug 766379 - Settings API: Add warning if we get or set a non-existing setting. r=fabrice
authorGregor Wagner <anygregor@gmail.com>
Wed, 20 Jun 2012 12:56:23 -0700
changeset 97170 8e3fa5b800c589615c0f6b753ac6258e369e849a
parent 97169 d9e9f7ebe2a15c1b117f9a84e7cd4419b2367682
child 97171 0fd12ab9899a16ab71900777a21c920d6f3c7e57
push id10914
push usergwagner@mozilla.com
push dateWed, 20 Jun 2012 19:57:08 +0000
treeherdermozilla-inbound@8e3fa5b800c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs766379
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 766379 - Settings API: Add warning if we get or set a non-existing setting. r=fabrice
dom/settings/SettingsManager.js
dom/settings/tests/test_settings_basics.html
--- a/dom/settings/SettingsManager.js
+++ b/dom/settings/SettingsManager.js
@@ -52,43 +52,56 @@ SettingsLock.prototype = {
                                        Services.DOMRequest.fireSuccess(request, 0);
                                        this._open = false; }.bind(lock);
           req.onerror = function() { Services.DOMRequest.fireError(request, 0) };
           break;
         case "set":
           for (let key in info.settings) {
             debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
 
+            let checkKeyRequest = store.get(key);
+            checkKeyRequest.onsuccess = function (event) {
+              if (!event.target.result) {
+                dump("MOZSETTINGS-SET-WARNING: " + key + " is not in the database. Please add it to build/settings.js\n");
+              }
+            }
+
             if(typeof(info.settings[key]) != 'object') {
               req = store.put({settingName: key, settingValue: info.settings[key]});
             } else {
               //Workaround for cloning issues
               let obj = JSON.parse(JSON.stringify(info.settings[key]));
               req = store.put({settingName: key, settingValue: obj});
             }
 
             req.onsuccess = function() { 
               lock._open = true;
               Services.DOMRequest.fireSuccess(request, 0);
               cpmm.sendAsyncMessage("Settings:Changed", { key: key, value: info.settings[key] });
               lock._open = false;
             };
 
-            req.onerror = function() { Services.DOMRequest.fireError(request, 0) };
+            req.onerror = function() {
+              Services.DOMRequest.fireError(request, 0)
+            };
           }
           break;
         case "get":
           req = (info.name === "*") ? store.getAll()
                                     : store.getAll(info.name);
 
           req.onsuccess = function(event) {
             debug("Request for '" + info.name + "' successful. " + 
                   "Record count: " + event.target.result.length);
             debug("result: " + JSON.stringify(event.target.result));
 
+            if (event.target.result.length == 0) {
+              dump("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database. Please add it to build/settings.js\n");
+            }
+
             let results = {
               __exposedProps__: {
               }
             };
 
             for (var i in event.target.result) {
               let result = event.target.result[i];
               results[result.settingName] = result.settingValue;
--- a/dom/settings/tests/test_settings_basics.html
+++ b/dom/settings/tests/test_settings_basics.html
@@ -96,16 +96,26 @@ var steps = [
     req2 = lock.set(screenBright);
     req2.onsuccess = function () {
       ok(true, "set done");
       next();
     }
     req2.onerror = onFailure;
   },
   function() {
+    ok(true, "Get unknown key");
+    var lock = mozSettings.getLock();
+    req = lock.get("abc.def");
+    req.onsuccess = function() {
+      is(req.result["abc.def"], undefined, "no result");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function() {
     ok(true, "adding onsettingchange");
     navigator.mozSettings.onsettingchange = onsettingschangeWithNext;
     var lock = mozSettings.getLock();
     req2 = lock.get("screen.brightness");
     req2.onsuccess = function() {
       ok(true, "end adding onsettingchange");
       next();
     };