2012-03-26 21:49:38 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id={678695}
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug {678695} Settings API</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={678695}">Mozilla Bug {678695}</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
2012-06-12 18:13:11 +00:00
|
|
|
"use strict";
|
2012-03-26 21:49:38 +00:00
|
|
|
|
2013-05-14 01:32:09 +00:00
|
|
|
if (SpecialPowers.isMainProcess()) {
|
2014-08-28 04:01:30 +00:00
|
|
|
SpecialPowers.Cu.import("resource://gre/modules/SettingsRequestManager.jsm");
|
2013-03-26 23:49:12 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 04:01:29 +00:00
|
|
|
SpecialPowers.addPermission("settings-api-read", true, document);
|
|
|
|
SpecialPowers.addPermission("settings-api-write", true, document);
|
2012-11-01 00:26:05 +00:00
|
|
|
SpecialPowers.addPermission("settings-read", true, document);
|
|
|
|
SpecialPowers.addPermission("settings-write", true, document);
|
2014-08-28 04:01:30 +00:00
|
|
|
SpecialPowers.addPermission("settings-clear", true, document);
|
2012-03-26 21:49:38 +00:00
|
|
|
|
|
|
|
function onUnwantedSuccess() {
|
|
|
|
ok(false, "onUnwantedSuccess: shouldn't get here");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFailure() {
|
|
|
|
ok(false, "in on Failure!");
|
|
|
|
}
|
|
|
|
|
2013-01-05 00:04:28 +00:00
|
|
|
const wifi = {"net3g.apn": "internet.mnc012.mcc345.gprs"};
|
|
|
|
const wifi2 = {"net3g.apn": "internet.mnc012.mcc345.test"};
|
|
|
|
var wifi3 = {"net3g.apn2": "internet.mnc012.mcc345.test3"};
|
2012-03-26 21:49:38 +00:00
|
|
|
var wifiEnabled = {"wifi.enabled": true};
|
|
|
|
var wifiDisabled = {"wifi.enabled": false};
|
|
|
|
var screenBright = {"screen.brightness": 0.7};
|
2013-01-05 00:04:28 +00:00
|
|
|
var screenBright2 = {"screen.brightness": 0.1};
|
2012-03-26 21:49:38 +00:00
|
|
|
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"}};
|
|
|
|
|
2012-12-14 00:46:13 +00:00
|
|
|
var combination = {
|
|
|
|
"wifi.enabled": false,
|
|
|
|
"screen.brightness": 0.7,
|
|
|
|
"wifi.networks[0]": { ssid: "myfreenetwork", mac: "01:23:45:67:89:ab", passwd: "secret" },
|
2013-01-05 00:04:28 +00:00
|
|
|
"test.test": true,
|
|
|
|
"net3g.apn2": "internet.mnc012.mcc345.gprs"
|
2012-12-14 00:46:13 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 21:49:38 +00:00
|
|
|
function equals(o1, o2) {
|
|
|
|
var k1 = Object.keys(o1).sort();
|
|
|
|
var k2 = Object.keys(o2).sort();
|
|
|
|
if (k1.length != k2.length) return false;
|
|
|
|
return k1.zip(k2, function(keyPair) {
|
|
|
|
if(typeof o1[keyPair[0]] == typeof o2[keyPair[1]] == "object"){
|
|
|
|
return equals(o1[keyPair[0]], o2[keyPair[1]])
|
|
|
|
} else {
|
|
|
|
return o1[keyPair[0]] == o2[keyPair[1]];
|
|
|
|
}
|
|
|
|
}).all();
|
|
|
|
};
|
|
|
|
|
2012-06-07 21:23:55 +00:00
|
|
|
function observer1(setting) {
|
|
|
|
is(setting.settingName, "screen.brightness", "Same settingName");
|
|
|
|
is(setting.settingValue, "0.7", "Same settingvalue");
|
|
|
|
};
|
|
|
|
|
|
|
|
function observer2(setting) {
|
|
|
|
is(setting.settingName, "screen.brightness", "Same settingName");
|
|
|
|
is(setting.settingValue, "0.7", "Same settingvalue");
|
|
|
|
};
|
|
|
|
|
|
|
|
function observerWithNext(setting) {
|
|
|
|
is(setting.settingName, "screen.brightness", "Same settingName");
|
|
|
|
is(setting.settingValue, "0.7", "Same settingvalue");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
|
|
|
function onsettingschangeWithNext(event) {
|
|
|
|
is(event.settingName, "screen.brightness", "Same settingName");
|
|
|
|
is(event.settingValue, "0.7", "Same settingvalue");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
2012-03-26 21:49:38 +00:00
|
|
|
function check(o1, o2) {
|
|
|
|
is(JSON.stringify(o1), JSON.stringify(o2), "same");
|
|
|
|
}
|
|
|
|
|
|
|
|
var req, req2, req3, req4, req5, req6;
|
|
|
|
var index = 0;
|
|
|
|
|
2013-05-14 01:32:09 +00:00
|
|
|
var mozSettings = navigator.mozSettings;
|
2012-03-26 21:49:38 +00:00
|
|
|
|
|
|
|
var steps = [
|
|
|
|
function () {
|
|
|
|
ok(true, "Deleting database");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
2013-01-05 00:04:28 +00:00
|
|
|
next();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Setting wifi");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.set(wifi);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
var lock2 = mozSettings.createLock();
|
|
|
|
req2 = lock2.get("net3g.apn");
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
is(Object.keys(req2.result).length, 1, "length 1");
|
|
|
|
check(wifi, req2.result);
|
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Change wifi1");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.set(wifi2);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
2012-03-26 21:49:38 +00:00
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
2013-01-05 00:04:28 +00:00
|
|
|
ok(true, "Get changed net3g.apn");
|
|
|
|
req2 = lock.get("net3g.apn");
|
2012-03-26 21:49:38 +00:00
|
|
|
req2.onsuccess = function () {
|
2013-01-05 00:04:28 +00:00
|
|
|
is(Object.keys(req2.result).length, 1, "length 1");
|
|
|
|
check(wifi2, req2.result);
|
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Set Combination");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req3 = lock.set(combination);
|
|
|
|
req3.onsuccess = function () {
|
2012-03-26 21:49:38 +00:00
|
|
|
ok(true, "set done");
|
2013-01-05 00:04:28 +00:00
|
|
|
req4 = lock.get("net3g.apn2");
|
|
|
|
req4.onsuccess = function() {
|
|
|
|
ok(true, "Done");
|
|
|
|
check(combination["net3g.apn2"], req4.result["net3g.apn2"]);
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req3.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req4 = lock.get("net3g.apn2");
|
|
|
|
req4.onsuccess = function() {
|
|
|
|
ok(true, "Done");
|
|
|
|
check(combination["net3g.apn2"], req4.result["net3g.apn2"]);
|
2012-03-26 21:49:38 +00:00
|
|
|
next();
|
|
|
|
}
|
2013-01-05 00:04:28 +00:00
|
|
|
req4.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
},
|
2012-06-20 19:56:23 +00:00
|
|
|
function() {
|
|
|
|
ok(true, "Get unknown key");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-20 19:56:23 +00:00
|
|
|
req = lock.get("abc.def");
|
|
|
|
req.onsuccess = function() {
|
|
|
|
is(req.result["abc.def"], undefined, "no result");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2012-03-26 21:49:38 +00:00
|
|
|
function() {
|
2012-06-07 21:23:55 +00:00
|
|
|
ok(true, "adding onsettingchange");
|
|
|
|
navigator.mozSettings.onsettingchange = onsettingschangeWithNext;
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req2 = lock.get("screen.brightness");
|
|
|
|
req2.onsuccess = function() {
|
|
|
|
ok(true, "end adding onsettingchange");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "Test onsettingchange");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done, observer has to call next");
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "delete onsettingschange");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
navigator.mozSettings.onsettingchange = null;
|
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Waiting for all set callbacks");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req = lock.get("screen.brightness");
|
|
|
|
req.onsuccess = function() {
|
|
|
|
ok(true, "Done");
|
|
|
|
next();
|
2012-03-26 21:49:38 +00:00
|
|
|
}
|
2012-06-07 21:23:55 +00:00
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "adding Observers 1");
|
|
|
|
navigator.mozSettings.addObserver("screen.brightness", observer1);
|
|
|
|
navigator.mozSettings.addObserver("screen.brightness", observer1);
|
|
|
|
navigator.mozSettings.addObserver("screen.brightness", observer2);
|
|
|
|
navigator.mozSettings.addObserver("screen.brightness", observerWithNext);
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req2 = lock.get("screen.brightness");
|
|
|
|
req2.onsuccess = function() {
|
2012-06-07 21:23:55 +00:00
|
|
|
ok(true, "set observeSetting done!");
|
2012-03-26 21:49:38 +00:00
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
2012-06-07 21:23:55 +00:00
|
|
|
ok(true, "test observers");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "removing Event Listener");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
navigator.mozSettings.removeObserver("screen.brightness", observer2);
|
|
|
|
navigator.mozSettings.removeObserver("screen.brightness", observer1);
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "test Event Listener");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
2012-06-07 21:23:55 +00:00
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "removing Event Listener");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
navigator.mozSettings.removeObserver("screen.brightness", observerWithNext);
|
|
|
|
req = lock.set(screenBright);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
navigator.mozSettings.removeObserver("screen.brightness", observer2);
|
|
|
|
navigator.mozSettings.removeObserver("screen.brightness", observer1);
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "removing Event Listener");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-06-07 21:23:55 +00:00
|
|
|
req = lock.get("screen.brightness");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "get done");
|
2012-03-26 21:49:38 +00:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Nested test");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("screen.brightness");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
req3 = lock.set({"screen.brightness": req.result["screen.brightness"] + 1})
|
|
|
|
req3.onsuccess = function () {
|
|
|
|
req4 = lock.get("screen.brightness");
|
|
|
|
req4.onsuccess = function() {
|
|
|
|
is(req4.result["screen.brightness"], 1.7, "same Value");
|
|
|
|
}
|
|
|
|
req4.onerror = onFailure;
|
|
|
|
}
|
|
|
|
req3.onerror = onFailure;
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
req2 = lock.get("screen.brightness");
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
is(req2.result["screen.brightness"], 0.7, "same Value");
|
|
|
|
}
|
|
|
|
req2.onerror = onFailure;
|
2013-03-12 05:31:19 +00:00
|
|
|
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req5 = lock2.get("screen.brightness");
|
|
|
|
req5.onsuccess = function () {
|
|
|
|
is(req5.result["screen.brightness"], 1.7, "same Value");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
req5.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Deleting database");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
2014-08-28 04:01:30 +00:00
|
|
|
next();
|
2012-03-26 21:49:38 +00:00
|
|
|
};
|
2014-08-28 04:01:30 +00:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req2 = lock.set(wifi);
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
}
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
|
|
|
|
ok(true, "Get all settings");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
2014-08-28 04:01:30 +00:00
|
|
|
req3 = lock2.get("*");
|
|
|
|
req3.onsuccess = function () {
|
|
|
|
is(Object.keys(req3.result).length, 1, "length 1");
|
|
|
|
check(req3.result, wifi);
|
|
|
|
ok(true, JSON.stringify(req3.result));
|
2012-03-26 21:49:38 +00:00
|
|
|
ok(true, "Get all settings Done");
|
|
|
|
};
|
2014-08-28 04:01:30 +00:00
|
|
|
req3.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
|
2014-08-28 04:01:30 +00:00
|
|
|
req4 = lock2.get("net3g.apn");
|
|
|
|
req4.onsuccess = function () {
|
|
|
|
is(Object.keys(req4.result).length, 1, "length 1");
|
|
|
|
check(wifi, req4.result);
|
2012-03-26 21:49:38 +00:00
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
2014-08-28 04:01:30 +00:00
|
|
|
req4.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
},
|
|
|
|
function () {
|
2013-01-05 00:04:28 +00:00
|
|
|
ok(true, "Change wifi1");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifi2);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
ok(true, "Get changed net3g.apn");
|
|
|
|
req2 = lock.get("net3g.apn");
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
is(Object.keys(req2.result).length, 1, "length 1");
|
|
|
|
check(wifi2, req2.result);
|
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Test locking");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
var lock2 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifiEnabled);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Test Locking Done");
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
req2 = lock2.set(wifiDisabled);
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Test locking result");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("wifi.enabled");
|
|
|
|
req.onsuccess = function() {
|
|
|
|
check(req.result, wifiDisabled);
|
|
|
|
ok(true, "Test1 locking result done");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Test locking heavy");
|
|
|
|
for (var i=0; i<30; i++) {
|
|
|
|
// only new locks!
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
var obj = {};
|
|
|
|
obj["wifi.enabled" + i] = true;
|
|
|
|
req = lock.set( obj );
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set1 Done");
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
};
|
|
|
|
{
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
2013-01-05 00:04:28 +00:00
|
|
|
req2 = lock2.get("*");
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
is(Object.keys(req2.result).length, 32, "length 12");
|
|
|
|
ok(true, JSON.stringify(req2.result));
|
2012-03-26 21:49:38 +00:00
|
|
|
ok(true, "Get all settings Done");
|
|
|
|
};
|
2013-01-05 00:04:28 +00:00
|
|
|
req2.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
}
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
var obj = {};
|
|
|
|
obj["wifi.enabled" + 30] = true;
|
2013-01-05 00:04:28 +00:00
|
|
|
req3 = lock2.set( obj );
|
|
|
|
req3.onsuccess = function () {
|
2012-03-26 21:49:38 +00:00
|
|
|
ok(true, "Set12 Done");
|
|
|
|
};
|
2013-01-05 00:04:28 +00:00
|
|
|
req3.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock3 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
// with one lock
|
|
|
|
for (var i = 0; i < 30; i++) {
|
2013-01-05 00:04:28 +00:00
|
|
|
req4 = lock3.get("wifi.enabled" + i);
|
2012-03-26 21:49:38 +00:00
|
|
|
var testObj = {};
|
|
|
|
testObj["wifi.enabled" + i] = true;
|
2013-01-05 00:04:28 +00:00
|
|
|
req4.onsuccess = function () {
|
2012-03-26 21:49:38 +00:00
|
|
|
check(this.request.result, this.testObj);
|
|
|
|
ok(true, "Get1 Done");
|
2013-01-05 00:04:28 +00:00
|
|
|
}.bind({testObj: testObj, request: req4});
|
|
|
|
req4.onerror = onFailure;
|
2012-03-26 21:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ok(true, "start next2!");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock4 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
for (var i=0; i<30; i++) {
|
|
|
|
var obj = {};
|
|
|
|
obj["wifi.enabled" + i] = false;
|
|
|
|
req4 = lock4.set( obj );
|
|
|
|
req4.onsuccess = function () {
|
|
|
|
ok(true, "Set2 Done");
|
|
|
|
};
|
|
|
|
req4.onerror = onFailure;
|
|
|
|
}
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock5 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
for (var i=0; i<30; i++) {
|
|
|
|
req5 = lock5.get("wifi.enabled" + i);
|
|
|
|
var testObj = {};
|
|
|
|
testObj["wifi.enabled" + i] = false;
|
|
|
|
req5.onsuccess = function () {
|
|
|
|
check(this.request.result, this.testObj);
|
|
|
|
ok(true, "Get2 Done");
|
|
|
|
}.bind({testObj: testObj, request: req5});
|
|
|
|
req5.onerror = onFailure;
|
|
|
|
}
|
2013-03-12 05:31:19 +00:00
|
|
|
|
2014-08-28 04:01:30 +00:00
|
|
|
var lock6 = mozSettings.createLock();
|
|
|
|
req6 = lock6.clear();
|
2012-03-26 21:49:38 +00:00
|
|
|
req6.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req6.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "reverse Test locking");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
|
|
|
|
req = lock.set(wifiEnabled);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Test Locking Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
req2 = lock2.set(wifiDisabled);
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Test locking result");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2013-03-12 05:31:19 +00:00
|
|
|
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("wifi.enabled");
|
|
|
|
req.onsuccess = function() {
|
|
|
|
check(req.result, wifiEnabled);
|
|
|
|
ok(true, "Test2 locking result done");
|
|
|
|
}
|
|
|
|
req.onerror = onFailure;
|
2013-03-12 05:31:19 +00:00
|
|
|
|
2014-08-28 04:01:30 +00:00
|
|
|
var lock2 = mozSettings.createLock();
|
|
|
|
req2 = lock2.clear();
|
2012-03-26 21:49:38 +00:00
|
|
|
req2.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
|
2014-08-28 04:01:30 +00:00
|
|
|
var lock3 = mozSettings.createLock();
|
|
|
|
req3 = lock3.set(wifi);
|
2012-03-26 21:49:38 +00:00
|
|
|
req3.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
req3.onerror = onFailure;
|
2013-03-12 05:31:19 +00:00
|
|
|
|
2012-03-26 21:49:38 +00:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get all settings");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("*");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 1, "length 1");
|
|
|
|
check(wifi, req.result);
|
|
|
|
ok(true, "Get all settings Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get net3g.apn");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("net3g.apn");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 1, "length 1");
|
|
|
|
check(wifi, req.result);
|
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
2013-01-05 00:04:28 +00:00
|
|
|
ok(true, "Change wifi2");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifi2);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get net3g.apn");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("net3g.apn");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 1, "length 1");
|
|
|
|
check(wifi2, req.result);
|
|
|
|
ok(true, "Get net3g.apn Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Add wifi.enabled");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifiEnabled);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get Wifi Enabled");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("wifi.enabled");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 1, "length 1");
|
|
|
|
check(wifiEnabled, req.result);
|
|
|
|
ok(true, "Get wifi.enabledDone");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get all");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("*");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 2, "length 2");
|
|
|
|
check(wifiEnabled["wifi.enabled"], req.result["wifi.enabled"]);
|
|
|
|
check(wifi2["net3g.apn"], req.result["net3g.apn"]);
|
|
|
|
ok(true, "Get all Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Add wifiNetworks");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifiNetworks0);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
|
|
|
|
req2 = lock.set(wifiNetworks1);
|
|
|
|
req2.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req2.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Get Wifi Networks");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.get("wifi.networks[0]");
|
|
|
|
req.onsuccess = function () {
|
|
|
|
is(Object.keys(req.result).length, 1, "length 1");
|
|
|
|
check(wifiNetworks0, req.result);
|
|
|
|
ok(true, "Get wifi.networks[0]");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "Clear DB, multiple locks");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock4 = mozSettings.createLock();
|
|
|
|
var lock3 = mozSettings.createLock();
|
|
|
|
var lock2 = mozSettings.createLock();
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
var lock6 = mozSettings.createLock();
|
|
|
|
var lock7 = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
ok(true, "Add wifiNetworks");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.set(wifiNetworks0);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Set Done");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2012-05-23 01:18:56 +00:00
|
|
|
function () {
|
|
|
|
ok(true, "Test set after lock closed");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lockx = mozSettings.createLock();
|
2012-05-23 01:18:56 +00:00
|
|
|
var cb = function() {
|
|
|
|
var reqx = null;
|
|
|
|
try {
|
|
|
|
reqx = lockx.set(wifiNetworks0);
|
|
|
|
ok(false, "should have thrown");
|
|
|
|
} catch (ex) {
|
|
|
|
ok(reqx == null, "request is still null");
|
|
|
|
ok(true, "Caught Exception");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SimpleTest.executeSoon(cb);
|
|
|
|
},
|
2012-03-26 21:49:38 +00:00
|
|
|
function() {
|
|
|
|
ok(true, "Clear DB");
|
2012-09-06 00:33:03 +00:00
|
|
|
var lock = mozSettings.createLock();
|
2012-03-26 21:49:38 +00:00
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2012-12-14 00:46:13 +00:00
|
|
|
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;
|
|
|
|
},
|
2013-01-16 03:32:49 +00:00
|
|
|
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);
|
|
|
|
},
|
2012-12-14 00:46:13 +00:00
|
|
|
function() {
|
|
|
|
ok(true, "Clear DB");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2013-03-12 05:31:19 +00:00
|
|
|
function() {
|
|
|
|
ok(true, "Set object value");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.set({"setting-obj": {foo: {bar: 23}}});
|
|
|
|
req.onsuccess = function() {
|
|
|
|
req2 = lock.get("setting-obj");
|
|
|
|
req2.onsuccess = function(event) {
|
|
|
|
var result = event.target.result["setting-obj"];
|
|
|
|
ok(result, "Got valid result");
|
|
|
|
ok(typeof result == "object", "Result is object");
|
|
|
|
ok("foo" in result && "bar" in result.foo, "Result has properties");
|
|
|
|
ok(result.foo.bar == 23, "Result properties are set");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "Clear DB");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2014-08-28 04:01:30 +00:00
|
|
|
function () {
|
|
|
|
ok(true, "Call success callback when transaction commits");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
lock.onsettingstransactionsuccess = function () {
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req = lock.set({"setting-obj": {foo: {bar: 23}}});
|
|
|
|
req.onsuccess = function() {
|
|
|
|
req2 = lock.get("setting-obj");
|
|
|
|
req2.onsuccess = function(event) {
|
|
|
|
var result = event.target.result["setting-obj"];
|
|
|
|
ok(result, "Got valid result");
|
|
|
|
ok(typeof result == "object", "Result is object");
|
|
|
|
ok("foo" in result && "bar" in result.foo, "Result has properties");
|
|
|
|
ok(result.foo.bar == 23, "Result properties are set");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
ok(true, "Clear DB");
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
req = lock.clear();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "Deleted the database");
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
req.onerror = onFailure;
|
|
|
|
},
|
2012-03-26 21:49:38 +00:00
|
|
|
function () {
|
|
|
|
ok(true, "all done!\n");
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
ok(true, "Begin!");
|
|
|
|
if (index >= steps.length) {
|
|
|
|
ok(false, "Shouldn't get here!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
steps[index]();
|
|
|
|
} catch(ex) {
|
|
|
|
ok(false, "Caught exception", ex);
|
|
|
|
}
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-05-14 01:32:09 +00:00
|
|
|
addLoadEvent(next);
|
2012-03-26 21:49:38 +00:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|