mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-08-15 02:29:04 +00:00
146 lines
4.2 KiB
HTML
146 lines
4.2 KiB
HTML
|
<!--
|
||
|
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;
|
||
|
const dbName = location.pathname + location.search;
|
||
|
|
||
|
// 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);
|
||
|
request.onerror = errorHandler;
|
||
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
||
|
request.onsuccess = unexpectedSuccessHandler;
|
||
|
let event = yield undefined;
|
||
|
|
||
|
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;
|
||
|
event = yield undefined;
|
||
|
|
||
|
ok(db === event.target.result, "created database");
|
||
|
|
||
|
objectStore =
|
||
|
db.transaction(objectStoreName).objectStore(objectStoreName);
|
||
|
objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
|
||
|
event = yield undefined;
|
||
|
|
||
|
ok(testValue == event.target.result, "data exists");
|
||
|
|
||
|
let iframe = document.createElement("iframe");
|
||
|
iframe.setAttribute("mozbrowser", "");
|
||
|
// 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);
|
||
|
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);
|
||
|
yield undefined;
|
||
|
|
||
|
request = indexedDB.open(dbName, 1);
|
||
|
request.onerror = errorHandler;
|
||
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
||
|
request.onsuccess = grabEventAndContinueHandler;
|
||
|
event = yield undefined;
|
||
|
|
||
|
db = event.target.result;
|
||
|
db.onerror = errorHandler;
|
||
|
|
||
|
objectStore =
|
||
|
db.transaction(objectStoreName).objectStore(objectStoreName);
|
||
|
objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
|
||
|
event = yield undefined;
|
||
|
|
||
|
ok(testValue == event.target.result, "data still exists");
|
||
|
|
||
|
finish();
|
||
|
yield undefined;
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
|
||
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||
|
</head>
|
||
|
|
||
|
<body onload="testGenerator.next();"></body>
|
||
|
|
||
|
</html>
|