1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #10443 from Snuffleupagus/getVisibleElements-fixes

Prevent `TypeError: views[index] is undefined` being throw in `getVisibleElements` when the viewer, or all pages, are hidden
This commit is contained in:
Tim van der Meij 2019-01-13 15:41:48 +01:00 committed by GitHub
commit 5cb00b7967
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 31 deletions

View file

@ -690,6 +690,66 @@ describe('ui_utils', function() {
scrollOverDocument(pages, true);
});
it('handles `sortByVisibility` correctly', function() {
const scrollEl = {
scrollTop: 75,
scrollLeft: 0,
clientHeight: 750,
clientWidth: 1500,
};
const views = makePages([
[[100, 150]],
[[100, 150]],
[[100, 150]],
]);
const visible = getVisibleElements(scrollEl, views);
const visibleSorted = getVisibleElements(scrollEl, views,
/* sortByVisibility = */ true);
const viewsOrder = [], viewsSortedOrder = [];
for (const view of visible.views) {
viewsOrder.push(view.id);
}
for (const view of visibleSorted.views) {
viewsSortedOrder.push(view.id);
}
expect(viewsOrder).toEqual([0, 1, 2]);
expect(viewsSortedOrder).toEqual([1, 2, 0]);
});
it('handles views being empty', function() {
const scrollEl = {
scrollTop: 10,
scrollLeft: 0,
clientHeight: 750,
clientWidth: 1500,
};
const views = [];
expect(getVisibleElements(scrollEl, views)).toEqual({
first: undefined, last: undefined, views: [],
});
});
it('handles all views being hidden (without errors)', function() {
const scrollEl = {
scrollTop: 100000,
scrollLeft: 0,
clientHeight: 750,
clientWidth: 1500,
};
const views = makePages([
[[100, 150]],
[[100, 150]],
[[100, 150]],
]);
expect(getVisibleElements(scrollEl, views)).toEqual({
first: undefined, last: undefined, views: [],
});
});
// This sub-suite is for a notionally internal helper function for
// getVisibleElements.
describe('backtrackBeforeAllVisibleElements', function() {