2012-10-23 20:31:19 +04: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, "appFrame: " + message] }));
|
|
|
|
}
|
|
|
|
|
|
|
|
function info(message)
|
|
|
|
{
|
|
|
|
alert(JSON.stringify({ type: "info",
|
|
|
|
args: ["appFrame: " + message] }));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 22:32:38 +04:00
|
|
|
const dbName = location.pathname + location.search;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
2012-11-10 22:32:38 +04:00
|
|
|
// Determine whether our parent iframe asked us to create a remote
|
|
|
|
// browser frame here.
|
|
|
|
let remote_browser;
|
|
|
|
if (location.search.indexOf("remote_browser=true") != -1) {
|
|
|
|
remote_browser = true;
|
|
|
|
}
|
|
|
|
else if (location.search.indexOf("remote_browser=false") != -1) {
|
|
|
|
remote_browser = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(false, "Expected remote_browser={true,false} in query string.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = indexedDB.open(dbName, 1);
|
2012-10-23 20:31:19 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2012-10-23 20:31:19 +04: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-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
|
|
|
ok(db === event.target.result, "created database");
|
|
|
|
|
|
|
|
objectStore =
|
|
|
|
db.transaction(objectStoreName).objectStore(objectStoreName);
|
|
|
|
objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
|
|
|
ok(testValue == event.target.result, "data exists");
|
|
|
|
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
iframe.setAttribute("mozbrowser", "");
|
2012-11-10 22:32:38 +04:00
|
|
|
// Send our querystring to the subframe because
|
|
|
|
// webapp_clearBrowserData_browserFrame uses its pathname + querystring to
|
|
|
|
// open a database which it assumes hasn't been touched by another test.
|
|
|
|
iframe.setAttribute("src", "webapp_clearBrowserData_browserFrame.html" + location.search);
|
|
|
|
iframe.setAttribute("remote", remote_browser);
|
2012-10-23 20:31:19 +04:00
|
|
|
iframe.addEventListener("mozbrowsershowmodalprompt", function(event) {
|
|
|
|
let message = JSON.parse(event.detail.message);
|
|
|
|
switch (message.type) {
|
|
|
|
case "block":
|
|
|
|
info("blocking browserFrame");
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
let request = navigator.mozApps.getSelf();
|
|
|
|
request.onsuccess = function() {
|
|
|
|
let app = request.result;
|
|
|
|
ok(app, "got app");
|
|
|
|
|
|
|
|
info("clearing browser data");
|
|
|
|
app.clearBrowserData();
|
|
|
|
|
|
|
|
info("unblocking browserFrame");
|
|
|
|
event.detail.unblock();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "done":
|
|
|
|
continueToNextStepSync();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
alert(event.detail.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
info("loading browser frame");
|
|
|
|
|
|
|
|
document.body.appendChild(iframe);
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
2012-11-10 22:32:38 +04:00
|
|
|
request = indexedDB.open(dbName, 1);
|
2012-10-23 20:31:19 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
|
|
|
db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
|
|
|
|
objectStore =
|
|
|
|
db.transaction(objectStoreName).objectStore(objectStoreName);
|
|
|
|
objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
|
|
|
|
ok(testValue == event.target.result, "data still exists");
|
|
|
|
|
|
|
|
finish();
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2012-10-23 20:31:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="testGenerator.next();"></body>
|
|
|
|
|
|
|
|
</html>
|