1 // Tests for BookReaderImages.php
3 // $$$ TODO -- make the test host configurable/automagic
7 // $$$ set to test host
8 var testHost = 'http://www-mang.archive.org';
10 // Returns locator URL for the given id
11 function jsLocateURL(identifier, book) {
12 var bookURL = testHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
14 bookURL += '&book=' + book;
19 // Set up dummy BookReader class for JSLocate
20 function BookReader() {
23 BookReader.prototype.init = function() {
28 // Test image info - jpeg
29 asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
31 $.getScript( jsLocateURL('armageddonafter00couruoft'), function() {
32 equals(br.bookTitle, 'Armageddon and after', 'Title');
37 asyncTest("Image info for jpeg", function() {
39 var expected = {"width":1349,"height":2105,"bits":8,"type":"jpeg"};
40 var imageInfoURL = br.getPageURI(8) + '&ext=json&callback=?';
42 $.getJSON(imageInfoURL, function(data) {
43 equals(data != null, true, 'data is not null');
45 equals(data.width, expected.width, 'Image width');
46 same(data, expected, 'Image info object');
55 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
57 $.getScript( jsLocateURL('zc-f-c-b-4', 'concept-of-infection'), function() {
58 equals(br.numLeafs, 13, 'numLeafs');
63 asyncTest("Image info for 1-bit jp2", function() {
65 var expected = {"width":3295,"height":2561,"bits":1,"type":"jp2"};
66 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
68 $.getJSON(imageInfoURL, function(data) {
69 equals(data != null, true, 'data is not null');
71 equals(data.width, expected.width, 'Image width');
72 same(data, expected, 'Image info object');
78 /// windwavesatseabr00bige - jp2 zip
79 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
81 $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
82 equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
87 test("Image URI for windwavesatseabr00bige page index 5", function() {
90 var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
91 var pageURI = br.getPageURI(index);
92 var reg = new RegExp('file=.*$');
93 var actualEnding = reg.exec(pageURI);
94 equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
97 asyncTest("Load windwavesatseabr00bige image 5", function() {
98 var pageURI = br.getPageURI(5);
99 var img = new Image();
100 $(img).bind( 'load error', function(eventObj) {
101 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
104 // Actually load the image
105 .attr('src', pageURI);
109 /// nybc200109 - 1-bit tiff zip
110 asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
112 $.getScript( jsLocateURL('nybc200109'), function() {
120 asyncTest("Image info for 1-bit tiff", function() {
122 var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
123 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
125 $.getJSON(imageInfoURL, function(data) {
126 equals(data != null, true, 'data is not null');
128 equals(data.width, expected.width, 'Image width');
129 same(data, expected, 'Image info object');
135 asyncTest("Load 1-bit tiff image from zip", function() {
137 var pageURI = br.getPageURI(6, 16);
138 var img = new Image();
139 $(img).bind( 'load error', function(eventObj) {
140 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
141 equals(this.width, 318, 'Image width');
144 .attr('src', pageURI);
149 /// asamoandictiona00pragoog - tiff zip
150 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
152 $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
154 'A Samoan dictionary: English and Samoan, and Samoan and English;',
160 asyncTest("Image info for 8-bit tiff", function() {
162 var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
163 var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
165 $.getJSON(imageInfoURL, function(data) {
166 equals(data != null, true, 'data is not null');
168 equals(data.width, expected.width, 'Image width');
169 same(data, expected, 'Image info object');
175 asyncTest("Load tiff image from zip", function() {
177 var pageURI = br.getPageURI(23, 8);
178 var img = new Image();
179 $(img).bind( 'load error', function(eventObj) {
180 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
181 equals(this.width, 351, 'Image width');
184 .attr('src', pageURI);
188 /// hccapp56191900uoft - jpeg tar
189 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
191 $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
192 equals(br.numLeafs, 1101, 'Number of pages');
197 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
199 var pageURI = br.getPageURI(6, 8);
200 var img = new Image();
201 $(img).bind( 'load error', function(eventObj) {
202 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
203 equals(this.width, 244, 'Image width');
206 .attr('src', pageURI);