mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 05:35:31 +00:00
7be7b11a1c
This patch is generated by the following sed script: find . ! -wholename '*/.hg*' -type f \( -iname '*.html' -o -iname '*.xhtml' -o -iname '*.xul' -o -iname '*.js' \) -exec sed -i -e 's/\(\(text\|application\)\/javascript\);version=1.[0-9]/\1/g' {} \; MozReview-Commit-ID: AzhtdwJwVNg --HG-- extra : rebase_source : e8f90249454c0779d926f87777f457352961748d
124 lines
3.6 KiB
HTML
124 lines
3.6 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
Bug 970517 - Storage inspector front end - tests
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Storage inspector test for correct values in the sidebar</title>
|
|
</head>
|
|
<body>
|
|
<script type="application/javascript">
|
|
"use strict";
|
|
let partialHostname = location.hostname.match(/^[^.]+(\..*)$/)[1];
|
|
let cookieExpiresTime = 2000000000000;
|
|
// Setting up some cookies to eat.
|
|
document.cookie = "c1=" + JSON.stringify([
|
|
"foo", "Bar", {
|
|
foo: "Bar"
|
|
}]) + "; expires=" + new Date(cookieExpiresTime).toGMTString() +
|
|
"; path=/browser";
|
|
document.cookie = "cs2=sessionCookie; path=/; domain=" + partialHostname;
|
|
// URLEncoded cookie
|
|
document.cookie = "c_encoded=" + encodeURIComponent(JSON.stringify({foo: {foo1: "bar"}}));
|
|
|
|
// ... and some local storage items ..
|
|
const es6 = "for";
|
|
localStorage.setItem("ls1", JSON.stringify({
|
|
es6, the: "win", baz: [0, 2, 3, {
|
|
deep: "down",
|
|
nobody: "cares"
|
|
}]}));
|
|
localStorage.setItem("ls2", "foobar-2");
|
|
localStorage.setItem("ls3", "http://foobar.com/baz.php");
|
|
// ... and finally some session storage items too
|
|
sessionStorage.setItem("ss1", "This#is#an#array");
|
|
sessionStorage.setItem("ss2", "This~is~another~array");
|
|
sessionStorage.setItem("ss3", "this#is~an#object~foo#bar");
|
|
sessionStorage.setItem("ss4", "#array##with#empty#items");
|
|
// long string that is almost an object and might trigger exponential
|
|
// regexp backtracking
|
|
let s = "a".repeat(1000);
|
|
sessionStorage.setItem("ss5", `${s}=${s}=${s}=${s}&${s}=${s}&${s}`);
|
|
console.log("added cookies and stuff from main page");
|
|
|
|
let idbGenerator = function*() {
|
|
let request = indexedDB.open("idb1", 1);
|
|
request.onerror = function() {
|
|
throw new Error("error opening db connection");
|
|
};
|
|
let db = yield new Promise(done => {
|
|
request.onupgradeneeded = event => {
|
|
let db = event.target.result;
|
|
let store1 = db.createObjectStore("obj1", { keyPath: "id" });
|
|
store1.createIndex("name", "name", { unique: false });
|
|
store1.createIndex("email", "email", { unique: true });
|
|
db.createObjectStore("obj2", { keyPath: "id2" });
|
|
store1.transaction.oncomplete = () => {
|
|
done(db);
|
|
};
|
|
};
|
|
});
|
|
|
|
// Prevents AbortError
|
|
yield new Promise(done => {
|
|
request.onsuccess = done;
|
|
});
|
|
|
|
let transaction = db.transaction(["obj1", "obj2"], "readwrite");
|
|
let store1 = transaction.objectStore("obj1");
|
|
let store2 = transaction.objectStore("obj2");
|
|
|
|
store1.add({id: 1, name: "foo", email: "foo@bar.com"});
|
|
store1.add({id: 2, name: "foo2", email: "foo2@bar.com"});
|
|
store1.add({id: 3, name: "foo2", email: "foo3@bar.com"});
|
|
store2.add({
|
|
id2: 1,
|
|
name: "foo",
|
|
email: "foo@bar.com",
|
|
extra: "baz"});
|
|
|
|
db.close();
|
|
|
|
request = indexedDB.open("idb2", 1);
|
|
let db2 = yield new Promise(done => {
|
|
request.onupgradeneeded = event => {
|
|
let db2 = event.target.result;
|
|
let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
|
|
store3.createIndex("name2", "name2", { unique: true });
|
|
store3.transaction.oncomplete = () => {
|
|
done(db2);
|
|
};
|
|
};
|
|
});
|
|
|
|
// Prevents AbortError during close()
|
|
yield new Promise(done => {
|
|
request.onsuccess = done;
|
|
});
|
|
|
|
db2.close();
|
|
console.log("added cookies and stuff from main page");
|
|
};
|
|
|
|
function deleteDB(dbName) {
|
|
return new Promise(resolve => {
|
|
dump("removing database " + dbName + " from " + document.location + "\n");
|
|
indexedDB.deleteDatabase(dbName).onsuccess = resolve;
|
|
});
|
|
}
|
|
|
|
window.setup = function*() {
|
|
yield idbGenerator();
|
|
};
|
|
|
|
window.clear = function*() {
|
|
yield deleteDB("idb1");
|
|
yield deleteDB("idb2");
|
|
|
|
dump("removed indexedDB data from " + document.location + "\n");
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|