chromium/third_party/blink/web_tests/storage/indexeddb/resources/intversion-abort-in-initial-upgradeneeded.js

if (this.importScripts) {
    importScripts('../../../resources/js-test.js');
    importScripts('shared.js');
}

description("Test that an abort in the initial upgradeneeded sets version back to 0");

function test()
{
    setDBNameFromPath();

    request = evalAndLog("indexedDB.deleteDatabase(dbname)");
    request.onsuccess = deleteSuccess;
    request.onerror = unexpectedErrorCallback;
}

function deleteSuccess() {
    request = evalAndLog("indexedDB.open(dbname, 2)");
    request.onsuccess = unexpectedSuccessCallback;
    evalAndLog("request.onupgradeneeded = upgradeNeeded");
    evalAndLog("request.onerror = onError");
    request.onblocked = unexpectedBlockedCallback;
}

function upgradeNeeded(evt)
{
    preamble(evt);
    db = event.target.result;
    shouldBe("db.version", "2");
    transaction = event.target.transaction;
    transaction.oncomplete = unexpectedCompleteCallback;
    transaction.onabort = onAbort;
    evalAndLog("transaction.abort()");
}

function onAbort(evt)
{
    preamble(evt);
    shouldBe("event.target.db.version", "0");
    shouldBeNonNull("request.transaction");
}

function onError(evt)
{
    preamble(evt);
    shouldBe("request", "event.target");
    shouldBeUndefined("event.target.result");
    shouldBeNonNull("event.target.error");
    shouldBeEqualToString("event.target.error.name", "AbortError");
    shouldBeNull("request.transaction");
    finishJSTest();
}

test();