Unit tests for proportional "within width/height" scaling
[bookreader.git] / BookReaderIA / test / unit / Images.js
1 // Tests for BookReaderImages.php
2
3 // Depends on common.js
4
5 module("Images");
6
7 /* Item no longer available
8 // Test image info - jpeg
9 asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
10     expect(1);
11     $.getScript( jsLocateURL('armageddonafter00couruoft'), function() {
12         equals(br.bookTitle, 'Armageddon and after', 'Title');
13         start();
14     });
15 });
16
17 asyncTest("Image info for jpeg", function() {
18     expect(3);
19     var expected = {"width":1349,"height":2105,"bits":8,"type":"jpeg"};
20     var imageInfoURL = br.getPageURI(8) + '&ext=json&callback=?';
21     
22     $.getJSON(imageInfoURL, function(data) {
23         equals(data != null, true, 'data is not null');
24         if (data != null) {
25             equals(data.width, expected.width, 'Image width');
26             same(data, expected, 'Image info object');
27         }
28         start();
29     });
30 });
31 */
32
33 // Test image info
34 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
35     expect(1);
36     $.getScript( jsLocateURL('zc-f-c-b-4', 'concept-of-infection'), function() {
37         equals(br.numLeafs, 13, 'numLeafs');
38         start();
39     });
40 });
41
42 asyncTest("Image info for 1-bit jp2", function() {
43     expect(3);
44     var expected = {"width":3295,"height":2561,"bits":1,"type":"jp2"};
45     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
46     
47     $.getJSON(imageInfoURL, function(data) {
48         equals(data != null, true, 'data is not null');
49         if (data != null) {
50             equals(data.width, expected.width, 'Image width');
51             same(data, expected, 'Image info object');
52         }
53         start();
54     });
55 });
56
57 /// windwavesatseabr00bige - jp2 zip
58 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
59     expect(1);
60     $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
61         equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
62         start();
63     });
64 });
65     
66 test("Image URI for windwavesatseabr00bige page index 5", function() {
67     expect(1);
68     var index = 5;
69     var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
70     var pageURI = br.getPageURI(index);
71     var reg = new RegExp('file=.*$');
72     var actualEnding = reg.exec(pageURI);
73     equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
74 });
75
76 asyncTest("Load windwavesatseabr00bige image 5", function() {
77     var pageURI = br.getPageURI(5);
78     var img = new Image();
79     $(img).bind( 'load error', function(eventObj) {
80         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
81         start();
82     })
83     // Actually load the image
84     .attr('src', pageURI);
85 });
86
87
88 /// nybc200109 - 1-bit tiff zip
89 asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
90     expect(1);
91     $.getScript( jsLocateURL('nybc200109'), function() {
92         equals(br.numLeafs,
93                694,
94                'Number of pages');
95         start();
96     });
97 });
98
99 asyncTest("Image info for 1-bit tiff", function() {
100     expect(3);
101     var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
102     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
103     
104     $.getJSON(imageInfoURL, function(data) {
105         equals(data != null, true, 'data is not null');
106         if (data != null) {
107             equals(data.width, expected.width, 'Image width');
108             same(data, expected, 'Image info object');
109         }
110         start();
111     });
112 });
113
114 asyncTest("Load 1-bit tiff image from zip", function() {
115     expect(2);
116     var pageURI = br.getPageURI(6, 16);
117     var img = new Image();
118     $(img).bind( 'load error', function(eventObj) {
119         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
120         equals(this.width, 1272, 'Image width');
121         start();
122     })
123     .attr('src', pageURI);
124 });
125
126
127
128 /// asamoandictiona00pragoog - tiff zip
129 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
130     expect(1);
131     $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
132         equals(br.bookTitle,
133                'A Samoan dictionary: English and Samoan, and Samoan and English;',
134                'Book title');
135         start();
136     });
137 });
138
139 asyncTest("Image info for 8-bit tiff", function() {
140     expect(3);
141     var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
142     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
143     
144     $.getJSON(imageInfoURL, function(data) {
145         equals(data != null, true, 'data is not null');
146         if (data != null) {
147             equals(data.width, expected.width, 'Image width');
148             same(data, expected, 'Image info object');
149         }
150         start();
151     });
152 });
153
154 asyncTest("Load tiff image from zip", function() {
155     expect(2);
156     var pageURI = br.getPageURI(23, 8);
157     var img = new Image();
158     $(img).bind( 'load error', function(eventObj) {
159         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
160         equals(this.width, 701, 'Image width');
161         start();
162     })
163     .attr('src', pageURI);
164 });
165
166
167 /// hccapp56191900uoft - jpeg tar
168 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
169     expect(1);
170     $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
171         equals(br.numLeafs, 1101, 'Number of pages');
172         start();
173     });
174 });
175
176 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
177     expect(2);
178     var pageURI = br.getPageURI(6, 8);
179     var img = new Image();
180     $(img).bind( 'load error', function(eventObj) {
181         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
182         equals(this.width, 243, 'Image width');
183         start();
184     })
185     .attr('src', pageURI);
186 });
187
188 asyncTest('Load image region - /download/populationsc18400378unit/page/n800_x1544_y4144_w1192_h848_s4.jpg', function() {
189     expect(3);
190     var pageURI = testHost() + '/download/populationsc18400378unit/page/n800_x1544_y4144_w1192_h848_s4.jpg';
191     
192     var img = new Image();
193     $(img).bind( 'load error', function(eventObj) {
194         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
195         equals(this.width, 299, 'Image width');
196         equals(this.height, 212, 'Image height');
197         start();
198     })
199     .attr('src', pageURI);    
200
201 });
202
203 asyncTest('Load image region using decimal coordinates - /download/populationsc18400378unit/page/n800_x0.75_y0.75_w0.25_h0.25_s4.jpg', function() {
204     expect(3);
205     var pageURI = testHost() + '/download/populationsc18400378unit/page/n800_x0.75_y0.75_w0.25_h0.25_s4.jpg';
206     
207     var img = new Image();
208     $(img).bind( 'load error', function(eventObj) {
209         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
210         equals(this.width, 337, 'Image width');
211         equals(this.height, 342, 'Image height');
212         start();
213     })
214     .attr('src', pageURI);    
215
216 });
217
218
219 asyncTest('Load image region - /download/tomslademotorcyc00fitz/page/page3_x256_y96_w1720_h152_s4.jpg', function() {
220     expect(3);
221     var pageURI = testHost() + '/download/tomslademotorcyc00fitz/page/page3_x256_y96_w1720_h152_s4.jpg';
222     
223     var img = new Image();
224     $(img).bind( 'load error', function(eventObj) {
225         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
226         equals(this.width, 430, 'Image width');
227         equals(this.height, 38, 'Image height');
228         start();
229     })
230     .attr('src', pageURI);    
231
232 });
233
234 asyncTest('Load cover, fitting within 400x400', function() {
235     expect(3);
236     var pageURI = testHost() + '/download/mechanicstheor00loverich/page/cover_w400_h400.jpg';
237     
238     var img = new Image();
239     $(img).bind( 'load error', function(eventObj) {
240         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
241         equals(this.width, 264, 'Image width');
242         equals(this.height, 487, 'Image height');
243         start();
244     })
245     .attr('src', pageURI);    
246
247 });
248
249 asyncTest('Load cover, fitting within 100x400', function() {
250     expect(3);
251     var pageURI = testHost() + '/download/mechanicstheor00loverich/page/cover_w100_h400.jpg';
252     
253     var img = new Image();
254     $(img).bind( 'load error', function(eventObj) {
255         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
256         equals(this.width, 132, 'Image width');
257         equals(this.height, 244, 'Image height');
258         start();
259     })
260     .attr('src', pageURI);    
261
262 });
263
264
265 asyncTest('Load image region from tiff, via br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584', function() {
266
267     $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() {
268
269         expect(3);
270         var pageURI = br.getRegionURI(17, undefined, undefined, 1944, 1708, 668, 584);
271         
272         var img = new Image();
273         $(img).bind( 'load error', function(eventObj) {
274             equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
275             equals(this.width, 668, 'Image width');
276             equals(this.height, 584, 'Image height');
277             start();
278         })
279         .attr('src', pageURI);
280         
281     });
282 });
283
284 asyncTest('Same image rotated 90 degrees, br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584_rot90', function() {
285
286     $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() {
287
288         expect(3);
289         var pageURI = br.getRegionURI(17, undefined, 90, 1944, 1708, 668, 584);
290         
291         var img = new Image();
292         $(img).bind( 'load error', function(eventObj) {
293             equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
294             equals(this.width, 584, 'Image width');
295             equals(this.height, 668, 'Image height');
296             start();
297         })
298         .attr('src', pageURI);
299         
300     });
301 });
302