Bug 1287723 - Fix test_screenshot.py for handling secondary chrome windows. r=automatedtester
authorHenrik Skupin <mail@hskupin.info>
Mon, 25 Jul 2016 12:17:06 +0200
changeset 348741 4a4de3609f4e76bbfb7653167abb035680ac67dc
parent 348634 5c6a56bb4a6cb28028b4206bcb3f2cb86baa0528
child 348742 4f2b848f4e5d64706920b21fd9a885822ad2803f
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1287723
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1287723 - Fix test_screenshot.py for handling secondary chrome windows. r=automatedtester MozReview-Commit-ID: G11xJFsGdRy
testing/marionette/harness/marionette/chrome/test_dialog.xul
testing/marionette/harness/marionette/tests/unit/test_screenshot.py
testing/marionette/jar.mn
new file mode 100644
--- /dev/null
+++ b/testing/marionette/harness/marionette/chrome/test_dialog.xul
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<!DOCTYPE dialog [
+]>
+
+<dialog id="dialogTest"
+        buttons="accept, cancel"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+
+  <vbox id="things">
+    <checkbox id="testBox" label="box" />
+  </vbox>
+
+</dialog>
--- a/testing/marionette/harness/marionette/tests/unit/test_screenshot.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_screenshot.py
@@ -43,31 +43,31 @@ class ScreenCaptureTestCase(MarionetteTe
         image = base64.decodestring(string)
         width, height = struct.unpack(">LL", image[16:24])
         return int(width), int(height)
 
 
 class Chrome(ScreenCaptureTestCase):
     @property
     def primary_window_dimensions(self):
-        current_window = self.marionette.current_window_handle
+        current_window = self.marionette.current_chrome_window_handle
         self.marionette.switch_to_window(self.original_window)
         with self.marionette.using_context("chrome"):
             rv = tuple(self.marionette.execute_script("""
-                let el = document.getElementsByTagName("window")[0];
+                let el = document.documentElement;
                 let rect = el.getBoundingClientRect();
                 return [rect.width, rect.height];
                 """))
         self.marionette.switch_to_window(current_window)
         return rv
 
     def setUp(self):
         ScreenCaptureTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.original_window = self.marionette.current_window_handle
+        self.original_window = self.marionette.current_chrome_window_handle
 
     def tearDown(self):
         self.marionette.switch_to_window(self.original_window)
 
     # A full chrome window screenshot is not the outer dimensions of
     # the window, but instead the bounding box of the <window> inside
     # <browser>.
     def test_window(self):
@@ -79,34 +79,40 @@ class Chrome(ScreenCaptureTestCase):
     def test_chrome_delegation(self):
         with self.marionette.using_context("content"):
             content = self.marionette.screenshot()
         chrome = self.marionette.screenshot()
         self.assertNotEqual(content, chrome)
 
     # This tests that GeckoDriver#takeScreenshot uses
     # currentContext.document.documentElement instead of looking for a
-    # <window> element, which does not exist for secondary windows.
+    # <window> element, which does not exist for all windows.
     def test_secondary_windows(self):
+        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
         ss = self.marionette.screenshot()
         self.marionette.execute_script("""
-            window.open('chrome://marionette/content/doesnotexist.xul',
-            'foo',
-            'chrome');
+            window.open('chrome://marionette/content/test_dialog.xul', 'foo',
+                        'dialog,height=200,width=300');
             """)
-        self.marionette.switch_to_window("foo")
-        # there can be a race between opening and registering the window
-        # and switching to it. Waiting a tiny amount of time is enough not to
-        # break anything.
-        time.sleep(0.002)
+        self.assertEqual(len(self.marionette.chrome_window_handles), 2)
+        # TODO: Bug 1288769 prevents us from switching to the dialog via its name
+        # self.marionette.switch_to_window('foo')
+        new_win = None
+        for win in self.marionette.chrome_window_handles:
+            if win != self.original_window:
+                new_win = win
+                break
+        self.marionette.switch_to_window(new_win)
         ss = self.marionette.screenshot()
         size = self.get_image_dimensions(ss)
         self.assert_png(ss)
         self.assertNotEqual(self.primary_window_dimensions, size)
 
+        self.marionette.close_chrome_window()
+
 
 class Content(ScreenCaptureTestCase):
     @property
     def body_scroll_dimensions(self):
         return tuple(self.marionette.execute_script(
             "return [document.body.scrollWidth, document.body.scrollHeight]"))
 
     @property
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -23,16 +23,17 @@ marionette.jar:
   content/capture.js (capture.js)
   content/cookies.js (cookies.js)
   content/atom.js (atom.js)
   content/evaluate.js (evaluate.js)
   content/logging.js (logging.js)
 #ifdef ENABLE_TESTS
   content/test.xul  (harness/marionette/chrome/test.xul)
   content/test2.xul  (harness/marionette/chrome/test2.xul)
+  content/test_dialog.xul  (harness/marionette/chrome/test_dialog.xul)
   content/test_nested_iframe.xul  (harness/marionette/chrome/test_nested_iframe.xul)
   content/test_anonymous_content.xul  (harness/marionette/chrome/test_anonymous_content.xul)
 #endif
 
 % content specialpowers %content/
   content/specialpowers.js (../specialpowers/content/specialpowers.js)
   content/SpecialPowersObserver.jsm (../specialpowers/content/SpecialPowersObserver.jsm)
 * content/specialpowersAPI.js (../specialpowers/content/specialpowersAPI.js)