Back out 5 changesets (bug 1159385, bug 1165558) for making browser_pdfjs_zoom.js frequently leak on Windows

CLOSED TREE

Backed out changeset 9c0a6b934c7a (bug 1159385)
Backed out changeset 1dcf1d5a95ce (bug 1159385)
Backed out changeset 50b20aa3fd46 (bug 1159385)
Backed out changeset 863379c3fe31 (bug 1159385)
Backed out changeset 8decc8f8fcb1 (bug 1165558)
This commit is contained in:
Phil Ringnalda 2015-10-13 21:36:10 -07:00
parent 122a5a5176
commit bad48ad6fa
7 changed files with 328 additions and 323 deletions

View File

@ -1,4 +1,5 @@
[DEFAULT]
skip-if = e10s # Bug 1159385
support-files = file_pdfjs_test.pdf
[browser_pdfjs_main.js]

View File

@ -4,7 +4,9 @@
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() {
function test() {
var tab;
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');
@ -15,68 +17,70 @@ add_task(function* test() {
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
function* (newTabBrowser) {
ok(gBrowser.isFindBarInitialized(), "Browser FindBar initialized!");
waitForExplicitFinish();
registerCleanupFunction(function() {
gBrowser.removeTab(tab);
});
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
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, tab, finish);
}, false, true);
}, true);
}
function runTests(document, window, tab, callback) {
//
// Overall sanity tests
//
let [ viewer, PDFJS ] = yield ContentTask.spawn(newTabBrowser, null, function() {
return [ content.document.querySelector('div#viewer') !== null,
'PDFJS' in content.wrappedJSObject ];
});
ok(document.querySelector('div#viewer'), "document content has viewer UI");
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
ok(viewer, "document content has viewer UI");
ok(PDFJS, "window content has PDFJS object");
//
// Browser Find
//
ok(gBrowser.isFindBarInitialized(tab), "Browser FindBar initialized!");
//
// Sidebar: open
//
let contains = yield ContentTask.spawn(newTabBrowser, null, function() {
var sidebar = content.document.querySelector('button#sidebarToggle'),
outerContainer = content.document.querySelector('div#outerContainer');
var sidebar = document.querySelector('button#sidebarToggle'),
outerContainer = document.querySelector('div#outerContainer');
sidebar.click();
return outerContainer.classList.contains('sidebarOpen');
});
ok(contains, "sidebar opens on click");
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
//
// Sidebar: close
//
contains = yield ContentTask.spawn(newTabBrowser, null, function() {
var sidebar = content.document.querySelector('button#sidebarToggle'),
outerContainer = content.document.querySelector('div#outerContainer');
sidebar.click();
return outerContainer.classList.contains('sidebarOpen');
});
ok(!contains, "sidebar closes on click");
ok(!outerContainer.classList.contains('sidebarOpen'), 'sidebar closes on click');
//
// Page change from prev/next buttons
//
let pageNumber = yield ContentTask.spawn(newTabBrowser, null, function() {
var prevPage = content.document.querySelector('button#previous'),
nextPage = content.document.querySelector('button#next');
var prevPage = document.querySelector('button#previous'),
nextPage = document.querySelector('button#next');
return content.document.querySelector('input#pageNumber').value;
});
is(parseInt(pageNumber), 1, 'initial page is 1');
var pageNumber = document.querySelector('input#pageNumber');
is(parseInt(pageNumber.value), 1, 'initial page is 1');
//
// Bookmark button
//
let numBookmarks = yield ContentTask.spawn(newTabBrowser, null, function() {
var viewBookmark = content.document.querySelector('a#viewBookmark');
var viewBookmark = document.querySelector('a#viewBookmark');
viewBookmark.click();
return viewBookmark.href.length;
});
ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
ok(numBookmarks > 0, "viewBookmark button has href");
});
});
callback();
}

View File

