From 53230f5ec7d525932f3dac7556ea08757da2ff76 Mon Sep 17 00:00:00 2001 From: Gregor Wagner Date: Thu, 13 Dec 2012 16:46:13 -0800 Subject: [PATCH] Bug 821484 - ASSERTION: mDone shouldn't have been set to true already!: '!mDone', file dom/base/DOMRequest.cpp, line 113. r=sicking --- dom/settings/SettingsManager.js | 19 ++++++---- dom/settings/tests/test_settings_basics.html | 37 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/dom/settings/SettingsManager.js b/dom/settings/SettingsManager.js index 4f2c0ebeb736..6fea374e179c 100644 --- a/dom/settings/SettingsManager.js +++ b/dom/settings/SettingsManager.js @@ -54,7 +54,10 @@ SettingsLock.prototype = { req.onerror = function() { Services.DOMRequest.fireError(request, 0) }; break; case "set": - for (let key in info.settings) { + let keys = Object.getOwnPropertyNames(info.settings); + for (let i = 0; i < keys.length; i++) { + let key = keys[i]; + let last = i === keys.length - 1; debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key])); let checkKeyRequest = store.get(key); @@ -72,15 +75,19 @@ SettingsLock.prototype = { req = store.put({settingName: key, settingValue: obj}); } - req.onsuccess = function() { - lock._open = true; - Services.DOMRequest.fireSuccess(request, 0); + req.onsuccess = function() { + if (last && !request.error) { + lock._open = true; + Services.DOMRequest.fireSuccess(request, 0); + lock._open = false; + } cpmm.sendAsyncMessage("Settings:Changed", { key: key, value: info.settings[key] }); - lock._open = false; }; req.onerror = function() { - Services.DOMRequest.fireError(request, 0) + if (!request.error) { + Services.DOMRequest.fireError(request, req.error.name) + } }; } break; diff --git a/dom/settings/tests/test_settings_basics.html b/dom/settings/tests/test_settings_basics.html index 032908bb0e76..a879fb064f67 100644 --- a/dom/settings/tests/test_settings_basics.html +++ b/dom/settings/tests/test_settings_basics.html @@ -43,6 +43,13 @@ var screenBright = {"screen.brightness": 0.7}; var wifiNetworks0 = { "wifi.networks[0]": { ssid: "myfreenetwork", mac: "01:23:45:67:89:ab", passwd: "secret"}}; var wifiNetworks1 = { "wifi.networks[1]": { ssid: "myfreenetwork2", mac: "01:23:45:67:89:ab", passwd: "secret2"}}; +var combination = { + "wifi.enabled": false, + "screen.brightness": 0.7, + "wifi.networks[0]": { ssid: "myfreenetwork", mac: "01:23:45:67:89:ab", passwd: "secret" }, + "test.test": true +} + function equals(o1, o2) { var k1 = Object.keys(o1).sort(); var k2 = Object.keys(o2).sort(); @@ -611,6 +618,36 @@ var steps = [ }; req.onerror = onFailure; }, + function() { + ok(true, "Set with multiple arguments"); + var lock = mozSettings.createLock(); + req = lock.set(combination); + req.onsuccess = function () { + ok(true, "Set Done"); + next(); + }; + req.onerror = onFailure; + }, + function() { + ok(true, "request argument from multiple set"); + var lock = mozSettings.createLock(); + req = lock.get("screen.brightness"); + req.onsuccess = function () { + check(req.result["screen.brightness"], 0.7, "get done"); + next(); + } + req.onerror = onFailure; + }, + function() { + ok(true, "Clear DB"); + var lock = mozSettings.createLock(); + req = lock.clear(); + req.onsuccess = function () { + ok(true, "Deleted the database"); + next(); + }; + req.onerror = onFailure; + }, function () { ok(true, "all done!\n"); SimpleTest.finish();