Bug 1140542 - Support capturing secondary chrome windows; r=automatedtester

A <window> object may not exist in popup windows that are spawned from
a <window>.  document.documentElement is equivalent to <window> in
the case of the primary window, but lets us support the ChromeWindow's
document when it isn't.

--HG--
extra : commitid : GVJfQ7yGGdV
extra : rebase_source : af351c5bd91eb865c657a2f45479c5b360c50fc6
extra : amend_source : f3ddef37a7f663fcf4f049f13eac3cf94df2ad29
This commit is contained in:
Andreas Tolfsen 2016-01-27 16:43:33 +00:00
Родитель d34dde504d
Коммит 257cb763cb
2 изменённых файлов: 34 добавлений и 9 удалений

Просмотреть файл

@ -45,24 +45,33 @@ class ScreenCaptureTestCase(MarionetteTestCase):
class Chrome(ScreenCaptureTestCase):
@property
def primary_window_dimensions(self):
return tuple(self.marionette.execute_script("""
let win = document.getElementsByTagName("window")[0];
let rect = win.getBoundingClientRect();
return [rect.width, rect.height];"""))
current_window = self.marionette.current_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 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
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):
string = self.marionette.screenshot()
self.assert_png(string)
ss = self.marionette.screenshot()
self.assert_png(ss)
self.assertEqual(self.primary_window_dimensions,
self.get_image_dimensions(string))
self.get_image_dimensions(ss))
def test_chrome_delegation(self):
with self.marionette.using_context("content"):
@ -70,6 +79,22 @@ class Chrome(ScreenCaptureTestCase):
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.
def test_secondary_windows(self):
ss = self.marionette.screenshot()
self.marionette.execute_script("""
window.open('chrome://marionette/content/doesnotexist.xul',
'foo',
'chrome');
""")
self.marionette.switch_to_window("foo")
ss = self.marionette.screenshot()
size = self.get_image_dimensions(ss)
self.assert_png(ss)
self.assertNotEqual(self.primary_window_dimensions, size)
class Content(ScreenCaptureTestCase):
@property

Просмотреть файл

@ -2596,7 +2596,7 @@ GeckoDriver.prototype.takeScreenshot = function(cmd, resp) {
if (this.appName == "B2G") {
doc = win.document.body;
} else {
doc = win.document.getElementsByTagName("window")[0];
doc = win.document.documentElement;
}
let docRect = doc.getBoundingClientRect();
let width = docRect.width;