summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/page_localstorage_snapshotting.html
blob: b64f4b8cabac42d8e8be143072d93b54b2ddb927 (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
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
<script>
/**
 * Helper page used by browser_localStorage_snapshotting.js.
 *
 * We expose methods to be invoked by ContentTask.spawn() calls.
 *
 **/
var pageName = document.location.search.substring(1);
window.addEventListener(
  "load",
  () => { document.getElementById("pageNameH").textContent = pageName; });

function applyMutations(mutations) {
  mutations.forEach(function([key, value]) {
    if (key !== null) {
      if (value === null) {
        localStorage.removeItem(key);
      } else {
        localStorage.setItem(key, value);
      }
    } else {
      localStorage.clear();
    }
  });
}

function getState() {
  let state = {};
  let length = localStorage.length;
  for (let index = 0; index < length; index++) {
    let key = localStorage.key(index);
    state[key] = localStorage.getItem(key);
  }
  return state;
}

function getKeys() {
  return Object.keys(localStorage);
}

function beginExplicitSnapshot() {
  localStorage.beginExplicitSnapshot();
}

function checkpointExplicitSnapshot() {
  localStorage.checkpointExplicitSnapshot();
}

function endExplicitSnapshot() {
  localStorage.endExplicitSnapshot();
}

function getHasSnapshot() {
  return localStorage.hasSnapshot;
}

function getSnapshotUsage() {
  return localStorage.snapshotUsage;
}

</script>
</head>
<body><h2 id="pageNameH"></h2></body>
</html>