Do not leak event listeners on navigation

This patch:
- introduces helper.addEventListener/helper.removeEventListeners
  to simplify event management
- moves NavigatorWatchdog over to the helper.addEventListener to
  stop leaking event listeners
This commit is contained in:
Andrey Lushnikov
2017-07-22 17:03:58 -07:00
parent 5757bc18f2
commit c4904b4e10
3 changed files with 56 additions and 27 deletions

View File

@@ -364,7 +364,7 @@ describe('Puppeteer', function() {
} catch (e) {
error = e;
}
expect(error.message).toContain('SSL Certiciate error');
expect(error.message).toContain('SSL Certificate error');
}));
it('should fail when exceeding maximum navigation timeout', SX(async function() {
let error = null;
@@ -492,6 +492,15 @@ describe('Puppeteer', function() {
// Expect navigation to succeed.
expect(response.ok).toBe(true);
}));
it('should not leak listeners durint navigation', SX(async function() {
let warning = null;
const warningHandler = w => warning = w;
process.on('warning', warningHandler);
for (let i = 0; i < 20; ++i)
await page.navigate(EMPTY_PAGE);
process.removeListener('warning', warningHandler);
expect(warning).toBe(null);
}));
});
describe('Page.waitForNavigation', function() {