Bug 1146990 - Log the URL of each tab when test leaks window handles; r?maja_zf
MozReview-Commit-ID: 1k5wpRNrsmY
--- a/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
+++ b/testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
@@ -14,22 +14,30 @@ class FirefoxTestCase(MarionetteTestCase
It enhances the Marionette testcase by inserting the Puppeteer mixin class,
so Firefox specific API modules are exposed to test scope.
"""
def __init__(self, *args, **kwargs):
MarionetteTestCase.__init__(self, *args, **kwargs)
def _check_and_fix_leaked_handles(self):
handle_count = len(self.marionette.window_handles)
+ url = []
try:
- self.assertEqual(handle_count, self._start_handle_count,
- 'A test must not leak window handles. This test started with '
- '%s open top level browsing contexts, but ended with %s.' %
- (self._start_handle_count, handle_count))
+ #Verify the existence of leaked tabs and print their URLs.
+ if self._start_handle_count < handle_count:
+ message = ('A test must not leak window handles. This test started with '
+ '%s open top level browsing contexts, but ended with %s.'
+ ' Remaining Tabs URLs:') % (self._start_handle_count , handle_count)
+ with self.marionette.using_context('content'):
+ for tab in self.marionette.window_handles:
+ if tab not in self._init_tab_handles:
+ url.append(' %s' % self.marionette.get_url())
+ self.assertListEqual(self._init_tab_handles , self.marionette.window_handles ,
+ message + ','.join(url))
finally:
# For clean-up make sure we work on a proper browser window
if not self.browser or self.browser.closed:
# Find a proper replacement browser window
# TODO: We have to make this less error prone in case no browser is open.
self.browser = self.windows.switch_to(lambda win: type(win) is BrowserWindow)
# Ensure to close all the remaining chrome windows to give following
@@ -62,16 +70,17 @@ class FirefoxTestCase(MarionetteTestCase
# Ensure that we always have a valid browser instance available
self.browser = self.windows.switch_to(lambda win: type(win) is BrowserWindow)
def setUp(self, *args, **kwargs):
MarionetteTestCase.setUp(self, *args, **kwargs)
Puppeteer.set_marionette(self, self.marionette)
self._start_handle_count = len(self.marionette.window_handles)
+ self._init_tab_handles = self.marionette.window_handles
self.marionette.set_context('chrome')
self.browser = self.windows.current
self.browser.focus()
with self.marionette.using_context(self.marionette.CONTEXT_CONTENT):
# Ensure that we have a default page opened
self.marionette.navigate(self.prefs.get_pref('browser.newtab.url'))