Add reference to bug report to regression test
[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-mang.archive.org';
9
10 // Returns locator URL for the given id
11 function jsLocateURL(bookId) {
12     return testHost + '/bookreader/BookReaderJSLocate.php?id=' + bookId;
13 }
14
15 // Set up dummy BookReader class for JSLocate
16 function BookReader() {
17 };
18
19 BookReader.prototype.init = function() {
20     return true;
21 };
22
23
24 /// windwavesatseabr00bige - jp2 zip
25 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
26     expect(1);
27     $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
28         equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
29         start();
30     });
31 });
32     
33 test("Image URI for windwavesatseabr00bige page index 5", function() {
34     expect(1);
35     var index = 5;
36     var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
37     var pageURI = br.getPageURI(index);
38     var reg = new RegExp('file=.*$');
39     var actualEnding = reg.exec(pageURI);
40     equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
41 });
42
43 asyncTest("Load windwavesatseabr00bige image 5", function() {
44     var pageURI = br.getPageURI(5);
45     var img = new Image();
46     $(img).bind( 'load error', function(eventObj) {
47         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
48         start();
49     })
50     // Actually load the image
51     .attr('src', pageURI);
52 });
53
54
55 /// asamoandictiona00pragoog - tiff zip
56 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
57     expect(1);
58     $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
59         equals(br.bookTitle,
60                'A Samoan dictionary: English and Samoan, and Samoan and English;',
61                'Book title');
62         start();
63     });
64 });
65
66 asyncTest("Load tiff image from zip", function() {
67     expect(2);
68     var pageURI = br.getPageURI(23, 8);
69     var img = new Image();
70     $(img).bind( 'load error', function(eventObj) {
71         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
72         equals(this.width, 351, 'Image width');
73         start();
74     })
75     .attr('src', pageURI);
76 });
77
78
79 /// hccapp56191900uoft - jpeg tar
80 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
81     expect(1);
82     $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
83         equals(br.numLeafs, 1101, 'Number of pages');
84         start();
85     });
86 });
87
88 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
89     expect(2);
90     var pageURI = br.getPageURI(6, 8);
91     var img = new Image();
92     $(img).bind( 'load error', function(eventObj) {
93         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
94         equals(this.width, 244, 'Image width');
95         start();
96     })
97     .attr('src', pageURI);
98 });
99