diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/IndexedDB/idbcursor-advance.htm | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbcursor-advance.htm')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbcursor-advance.htm | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbcursor-advance.htm b/testing/web-platform/tests/IndexedDB/idbcursor-advance.htm new file mode 100644 index 0000000000..624ed14f1f --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbcursor-advance.htm @@ -0,0 +1,247 @@ +<!DOCTYPE html> +<title>IDBCursor.advance()</title> +<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/support.js"></script> + +<script> + +function upgrade_func(t, db, tx) { + var objStore = db.createObjectStore("test"); + objStore.createIndex("index", ""); + + objStore.add("cupcake", 5); + objStore.add("pancake", 3); // Yes, it is intended + objStore.add("pie", 1); + objStore.add("pie", 4); + objStore.add("taco", 2); +} + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index").openCursor(); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 3, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "cupcake"); + assert_equals(cursor.primaryKey, 5); + break; + + case 1: + assert_equals(cursor.value, "pie"); + assert_equals(cursor.primaryKey, 1); + break; + + case 2: + assert_equals(cursor.value, "taco"); + assert_equals(cursor.primaryKey, 2); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(2); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - advances" +); + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index").openCursor(null, "prev"); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 3, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "taco"); + assert_equals(cursor.primaryKey, 2); + break; + + case 1: + assert_equals(cursor.value, "pie"); + assert_equals(cursor.primaryKey, 1); + break; + + case 2: + assert_equals(cursor.value, "cupcake"); + assert_equals(cursor.primaryKey, 5); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(2); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - advances backwards" +); + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index") + .openCursor(); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 1, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "cupcake"); + assert_equals(cursor.primaryKey, 5); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(100000); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - skip far forward" +); + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index") + .openCursor(IDBKeyRange.lowerBound("cupcake", true)); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 2, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "pancake"); + assert_equals(cursor.primaryKey, 3); + break; + + case 1: + assert_equals(cursor.value, "pie"); + assert_equals(cursor.primaryKey, 4); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(2); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - within range" +); + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index") + .openCursor("pancake"); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 1, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "pancake"); + assert_equals(cursor.primaryKey, 3); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(1); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - within single key range" +); + +indexeddb_test( + upgrade_func, + function(t, db) { + var count = 0; + var rq = db.transaction("test", "readonly", {durability: 'relaxed'}).objectStore("test").index("index") + .openCursor("pie"); + + rq.onsuccess = t.step_func(function(e) { + if (!e.target.result) { + assert_equals(count, 2, "count"); + t.done(); + return; + } + var cursor = e.target.result; + + switch(count) { + case 0: + assert_equals(cursor.value, "pie"); + assert_equals(cursor.primaryKey, 1); + break; + + case 1: + assert_equals(cursor.value, "pie"); + assert_equals(cursor.primaryKey, 4); + break; + + default: + assert_unreached("Unexpected count: " + count); + } + + count++; + cursor.advance(1); + }); + rq.onerror = t.unreached_func("unexpected error") + }, + document.title + " - within single key range, with several results" +); + +</script> |