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";
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
getCurrentUsage(grabFileUsageAndContinueHandler);
|
2013-07-11 01:52:35 +04:00
|
|
|
let startUsage = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
const fileData1 = {
|
|
|
|
key: 1,
|
2018-10-19 15:55:39 +03:00
|
|
|
obj: { id: 1, file: getRandomFile("random.bin", 100000) },
|
2014-01-31 22:53:37 +04:00
|
|
|
};
|
|
|
|
const fileData2 = {
|
|
|
|
key: 2,
|
2018-10-19 15:55:39 +03:00
|
|
|
obj: { id: 1, file: getRandomFile("random.bin", 100000) },
|
2014-01-31 22:53:37 +04:00
|
|
|
};
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2016-10-25 22:18:29 +03:00
|
|
|
SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] },
|
|
|
|
continueToNextStep);
|
|
|
|
yield undefined;
|
|
|
|
|
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.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, { });
|
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
objectStore.createIndex("index", "id", { unique: true });
|
|
|
|
|
|
|
|
objectStore.add(fileData1.obj, fileData1.key);
|
|
|
|
|
|
|
|
request = objectStore.add(fileData2.obj, fileData2.key);
|
|
|
|
request.addEventListener("error", new ExpectError("ConstraintError", true));
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
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");
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
getCurrentUsage(grabFileUsageAndContinueHandler);
|
2013-07-11 01:52:35 +04:00
|
|
|
let usage = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size,
|
|
|
|
"Correct file usage");
|
2011-12-16 11:34:24 +04:00
|
|
|
|
|
|
|
let trans = db.transaction([objectStoreName], READ_WRITE);
|
2014-01-31 22:53:37 +04:00
|
|
|
trans.objectStore(objectStoreName).delete(fileData1.key);
|
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(event.type, "complete", "Got correct event type");
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
getCurrentUsage(grabFileUsageAndContinueHandler);
|
2013-07-11 01:52:35 +04:00
|
|
|
usage = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size,
|
|
|
|
"OS files exists");
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
fileData1.obj.file = null;
|
|
|
|
fileData2.obj.file = null;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
scheduleGC();
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2015-11-22 12:44:43 +03:00
|
|
|
// Flush pending file deletions before checking usage.
|
2015-06-30 15:59:27 +03:00
|
|
|
flushPendingFileDeletions();
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
getCurrentUsage(grabFileUsageAndContinueHandler);
|
2013-07-11 01:52:35 +04:00
|
|
|
let endUsage = yield undefined;
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2014-01-31 22:53:37 +04:00
|
|
|
is(endUsage, startUsage, "OS files deleted");
|
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>
|