chromium/third_party/blink/web_tests/storage/indexeddb/cursor-overloads.html

<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
<script>
description("Validate the overloads of IDBObjectStore.openCursor(), IDBIndex.openCursor() and IDBIndex.openKeyCursor().");

indexedDBTest(prepareDatabase, verifyOverloads);
function prepareDatabase()
{
    db = event.target.result;
    event.target.transaction.onabort = unexpectedAbortCallback;
    evalAndLog("store = db.createObjectStore('store')");
    evalAndLog("index = store.createIndex('index', 'value')");
    evalAndLog("store.put({value: 0}, 0)");
}

function verifyOverloads()
{
    debug("");
    debug("verifyOverloads():");
    evalAndLog("trans = db.transaction('store', 'readonly', {durability: 'relaxed'})");
    evalAndLog("store = trans.objectStore('store')");
    evalAndLog("index = store.index('index')");

    checkCursorDirection("store.openCursor()", "next");
    checkCursorDirection("store.openCursor(0)", "next");
    checkCursorDirection("store.openCursor(0, 'next')", "next");
    checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
    checkCursorDirection("store.openCursor(0, 'prev')", "prev");
    checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");

    checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
    checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'next')", "next");
    checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
    checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'prev')", "prev");
    checkCursorDirection("store.openCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");

    checkCursorDirection("store.openKeyCursor()", "next");
    checkCursorDirection("store.openKeyCursor(0)", "next");
    checkCursorDirection("store.openKeyCursor(0, 'next')", "next");
    checkCursorDirection("store.openKeyCursor(0, 'nextunique')", "nextunique");
    checkCursorDirection("store.openKeyCursor(0, 'prev')", "prev");
    checkCursorDirection("store.openKeyCursor(0, 'prevunique')", "prevunique");

    checkCursorDirection("store.openKeyCursor(IDBKeyRange.only(0))", "next");
    checkCursorDirection("store.openKeyCursor(IDBKeyRange.only(0), 'next')", "next");
    checkCursorDirection("store.openKeyCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
    checkCursorDirection("store.openKeyCursor(IDBKeyRange.only(0), 'prev')", "prev");
    checkCursorDirection("store.openKeyCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");

    checkCursorDirection("index.openCursor()", "next");
    checkCursorDirection("index.openCursor(0)", "next");
    checkCursorDirection("index.openCursor(0, 'next')", "next");
    checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
    checkCursorDirection("index.openCursor(0, 'prev')", "prev");
    checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");

    checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
    checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'next')", "next");
    checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
    checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'prev')", "prev");
    checkCursorDirection("index.openCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");

    checkCursorDirection("index.openKeyCursor()", "next");
    checkCursorDirection("index.openKeyCursor(0)", "next");
    checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
    checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
    checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
    checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");

    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'next')", "next");
    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')", "nextunique");
    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'prev')", "prev");
    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')", "prevunique");

    trans.oncomplete = finishJSTest;
}

function checkCursorDirection(statement, direction)
{
    request = eval(statement);
    request.onerror = unexpectedErrorCallback;
    request.onsuccess = function() {
        debug(statement);
        shouldBeNonNull("event.target.result")
        shouldBeEqualToString("event.target.result.direction", direction);
    };
}

</script>