summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbcursor-advance.htm
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/IndexedDB/idbcursor-advance.htm
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbcursor-advance.htm')
-rw-r--r--testing/web-platform/tests/IndexedDB/idbcursor-advance.htm243
1 files changed, 243 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 000000000..f4ecbc0e5
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/idbcursor-advance.htm
@@ -0,0 +1,243 @@
+<!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="support.js"></script>
+
+<script>
+
+ var db, open;
+
+ setup(function() {
+ open = indexedDB.open("testdb-" + new Date().getTime());
+ open.onupgradeneeded = function(e) {
+ db = e.target.result;
+ 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);
+ };
+ },
+ { explicit_done: true });
+
+
+ open.onsuccess = function() {
+
+ async_test(document.title + " - advances").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index").openCursor();
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 3, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+ async_test(document.title + " - advances backwards").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index").openCursor(null, "prev");
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 3, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+ async_test(document.title + " - skip far forward").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index")
+ .openCursor();
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 1, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+
+ async_test(document.title + " - within range").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index")
+ .openCursor(IDBKeyRange.lowerBound("cupcake", true));
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 2, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+
+ async_test(document.title + " - within single key range").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index")
+ .openCursor("pancake");
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 1, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+
+ async_test(document.title + " - within single key range, with several results").step(function(e) {
+ var count = 0;
+ var rq = db.transaction("test").objectStore("test").index("index")
+ .openCursor("pie");
+
+ rq.onsuccess = this.step_func(function(e) {
+ if (!e.target.result) {
+ assert_equals(count, 2, "count");
+ this.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 = fail(this, "unexpected error")
+ });
+
+
+ // Stop blocking the testing system from hereon
+ done();
+ }
+
+</script>
+
+<div id="log"></div>