forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for IDBObjectStore.delete while iterating a cursor.
Differential Revision: https://phabricator.services.mozilla.com/D48504 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1168606 gecko-commit: fc34f807986e87758aa1433c228497fd9eb1c974 gecko-integration-branch: autoland gecko-reviewers: asuth
- Loading branch information
1 parent
ec1b234
commit b601127
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<!DOCTYPE html> | ||
<title>IDBObjectStore.delete() and IDBCursor.continue() - object store - remove a record from the object store while iterating cursor</title> | ||
<link rel="author" title="Mozilla" href="https://www.mozilla.org"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
|
||
<script> | ||
/* The goal here is to test that any prefetching of cursor values performs | ||
* correct invalidation of prefetched data. This test is motivated by the | ||
* particularities of the Firefox implementation of preloading, and is | ||
* specifically motivated by an edge case when prefetching prefetches at | ||
* least 2 extra records and at most determines whether a mutation is | ||
* potentially relevant based on current cursor position and direction and | ||
* does not test for key equivalence. Future implementations may want to | ||
* help refine this test if their cursors are more clever. | ||
* | ||
* Step-wise we: | ||
* - Open a cursor, returning key 0. | ||
* - When the cursor request completes, without yielding control: | ||
* - Issue a delete() call that won't actually delete anything but looks | ||
* relevant. This should purge prefetched records 1 and 2. | ||
* - Issue a continue() which should result in record 1 being fetched | ||
* again and record 2 being prefetched again. | ||
* - Delete record 2. Unless there's a synchronously available source | ||
* of truth, the data from continue() above will not be present and | ||
* we'll expect the implementation to need to set a flag to invalidate | ||
* the prefetched data when it arrives. | ||
* - When the cursor request completes, validate we got record 1 and issue | ||
* a continue. | ||
* - When the request completes, we should have a null cursor result value | ||
* because 2 was deleted. | ||
*/ | ||
var db, | ||
count = 0, | ||
t = async_test(), | ||
records = [ { pKey: "primaryKey_0" }, | ||
{ pKey: "primaryKey_1" }, | ||
{ pKey: "primaryKey_2" } ]; | ||
|
||
// This is a key that is not present in the database, but that is known to | ||
// be relevant to a forward iteration of the above keys by comparing to be | ||
// greater than all of them. | ||
var plausibleFutureKey = "primaryKey_9"; | ||
|
||
var open_rq = createdb(t); | ||
open_rq.onupgradeneeded = function(e) { | ||
db = e.target.result; | ||
|
||
var objStore = db.createObjectStore("test", { keyPath: "pKey" }); | ||
|
||
for (var i = 0; i < records.length; i++) | ||
objStore.add(records[i]); | ||
}; | ||
|
||
open_rq.onsuccess = t.step_func(CursorDeleteRecord); | ||
|
||
|
||
function CursorDeleteRecord(e) { | ||
var txn = db.transaction("test", "readwrite"), | ||
object_store = txn.objectStore("test"), | ||
cursor_rq = object_store.openCursor(); | ||
|
||
var iteration = 0; | ||
|
||
cursor_rq.onsuccess = t.step_func(function(e) { | ||
var cursor = e.target.result; | ||
|
||
switch (iteration) { | ||
case 0: | ||
object_store.delete(plausibleFutureKey); | ||
assert_true(cursor != null, "cursor valid"); | ||
assert_equals(cursor.value.pKey, records[iteration].pKey); | ||
cursor.continue(); | ||
object_store.delete(records[2].pKey); | ||
break; | ||
case 1: | ||
assert_true(cursor != null, "cursor valid"); | ||
assert_equals(cursor.value.pKey, records[iteration].pKey); | ||
cursor.continue(); | ||
break; | ||
case 2: | ||
assert_equals(cursor, null, "cursor no longer valid"); | ||
break; | ||
}; | ||
iteration++; | ||
}); | ||
|
||
txn.oncomplete = t.step_func(VerifyRecordWasDeleted); | ||
} | ||
|
||
|
||
function VerifyRecordWasDeleted(e) { | ||
var cursor_rq = db.transaction("test") | ||
.objectStore("test") | ||
.openCursor(); | ||
|
||
cursor_rq.onsuccess = t.step_func(function(e) { | ||
var cursor = e.target.result; | ||
|
||
if (!cursor) { | ||
assert_equals(count, 2, 'count'); | ||
t.done(); | ||
} | ||
|
||
assert_equals(cursor.value.pKey, records[count].pKey); | ||
count++; | ||
cursor.continue(); | ||
}); | ||
} | ||
|
||
</script> | ||
|
||
<div id="log"></div> |