gecko/dom/settings/tests/test_settings_blobs.html
Ryan VanderMeulen 4f864e03ab Backed out 11 changesets (bug 1059079, bug 1015518, bug 900551, bug 846200) for Gaia UI test failures on a CLOSED TREE.
Backed out changeset d85b4e48b3b4 (bug 1015518)
Backed out changeset 663b73ba69ec (bug 1015518)
Backed out changeset 5cf1cb5fa022 (bug 900551)
Backed out changeset b953dd5bfdaa (bug 900551)
Backed out changeset a2b6d7c84100 (bug 900551)
Backed out changeset ceb79fe83d15 (bug 900551)
Backed out changeset f6acf344fbf0 (bug 900551)
Backed out changeset fa269ea53937 (bug 846200)
Backed out changeset b89c84a850f9 (bug 846200)
Backed out changeset b7a7dfbe4e3f (bug 846200)
Backed out changeset c6f54d821c11 (bug 1059079)
2014-08-28 12:49:49 -04:00

154 lines
4.0 KiB
HTML

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=821630
-->
<head>
<title>Test for Bug 821630 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=821630">Mozilla Bug 821630</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.7">
"use strict";
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm");
}
SpecialPowers.addPermission("settings-read", true, document);
SpecialPowers.addPermission("settings-write", true, document);
function onUnwantedSuccess() {
ok(false, "onUnwantedSuccess: shouldn't get here");
}
function onFailure() {
return function(s) {
if (s) {
ok(false, "in on Failure! - " + s);
} else {
ok(false, "in on Failure!");
}
}
}
let mozSettings = window.navigator.mozSettings;
let req;
let storedBlob = new Blob(['12345'], {"type": "text/plain"});
function checkBlob(blob) {
try {
let url = URL.createObjectURL(blob);
ok(true, "Valid blob");
} catch (e) {
ok(false, "Valid blob");
}
}
let steps = [
function() {
let lock = mozSettings.createLock();
req = lock.clear();
req.onsuccess = next;
req.onerror = onFailure("Deleting database");
},
function() {
function obs(e) {
checkBlob(e.settingValue);
mozSettings.removeObserver("test1", obs);
next();
}
mozSettings.addObserver("test1", obs);
next();
},
function() {
// next is called by the observer above
let req = mozSettings.createLock().set({"test1": storedBlob});
req.onerror = onFailure("Saving blob");
},
function() {
let req = mozSettings.createLock().get("test1");
req.onsuccess = function(event) {
checkBlob(event.target.result["test1"]);
next();
};
req.onerror = onFailure("Getting blob");
},
function() {
let req = mozSettings.createLock().set({"test2": [1, 2, storedBlob, 4]});
req.onsuccess = next;
req.onerror = onFailure("Saving array");
},
function() {
let req = mozSettings.createLock().get("test2");
req.onsuccess = function(event) {
let val = event.target.result["test2"];
ok(Array.isArray(val), "Result is an array");
ok(val[0] == 1 && val[1] == 2 && val[3] == 4, "Primitives are preserved");
checkBlob(val[2]);
next();
};
req.onerror = onFailure("Getting array");
},
function() {
let req = mozSettings.createLock().set({"test3": {foo: "bar", baz: {number: 1, arr: [storedBlob]}}});
req.onsuccess = next();
req.onerror = onFailure("Saving object");
},
function() {
let req = mozSettings.createLock().get("test3");
req.onsuccess = function(event) {
let val = event.target.result["test3"];
ok(typeof(val) == "object", "Result is an object");
ok("foo" in val && typeof(val.foo) == "string", "String property preserved");
ok("baz" in val && typeof(val.baz) == "object", "Object property preserved");
let baz = val.baz;
ok("number" in baz && baz.number == 1, "Primite inside object preserved");
ok("arr" in baz && Array.isArray(baz.arr), "Array inside object is preserved");
checkBlob(baz.arr[0]);
next();
};
req.onerror = onFailure("Getting object");
},
function() {
let req = mozSettings.createLock().clear();
req.onsuccess = function() {
next();
};
req.onerror = onFailure("Deleting database");
},
function () {
ok(true, "all done!\n");
SimpleTest.finish();
}
];
function next() {
try {
let step = steps.shift();
if (step) {
step();
}
} catch(ex) {
ok(false, "Caught exception", ex);
}
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(next);
</script>
</pre>
</body>
</html>