@ -139,7 +139,9 @@ const TESTS = [
}
];
add_task(function* test() {
function test() {
var tab;
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let handlerInfo = mimeService.getFromTypeAndExtension('application/pdf', 'pdf');
@ -149,85 +151,51 @@ add_task(function* test() {
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
function* (newTabBrowser) {
waitForExplicitFinish();
registerCleanupFunction(function() {
gBrowser.removeTab(tab);
});
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
yield ContentTask.spawn(newTabBrowser, null, function* () {
yield new Promise((resolve) => {
content.addEventListener("documentload", function() {
resolve();
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();
});
}, false, true);
});
});
}, true);
}
let [ viewer, pdfjs ] = yield ContentTask.spawn(newTabBrowser, null, function* () {
function runTests(document, window, finish) {
// Check if PDF is opened with internal viewer
return [ content.document.querySelector('div#viewer') !== null,
'PDFJS' in content.wrappedJSObject ];
ok(document.querySelector('div#viewer'), "document content has viewer UI");
ok('PDFJS' in window.wrappedJSObject, "window content has PDFJS object");
// 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();
});
ok(viewer, "document content has viewer UI");
ok(pdfjs, "window content has PDFJS object");
yield ContentTask.spawn(newTabBrowser, null, contentSetUp);
yield Task.spawn(runTests(newTabBrowser));
let [ pageNumberValue, pageNumberMax ] = yield ContentTask.spawn(newTabBrowser, null,
function*() {
let pageNumber = content.document.querySelector('input#pageNumber');
return [ pageNumber.value, pageNumber.max ];
}, function () {
ok(false, "Outline items have been found");
finish();
});
is(pageNumberValue, pageNumberMax, "Document is left on the last page");
});
});
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);
}
/**
@ -239,22 +207,13 @@ function* contentSetUp() {
* @param test
* @param callback
*/
function* runTests(browser) {
for (let test of TESTS) {
let pgNumber = yield ContentTask.spawn(browser, test, function* (test) {
let window = content;
let document = window.document;
let deferred = {};
deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});
let pageNumber = document.querySelector('input#pageNumber');
function runNextTest(document, window, endCallback) {
var test = TESTS.shift(),
deferred = Promise.defer(),
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);
var timeout = window.setTimeout(() => deferred.reject(), 5000);
window.addEventListener('pagechange', function pageChange() {
if (pageNumber.value == test.expectedPage) {
window.removeEventListener('pagechange', pageChange);
@ -265,6 +224,7 @@ function* runTests(browser) {
// 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)
@ -282,10 +242,64 @@ function* runTests(browser) {
}
el.dispatchEvent(ev);
return yield deferred.promise;
// 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();
});
}
/**
* 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();
}
});
info("Element '" + test.action.selector + "' has been found");
is(pgNumber, test.expectedPage, test.message);
}
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;
}

View File

@ -4,7 +4,9 @@
const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
add_task(function* test() {
function test() {
var tab;
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');
@ -15,79 +17,60 @@ add_task(function* test() {
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
function* (browser) {
// check that PDF is opened with internal viewer
let [ viewer, pdfjs ] = yield ContentTask.spawn(browser, null, function* () {
yield new Promise((resolve) => {
content.addEventListener("documentload", function documentload() {
content.removeEventListener("documentload", documentload);
resolve();
});
});
return [ content.document.querySelector('div#viewer') !== null,
'PDFJS' in content.wrappedJSObject ]
waitForExplicitFinish();
registerCleanupFunction(function() {
gBrowser.removeTab(tab);
});
ok(viewer, "document content has viewer UI");
ok(pdfjs, "window content has PDFJS object");
tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
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, finish);
}, 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
let sidebarOpen = yield ContentTask.spawn(browser, null, function* () {
var sidebar = content.document.querySelector('button#sidebarToggle');
var outerContainer = content.document.querySelector('div#outerContainer');
var sidebar = document.querySelector('button#sidebarToggle');
var outerContainer = document.querySelector('div#outerContainer');
sidebar.click();
return outerContainer.classList.contains('sidebarOpen');
});
ok(sidebarOpen, 'sidebar opens on click');
ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
// check that thumbnail view is open
let [ thumbnailClass, outlineClass ] = yield ContentTask.spawn(browser, null, function* () {
var thumbnailView = content.document.querySelector('div#thumbnailView');
var outlineView = content.document.querySelector('div#outlineView');
var thumbnailView = document.querySelector('div#thumbnailView');
var outlineView = document.querySelector('div#outlineView');
return [ thumbnailView.getAttribute('class'),
outlineView.getAttribute('class') ]
});
is(thumbnailClass, null, 'Initial view is thumbnail view');
is(outlineClass, 'hidden', 'Outline view is hidden initially');
is(thumbnailView.getAttribute('class'), null, 'Initial view is thumbnail view');
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden initially');
//switch to outline view
[ thumbnailClass, outlineClass ] = yield ContentTask.spawn(browser, null, function* () {
var viewOutlineButton = content.document.querySelector('button#viewOutline');
var viewOutlineButton = document.querySelector('button#viewOutline');
viewOutlineButton.click();
var thumbnailView = content.document.querySelector('div#thumbnailView');
var outlineView = content.document.querySelector('div#outlineView');
return [ thumbnailView.getAttribute('class'),
outlineView.getAttribute('class') ];
});
is(thumbnailClass, 'hidden', 'Thumbnail view is hidden when outline is selected');
is(outlineClass, '', 'Outline view is visible when selected');
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
[ thumbnailClass, outlineClass ] = yield ContentTask.spawn(browser, null, function* () {
var viewThumbnailButton = content.document.querySelector('button#viewThumbnail');
var viewThumbnailButton = document.querySelector('button#viewThumbnail');
viewThumbnailButton.click();
var thumbnailView = content.document.querySelector('div#thumbnailView');
var outlineView = content.document.querySelector('div#outlineView');
is(thumbnailView.getAttribute('class'), '', 'Thumbnail view is visible when selected');
is(outlineView.getAttribute('class'), 'hidden', 'Outline view is hidden when thumbnail is selected');
let rval = [ thumbnailView.getAttribute('class'),
outlineView.getAttribute('class') ];
var sidebar = content.document.querySelector('button#sidebarToggle');
sidebar.click();
return rval;
});
is(thumbnailClass, '', 'Thumbnail view is visible when selected');
is(outlineClass, 'hidden', 'Outline view is hidden when thumbnail is selected');
});
});
callback();
}

View File

@ -28,7 +28,6 @@ const TESTS = [
{
action: {
keyboard: true,
keyCode: 61,
event: "+"
},
expectedZoom: 1, // 1 - zoom in
@ -38,7 +37,6 @@ const TESTS = [
{
action: {
keyboard: true,
keyCode: 109,
event: "-"
},
expectedZoom: -1, // -1 - zoom out
@ -56,7 +54,11 @@ const TESTS = [
}
];
add_task(function* test() {
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;
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"]
.getService(Ci.nsIHandlerService);
let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
@ -70,92 +72,70 @@ add_task(function* test() {
info('Pref action: ' + handlerInfo.preferredAction);
yield BrowserTestUtils.withNewTab({ gBrowser, url: TESTROOT + "file_pdfjs_test.pdf" },
function* (newTabBrowser) {
let initialWidth = 0; // the initial width of the PDF document
let previousWidth = 0; // the width of the PDF document at previous step/test
waitForExplicitFinish();
registerCleanupFunction(function() {
gBrowser.removeTab(tab);
});
tab = gBrowser.selectedTab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
var newTabBrowser = gBrowser.getBrowserForTab(tab);
newTabBrowser.addEventListener("load", function eventHandler() {
newTabBrowser.removeEventListener("load", eventHandler, true);
var document = newTabBrowser.contentDocument,
window = newTabBrowser.contentWindow;
initialWidth = previousWidth =
yield ContentTask.spawn(newTabBrowser, null, function* () {
// Runs tests after all 'load' event handlers have fired off
return yield new Promise((resolve) => {
content.addEventListener("documentload", function loaded() {
content.removeEventListener("documentload", loaded);
resolve(parseInt(content.document.querySelector("div#pageContainer1").style.width));
window.addEventListener("documentload", function() {
initialWidth = parseInt(document.querySelector("div#pageContainer1").style.width);
previousWidth = initialWidth;
runTests(document, window, finish);
}, false, true);
});
});
}, true);
}
// Basic tests.
let [ viewer, pdfjs ] = yield ContentTask.spawn(newTabBrowser, null, function* () {
function runTests(document, window, callback) {
// check that PDF is opened with internal viewer
return [ content.document.querySelector('div#viewer') !== null,
'PDFJS' in content.wrappedJSObject ];
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(), finish);
});
}
ok(viewer, "document content has viewer UI");
ok(pdfjs, "window content has PDFJS object");
function waitForDocumentLoad(document) {
var deferred = Promise.defer();
var interval = setInterval(function () {
if (document.querySelector("div#pageContainer1") != null){
clearInterval(interval);
deferred.resolve();
}
}, 500);
for (let test of TESTS) {
yield ContentTask.spawn(newTabBrowser, test, function* (test) {
let document = content.document;
return deferred.promise;
}
function zoomPDF(document, window, test, endCallback) {
var renderedPage;
function waitForRender() {
return new Promise((resolve) => {
document.addEventListener("pagerendered", function onPageRendered(e) {
if(e.detail.pageNumber !== 1) {
return;
}
document.removeEventListener("pagerendered", onPageRendered, true);
resolve();
}, true);
});
}
// 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);
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();
});
if (test.action.selector) {
info("Element '" + test.action.selector + "' has been found");
}
let { actualWidth, zoomValue } = yield ContentTask.spawn(newTabBrowser, null, function* () {
var pageZoomScale = content.document.querySelector('select#scaleSelect');
var pageZoomScale = 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 pageContainer = document.querySelector('div#pageContainer1');
let actualWidth = parseInt(pageContainer.style.width);
return { actualWidth, zoomValue };
});
// the actual zoom of the PDF document
let computedZoomValue = parseInt(((actualWidth/initialWidth).toFixed(2))*100) + "%";
is(computedZoomValue, zoomValue, "Content has correct zoom");
@ -164,7 +144,32 @@ add_task(function* test() {
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 });
}
}

View File

@ -321,7 +321,7 @@ this.BrowserTestUtils = {
* Waits for an event to be fired on a specified element.
*
* Usage:
* let promiseEvent = BrowserTestUtils.waitForEvent(element, "eventName");
* let promiseEvent = BrowserTestUtil.waitForEvent(element, "eventName");
* // Do some processing here that will cause the event to be fired
* // ...
* // Now yield until the Promise is fulfilled

View File

@ -396,9 +396,7 @@ ExternalHelperAppParent::SetContentCharset(const nsACString& aContentCharset)
NS_IMETHODIMP
ExternalHelperAppParent::GetContentDisposition(uint32_t *aContentDisposition)
{
// NB: mContentDisposition may or may not be set to a non UINT32_MAX value in
// nsExternalHelperAppService::DoContentContentProcessHelper
if (mContentDispositionHeader.IsEmpty() && mContentDisposition == UINT32_MAX)
if (mContentDispositionHeader.IsEmpty())
return NS_ERROR_NOT_AVAILABLE;
*aContentDisposition = mContentDisposition;