1 // Tests for BookReaderPreview.php
3 // Depends on common.js
7 function Book(identifier, previewWidth, coverWidth, titleWidth, bookId) {
8 this.identifier = identifier;
9 this.previewWidth = previewWidth;
10 this.coverWidth = coverWidth;
11 this.titleWidth = titleWidth;
12 if (bookId === undefined) {
19 // Old books using title page as cover (ignoring marked cover)
20 new Book('coloritsapplicat00andriala', 1974, 1974, 1974),
21 new Book('lietuvostsrmoksl50liet', 1887, 1887, 1887),
22 new Book('oldtestamentrevi02slsn', 2019, 2019, 2019),
24 // Protected book with marked cover returned as cover
25 new Book('joyofsoaringtrai00conw', 2571, 2571, 2419)
28 for (index in books) {
30 var i = index; // closure
32 asyncTest("Load preview for " + books[index].identifier, function() {
36 var identifier = book.identifier;
38 var pageURI = previewURL(identifier, book.bookId, 'preview');
39 var img = new Image();
40 $(img).bind( 'load error', function(eventObj) {
41 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
42 equals(this.width, book.previewWidth, 'Preview width');
45 .attr('src', pageURI);
50 asyncTest("Load cover for " + books[index].identifier, function() {
54 var identifier = book.identifier;
56 var pageURI = previewURL(identifier, book.bookId, 'cover');
57 var img = new Image();
58 $(img).bind( 'load error', function(eventObj) {
59 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
60 equals(this.width, book.coverWidth, 'Cover width');
63 .attr('src', pageURI);
68 asyncTest("Load title for " + books[index].identifier, function() {
72 var identifier = book.identifier;
74 var pageURI = previewURL(identifier, book.bookId, 'title');
75 var img = new Image();
76 $(img).bind( 'load error', function(eventObj) {
77 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
78 equals(this.width, book.titleWidth, 'Title image width');
81 .attr('src', pageURI);
89 var identifier = 'SubBookTest';
90 asyncTest("Load title for book without title specified " + identifier, function() {
93 var pageURI = previewURL(identifier, identifier, 'title');
94 var img = new Image();
95 $(img).bind( 'load error', function(eventObj) {
96 equals(eventObj.type, 'error', 'Load image (' + pageURI + '). Event handler called');
99 .attr('src', pageURI);
104 var subPrefix = 'subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume';
105 asyncTest("Load preview for book in sub-dir " + identifier + '/' + subPrefix, function() {
108 var pageURI = previewURL(identifier, subPrefix, 'title');
109 var img = new Image();
110 $(img).bind( 'load error', function(eventObj) {
111 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
112 equals(this.width, 5100, 'Preview image width');
115 .attr('src', pageURI);