updating tests

This commit is contained in:
Artur Adib 2012-05-24 12:22:46 -04:00
parent 139200e772
commit 932628981f
4 changed files with 72 additions and 26 deletions

View File

@ -14,6 +14,7 @@ include $(topsrcdir)/config/rules.mk
_BROWSER_TEST_FILES = \
head.js \
browser_pdfjs_main.js \
browser_pdfjs_zoom.js \
file_pdfjs_test.pdf \
$(NULL)

View File

@ -32,7 +32,7 @@ function test() {
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
// Thumbnails are created asynchronously - wait for them
waitForElement(document, 'canvas#thumbnail2', function(error) {
waitForElement(document, 'canvas#thumbnail2', function(error, thumbnail) {
if (error)
finish();
@ -42,7 +42,6 @@ function test() {
var pageNumber = document.querySelector('input#pageNumber');
is(parseInt(pageNumber.value), 1, 'initial page is 1');
var thumbnail = document.querySelector('canvas#thumbnail2');
ok(thumbnail, 'thumbnail2 is available');
if (thumbnail) {
thumbnail.click();
@ -73,25 +72,7 @@ function test() {
var viewBookmark = document.querySelector('a#viewBookmark');
viewBookmark.click();
ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
//
// Zoom in/out
//
var zoomOut = document.querySelector('button.zoomOut'),
zoomIn = document.querySelector('button.zoomIn');
// Zoom in
var oldWidth = document.querySelector('canvas#page1').width;
zoomIn.click();
var newWidth = document.querySelector('canvas#page1').width;
ok(oldWidth < newWidth, 'zooming in increases page width (old: '+oldWidth+', new: '+newWidth+')');
// Zoom out
var oldWidth = document.querySelector('canvas#page1').width;
zoomOut.click();
var newWidth = document.querySelector('canvas#page1').width;
ok(oldWidth > newWidth, 'zooming out decreases page width (old: '+oldWidth+', new: '+newWidth+')');
finish();
});
}, true, true);

View File

@ -0,0 +1,63 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
function test() {
waitForExplicitFinish();
var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
var newTabBrowser = gBrowser.getBrowserForTab(tab);
newTabBrowser.addEventListener("pagechange", function onPageChange() {
newTabBrowser.removeEventListener("pagechange", onPageChange, true);
var document = newTabBrowser.contentDocument,
window = newTabBrowser.contentWindow;
//
// Zoom in/out
//
var zoomOut = document.querySelector('button.zoomOut'),
zoomIn = document.querySelector('button.zoomIn');
var newWidth, oldWidth;
// We need to query the DOM every time since zoom in/out operations destroy the canvas element
waitForElement(document, 'canvas#page1', function(error, page1) {
if (error)
finish();
oldWidth = page1.width;
zoomIn.click();
waitForElement(document, 'canvas#page1', function(error, page1) {
if (error)
finish();
newWidth = page1.width;
ok(oldWidth < newWidth, 'zooming in increases page width (old: '+oldWidth+', new: '+newWidth+')');
// Zoom out
oldWidth = newWidth;
zoomOut.click();
waitForElement(document, 'canvas#page1', function(error, page1) {
if (error)
finish();
newWidth = page1.width;
ok(oldWidth > newWidth, 'zooming out decreases page width (old: '+oldWidth+', new: '+newWidth+')');
finish();
});
});
});
}, true, true);
registerCleanupFunction(function() {
gBrowser.removeTab(tab);
});
}

View File

@ -1,19 +1,20 @@
// Waits for element 'el' to exist in the DOM of 'doc' before executing 'callback'
// Waits for element 'sel' to exist in the DOM of 'doc' before executing 'callback'
// Useful when elements are created asynchronously, e.g. after a Web Worker task
function waitForElement(doc, el, callback) {
function waitForElement(doc, sel, callback) {
var time = 0,
interval = 10,
timeout = 5000;
var checkEl = setInterval(function() {
if (doc.querySelector(el)) {
var el = doc.querySelector(sel);
if (el) {
clearInterval(checkEl);
if (callback) callback();
if (callback) callback(null, el);
}
time += interval;
if (time > timeout) {
ok(false, 'waitForElement timed out on element: '+el);
ok(false, 'waitForElement timed out on element: '+sel);
clearInterval(checkEl);
if (callback) callback(true);
}