chromium/third_party/blink/web_tests/storage/indexeddb/resources/setversion-not-blocked.js

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

description("Test that setVersion is not blocked if handle closed in versionchange handler.");

indexedDBTest(prepareDatabase, onOpen);
evalAndLog("versionchangeEventFired = false");
function prepareDatabase(evt)
{
    preamble(evt);
    evalAndLog("h1 = event.target.result");
    evalAndLog("h1.onversionchange = h1OnVersionChange");
}

function h1OnVersionChange(evt)
{
    preamble(evt);
    evalAndLog("versionchangeEventFired = true");
    shouldBe("event.oldVersion", "1");
    shouldBe("event.newVersion", "2");
    evalAndLog("h1.close()");
}

function onOpen(evt)
{
    request = evalAndLog("indexedDB.open(dbname, 2)");
    request.onerror = unexpectedErrorCallback;
    request.onblocked = unexpectedBlockedCallback;
    request.onupgradeneeded = function h2UpgradeNeeded(evt) {
        preamble(evt);
        shouldBe("event.oldVersion", "1");
        shouldBe("event.newVersion", "2");
    };
    request.onsuccess = function h2OpenSuccess(evt) {
        preamble(evt);
        shouldBeTrue("versionchangeEventFired");
        finishJSTest();
    };
}