gecko-dev/dom/contacts/tests/test_contacts_getall2.html

121 строка
2.8 KiB
HTML

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=836519
-->
<head>
<title>Mozilla Bug 836519</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=836519">Mozilla Bug 836519</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
<script class="testbody" type="text/javascript;version=1.8">
"use strict";
let req;
let steps = [
clearDatabase,
function() {
// add a contact
createResult1 = new mozContact({});
req = navigator.mozContacts.save(createResult1);
req.onsuccess = function() {
next();
};
req.onerror = onFailure;
},
getOne(),
getOne("Retrieving one contact with getAll - cached"),
clearDatabase,
addContacts,
getAll(),
getAll("Retrieving 40 contacts with getAll - cached"),
function() {
ok(true, "Deleting one contact");
req = mozContacts.remove(createResult1);
req.onsuccess = function() {
next();
};
req.onerror = onFailure;
},
function() {
ok(true, "Test cache invalidation");
req = mozContacts.getAll({});
let count = 0;
req.onsuccess = function(event) {
ok(true, "on success");
if (req.result) {
ok(true, "result is valid");
count++;
req.continue();
} else {
is(count, 39, "last contact - 39 contacts returned");
next();
}
};
req.onerror = onFailure;
},
clearDatabase,
addContacts,
function() {
ok(true, "Test cache consistency when deleting contact during getAll");
req = mozContacts.find({});
req.onsuccess = function(e) {
let lastContact = e.target.result[e.target.result.length-1];
req = mozContacts.getAll({});
let count = 0;
let firstResult = true;
req.onsuccess = function(event) {
ok(true, "on success");
if (firstResult) {
if (req.result) {
count++;
}
let delReq = mozContacts.remove(lastContact);
delReq.onsuccess = function() {
firstResult = false;
req.continue();
};
} else {
if (req.result) {
ok(true, "result is valid");
count++;
req.continue();
} else {
is(count, 40, "last contact - 40 contacts returned");
next();
}
}
};
};
},
clearDatabase,
function() {
ok(true, "all done!\n");
SimpleTest.finish();
}
];
start_tests();
</script>
</pre>
</body>
</html>