Bug 793239 - SettingsLock should have a state property to indicate if it is still valid; r=gwagner

This commit is contained in:
Reuben Morais 2013-01-15 22:32:49 -05:00
parent 9c5603816b
commit b7b5a5f102
4 changed files with 37 additions and 3 deletions

View File

@ -11,6 +11,9 @@ interface nsIVariant;
[scriptable, uuid(ef95ddd0-6308-11e1-b86c-0800200c9a66)]
interface nsIDOMSettingsLock : nsISupports
{
// Whether this lock is invalid
readonly attribute boolean closed;
// Contains a JSON object with name/value pairs to be set.
nsIDOMDOMRequest set(in nsIVariant settings);

View File

@ -24,7 +24,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
const nsIClassInfo = Ci.nsIClassInfo;
const SETTINGSLOCK_CONTRACTID = "@mozilla.org/settingsLock;1";
const SETTINGSLOCK_CID = Components.ID("{ef95ddd0-6308-11e1-b86c-0800200c9a66}");
const SETTINGSLOCK_CID = Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}");
const nsIDOMSettingsLock = Ci.nsIDOMSettingsLock;
function SettingsLock(aSettingsManager)
@ -38,6 +38,10 @@ function SettingsLock(aSettingsManager)
SettingsLock.prototype = {
get closed() {
return !this._open;
},
process: function process() {
let lock = this;
lock._open = false;

View File

@ -2,5 +2,5 @@ component {c40b1c70-00fb-11e2-a21f-0800200c9a66} SettingsManager.js
contract @mozilla.org/settingsManager;1 {c40b1c70-00fb-11e2-a21f-0800200c9a66}
category JavaScript-navigator-property mozSettings @mozilla.org/settingsManager;1
component {ef95ddd0-6308-11e1-b86c-0800200c9a66} SettingsManager.js
contract @mozilla.org/settingsLock;1 {ef95ddd0-6308-11e1-b86c-0800200c9a66}
component {60c9357c-3ae0-4222-8f55-da01428470d5} SettingsManager.js
contract @mozilla.org/settingsLock;1 {60c9357c-3ae0-4222-8f55-da01428470d5}

View File

@ -697,6 +697,33 @@ var steps = [
}
req.onerror = onFailure;
},
function() {
ok(true, "Test closed attribute on a valid lock");
var lock = mozSettings.createLock();
is(lock.closed, false, "closed attribute is false on creation");
req = lock.get("screen.brightness");
req.onsuccess = function () {
is(lock.closed, false, "closed attribute is false on success callback");
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Test closed attribute on invalid lock");
var lockx = mozSettings.createLock();
var cb = function() {
var reqx = null;
try {
reqx = lockx.set(wifiNetworks0);
ok(false, "should have thrown");
} catch (ex) {
is(lockx.closed, true, "closed attribute is true");
ok(true, "Caught Exception");
next();
}
}
SimpleTest.executeSoon(cb);
},
function() {
ok(true, "Clear DB");
var lock = mozSettings.createLock();