-
Notifications
You must be signed in to change notification settings - Fork 216
/
promises.html
82 lines (74 loc) · 2.97 KB
/
promises.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>imgcache.js - Tests - promises</title>
<script src="../lib/imgcache.js"></script>
<script src="../lib/imgcache-promise.js"></script>
<link rel="stylesheet" href="examples.css">
</head>
<body>
<h1>imgcache-promise.js - Promises</h1>
<div class="clearfix">
<h3>Errors</h3>
<ul class="errors" id="errors">
</ul>
</div>
<div class="clearfix">
<div id="actions">
<p>Check out the console to see what's going on - failure to load cordova is expected</p>
</div>
<div class="note">
<p>Don't forget to accept your browser request to store data on the local computer!</p>
</div>
<div class="note">
<p>If this file is opened in Chrome from a "file://" url, run Chrome with the following flags: <code>--allow-file-access-from-files --allow-file-access</code> in order to <a href="http://stackoverflow.com/questions/6427870/html5-file-api-security-error-while-reading-a-file">avoid a security error</a>.</p>
<p>Otherwise run the page from a web server - <a href="http://updates.html5rocks.com/2011/08/Debugging-the-Filesystem-API">More info</a></p>
</div>
</div>
<script>
var correctUrl = 'https://data-gov.tw.rpi.edu/w/images/thumb/f/f1/Processing_Tutorial_Finished.png/180px-Processing_Tutorial_Finished.png',
wrongUrl = 'http://expected.error.error/error.jpg';
var addError = function (error) {
document.getElementById('errors').appendChild(document.createElement('li').appendChild(document.createTextNode(error)));
};
ImgCachePromise.cacheFile(correctUrl, function (progressEvent) {
console.log('progress: ' + progressEvent.loaded + '/' + progressEvent.total);
})
.then(function () {
console.log('SUCCESS - expected: A cached');
return ImgCachePromise.getCachedFile(correctUrl)
})
.catch(function () {
addError('unexpected: A not cached');
})
.then(function (file_entry) {
console.log('SUCCESS - expected: B got file entry');
console.log(file_entry);
})
.catch(function () {
addError('unexpected: B not cached');
})
.then(function () {
/* test errors : those are expected to call fail callbacks */
return ImgCachePromise.cacheFile(wrongUrl)
})
.then(function () {
addError('unexpected: C cached');
})
.catch(function () {
console.log('SUCCESS - expected: C not cached');
})
.then(function () {
return ImgCachePromise.getCachedFile(wrongUrl)
})
.then(function (file_entry) {
addError('unexpected: D got file entry');
console.log(file_entry);
})
.catch(function () {
console.log('SUCCESS - expected: D not cached');
});
</script>
</body>
</html>