This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.html
120 lines (101 loc) · 3.42 KB
/
test.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="http://dev.jquery.com/view/trunk/qunit/testrunner.js" type="text/javascript"></script>
<script src="jquery.cacheimage.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://dev.jquery.com/view/trunk/qunit/testsuite.css" type="text/css" media="screen" />
<style type="text/css">
#main { display: none; }
</style>
</head>
<body>
<h1>jquery.cacheimage.js tests</h1>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div id="main">
<img src="fixtures/images/stateless-logo.png" id="image1" alt="" />
</div>
<script type="text/javascript">
//<![CDATA[
(function ($) {
test('Image from DOM should be loaded into memory', function () {
stop();
$('#image1').cacheImage({
load: function (e) {
ok(this.height > 0, 'Image loaded');
start();
},
error: function (e) {
ok(false, 'Image ' + this.src + ' did not load');
start();
}
});
});
test('Image from static call should be loaded into memory', function () {
stop();
var image = $.cacheImage(url('fixtures/images/stateless-logo.png'), {
load: function (e) {
ok(this.height > 0, 'Image loaded');
start();
},
error: function (e) {
ok(false, 'Image ' + this.src + ' did not load');
start();
}
});
ok(image.height === 0, 'Image not in cache');
});
test('Multiple images from static call should be loaded into memory', function () {
var loaded = 0;
stop();
$.cacheImage([url('fixtures/images/stateless-logo.png'), url('fixtures/images/stateless-logo.png')], {
load: function (e) {
loaded++;
if (loaded === 2) {
ok(this.height > 0, 'Images loaded');
start();
}
},
error: function (e) {
ok(false, 'Image ' + this.src + ' did not load');
start();
}
});
});
test('Error callback should be called on error', function () {
stop();
var image = $.cacheImage('http://localhost/no-such-image', {
error: function (e) {
ok(e.type === 'error', 'Error was caught');
start();
}
});
});
test('Complete callback should be called on error', function () {
stop();
var image = $.cacheImage('http://localhost/no-such-image', {
complete: function (e) {
ok(true, 'Complete callback was triggered on error');
start();
}
});
});
test('Complete callback should be called on load', function () {
stop();
var image = $.cacheImage('fixtures/images/stateless-logo.png', {
complete: function (e) {
ok(true, 'Complete callback was triggered on load');
start();
}
});
});
})(jQuery);
//]]>
</script>
</body>
</html>