2011-12-16 11:34:24 +04:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Indexed Database Property Test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript">
|
2016-12-01 12:11:32 +03:00
|
|
|
function* testSteps()
|
2011-12-16 11:34:24 +04:00
|
|
|
{
|
2013-07-29 21:12:21 +04:00
|
|
|
const READ_WRITE = "readwrite";
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
const name = window.location.pathname;
|
|
|
|
|
|
|
|
const objectStoreName = "Blobs";
|
|
|
|
|
|
|
|
const fileData = { key: 1, file: getRandomFile("random.bin", 100000) };
|
|
|
|
|
|
|
|
{
|
2012-07-13 09:37:28 +04:00
|
|
|
let request = indexedDB.open(name, 1);
|
2011-12-16 11:34:24 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(event.type, "upgradeneeded", "Got correct event type");
|
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
|
|
|
|
let objectStore = db.createObjectStore(objectStoreName, { });
|
|
|
|
|
|
|
|
objectStore.add(fileData.file, fileData.key);
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(event.type, "success", "Got correct event type");
|
|
|
|
|
|
|
|
let trans = db.transaction([objectStoreName], READ_WRITE);
|
|
|
|
objectStore = trans.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
objectStore.delete(fileData.key);
|
|
|
|
|
|
|
|
trans.oncomplete = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
|
|
|
|
|
|
|
|
trans = db.transaction([objectStoreName], READ_WRITE);
|
|
|
|
objectStore = trans.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
request = objectStore.add(fileData.file, fileData.key);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
trans.oncomplete = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(getFileDBRefCount(name, 1), 1, "Correct db ref count");
|
|
|
|
|
|
|
|
fileData.file = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduleGC();
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2011-12-20 15:23:27 +04:00
|
|
|
is(getFileRefCount(name, 1), 0, "Correct ref count");
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
{
|
2012-07-13 09:37:28 +04:00
|
|
|
let request = indexedDB.open(name, 1);
|
2011-12-16 11:34:24 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(event.type, "success", "Got correct event type");
|
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
|
|
|
|
let trans = db.transaction([objectStoreName], READ_WRITE);
|
|
|
|
objectStore = trans.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
request = objectStore.get(fileData.key);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
let result = event.target.result;
|
|
|
|
ok(result, "Got result");
|
|
|
|
|
|
|
|
objectStore.delete(fileData.key);
|
|
|
|
|
|
|
|
trans.oncomplete = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(getFileDBRefCount(name, 1), 0, "Correct db ref count");
|
|
|
|
|
|
|
|
trans = db.transaction([objectStoreName], READ_WRITE);
|
|
|
|
objectStore = trans.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
request = objectStore.add(result, fileData.key);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
trans.oncomplete = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
is(getFileDBRefCount(name, 1), 1, "Correct db ref count");
|
|
|
|
|
|
|
|
event = null;
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduleGC();
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2011-12-20 15:23:27 +04:00
|
|
|
is(getFileRefCount(name, 1), 0, "Correct ref count");
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
</script>
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript" src="file.js"></script>
|
|
|
|
<script type="text/javascript" src="helpers.js"></script>
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|