mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1159385 - Make PDFJS browser-chrome tests e10s compatible. r=yury
This commit is contained in:
parent
af838ad249
commit
e4b6aa22d0
@ -1,12 +1,10 @@
|
||||
[DEFAULT]
|
||||
support-files = file_pdfjs_test.pdf
|
||||
support-files =
|
||||
file_pdfjs_test.pdf
|
||||
head.js
|
||||
|
||||
[browser_pdfjs_main.js]
|
||||
skip-if = e10s # Bug 1159385
|
||||
[browser_pdfjs_navigation.js]
|
||||
skip-if = e10s # Bug 1159385
|
||||
[browser_pdfjs_savedialog.js]
|
||||
[browser_pdfjs_views.js]
|
||||
skip-if = e10s # Bug 1159385
|
||||
[browser_pdfjs_zoom.js]
|
||||
skip-if = e10s # Bug 1159385
|
||||
|
@ -4,9 +4,7 @@
|
||||
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
|
||||
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
|
||||
|
||||
function test() {
|
||||
var tab;
|
||||
|
||||
add_task(function* test() {
|
||||
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
|
||||
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
|
||||
@ -17,82 +15,53 @@ function test() {
|
||||
|
||||
info('Pref action: ' + handlerInfo.preferredAction);
|
||||
|
||||
waitForExplicitFinish();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
|
||||
function* (newTabBrowser) {
|
||||
ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
|
||||
|
||||
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
|
||||
var newTabBrowser = gBrowser.getBrowserForTab(tab);
|
||||
newTabBrowser.addEventListener("load", function eventHandler() {
|
||||
newTabBrowser.removeEventListener("load", eventHandler, true);
|
||||
yield waitForPdfJS(newTabBrowser);
|
||||
|
||||
var document = newTabBrowser.contentDocument,
|
||||
window = newTabBrowser.contentWindow;
|
||||
yield ContentTask.spawn(newTabBrowser, null, function* () {
|
||||
//
|
||||
// Overall sanity tests
|
||||
//
|
||||
ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
|
||||
|
||||
// Runs tests after all 'load' event handlers have fired off
|
||||
window.addEventListener("documentload", function() {
|
||||
runTests(document, window, tab, function () {
|
||||
closePDFViewer(window, finish);
|
||||
//
|
||||
// Sidebar: open
|
||||
//
|
||||
var sidebar = content.document.querySelector('button#sidebarToggle'),
|
||||
outerContainer = content.document.querySelector('div#outerContainer');
|
||||
|
||||
sidebar.click();
|
||||
ok(outerContainer.classList.contains('sidebarOpen'), "sidebar opens on click");
|
||||
|
||||
//
|
||||
// Sidebar: close
|
||||
//
|
||||
sidebar.click();
|
||||
ok(!outerContainer.classList.contains('sidebarOpen'), "sidebar closes on click");
|
||||
|
||||
//
|
||||
// Page change from prev/next buttons
|
||||
//
|
||||
var prevPage = content.document.querySelector('button#previous'),
|
||||
nextPage = content.document.querySelector('button#next');
|
||||
|
||||
var pgNumber = content.document.querySelector('input#pageNumber').value;
|
||||
is(parseInt(pgNumber, 10), 1, 'initial page is 1');
|
||||
|
||||
//
|
||||
// Bookmark button
|
||||
//
|
||||
var viewBookmark = content.document.querySelector('a#viewBookmark');
|
||||
viewBookmark.click();
|
||||
|
||||
ok(viewBookmark.href.length > 0, "viewBookmark button has href");
|
||||
|
||||
var viewer = content.wrappedJSObject.PDFViewerApplication;
|
||||
yield viewer.close();
|
||||
});
|
||||
}, false, true);
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
function runTests(document, window, tab, callback) {
|
||||
|
||||
//
|
||||
// Overall sanity tests
|
||||
//
|
||||
ok(document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
|
||||
ok('PDFViewerApplication' in window.wrappedJSObject,
|
||||
"window content has viewer object");
|
||||
|
||||
//
|
||||
// Browser Find
|
||||
//
|
||||
ok(gBrowser.isFindBarInitialized(tab), "Browser FindBar initialized!");
|
||||
|
||||
//
|
||||
// Sidebar: open
|
||||
//
|
||||
var sidebar = document.querySelector('button#sidebarToggle'),
|
||||
outerContainer = document.querySelector('div#outerContainer');
|
||||
|
||||
sidebar.click();
|
||||
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
|
||||
|
||||
//
|
||||
// Sidebar: close
|
||||
//
|
||||
sidebar.click();
|
||||
ok(!outerContainer.classList.contains('sidebarOpen'), 'sidebar closes on click');
|
||||
|
||||
//
|
||||
// Page change from prev/next buttons
|
||||
//
|
||||
var prevPage = document.querySelector('button#previous'),
|
||||
nextPage = document.querySelector('button#next');
|
||||
|
||||
var pageNumber = document.querySelector('input#pageNumber');
|
||||
is(parseInt(pageNumber.value), 1, 'initial page is 1');
|
||||
|
||||
//
|
||||
// Bookmark button
|
||||
//
|
||||
var viewBookmark = document.querySelector('a#viewBookmark');
|
||||
viewBookmark.click();
|
||||
ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
|
||||
|
||||
callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys PDF.js viewer opened document.
|
||||
*/
|
||||
function closePDFViewer(window, callback) {
|
||||
var viewer = window.wrappedJSObject.PDFViewerApplication;
|
||||
viewer.close().then(callback);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -139,9 +139,7 @@ const TESTS = [
|
||||
}
|
||||
];
|
||||
|
||||
function test() {
|
||||
var tab;
|
||||
|
||||
add_task(function* test() {
|
||||
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
|
||||
|
||||
@ -151,51 +149,73 @@ function test() {
|
||||
|
||||
info('Pref action: ' + handlerInfo.preferredAction);
|
||||
|
||||
waitForExplicitFinish();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
|
||||
function* (newTabBrowser) {
|
||||
yield waitForPdfJS(newTabBrowser);
|
||||
|
||||
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
var newTabBrowser = gBrowser.getBrowserForTab(tab);
|
||||
newTabBrowser.addEventListener("load", function eventHandler() {
|
||||
newTabBrowser.removeEventListener("load", eventHandler, true);
|
||||
|
||||
var document = newTabBrowser.contentDocument,
|
||||
window = newTabBrowser.contentWindow;
|
||||
|
||||
// Runs tests after all 'load' event handlers have fired off
|
||||
window.addEventListener("documentload", function() {
|
||||
runTests(document, window, function () {
|
||||
var pageNumber = document.querySelector('input#pageNumber');
|
||||
is(pageNumber.value, pageNumber.max, "Document is left on the last page");
|
||||
finish();
|
||||
yield ContentTask.spawn(newTabBrowser, null, function* () {
|
||||
// Check if PDF is opened with internal viewer
|
||||
ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
|
||||
});
|
||||
}, false, true);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function runTests(document, window, finish) {
|
||||
// Check if PDF is opened with internal viewer
|
||||
ok(document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
|
||||
yield ContentTask.spawn(newTabBrowser, null, contentSetUp);
|
||||
|
||||
// Wait for outline items, the start the navigation actions
|
||||
waitForOutlineItems(document).then(function () {
|
||||
// The key navigation has to happen in page-fit, otherwise it won't scroll
|
||||
// trough a complete page
|
||||
setZoomToPageFit(document).then(function () {
|
||||
runNextTest(document, window, finish);
|
||||
}, function () {
|
||||
ok(false, "Current scale has been set to 'page-fit'");
|
||||
finish();
|
||||
yield Task.spawn(runTests(newTabBrowser));
|
||||
|
||||
yield ContentTask.spawn(newTabBrowser, null, function*() {
|
||||
let pageNumber = content.document.querySelector('input#pageNumber');
|
||||
is(pageNumber.value, pageNumber.max, "Document is left on the last page");
|
||||
});
|
||||
});
|
||||
}, function () {
|
||||
ok(false, "Outline items have been found");
|
||||
finish();
|
||||
});
|
||||
});
|
||||
|
||||
function* contentSetUp() {
|
||||
/**
|
||||
* Outline Items gets appended to the document later on we have to
|
||||
* wait for them before we start to navigate though document
|
||||
*
|
||||
* @param document
|
||||
* @returns {deferred.promise|*}
|
||||
*/
|
||||
function waitForOutlineItems(document) {
|
||||
return new Promise((resolve, reject) => {
|
||||
document.addEventListener("outlineloaded", function outlineLoaded(evt) {
|
||||
document.removeEventListener("outlineloaded", outlineLoaded);
|
||||
var outlineCount = evt.detail.outlineCount;
|
||||
|
||||
if (document.querySelectorAll(".outlineItem").length === outlineCount) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The key navigation has to happen in page-fit, otherwise it won't scroll
|
||||
* through a complete page
|
||||
*
|
||||
* @param document
|
||||
* @returns {deferred.promise|*}
|
||||
*/
|
||||
function setZoomToPageFit(document) {
|
||||
return new Promise((resolve) => {
|
||||
document.addEventListener("pagerendered", function onZoom(e) {
|
||||
document.removeEventListener("pagerendered", onZoom);
|
||||
document.querySelector("#viewer").click();
|
||||
resolve();
|
||||
});
|
||||
|
||||
var select = document.querySelector("select#scaleSelect");
|
||||
select.selectedIndex = 2;
|
||||
select.dispatchEvent(new Event("change"));
|
||||
});
|
||||
}
|
||||
|
||||
yield waitForOutlineItems(content.document);
|
||||
yield setZoomToPageFit(content.document);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,99 +227,55 @@ function runTests(document, window, finish) {
|
||||
* @param test
|
||||
* @param callback
|
||||
*/
|
||||
function runNextTest(document, window, endCallback) {
|
||||
var test = TESTS.shift(),
|
||||
deferred = Promise.defer(),
|
||||
pageNumber = document.querySelector('input#pageNumber');
|
||||
function* runTests(browser) {
|
||||
yield ContentTask.spawn(browser, TESTS, function* (TESTS) {
|
||||
let window = content;
|
||||
let document = window.document;
|
||||
|
||||
// Add an event-listener to wait for page to change, afterwards resolve the promise
|
||||
var timeout = window.setTimeout(() => deferred.reject(), 5000);
|
||||
window.addEventListener('pagechange', function pageChange() {
|
||||
if (pageNumber.value == test.expectedPage) {
|
||||
window.removeEventListener('pagechange', pageChange);
|
||||
window.clearTimeout(timeout);
|
||||
deferred.resolve(pageNumber.value);
|
||||
for (let test of TESTS) {
|
||||
let deferred = {};
|
||||
deferred.promise = new Promise((resolve, reject) => {
|
||||
deferred.resolve = resolve;
|
||||
deferred.reject = reject;
|
||||
});
|
||||
|
||||
let pageNumber = document.querySelector('input#pageNumber');
|
||||
|
||||
// Add an event-listener to wait for page to change, afterwards resolve the promise
|
||||
let timeout = window.setTimeout(() => deferred.reject(), 5000);
|
||||
window.addEventListener('pagechange', function pageChange() {
|
||||
if (pageNumber.value == test.expectedPage) {
|
||||
window.removeEventListener('pagechange', pageChange);
|
||||
window.clearTimeout(timeout);
|
||||
deferred.resolve(+pageNumber.value);
|
||||
}
|
||||
});
|
||||
|
||||
// Get the element and trigger the action for changing the page
|
||||
var el = document.querySelector(test.action.selector);
|
||||
ok(el, "Element '" + test.action.selector + "' has been found");
|
||||
|
||||
// The value option is for input case
|
||||
if (test.action.value)
|
||||
el.value = test.action.value;
|
||||
|
||||
// Dispatch the event for changing the page
|
||||
if (test.action.event == "keydown") {
|
||||
var ev = document.createEvent("KeyboardEvent");
|
||||
ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
|
||||
test.action.keyCode, 0);
|
||||
el.dispatchEvent(ev);
|
||||
}
|
||||
else {
|
||||
var ev = new Event(test.action.event);
|
||||
}
|
||||
el.dispatchEvent(ev);
|
||||
|
||||
let pgNumber = yield deferred.promise;
|
||||
is(pgNumber, test.expectedPage, test.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Get the element and trigger the action for changing the page
|
||||
var el = document.querySelector(test.action.selector);
|
||||
ok(el, "Element '" + test.action.selector + "' has been found");
|
||||
|
||||
// The value option is for input case
|
||||
if (test.action.value)
|
||||
el.value = test.action.value;
|
||||
|
||||
// Dispatch the event for changing the page
|
||||
if (test.action.event == "keydown") {
|
||||
var ev = document.createEvent("KeyboardEvent");
|
||||
ev.initKeyEvent("keydown", true, true, null, false, false, false, false,
|
||||
test.action.keyCode, 0);
|
||||
el.dispatchEvent(ev);
|
||||
}
|
||||
else {
|
||||
var ev = new Event(test.action.event);
|
||||
}
|
||||
el.dispatchEvent(ev);
|
||||
|
||||
|
||||
// When the promise gets resolved we call the next test if there are any left
|
||||
// or else we call the final callback which will end the test
|
||||
deferred.promise.then(function (pgNumber) {
|
||||
is(pgNumber, test.expectedPage, test.message);
|
||||
|
||||
if (TESTS.length)
|
||||
runNextTest(document, window, endCallback);
|
||||
else
|
||||
endCallback();
|
||||
}, function () {
|
||||
ok(false, "Test '" + test.message + "' failed with timeout.");
|
||||
endCallback();
|
||||
var viewer = content.wrappedJSObject.PDFViewerApplication;
|
||||
yield viewer.close();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Outline Items gets appended to the document latter on we have to
|
||||
* wait for them before we start to navigate though document
|
||||
*
|
||||
* @param document
|
||||
* @returns {deferred.promise|*}
|
||||
*/
|
||||
function waitForOutlineItems(document) {
|
||||
var deferred = Promise.defer();
|
||||
document.addEventListener("outlineloaded", function outlineLoaded(evt) {
|
||||
document.removeEventListener("outlineloaded", outlineLoaded);
|
||||
var outlineCount = evt.detail.outlineCount;
|
||||
|
||||
if (document.querySelectorAll(".outlineItem").length === outlineCount) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* The key navigation has to happen in page-fit, otherwise it won't scroll
|
||||
* trough a complete page
|
||||
*
|
||||
* @param document
|
||||
* @returns {deferred.promise|*}
|
||||
*/
|
||||
function setZoomToPageFit(document) {
|
||||
var deferred = Promise.defer();
|
||||
document.addEventListener("pagerendered", function onZoom(e) {
|
||||
document.removeEventListener("pagerendered", onZoom);
|
||||
document.querySelector("#viewer").click();
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
var select = document.querySelector("select#scaleSelect");
|
||||
select.selectedIndex = 2;
|
||||
select.dispatchEvent(new Event("change"));
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,7 @@
|
||||
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
|
||||
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
|
||||
|
||||
function test() {
|
||||
var tab;
|
||||
|
||||
add_task(function* test() {
|
||||
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
|
||||
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
|
||||
@ -17,70 +15,47 @@ function test() {
|
||||
|
||||
info('Pref action: ' + handlerInfo.preferredAction);
|
||||
|
||||
waitForExplicitFinish();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
|
||||
function* (browser) {
|
||||
// check that PDF is opened with internal viewer
|
||||
yield waitForPdfJS(browser);
|
||||
|
||||
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
|
||||
var newTabBrowser = gBrowser.getBrowserForTab(tab);
|
||||
newTabBrowser.addEventListener("load", function eventHandler() {
|
||||
newTabBrowser.removeEventListener("load", eventHandler, true);
|
||||
yield ContentTask.spawn(browser, null, function* () {
|
||||
ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
|
||||
|
||||
var document = newTabBrowser.contentDocument,
|
||||
window = newTabBrowser.contentWindow;
|
||||
//open sidebar
|
||||
var sidebar = content.document.querySelector('button#sidebarToggle');
|
||||
var outerContainer = content.document.querySelector('div#outerContainer');
|
||||
|
||||
// Runs tests after all 'load' event handlers have fired off
|
||||
window.addEventListener("documentload", function() {
|
||||
runTests(document, window, function () {
|
||||
closePDFViewer(window, finish);
|
||||
sidebar.click();
|
||||
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
|
||||
|
||||
// check that thumbnail view is open
|
||||
var thumbnailView = content.document.querySelector('div#thumbnailView');
|
||||
var outlineView = content.document.querySelector('div#outlineView');
|
||||
|
||||
is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
|
||||
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
|
||||
|
||||
//switch to outline view
|
||||
var viewOutlineButton = content.document.querySelector('button#viewOutline');
|
||||
viewOutlineButton.click();
|
||||
|
||||
is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected');
|
||||
is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected');
|
||||
|
||||
//switch back to thumbnail view
|
||||
var viewThumbnailButton = content.document.querySelector('button#viewThumbnail');
|
||||
viewThumbnailButton.click();
|
||||
|
||||
is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
|
||||
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
|
||||
|
||||
sidebar.click();
|
||||
|
||||
var viewer = content.wrappedJSObject.PDFViewerApplication;
|
||||
yield viewer.close();
|
||||
});
|
||||
}, false, true);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function runTests(document, window, callback) {
|
||||
// check that PDF is opened with internal viewer
|
||||
ok(document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
|
||||
|
||||
//open sidebar
|
||||
var sidebar = document.querySelector('button#sidebarToggle');
|
||||
var outerContainer = document.querySelector('div#outerContainer');
|
||||
|
||||
sidebar.click();
|
||||
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
|
||||
|
||||
// check that thumbnail view is open
|
||||
var thumbnailView = document.querySelector('div#thumbnailView');
|
||||
var outlineView = document.querySelector('div#outlineView');
|
||||
|
||||
is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
|
||||
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
|
||||
|
||||
//switch to outline view
|
||||
var viewOutlineButton = document.querySelector('button#viewOutline');
|
||||
viewOutlineButton.click();
|
||||
|
||||
is(outlineView.getAttribute('class'), '', 'Outline view is visible when selected');
|
||||
is(thumbnailView.getAttribute('class'), 'hidden', 'Thumbnail view is hidden when outline is selected');
|
||||
|
||||
//switch back to thumbnail view
|
||||
var viewThumbnailButton = document.querySelector('button#viewThumbnail');
|
||||
viewThumbnailButton.click();
|
||||
|
||||
is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
|
||||
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
|
||||
|
||||
sidebar.click();
|
||||
|
||||
callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys PDF.js viewer opened document.
|
||||
*/
|
||||
function closePDFViewer(window, callback) {
|
||||
var viewer = window.wrappedJSObject.PDFViewerApplication;
|
||||
viewer.close().then(callback);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -28,6 +28,7 @@ const TESTS = [
|
||||
{
|
||||
action: {
|
||||
keyboard: true,
|
||||
keyCode: 61,
|
||||
event: "+"
|
||||
},
|
||||
expectedZoom: 1, // 1 - zoom in
|
||||
@ -37,6 +38,7 @@ const TESTS = [
|
||||
{
|
||||
action: {
|
||||
keyboard: true,
|
||||
keyCode: 109,
|
||||
event: "-"
|
||||
},
|
||||
expectedZoom: -1, // -1 - zoom out
|
||||
@ -54,11 +56,7 @@ const TESTS = [
|
||||
}
|
||||
];
|
||||
|
||||
var initialWidth; // the initial width of the PDF document
|
||||
var previousWidth; // the width of the PDF document at previous step/test
|
||||
|
||||
function test() {
|
||||
var tab;
|
||||
add_task(function* test() {
|
||||
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"]
|
||||
.getService(Ci.nsIHandlerService);
|
||||
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
@ -72,114 +70,83 @@ function test() {
|
||||
|
||||
info('Pref action: ' + handlerInfo.preferredAction);
|
||||
|
||||
waitForExplicitFinish();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" + "#zoom=100" },
|
||||
function* (newTabBrowser) {
|
||||
yield waitForPdfJS(newTabBrowser);
|
||||
|
||||
tab = gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
|
||||
var newTabBrowser = gBrowser.getBrowserForTab(tab);
|
||||
yield ContentTask.spawn(newTabBrowser, TESTS, function* (TESTS) {
|
||||
let document = content.document;
|
||||
|
||||
newTabBrowser.addEventListener("load", function eventHandler() {
|
||||
newTabBrowser.removeEventListener("load", eventHandler, true);
|
||||
function waitForRender() {
|
||||
return new Promise((resolve) => {
|
||||
document.addEventListener("pagerendered", function onPageRendered(e) {
|
||||
if(e.detail.pageNumber !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var document = newTabBrowser.contentDocument,
|
||||
window = newTabBrowser.contentWindow;
|
||||
document.removeEventListener("pagerendered", onPageRendered, true);
|
||||
resolve();
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
// Runs tests after all 'load' event handlers have fired off
|
||||
window.addEventListener("documentload", function() {
|
||||
initialWidth = parseInt(document.querySelector("div#pageContainer1").style.width);
|
||||
previousWidth = initialWidth;
|
||||
runTests(document, window, function () {
|
||||
closePDFViewer(window, finish);
|
||||
// check that PDF is opened with internal viewer
|
||||
ok(content.document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in content.wrappedJSObject, "window content has PDFJS object");
|
||||
|
||||
let initialWidth, previousWidth;
|
||||
initialWidth = previousWidth =
|
||||
parseInt(content.document.querySelector("div#pageContainer1").style.width);
|
||||
|
||||
for (let test of TESTS) {
|
||||
// We zoom using an UI element
|
||||
var ev;
|
||||
if (test.action.selector) {
|
||||
// Get the element and trigger the action for changing the zoom
|
||||
var el = document.querySelector(test.action.selector);
|
||||
ok(el, "Element '" + test.action.selector + "' has been found");
|
||||
|
||||
if (test.action.index){
|
||||
el.selectedIndex = test.action.index;
|
||||
}
|
||||
|
||||
// Dispatch the event for changing the zoom
|
||||
ev = new Event(test.action.event);
|
||||
}
|
||||
// We zoom using keyboard
|
||||
else {
|
||||
// Simulate key press
|
||||
ev = new content.KeyboardEvent("keydown",
|
||||
{ key: test.action.event,
|
||||
keyCode: test.action.keyCode,
|
||||
ctrlKey: true });
|
||||
el = content;
|
||||
}
|
||||
|
||||
el.dispatchEvent(ev);
|
||||
yield waitForRender();
|
||||
|
||||
var pageZoomScale = content.document.querySelector('select#scaleSelect');
|
||||
|
||||
// The zoom value displayed in the zoom select
|
||||
var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
|
||||
|
||||
let pageContainer = content.document.querySelector('div#pageContainer1');
|
||||
let actualWidth = parseInt(pageContainer.style.width);
|
||||
|
||||
// the actual zoom of the PDF document
|
||||
let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
|
||||
is(computedZoomValue, zoomValue, "Content has correct zoom");
|
||||
|
||||
// Check that document zooms in the expected way (in/out)
|
||||
let zoom = (actualWidth - previousWidth) * test.expectedZoom;
|
||||
ok(zoom > 0, test.message);
|
||||
|
||||
previousWidth = actualWidth;
|
||||
}
|
||||
|
||||
var viewer = content.wrappedJSObject.PDFViewerApplication;
|
||||
yield viewer.close();
|
||||
});
|
||||
}, false, true);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function runTests(document, window, callback) {
|
||||
// check that PDF is opened with internal viewer
|
||||
ok(document.querySelector('div#viewer'), "document content has viewer UI");
|
||||
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
|
||||
|
||||
// Start the zooming tests after the document is loaded
|
||||
waitForDocumentLoad(document).then(function () {
|
||||
zoomPDF(document, window, TESTS.shift(), callback);
|
||||
});
|
||||
}
|
||||
|
||||
function waitForDocumentLoad(document) {
|
||||
var deferred = Promise.defer();
|
||||
var interval = setInterval(function () {
|
||||
if (document.querySelector("div#pageContainer1") != null){
|
||||
clearInterval(interval);
|
||||
deferred.resolve();
|
||||
}
|
||||
}, 500);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function zoomPDF(document, window, test, endCallback) {
|
||||
var renderedPage;
|
||||
|
||||
document.addEventListener("pagerendered", function onPageRendered(e) {
|
||||
if(e.detail.pageNumber !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.removeEventListener("pagerendered", onPageRendered, true);
|
||||
|
||||
var pageZoomScale = document.querySelector('select#scaleSelect');
|
||||
|
||||
// The zoom value displayed in the zoom select
|
||||
var zoomValue = pageZoomScale.options[pageZoomScale.selectedIndex].innerHTML;
|
||||
|
||||
let pageContainer = document.querySelector('div#pageContainer1');
|
||||
let actualWidth = parseInt(pageContainer.style.width);
|
||||
|
||||
// the actual zoom of the PDF document
|
||||
let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
|
||||
is(computedZoomValue, zoomValue, "Content has correct zoom");
|
||||
|
||||
// Check that document zooms in the expected way (in/out)
|
||||
let zoom = (actualWidth - previousWidth) * test.expectedZoom;
|
||||
ok(zoom > 0, test.message);
|
||||
|
||||
// Go to next test (if there is any) or finish
|
||||
var nextTest = TESTS.shift();
|
||||
if (nextTest) {
|
||||
previousWidth = actualWidth;
|
||||
zoomPDF(document, window, nextTest, endCallback);
|
||||
}
|
||||
else
|
||||
endCallback();
|
||||
}, true);
|
||||
|
||||
// We zoom using an UI element
|
||||
if (test.action.selector) {
|
||||
// Get the element and trigger the action for changing the zoom
|
||||
var el = document.querySelector(test.action.selector);
|
||||
ok(el, "Element '" + test.action.selector + "' has been found");
|
||||
|
||||
if (test.action.index){
|
||||
el.selectedIndex = test.action.index;
|
||||
}
|
||||
|
||||
// Dispatch the event for changing the zoom
|
||||
el.dispatchEvent(new Event(test.action.event));
|
||||
}
|
||||
// We zoom using keyboard
|
||||
else {
|
||||
// Simulate key press
|
||||
EventUtils.synthesizeKey(test.action.event, { ctrlKey: true });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys PDF.js viewer opened document.
|
||||
*/
|
||||
function closePDFViewer(window, callback) {
|
||||
var viewer = window.wrappedJSObject.PDFViewerApplication;
|
||||
viewer.close().then(callback);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
11
browser/extensions/pdfjs/test/head.js
Normal file
11
browser/extensions/pdfjs/test/head.js
Normal file
@ -0,0 +1,11 @@
|
||||
function waitForPdfJS(browser) {
|
||||
// Runs tests after all 'load' event handlers have fired off
|
||||
return ContentTask.spawn(browser, null, function* () {
|
||||
yield new Promise((resolve) => {
|
||||
content.addEventListener("documentload", function listener() {
|
||||
content.removeEventListener("documentload", listener, false);
|
||||
resolve();
|
||||
}, false, true);
|
||||
});
|
||||
});
|
||||
}
|
@ -337,7 +337,7 @@ this.BrowserTestUtils = {
|
||||
* Waits for an event to be fired on a specified element.
|
||||
*
|
||||
* Usage:
|
||||
* let promiseEvent = BrowserTestUtil.waitForEvent(element, "eventName");
|
||||
* let promiseEvent = BrowserTestUtils.waitForEvent(element, "eventName");
|
||||
* // Do some processing here that will cause the event to be fired
|
||||
* // ...
|
||||
* // Now yield until the Promise is fulfilled
|
||||
|
Loading…
Reference in New Issue
Block a user