Skip to content

Commit

Permalink
Merge pull request #17767 from calixteman/automation_win_listener
Browse files Browse the repository at this point in the history
In the m-c automation, give the possibility to remove window listeners when a test ended
  • Loading branch information
calixteman committed Mar 6, 2024
2 parents 9ee4c65 + 6d0835d commit 6bb6ce6
Showing 1 changed file with 63 additions and 46 deletions.
109 changes: 63 additions & 46 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,47 +686,6 @@ const PDFViewerApplication = {
} else {
throw new Error("Not implemented: run");
}

if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
!("onscrollend" in document.documentElement)
) {
return;
}

const { mainContainer } = appConfig;
// Using the values lastScrollTop and lastScrollLeft is a workaround to
// https://bugzilla.mozilla.org/show_bug.cgi?id=1881974.
// TODO: remove them once the bug is fixed.
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
const scroll = () => {
if (
this._lastScrollTop === mainContainer.scrollTop &&
this._lastScrollLeft === mainContainer.scrollLeft
) {
return;
}
mainContainer.removeEventListener("scroll", scroll, {
passive: true,
});
this._isScrolling = true;
const scrollend = () => {
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
this._isScrolling = false;
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
mainContainer.removeEventListener("scrollend", scrollend);
mainContainer.removeEventListener("blur", scrollend);
};
mainContainer.addEventListener("scrollend", scrollend);
mainContainer.addEventListener("blur", scrollend);
};
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
},

get externalServices() {
Expand Down Expand Up @@ -1967,7 +1926,11 @@ const PDFViewerApplication = {
},

bindWindowEvents() {
const { eventBus, _boundEvents } = this;
const {
eventBus,
_boundEvents,
appConfig: { mainContainer },
} = this;

function addWindowResolutionChange(evt = null) {
if (evt) {
Expand Down Expand Up @@ -2034,6 +1997,46 @@ const PDFViewerApplication = {
"updatefromsandbox",
_boundEvents.windowUpdateFromSandbox
);

if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
!("onscrollend" in document.documentElement)
) {
return;
}

// Using the values lastScrollTop and lastScrollLeft is a workaround to
// https://bugzilla.mozilla.org/show_bug.cgi?id=1881974.
// TODO: remove them once the bug is fixed.
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
const scrollend = (_boundEvents.mainContainerScrollend = () => {
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
this._isScrolling = false;
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
mainContainer.removeEventListener("scrollend", scrollend);
mainContainer.removeEventListener("blur", scrollend);
});
const scroll = (_boundEvents.mainContainerScroll = () => {
if (
this._lastScrollTop === mainContainer.scrollTop &&
this._lastScrollLeft === mainContainer.scrollLeft
) {
return;
}
mainContainer.removeEventListener("scroll", scroll, {
passive: true,
});
this._isScrolling = true;
mainContainer.addEventListener("scrollend", scrollend);
mainContainer.addEventListener("blur", scrollend);
});
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
},

unbindEvents() {
Expand Down Expand Up @@ -2096,10 +2099,10 @@ const PDFViewerApplication = {
},

unbindWindowEvents() {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: unbindWindowEvents");
}
const { _boundEvents } = this;
const {
_boundEvents,
appConfig: { mainContainer },
} = this;

window.removeEventListener("visibilitychange", webViewerVisibilityChange);
window.removeEventListener("wheel", webViewerWheel, { passive: false });
Expand All @@ -2123,13 +2126,27 @@ const PDFViewerApplication = {
"updatefromsandbox",
_boundEvents.windowUpdateFromSandbox
);
mainContainer.removeEventListener(
"scroll",
_boundEvents.mainContainerScroll
);
mainContainer.removeEventListener(
"scrollend",
_boundEvents.mainContainerScrollend
);
mainContainer.removeEventListener(
"blur",
_boundEvents.mainContainerScrollend
);

_boundEvents.removeWindowResolutionChange?.();
_boundEvents.windowResize = null;
_boundEvents.windowHashChange = null;
_boundEvents.windowBeforePrint = null;
_boundEvents.windowAfterPrint = null;
_boundEvents.windowUpdateFromSandbox = null;
_boundEvents.mainContainerScroll = null;
_boundEvents.mainContainerScrollend = null;
},

_accumulateTicks(ticks, prop) {
Expand Down

0 comments on commit 6bb6ce6

Please sign in to comment.