2012-10-23 16:31:19 +00:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Indexed Database Clear Browser Data Test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript;version=1.7">
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function ok(cond, message)
|
|
|
|
{
|
|
|
|
alert(JSON.stringify({ type: "ok",
|
|
|
|
args: [!!cond, "browserFrame: " + message] }));
|
|
|
|
}
|
|
|
|
|
|
|
|
function info(message)
|
|
|
|
{
|
|
|
|
alert(JSON.stringify({ type: "info",
|
|
|
|
args: ["browserFrame: " + message] }));
|
|
|
|
}
|
|
|
|
|
|
|
|
function block()
|
|
|
|
{
|
|
|
|
info("about to block");
|
|
|
|
|
|
|
|
// This will block until the parent has cleared our database.
|
|
|
|
alert(JSON.stringify({ type: "block" }));
|
|
|
|
|
|
|
|
info("unblocked");
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish()
|
|
|
|
{
|
|
|
|
alert(JSON.stringify({ type: "done" }));
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onerror = ok.bind(window, false);
|
|
|
|
|
|
|
|
function testSteps()
|
|
|
|
{
|
|
|
|
const objectStoreName = "foo";
|
|
|
|
const testKey = 1;
|
|
|
|
const testValue = objectStoreName;
|
2012-11-10 18:32:38 +00:00
|
|
|
const dbName = window.location.pathname + window.location.search;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
2012-11-10 18:32:38 +00:00
|
|
|
let request = indexedDB.open(dbName, 1);
|
2012-10-23 16:31:19 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2013-07-10 21:52:35 +00:00
|
|
|
let event = yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
db.onversionchange = function(event) {
|
|
|
|
event.target.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
let objectStore = db.createObjectStore(objectStoreName);
|
|
|
|
objectStore.add(testValue, testKey);
|
|
|
|
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-10 21:52:35 +00:00
|
|
|
event = yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
ok(db === event.target.result, "created database");
|
|
|
|
|
|
|
|
objectStore =
|
|
|
|
db.transaction(objectStoreName).objectStore(objectStoreName);
|
|
|
|
objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
|
2013-07-10 21:52:35 +00:00
|
|
|
event = yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
ok(testValue == event.target.result, "data exists");
|
|
|
|
|
|
|
|
block();
|
|
|
|
|
2012-11-10 18:32:38 +00:00
|
|
|
request = indexedDB.open(dbName, 1);
|
2012-10-23 16:31:19 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2013-07-10 21:52:35 +00:00
|
|
|
event = yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
ok(event.type == "upgradeneeded", "db doesn't exist");
|
|
|
|
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-10 21:52:35 +00:00
|
|
|
event = yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
|
|
|
|
db = event.target.result;
|
|
|
|
info(db.objectStoreNames.length);
|
|
|
|
ok(!db.objectStoreNames.length, "no object stores");
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
2013-07-10 21:52:35 +00:00
|
|
|
yield undefined;
|
2012-10-23 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="testGenerator.next();"></body>
|
|
|
|
|
|
|
|
</html>
|