summaryrefslogtreecommitdiff
path: root/toolkit/devtools/storage/test/storage-complex-values.html
blob: aaaa0ef9b9a410ce5eff59a1abf2565073cc4e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!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;version=1.7">

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;
// ... and some local storage items ..
var 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");
console.log("added cookies and stuff from main page");

function success(event) {
  setupIDB.next(event);
}

window.idbGenerator = function*(callback) {
  let request = indexedDB.open("idb1", 1);
  request.onupgradeneeded = success;
  request.onerror = function(e) {
    throw new Error("error opening db connection");
  };
  let event = yield undefined;
  let db = event.target.result;
  let store1 = db.createObjectStore("obj1", { keyPath: "id" });
  store1.createIndex("name", "name", { unique: false });
  store1.createIndex("email", "email", { unique: true });
  let store2 = db.createObjectStore("obj2", { keyPath: "id2" });

  store1.add({id: 1, name: "foo", email: "foo@bar.com"}).onsuccess = success;
  yield undefined;
  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"}).onsuccess = success;
  yield undefined;
  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"}).onsuccess = success;
  yield undefined;
  store2.add({id2: 1, name: "foo", email: "foo@bar.com", extra: "baz"}).onsuccess = success;
  yield undefined;

  store1.transaction.oncomplete = success;
  yield undefined;
  db.close();

  request = indexedDB.open("idb2", 1);
  request.onupgradeneeded = success;
  event = yield undefined;

  let db2 = event.target.result;
  let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
  store3.createIndex("name2", "name2", { unique: true });
  store3.transaction.oncomplete = success;
  yield undefined;
  db2.close();
  console.log("added cookies and stuff from main page");
  callback();
}

function successClear(event) {
  clearIterator.next(event);
}

window.clear = function*(callback) {
  document.cookie = "c1=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/browser";
  document.cookie = "cs2=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
  localStorage.clear();
  sessionStorage.clear();
  indexedDB.deleteDatabase("idb1").onsuccess = successClear;
  yield undefined;
  indexedDB.deleteDatabase("idb2").onsuccess = successClear;
  yield undefined;
  console.log("removed cookies and stuff from main page");
  callback();
}
</script>
</body>
</html>