1 // Tests for BookReaderImages.php
3 // $$$ TODO -- make the test host configurable/automagic
7 // $$$ set to test host
8 var testHost = 'http://www-testflip.archive.org';
9 //var testHost = 'http://www-mang.archive.org';
11 // Returns locator URL for the given id
12 function jsLocateURL(identifier, book) {
13 var bookURL = testHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
15 bookURL += '&book=' + book;
20 // Set up dummy BookReader class for JSLocate
21 function BookReader() {
24 BookReader.prototype.init = function() {
29 // Test image info - jpeg
30 asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
32 $.getScript( jsLocateURL('armageddonafter00couruoft'), function() {
33 equals(br.bookTitle, 'Armageddon and after', 'Title');
38 asyncTest("Image info for jpeg", function() {
40 var expected = {"width":1349,"height":2105,"bits":8,"type":"jpeg"};
41 var imageInfoURL = br.getPageURI(8) + '&ext=json&callback=?';
43 $.getJSON(imageInfoURL, function(data) {
44 equals(data != null, true, 'data is not null');
46 equals(data.width, expected.width, 'Image width');
47 same(data, expected, 'Image info object');
56 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
58 $.getScript( jsLocateURL('zc-f-c-b-4', 'concept-of-infection'), function() {
59 equals(br.numLeafs, 13, 'numLeafs');
64 asyncTest("Image info for 1-bit jp2", function() {
66 var expected = {"width":3295,"height":2561,"bits":1,"type":"jp2"};
67 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
69 $.getJSON(imageInfoURL, function(data) {
70 equals(data != null, true, 'data is not null');
72 equals(data.width, expected.width, 'Image width');
73 same(data, expected, 'Image info object');
79 /// windwavesatseabr00bige - jp2 zip
80 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
82 $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
83 equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
88 test("Image URI for windwavesatseabr00bige page index 5", function() {
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');
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');
105 // Actually load the image
106 .attr('src', pageURI);
110 /// nybc200109 - 1-bit tiff zip
111 asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
113 $.getScript( jsLocateURL('nybc200109'), function() {
121 asyncTest("Image info for 1-bit tiff", function() {
123 var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
124 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
126 $.getJSON(imageInfoURL, function(data) {
127 equals(data != null, true, 'data is not null');
129 equals(data.width, expected.width, 'Image width');
130 same(data, expected, 'Image info object');
136 asyncTest("Load 1-bit tiff image from zip", function() {
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');
145 .attr('src', pageURI);
150 /// asamoandictiona00pragoog - tiff zip
151 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
153 $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
155 'A Samoan dictionary: English and Samoan, and Samoan and English;',
161 asyncTest("Image info for 8-bit tiff", function() {
163 var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
164 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
166 $.getJSON(imageInfoURL, function(data) {
167 equals(data != null, true, 'data is not null');
169 equals(data.width, expected.width, 'Image width');
170 same(data, expected, 'Image info object');
176 asyncTest("Load tiff image from zip", function() {
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');
185 .attr('src', pageURI);
189 /// hccapp56191900uoft - jpeg tar
190 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
192 $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
193 equals(br.numLeafs, 1101, 'Number of pages');
198 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
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');
207 .attr('src', pageURI);