1 // The buffer to store the results. We output the results after all
2 // tests finish. Note that we cannot have a DOM element where the
3 // results are stored in HTMLs because the DOM element to store
4 // results may change the number of pages.
8 function appendResult(result)
10 _results += '<br>' + result;
13 function pageNumberForElementShouldBe(id, expectedPageNumber)
15 var actualPageNumber = internals.pageNumber(document.getElementById(id));
16 if (actualPageNumber == expectedPageNumber)
17 appendResult('PASS: page number of "' + id + '" is ' + actualPageNumber);
19 appendResult('FAIL: expected page number of "' + id + '" is ' + expectedPageNumber + '. Was ' + actualPageNumber);
24 function numberOfPagesShouldBe(expectedNumberOfPages, pageWidthInPixels, pageHeightInPixels)
26 // pageWidthInPixels and pageHeightInPixels can be omitted. If omitted, 800x600 is used.
27 var actualNumberOfPages;
28 if (pageWidthInPixels && pageHeightInPixels)
29 actualNumberOfPages = internals.numberOfPages(pageWidthInPixels, pageHeightInPixels);
31 actualNumberOfPages = internals.numberOfPages();
33 if (actualNumberOfPages == expectedNumberOfPages)
34 appendResult('PASS: number of pages is ' + actualNumberOfPages);
36 appendResult('FAIL: expected number of pages is ' + expectedNumberOfPages + '. Was ' + actualNumberOfPages);
41 function runPrintingTest(testFunction)
43 if (window.testRunner) {
47 _results += '<p>Exception: ' + err.toString();
52 _results += '<br>All tests passed';
54 _results += 'This test requires testRunner. You can test this manually with the above description.';
57 var resultElement = document.createElement('p');
58 resultElement.innerHTML = _results;
59 var output = document.getElementById("console") || document.body;
60 output.appendChild(resultElement);
63 function ratioToPageHeightToPixels(heightInRatioToPageHeight)
65 var pageHeightInPixels = 600 * 1.25;
66 return Math.floor(pageHeightInPixels * heightInRatioToPageHeight);
69 function createBlockWithRatioToPageHeight(id, heightInRatioToPageHeight)
71 var element = document.createElement("div");
73 element.style.height = ratioToPageHeightToPixels(heightInRatioToPageHeight) + "px";
74 document.getElementById("sandbox").appendChild(element);
78 function createBlockWithNumberOfLines(id, childLines)
80 var element = document.createElement("div");
82 for (var i = 0; i < childLines; ++i) {
83 element.appendChild(document.createTextNode("line" + i));
84 element.appendChild(document.createElement("br"));
86 // Make sure that one page has about 20 lines.
87 element.style.lineHeight = ratioToPageHeightToPixels(0.05) + "px";
88 document.getElementById("sandbox").appendChild(element);