1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/settings/tests/test_settings_basics.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,789 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id={678695} 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug {678695} Settings API</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={678695}">Mozilla Bug {678695}</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +"use strict"; 1.26 + 1.27 +if (SpecialPowers.isMainProcess()) { 1.28 + SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm"); 1.29 +} 1.30 + 1.31 +SpecialPowers.addPermission("settings-read", true, document); 1.32 +SpecialPowers.addPermission("settings-write", true, document); 1.33 + 1.34 +function onUnwantedSuccess() { 1.35 + ok(false, "onUnwantedSuccess: shouldn't get here"); 1.36 +} 1.37 + 1.38 +function onFailure() { 1.39 + ok(false, "in on Failure!"); 1.40 +} 1.41 + 1.42 +const wifi = {"net3g.apn": "internet.mnc012.mcc345.gprs"}; 1.43 +const wifi2 = {"net3g.apn": "internet.mnc012.mcc345.test"}; 1.44 +var wifi3 = {"net3g.apn2": "internet.mnc012.mcc345.test3"}; 1.45 +var wifiEnabled = {"wifi.enabled": true}; 1.46 +var wifiDisabled = {"wifi.enabled": false}; 1.47 +var screenBright = {"screen.brightness": 0.7}; 1.48 +var screenBright2 = {"screen.brightness": 0.1}; 1.49 +var wifiNetworks0 = { "wifi.networks[0]": { ssid: "myfreenetwork", mac: "01:23:45:67:89:ab", passwd: "secret"}}; 1.50 +var wifiNetworks1 = { "wifi.networks[1]": { ssid: "myfreenetwork2", mac: "01:23:45:67:89:ab", passwd: "secret2"}}; 1.51 + 1.52 +var combination = { 1.53 + "wifi.enabled": false, 1.54 + "screen.brightness": 0.7, 1.55 + "wifi.networks[0]": { ssid: "myfreenetwork", mac: "01:23:45:67:89:ab", passwd: "secret" }, 1.56 + "test.test": true, 1.57 + "net3g.apn2": "internet.mnc012.mcc345.gprs" 1.58 +} 1.59 + 1.60 +function equals(o1, o2) { 1.61 + var k1 = Object.keys(o1).sort(); 1.62 + var k2 = Object.keys(o2).sort(); 1.63 + if (k1.length != k2.length) return false; 1.64 + return k1.zip(k2, function(keyPair) { 1.65 + if(typeof o1[keyPair[0]] == typeof o2[keyPair[1]] == "object"){ 1.66 + return equals(o1[keyPair[0]], o2[keyPair[1]]) 1.67 + } else { 1.68 + return o1[keyPair[0]] == o2[keyPair[1]]; 1.69 + } 1.70 + }).all(); 1.71 +}; 1.72 + 1.73 +function observer1(setting) { 1.74 + is(setting.settingName, "screen.brightness", "Same settingName"); 1.75 + is(setting.settingValue, "0.7", "Same settingvalue"); 1.76 +}; 1.77 + 1.78 +function observer2(setting) { 1.79 + is(setting.settingName, "screen.brightness", "Same settingName"); 1.80 + is(setting.settingValue, "0.7", "Same settingvalue"); 1.81 +}; 1.82 + 1.83 +function observerWithNext(setting) { 1.84 + is(setting.settingName, "screen.brightness", "Same settingName"); 1.85 + is(setting.settingValue, "0.7", "Same settingvalue"); 1.86 + next(); 1.87 +}; 1.88 + 1.89 +function onsettingschangeWithNext(event) { 1.90 + is(event.settingName, "screen.brightness", "Same settingName"); 1.91 + is(event.settingValue, "0.7", "Same settingvalue"); 1.92 + next(); 1.93 +}; 1.94 + 1.95 +function check(o1, o2) { 1.96 + is(JSON.stringify(o1), JSON.stringify(o2), "same"); 1.97 +} 1.98 + 1.99 +var req, req2, req3, req4, req5, req6; 1.100 +var index = 0; 1.101 + 1.102 +var mozSettings = navigator.mozSettings; 1.103 + 1.104 +var steps = [ 1.105 + function () { 1.106 + ok(true, "Deleting database"); 1.107 + var lock = mozSettings.createLock(); 1.108 + req = lock.clear(); 1.109 + req.onsuccess = function () { 1.110 + ok(true, "Deleted the database"); 1.111 + next(); 1.112 + }; 1.113 + }, 1.114 + function () { 1.115 + ok(true, "Setting wifi"); 1.116 + var lock = mozSettings.createLock(); 1.117 + req = lock.set(wifi); 1.118 + req.onsuccess = function () { 1.119 + ok(true, "set done"); 1.120 + } 1.121 + req.onerror = onFailure; 1.122 + 1.123 + var lock2 = mozSettings.createLock(); 1.124 + req2 = lock2.get("net3g.apn"); 1.125 + req2.onsuccess = function () { 1.126 + is(Object.keys(req2.result).length, 1, "length 1"); 1.127 + check(wifi, req2.result); 1.128 + ok(true, "Get net3g.apn Done"); 1.129 + next(); 1.130 + }; 1.131 + req2.onerror = onFailure; 1.132 + }, 1.133 + function () { 1.134 + ok(true, "Change wifi1"); 1.135 + var lock = mozSettings.createLock(); 1.136 + req = lock.set(wifi2); 1.137 + req.onsuccess = function () { 1.138 + ok(true, "Set Done"); 1.139 + }; 1.140 + req.onerror = onFailure; 1.141 + ok(true, "Get changed net3g.apn"); 1.142 + req2 = lock.get("net3g.apn"); 1.143 + req2.onsuccess = function () { 1.144 + is(Object.keys(req2.result).length, 1, "length 1"); 1.145 + check(wifi2, req2.result); 1.146 + ok(true, "Get net3g.apn Done"); 1.147 + next(); 1.148 + }; 1.149 + req2.onerror = onFailure; 1.150 + }, 1.151 + function () { 1.152 + ok(true, "Set Combination"); 1.153 + var lock = mozSettings.createLock(); 1.154 + req3 = lock.set(combination); 1.155 + req3.onsuccess = function () { 1.156 + ok(true, "set done"); 1.157 + req4 = lock.get("net3g.apn2"); 1.158 + req4.onsuccess = function() { 1.159 + ok(true, "Done"); 1.160 + check(combination["net3g.apn2"], req4.result["net3g.apn2"]); 1.161 + next(); 1.162 + } 1.163 + } 1.164 + req3.onerror = onFailure; 1.165 + }, 1.166 + function() { 1.167 + var lock = mozSettings.createLock(); 1.168 + req4 = lock.get("net3g.apn2"); 1.169 + req4.onsuccess = function() { 1.170 + ok(true, "Done"); 1.171 + check(combination["net3g.apn2"], req4.result["net3g.apn2"]); 1.172 + next(); 1.173 + } 1.174 + req4.onerror = onFailure; 1.175 + }, 1.176 + function() { 1.177 + ok(true, "Get unknown key"); 1.178 + var lock = mozSettings.createLock(); 1.179 + req = lock.get("abc.def"); 1.180 + req.onsuccess = function() { 1.181 + is(req.result["abc.def"], undefined, "no result"); 1.182 + next(); 1.183 + }; 1.184 + req.onerror = onFailure; 1.185 + }, 1.186 + function() { 1.187 + ok(true, "adding onsettingchange"); 1.188 + navigator.mozSettings.onsettingchange = onsettingschangeWithNext; 1.189 + var lock = mozSettings.createLock(); 1.190 + req2 = lock.get("screen.brightness"); 1.191 + req2.onsuccess = function() { 1.192 + ok(true, "end adding onsettingchange"); 1.193 + next(); 1.194 + }; 1.195 + req2.onerror = onFailure; 1.196 + }, 1.197 + function() { 1.198 + ok(true, "Test onsettingchange"); 1.199 + var lock = mozSettings.createLock(); 1.200 + req = lock.set(screenBright); 1.201 + req.onsuccess = function () { 1.202 + ok(true, "set done, observer has to call next"); 1.203 + } 1.204 + req.onerror = onFailure; 1.205 + }, 1.206 + function() { 1.207 + ok(true, "delete onsettingschange"); 1.208 + var lock = mozSettings.createLock(); 1.209 + navigator.mozSettings.onsettingchange = null; 1.210 + req = lock.set(screenBright); 1.211 + req.onsuccess = function () { 1.212 + ok(true, "set done"); 1.213 + next(); 1.214 + } 1.215 + req.onerror = onFailure; 1.216 + }, 1.217 + function () { 1.218 + ok(true, "Waiting for all set callbacks"); 1.219 + var lock = mozSettings.createLock(); 1.220 + req = lock.get("screen.brightness"); 1.221 + req.onsuccess = function() { 1.222 + ok(true, "Done"); 1.223 + next(); 1.224 + } 1.225 + req.onerror = onFailure; 1.226 + }, 1.227 + function() { 1.228 + ok(true, "adding Observers 1"); 1.229 + navigator.mozSettings.addObserver("screen.brightness", observer1); 1.230 + navigator.mozSettings.addObserver("screen.brightness", observer1); 1.231 + navigator.mozSettings.addObserver("screen.brightness", observer2); 1.232 + navigator.mozSettings.addObserver("screen.brightness", observerWithNext); 1.233 + var lock = mozSettings.createLock(); 1.234 + req2 = lock.get("screen.brightness"); 1.235 + req2.onsuccess = function() { 1.236 + ok(true, "set observeSetting done!"); 1.237 + next(); 1.238 + }; 1.239 + req2.onerror = onFailure; 1.240 + }, 1.241 + function() { 1.242 + ok(true, "test observers"); 1.243 + var lock = mozSettings.createLock(); 1.244 + req = lock.set(screenBright); 1.245 + req.onsuccess = function () { 1.246 + ok(true, "set done"); 1.247 + } 1.248 + req.onerror = onFailure; 1.249 + }, 1.250 + function() { 1.251 + ok(true, "removing Event Listener"); 1.252 + var lock = mozSettings.createLock(); 1.253 + req = lock.set(screenBright); 1.254 + req.onsuccess = function () { 1.255 + ok(true, "set done"); 1.256 + navigator.mozSettings.removeObserver("screen.brightness", observer2); 1.257 + navigator.mozSettings.removeObserver("screen.brightness", observer1); 1.258 + } 1.259 + req.onerror = onFailure; 1.260 + }, 1.261 + function() { 1.262 + ok(true, "test Event Listener"); 1.263 + var lock = mozSettings.createLock(); 1.264 + req = lock.set(screenBright); 1.265 + req.onsuccess = function () { 1.266 + ok(true, "set done"); 1.267 + } 1.268 + req.onerror = onFailure; 1.269 + }, 1.270 + function() { 1.271 + ok(true, "removing Event Listener"); 1.272 + var lock = mozSettings.createLock(); 1.273 + navigator.mozSettings.removeObserver("screen.brightness", observerWithNext); 1.274 + req = lock.set(screenBright); 1.275 + req.onsuccess = function () { 1.276 + ok(true, "set done"); 1.277 + navigator.mozSettings.removeObserver("screen.brightness", observer2); 1.278 + navigator.mozSettings.removeObserver("screen.brightness", observer1); 1.279 + next(); 1.280 + } 1.281 + req.onerror = onFailure; 1.282 + }, 1.283 + function() { 1.284 + ok(true, "removing Event Listener"); 1.285 + var lock = mozSettings.createLock(); 1.286 + req = lock.get("screen.brightness"); 1.287 + req.onsuccess = function () { 1.288 + ok(true, "get done"); 1.289 + next(); 1.290 + } 1.291 + req.onerror = onFailure; 1.292 + }, 1.293 + function () { 1.294 + ok(true, "Nested test"); 1.295 + var lock = mozSettings.createLock(); 1.296 + req = lock.get("screen.brightness"); 1.297 + req.onsuccess = function () { 1.298 + req3 = lock.set({"screen.brightness": req.result["screen.brightness"] + 1}) 1.299 + req3.onsuccess = function () { 1.300 + req4 = lock.get("screen.brightness"); 1.301 + req4.onsuccess = function() { 1.302 + is(req4.result["screen.brightness"], 1.7, "same Value"); 1.303 + } 1.304 + req4.onerror = onFailure; 1.305 + } 1.306 + req3.onerror = onFailure; 1.307 + }; 1.308 + req.onerror = onFailure; 1.309 + 1.310 + req2 = lock.get("screen.brightness"); 1.311 + req2.onsuccess = function () { 1.312 + is(req2.result["screen.brightness"], 0.7, "same Value"); 1.313 + } 1.314 + req2.onerror = onFailure; 1.315 + 1.316 + var lock2 = mozSettings.createLock(); 1.317 + req5 = lock2.get("screen.brightness"); 1.318 + req5.onsuccess = function () { 1.319 + is(req5.result["screen.brightness"], 1.7, "same Value"); 1.320 + next(); 1.321 + } 1.322 + req5.onerror = onFailure; 1.323 + }, 1.324 + function () { 1.325 + ok(true, "Deleting database"); 1.326 + var lock = mozSettings.createLock(); 1.327 + req = lock.clear(); 1.328 + req.onsuccess = function () { 1.329 + ok(true, "Deleted the database"); 1.330 + }; 1.331 + req.onerror = onFailure; 1.332 + req2 = lock.set(wifi); 1.333 + req2.onsuccess = function () { 1.334 + ok(true, "set done"); 1.335 + } 1.336 + req2.onerror = onFailure; 1.337 + 1.338 + ok(true, "Get all settings"); 1.339 + var lock2 = mozSettings.createLock(); 1.340 + req = lock2.get("*"); 1.341 + req.onsuccess = function () { 1.342 + is(Object.keys(req.result).length, 1, "length 1"); 1.343 + check(wifi, req.result); 1.344 + ok(true, JSON.stringify(req.result)); 1.345 + ok(true, "Get all settings Done"); 1.346 + }; 1.347 + req.onerror = onFailure; 1.348 + 1.349 + req2 = lock2.get("net3g.apn"); 1.350 + req2.onsuccess = function () { 1.351 + is(Object.keys(req2.result).length, 1, "length 1"); 1.352 + check(wifi, req2.result); 1.353 + ok(true, "Get net3g.apn Done"); 1.354 + next(); 1.355 + }; 1.356 + req2.onerror = onFailure; 1.357 + }, 1.358 + function () { 1.359 + ok(true, "Change wifi1"); 1.360 + var lock = mozSettings.createLock(); 1.361 + req = lock.set(wifi2); 1.362 + req.onsuccess = function () { 1.363 + ok(true, "Set Done"); 1.364 + }; 1.365 + req.onerror = onFailure; 1.366 + 1.367 + ok(true, "Get changed net3g.apn"); 1.368 + req2 = lock.get("net3g.apn"); 1.369 + req2.onsuccess = function () { 1.370 + is(Object.keys(req2.result).length, 1, "length 1"); 1.371 + check(wifi2, req2.result); 1.372 + ok(true, "Get net3g.apn Done"); 1.373 + next(); 1.374 + }; 1.375 + req2.onerror = onFailure; 1.376 + }, 1.377 + function () { 1.378 + ok(true, "Test locking"); 1.379 + var lock = mozSettings.createLock(); 1.380 + var lock2 = mozSettings.createLock(); 1.381 + req = lock.set(wifiEnabled); 1.382 + req.onsuccess = function () { 1.383 + ok(true, "Test Locking Done"); 1.384 + }; 1.385 + req.onerror = onFailure; 1.386 + 1.387 + req2 = lock2.set(wifiDisabled); 1.388 + req2.onsuccess = function () { 1.389 + ok(true, "Set Done"); 1.390 + next(); 1.391 + }; 1.392 + req2.onerror = onFailure; 1.393 + }, 1.394 + function () { 1.395 + ok(true, "Test locking result"); 1.396 + var lock = mozSettings.createLock(); 1.397 + req = lock.get("wifi.enabled"); 1.398 + req.onsuccess = function() { 1.399 + check(req.result, wifiDisabled); 1.400 + ok(true, "Test1 locking result done"); 1.401 + next(); 1.402 + } 1.403 + req.onerror = onFailure; 1.404 + }, 1.405 + function () { 1.406 + ok(true, "Test locking heavy"); 1.407 + for (var i=0; i<30; i++) { 1.408 + // only new locks! 1.409 + var lock = mozSettings.createLock(); 1.410 + var obj = {}; 1.411 + obj["wifi.enabled" + i] = true; 1.412 + req = lock.set( obj ); 1.413 + req.onsuccess = function () { 1.414 + ok(true, "Set1 Done"); 1.415 + }; 1.416 + req.onerror = onFailure; 1.417 + }; 1.418 + { 1.419 + var lock2 = mozSettings.createLock(); 1.420 + req2 = lock2.get("*"); 1.421 + req2.onsuccess = function () { 1.422 + is(Object.keys(req2.result).length, 32, "length 12"); 1.423 + ok(true, JSON.stringify(req2.result)); 1.424 + ok(true, "Get all settings Done"); 1.425 + }; 1.426 + req2.onerror = onFailure; 1.427 + } 1.428 + var lock2 = mozSettings.createLock(); 1.429 + var obj = {}; 1.430 + obj["wifi.enabled" + 30] = true; 1.431 + req3 = lock2.set( obj ); 1.432 + req3.onsuccess = function () { 1.433 + ok(true, "Set12 Done"); 1.434 + }; 1.435 + req3.onerror = onFailure; 1.436 + 1.437 + var lock3 = mozSettings.createLock(); 1.438 + // with one lock 1.439 + for (var i = 0; i < 30; i++) { 1.440 + req4 = lock3.get("wifi.enabled" + i); 1.441 + var testObj = {}; 1.442 + testObj["wifi.enabled" + i] = true; 1.443 + req4.onsuccess = function () { 1.444 + check(this.request.result, this.testObj); 1.445 + ok(true, "Get1 Done"); 1.446 + }.bind({testObj: testObj, request: req4}); 1.447 + req4.onerror = onFailure; 1.448 + } 1.449 + 1.450 + ok(true, "start next2!"); 1.451 + var lock4 = mozSettings.createLock(); 1.452 + for (var i=0; i<30; i++) { 1.453 + var obj = {}; 1.454 + obj["wifi.enabled" + i] = false; 1.455 + req4 = lock4.set( obj ); 1.456 + req4.onsuccess = function () { 1.457 + ok(true, "Set2 Done"); 1.458 + }; 1.459 + req4.onerror = onFailure; 1.460 + } 1.461 + var lock5 = mozSettings.createLock(); 1.462 + for (var i=0; i<30; i++) { 1.463 + req5 = lock5.get("wifi.enabled" + i); 1.464 + var testObj = {}; 1.465 + testObj["wifi.enabled" + i] = false; 1.466 + req5.onsuccess = function () { 1.467 + check(this.request.result, this.testObj); 1.468 + ok(true, "Get2 Done"); 1.469 + }.bind({testObj: testObj, request: req5}); 1.470 + req5.onerror = onFailure; 1.471 + } 1.472 + 1.473 + var lock5 = mozSettings.createLock(); 1.474 + req6 = lock5.clear(); 1.475 + req6.onsuccess = function () { 1.476 + ok(true, "Deleted the database"); 1.477 + next(); 1.478 + }; 1.479 + req6.onerror = onFailure; 1.480 + }, 1.481 + function () { 1.482 + ok(true, "reverse Test locking"); 1.483 + var lock2 = mozSettings.createLock(); 1.484 + var lock = mozSettings.createLock(); 1.485 + 1.486 + req = lock.set(wifiEnabled); 1.487 + req.onsuccess = function () { 1.488 + ok(true, "Test Locking Done"); 1.489 + next(); 1.490 + }; 1.491 + req.onerror = onFailure; 1.492 + 1.493 + req2 = lock2.set(wifiDisabled); 1.494 + req2.onsuccess = function () { 1.495 + ok(true, "Set Done"); 1.496 + }; 1.497 + req2.onerror = onFailure; 1.498 + }, 1.499 + function () { 1.500 + ok(true, "Test locking result"); 1.501 + var lock = mozSettings.createLock(); 1.502 + 1.503 + req = lock.get("wifi.enabled"); 1.504 + req.onsuccess = function() { 1.505 + check(req.result, wifiEnabled); 1.506 + ok(true, "Test2 locking result done"); 1.507 + } 1.508 + req.onerror = onFailure; 1.509 + 1.510 + req2 = lock.clear(); 1.511 + req2.onsuccess = function () { 1.512 + ok(true, "Deleted the database"); 1.513 + }; 1.514 + req2.onerror = onFailure; 1.515 + 1.516 + req3 = lock.set(wifi); 1.517 + req3.onsuccess = function () { 1.518 + ok(true, "set done"); 1.519 + next(); 1.520 + } 1.521 + req3.onerror = onFailure; 1.522 + 1.523 + }, 1.524 + function () { 1.525 + ok(true, "Get all settings"); 1.526 + var lock = mozSettings.createLock(); 1.527 + req = lock.get("*"); 1.528 + req.onsuccess = function () { 1.529 + is(Object.keys(req.result).length, 1, "length 1"); 1.530 + check(wifi, req.result); 1.531 + ok(true, "Get all settings Done"); 1.532 + next(); 1.533 + }; 1.534 + req.onerror = onFailure; 1.535 + }, 1.536 + function () { 1.537 + ok(true, "Get net3g.apn"); 1.538 + var lock = mozSettings.createLock(); 1.539 + req = lock.get("net3g.apn"); 1.540 + req.onsuccess = function () { 1.541 + is(Object.keys(req.result).length, 1, "length 1"); 1.542 + check(wifi, req.result); 1.543 + ok(true, "Get net3g.apn Done"); 1.544 + next(); 1.545 + }; 1.546 + req.onerror = onFailure; 1.547 + }, 1.548 + function () { 1.549 + ok(true, "Change wifi2"); 1.550 + var lock = mozSettings.createLock(); 1.551 + req = lock.set(wifi2); 1.552 + req.onsuccess = function () { 1.553 + ok(true, "Set Done"); 1.554 + next(); 1.555 + }; 1.556 + req.onerror = onFailure; 1.557 + }, 1.558 + function () { 1.559 + ok(true, "Get net3g.apn"); 1.560 + var lock = mozSettings.createLock(); 1.561 + req = lock.get("net3g.apn"); 1.562 + req.onsuccess = function () { 1.563 + is(Object.keys(req.result).length, 1, "length 1"); 1.564 + check(wifi2, req.result); 1.565 + ok(true, "Get net3g.apn Done"); 1.566 + next(); 1.567 + }; 1.568 + req.onerror = onFailure; 1.569 + }, 1.570 + function () { 1.571 + ok(true, "Add wifi.enabled"); 1.572 + var lock = mozSettings.createLock(); 1.573 + req = lock.set(wifiEnabled); 1.574 + req.onsuccess = function () { 1.575 + ok(true, "Set Done"); 1.576 + next(); 1.577 + }; 1.578 + req.onerror = onFailure; 1.579 + }, 1.580 + function () { 1.581 + ok(true, "Get Wifi Enabled"); 1.582 + var lock = mozSettings.createLock(); 1.583 + req = lock.get("wifi.enabled"); 1.584 + req.onsuccess = function () { 1.585 + is(Object.keys(req.result).length, 1, "length 1"); 1.586 + check(wifiEnabled, req.result); 1.587 + ok(true, "Get wifi.enabledDone"); 1.588 + next(); 1.589 + }; 1.590 + req.onerror = onFailure; 1.591 + }, 1.592 + function () { 1.593 + ok(true, "Get all"); 1.594 + var lock = mozSettings.createLock(); 1.595 + req = lock.get("*"); 1.596 + req.onsuccess = function () { 1.597 + is(Object.keys(req.result).length, 2, "length 2"); 1.598 + check(wifiEnabled["wifi.enabled"], req.result["wifi.enabled"]); 1.599 + check(wifi2["net3g.apn"], req.result["net3g.apn"]); 1.600 + ok(true, "Get all Done"); 1.601 + next(); 1.602 + }; 1.603 + req.onerror = onFailure; 1.604 + }, 1.605 + function () { 1.606 + ok(true, "Add wifiNetworks"); 1.607 + var lock = mozSettings.createLock(); 1.608 + req = lock.set(wifiNetworks0); 1.609 + req.onsuccess = function () { 1.610 + ok(true, "Set Done"); 1.611 + }; 1.612 + req.onerror = onFailure; 1.613 + 1.614 + req2 = lock.set(wifiNetworks1); 1.615 + req2.onsuccess = function () { 1.616 + ok(true, "Set Done"); 1.617 + next(); 1.618 + }; 1.619 + req2.onerror = onFailure; 1.620 + }, 1.621 + function () { 1.622 + ok(true, "Get Wifi Networks"); 1.623 + var lock = mozSettings.createLock(); 1.624 + req = lock.get("wifi.networks[0]"); 1.625 + req.onsuccess = function () { 1.626 + is(Object.keys(req.result).length, 1, "length 1"); 1.627 + check(wifiNetworks0, req.result); 1.628 + ok(true, "Get wifi.networks[0]"); 1.629 + next(); 1.630 + }; 1.631 + req.onerror = onFailure; 1.632 + }, 1.633 + function() { 1.634 + ok(true, "Clear DB, multiple locks"); 1.635 + var lock4 = mozSettings.createLock(); 1.636 + var lock3 = mozSettings.createLock(); 1.637 + var lock2 = mozSettings.createLock(); 1.638 + var lock = mozSettings.createLock(); 1.639 + var lock6 = mozSettings.createLock(); 1.640 + var lock7 = mozSettings.createLock(); 1.641 + req = lock.clear(); 1.642 + req.onsuccess = function () { 1.643 + ok(true, "Deleted the database"); 1.644 + next(); 1.645 + }; 1.646 + req.onerror = onFailure; 1.647 + }, 1.648 + function () { 1.649 + ok(true, "Add wifiNetworks"); 1.650 + var lock = mozSettings.createLock(); 1.651 + req = lock.set(wifiNetworks0); 1.652 + req.onsuccess = function () { 1.653 + ok(true, "Set Done"); 1.654 + next(); 1.655 + }; 1.656 + req.onerror = onFailure; 1.657 + }, 1.658 + function () { 1.659 + ok(true, "Test set after lock closed"); 1.660 + var lockx = mozSettings.createLock(); 1.661 + var cb = function() { 1.662 + var reqx = null; 1.663 + try { 1.664 + reqx = lockx.set(wifiNetworks0); 1.665 + ok(false, "should have thrown"); 1.666 + } catch (ex) { 1.667 + ok(reqx == null, "request is still null"); 1.668 + ok(true, "Caught Exception"); 1.669 + next(); 1.670 + } 1.671 + } 1.672 + SimpleTest.executeSoon(cb); 1.673 + }, 1.674 + function() { 1.675 + ok(true, "Clear DB"); 1.676 + var lock = mozSettings.createLock(); 1.677 + req = lock.clear(); 1.678 + req.onsuccess = function () { 1.679 + ok(true, "Deleted the database"); 1.680 + next(); 1.681 + }; 1.682 + req.onerror = onFailure; 1.683 + }, 1.684 + function() { 1.685 + ok(true, "Set with multiple arguments"); 1.686 + var lock = mozSettings.createLock(); 1.687 + req = lock.set(combination); 1.688 + req.onsuccess = function () { 1.689 + ok(true, "Set Done"); 1.690 + next(); 1.691 + }; 1.692 + req.onerror = onFailure; 1.693 + }, 1.694 + function() { 1.695 + ok(true, "request argument from multiple set"); 1.696 + var lock = mozSettings.createLock(); 1.697 + req = lock.get("screen.brightness"); 1.698 + req.onsuccess = function () { 1.699 + check(req.result["screen.brightness"], 0.7, "get done"); 1.700 + next(); 1.701 + } 1.702 + req.onerror = onFailure; 1.703 + }, 1.704 + function() { 1.705 + ok(true, "Test closed attribute on a valid lock"); 1.706 + var lock = mozSettings.createLock(); 1.707 + is(lock.closed, false, "closed attribute is false on creation"); 1.708 + req = lock.get("screen.brightness"); 1.709 + req.onsuccess = function () { 1.710 + is(lock.closed, false, "closed attribute is false on success callback"); 1.711 + next(); 1.712 + } 1.713 + req.onerror = onFailure; 1.714 + }, 1.715 + function () { 1.716 + ok(true, "Test closed attribute on invalid lock"); 1.717 + var lockx = mozSettings.createLock(); 1.718 + var cb = function() { 1.719 + var reqx = null; 1.720 + try { 1.721 + reqx = lockx.set(wifiNetworks0); 1.722 + ok(false, "should have thrown"); 1.723 + } catch (ex) { 1.724 + is(lockx.closed, true, "closed attribute is true"); 1.725 + ok(true, "Caught Exception"); 1.726 + next(); 1.727 + } 1.728 + } 1.729 + SimpleTest.executeSoon(cb); 1.730 + }, 1.731 + function() { 1.732 + ok(true, "Clear DB"); 1.733 + var lock = mozSettings.createLock(); 1.734 + req = lock.clear(); 1.735 + req.onsuccess = function () { 1.736 + ok(true, "Deleted the database"); 1.737 + next(); 1.738 + }; 1.739 + req.onerror = onFailure; 1.740 + }, 1.741 + function() { 1.742 + ok(true, "Set object value"); 1.743 + var lock = mozSettings.createLock(); 1.744 + req = lock.set({"setting-obj": {foo: {bar: 23}}}); 1.745 + req.onsuccess = function() { 1.746 + req2 = lock.get("setting-obj"); 1.747 + req2.onsuccess = function(event) { 1.748 + var result = event.target.result["setting-obj"]; 1.749 + ok(result, "Got valid result"); 1.750 + ok(typeof result == "object", "Result is object"); 1.751 + ok("foo" in result && "bar" in result.foo, "Result has properties"); 1.752 + ok(result.foo.bar == 23, "Result properties are set"); 1.753 + next(); 1.754 + }; 1.755 + }; 1.756 + }, 1.757 + function() { 1.758 + ok(true, "Clear DB"); 1.759 + var lock = mozSettings.createLock(); 1.760 + req = lock.clear(); 1.761 + req.onsuccess = function () { 1.762 + ok(true, "Deleted the database"); 1.763 + next(); 1.764 + }; 1.765 + req.onerror = onFailure; 1.766 + }, 1.767 + function () { 1.768 + ok(true, "all done!\n"); 1.769 + SimpleTest.finish(); 1.770 + } 1.771 +]; 1.772 + 1.773 +function next() { 1.774 + ok(true, "Begin!"); 1.775 + if (index >= steps.length) { 1.776 + ok(false, "Shouldn't get here!"); 1.777 + return; 1.778 + } 1.779 + try { 1.780 + steps[index](); 1.781 + } catch(ex) { 1.782 + ok(false, "Caught exception", ex); 1.783 + } 1.784 + index += 1; 1.785 +} 1.786 + 1.787 +SimpleTest.waitForExplicitFinish(); 1.788 +addLoadEvent(next); 1.789 +</script> 1.790 +</pre> 1.791 +</body> 1.792 +</html>