Merge branch 'master' into jp2levels
[bookreader.git] / BookReaderIA / test / unit / Images.js
1 // Tests for BookReaderImages.php
2
3 // $$$ TODO -- make the test host configurable/automagic
4
5 module("Images");
6
7 // $$$ set to test host
8 var testHost = 'http://www-testflip.archive.org';
9 //var testHost = 'http://www-mang.archive.org';
10
11 // Returns locator URL for the given id
12 function jsLocateURL(identifier, book) {
13     var bookURL = testHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
14     if (book) {
15         bookURL += '&book=' + book;
16     }
17     return bookURL;
18 }
19
20 // Set up dummy BookReader class for JSLocate
21 function BookReader() {
22 };
23
24 BookReader.prototype.init = function() {
25     return true;
26 };
27
28
29 // Test image info - jpeg
30 asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
31     expect(1);
32     $.getScript( jsLocateURL('armageddonafter00couruoft'), function() {
33         equals(br.bookTitle, 'Armageddon and after', 'Title');
34         start();
35     });
36 });
37
38 asyncTest("Image info for jpeg", function() {
39     expect(3);
40     var expected = {"width":1349,"height":2105,"bits":8,"type":"jpeg"};
41     var imageInfoURL = br.getPageURI(8) + '&ext=json&callback=?';
42     
43     $.getJSON(imageInfoURL, function(data) {
44         equals(data != null, true, 'data is not null');
45         if (data != null) {
46             equals(data.width, expected.width, 'Image width');
47             same(data, expected, 'Image info object');
48         }
49         start();
50     });
51 });
52
53
54
55 // Test image info
56 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
57     expect(1);
58     $.getScript( jsLocateURL('zc-f-c-b-4', 'concept-of-infection'), function() {
59         equals(br.numLeafs, 13, 'numLeafs');
60         start();
61     });
62 });
63
64 asyncTest("Image info for 1-bit jp2", function() {
65     expect(3);
66     var expected = {"width":3295,"height":2561,"bits":1,"type":"jp2"};
67     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
68     
69     $.getJSON(imageInfoURL, function(data) {
70         equals(data != null, true, 'data is not null');
71         if (data != null) {
72             equals(data.width, expected.width, 'Image width');
73             same(data, expected, 'Image info object');
74         }
75         start();
76     });
77 });
78
79 /// windwavesatseabr00bige - jp2 zip
80 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
81     expect(1);
82     $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
83         equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
84         start();
85     });
86 });
87     
88 test("Image URI for windwavesatseabr00bige page index 5", function() {
89     expect(1);
90     var index = 5;
91     var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
92     var pageURI = br.getPageURI(index);
93     var reg = new RegExp('file=.*$');
94     var actualEnding = reg.exec(pageURI);
95     equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
96 });
97
98 asyncTest("Load windwavesatseabr00bige image 5", function() {
99     var pageURI = br.getPageURI(5);
100     var img = new Image();
101     $(img).bind( 'load error', function(eventObj) {
102         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
103         start();
104     })
105     // Actually load the image
106     .attr('src', pageURI);
107 });
108
109
110 /// nybc200109 - 1-bit tiff zip
111 asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
112     expect(1);
113     $.getScript( jsLocateURL('nybc200109'), function() {
114         equals(br.numLeafs,
115                694,
116                'Number of pages');
117         start();
118     });
119 });
120
121 asyncTest("Image info for 1-bit tiff", function() {
122     expect(3);
123     var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
124     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
125     
126     $.getJSON(imageInfoURL, function(data) {
127         equals(data != null, true, 'data is not null');
128         if (data != null) {
129             equals(data.width, expected.width, 'Image width');
130             same(data, expected, 'Image info object');
131         }
132         start();
133     });
134 });
135
136 asyncTest("Load 1-bit tiff image from zip", function() {
137     expect(2);
138     var pageURI = br.getPageURI(6, 16);
139     var img = new Image();
140     $(img).bind( 'load error', function(eventObj) {
141         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
142         equals(this.width, 1272, 'Image width');
143         start();
144     })
145     .attr('src', pageURI);
146 });
147
148
149
150 /// asamoandictiona00pragoog - tiff zip
151 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
152     expect(1);
153     $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
154         equals(br.bookTitle,
155                'A Samoan dictionary: English and Samoan, and Samoan and English;',
156                'Book title');
157         start();
158     });
159 });
160
161 asyncTest("Image info for 8-bit tiff", function() {
162     expect(3);
163     var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
164     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
165     
166     $.getJSON(imageInfoURL, function(data) {
167         equals(data != null, true, 'data is not null');
168         if (data != null) {
169             equals(data.width, expected.width, 'Image width');
170             same(data, expected, 'Image info object');
171         }
172         start();
173     });
174 });
175
176 asyncTest("Load tiff image from zip", function() {
177     expect(2);
178     var pageURI = br.getPageURI(23, 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, 702, 'Image width');
183         start();
184     })
185     .attr('src', pageURI);
186 });
187
188
189 /// hccapp56191900uoft - jpeg tar
190 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
191     expect(1);
192     $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
193         equals(br.numLeafs, 1101, 'Number of pages');
194         start();
195     });
196 });
197
198 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
199     expect(2);
200     var pageURI = br.getPageURI(6, 8);
201     var img = new Image();
202     $(img).bind( 'load error', function(eventObj) {
203         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
204         equals(this.width, 244, 'Image width');
205         start();
206     })
207     .attr('src', pageURI);
208 });
209