Bug 1146990 - Log the URL of each tab when test leaks window handles; r?maja_zf draft
authorCarim Tho <carimtho@gmail.com>
Thu, 31 Mar 2016 20:28:38 -0300
changeset 346361 047c81f70c2b2a72a835d303f811b27c968a26e5
parent 343376 ea6298e1b4f7e22ce2311b2b6a918822f0adb112
child 517433 ef53f4c6e53fb311b1e93f6eae6d12459c4a8ee8
push id14360
push userbmo:carimtho@gmail.com
push dateThu, 31 Mar 2016 23:30:49 +0000
reviewersmaja_zf
bugs1146990
milestone48.0a1
Bug 1146990 - Log the URL of each tab when test leaks window handles; r?maja_zf MozReview-Commit-ID: 1k5wpRNrsmY
testing/puppeteer/firefox/firefox_puppeteer/testcases/base.py
--- 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'))