Simplify image unit tests -- single code path for both load and error
[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 asyncTest("JSLocate for windwavesatseabr00bige", function() {
24     expect(1);
25     $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
26         equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
27         start();
28     });
29 });
30     
31 test("Image URI for windwavesatseabr00bige page index 5", function() {
32     expect(1);
33     var index = 5;
34     var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
35     var pageURI = br.getPageURI(index);
36     var reg = new RegExp('file=.*$');
37     var actualEnding = reg.exec(pageURI);
38     equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
39 });
40
41 asyncTest("Load windwavesatseabr00bige image 5", function() {
42     var pageURI = br.getPageURI(5);
43     var img = new Image();
44     $(img).bind( 'load error', function(eventObj) {
45         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
46         start();
47     })
48     // Actually load the image
49     .attr('src', pageURI);
50 });
51
52 asyncTest("JSLocate for asamoandictiona00pragoog - tiff book", function() {
53     expect(1);
54     $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
55         equals(br.bookTitle,
56                'A Samoan dictionary: English and Samoan, and Samoan and English;',
57                'Book title');
58         start();
59     });
60 });
61
62 asyncTest("Load tiff image", function() {
63     expect(2);
64     var pageURI = br.getPageURI(23, 8);
65     var img = new Image();
66     $(img).bind( 'load error', function(eventObj) {
67         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
68         equals(this.width, 351, 'Image width');
69         start();
70     })
71     .attr('src', pageURI);
72 });