-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·139 lines (99 loc) · 3.87 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>FileStorage Test</title>
<meta name="description" content="">
<link rel="stylesheet" href="css/main.css">
<!-- FileStorage min -->
<script src="dist/fileStorage.min.js"></script>
<script>
"use strict";
fileStorage.filePath = "dist/workers/";
document.onreadystatechange = function () {
if (document.readyState == "complete") {
testMethod("iframe-auto");
testMethod("iframe-filesystem", "filesystem");
testMethod("iframe-indexeddb", "indexeddb");
testMethod("iframe-websql", "websql");
testMethod("iframe-ram", "ram");
testMethod("iframe-none", "none");
}
};
//-- Test storage methods -- pass nothing to automatically test
function testMethod(el, method) {
var iframe = document.getElementById(el);
iframe.style.background = "red";
//-- Simple events
var evt = new CustomEvent("stored");
//-- Test auto picking
var store = new fileStorage.storage(method);
//-- Check that selected method was used
if(method && store.getStorageType() != method) {
//iframe.style.background = "green";
return;
}
//-- Say what we selected
if(!method) {
document.getElementById("selected").innerHTML = store.getStorageType();
}
//-- Links must be absolute for workers
store.batch(["/tests/testpage.html", "/imgs/storage-closet.png"], function() {
iframe.dispatchEvent(evt);
});
iframe.addEventListener("stored", function() {
store.get("/tests/testpage.html", function(url) {
iframe.src = url;
});
}, false);
iframe.onload = function() {
var srcs, resources;
if(store.getStorageType() == "filesystem" ||
store.getStorageType() == "none") {
iframe.style.background = "green";
}
srcs = iframe.contentDocument.querySelectorAll('[src]');
resources = Array.prototype.slice.call(srcs);
resources.forEach(function(item){
var src = item.getAttribute("src");
store.get(src, function(url){
item.setAttribute("src", url);
iframe.style.background = "green";
});
});
}
}
</script>
</head>
<body>
<div id="controls">
</div>
<h1>fileStorage Test</h1>
<p>Testing persistence of different methods</p>
<div class="auto-test">
<h3>auto-selected: <em id="selected"></em></h3>
<iframe id="iframe-auto" src="tests/defaultpage.html"></iframe>
</div>
<div class="test">
<h3>storage: <em>filesystem</em></h3>
<iframe id="iframe-filesystem" src="tests/defaultpage.html"></iframe>
</div>
<div class="test">
<h3>storage: <em>indexeddb</em></h3>
<iframe id="iframe-indexeddb" src="tests/defaultpage.html"></iframe>
</div>
<div class="test">
<h3>storage: <em>websql</em></h3>
<iframe id="iframe-websql" src="tests/defaultpage.html"></iframe>
</div>
<div class="test">
<h3>storage: <em>ram</em></h3>
<iframe id="iframe-ram" src="tests/defaultpage.html"></iframe>
</div>
<div class="test">
<h3>storage: <em>none</em></h3>
<iframe id="iframe-none" src="tests/defaultpage.html"></iframe>
</div>
</body>
</html>