Skip to content

Commit

Permalink
Backed out changeset 51abb63ca246 (bug 1507803) for frequent marionet…
Browse files Browse the repository at this point in the history
…te failures

UltraBlame original commit: 1bfd0fb3b0d740be0ea913164dce90263aa822d1
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent 5b9fa02 commit 216af16
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,3 @@ def loaded(handle):
message="Window with handle '{}'' did not finish loading".format(new_window))

return new_window

def open_chrome_window(self, url):
"""Open a new chrome window with the specified chrome URL.
Can be replaced with "WebDriver:NewWindow" once the command
supports opening generic chrome windows beside browsers (bug 1507771).
"""
def open_with_js():
with self.marionette.using_context("chrome"):
self.marionette.execute_async_script("""
let [url, resolve] = arguments;
function waitForEvent(target, type, args) {
return new Promise(resolve => {
let params = Object.assign({once: true}, args);
target.addEventListener(type, event => {
dump(`** Received DOM event ${event.type} for ${event.target}\n`);
resolve();
}, params);
});
}
function waitForFocus(win) {
return Promise.all([
waitForEvent(win, "activate"),
waitForEvent(win, "focus", {capture: true}),
]);
}
(async function() {
// Open a window, wait for it to receive focus
let win = window.openDialog(url, null, "chrome,centerscreen");
// Bug 1507803 - Missing focus/activate event when tests are
// run in the background.
win.focus();
await waitForFocus(win);
// Now refocus our original window and wait for that to happen.
let focused = waitForFocus(window);
window.focus();
await focused;
resolve();
})();
""", script_args=(url,))

return self.open_window(trigger=open_with_js)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ def setUp(self):
super(TestAnonymousNodes, self).setUp()
self.marionette.set_context("chrome")

url = "chrome://marionette/content/test_anonymous_content.xul"
new_window = self.open_chrome_window(url)
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test_anonymous_content.xul',
'foo', 'chrome,centerscreen');
""")

new_window = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(new_window)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def setUp(self):

self.marionette.set_context("chrome")

new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'_blank', 'chrome,centerscreen');
""")

new_window = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(new_window)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def tearDown(self):
super(TestClickChrome, self).tearDown()

def test_click(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen'); """)

win = self.open_window(open_with_js)
self.marionette.switch_to_window(win)

def checked():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def setUp(self):

self.marionette.set_context("chrome")

self.win = self.open_chrome_window("chrome://marionette/content/test.xul")
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

self.win = self.open_window(open_window_with_js)
self.marionette.switch_to_window(self.win)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def setUp(self):

self.marionette.set_context("chrome")

new_window = self.open_chrome_window("chrome://marionette/content/test2.xul")
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test2.xul',
'foo', 'chrome,centerscreen');
""")

new_window = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(new_window)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,13 @@ def test_permission(self):

@skip_if_mobile("New windows not supported in Fennec")
def test_unmarshal_element_collection(self):

def open_window_with_js():
self.marionette.execute_script(
"window.open('chrome://marionette/content/test.xul', 'xul', 'chrome');")

try:
win = self.open_chrome_window("chrome://marionette/content/test.xul")
win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)

expected = self.marionette.find_elements(By.TAG_NAME, "textbox")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def setUp(self):

self.marionette.set_context("chrome")

win = self.open_chrome_window("chrome://marionette/content/test.xul")
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(open_window_with_js)
self.marionette.switch_to_window(win)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ def test_browser_window(self):

@skip_if_mobile("Fennec doesn't support other chrome windows")
def test_no_browser_window(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)

chrome_url = self.marionette.execute_script("return window.location.href;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ def setUp(self):
super(TestPageSourceChrome, self).setUp()
self.marionette.set_context("chrome")

new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
def open_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

new_window = self.open_window(open_with_js)
self.marionette.switch_to_window(new_window)

def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,22 @@ def window_dimensions(self):
return [rect.width, rect.height];
"""))

def open_dialog(self):
return self.open_chrome_window("chrome://marionette/content/test_dialog.xul")
def open_dialog(self, url=None, width=None, height=None):
if url is None:
url = "chrome://marionette/content/test_dialog.xul"

def opener():
features = "chrome"
if height is not None:
features += ",height={}".format(height)
if width is not None:
features += ",width={}".format(width)

self.marionette.execute_script("""
window.openDialog(arguments[0], "", arguments[1]);
""", script_args=[url, features])

return self.open_window(opener)

def test_capture_different_context(self):
"""Check that screenshots in content and chrome are different."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def setUp(self):
super(TestSwitchFrameChrome, self).setUp()
self.marionette.set_context("chrome")

new_window = self.open_chrome_window("chrome://marionette/content/test.xul")
def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

new_window = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(new_window)
self.assertNotEqual(self.start_window, self.marionette.current_chrome_window_handle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ def tearDown(self):
super(TestTitleChrome, self).tearDown()

def test_get_chrome_title(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(open_window_with_js)
self.marionette.switch_to_window(win)

title = self.marionette.execute_script(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def test_close_chrome_window_for_browser_window(self):
self.assertNotIn(win, self.marionette.window_handles)

def test_close_chrome_window_for_non_browser_window(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)

self.assertIn(win, self.marionette.chrome_window_handles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ def test_close_chrome_window_for_browser_window(self):

@skip_if_mobile("Interacting with chrome windows not available for Fennec")
def test_close_chrome_window_for_non_browser_window(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)

self.assertIn(win, self.marionette.chrome_window_handles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def test_chrome_window_handles_with_scopes(self):

def test_chrome_window_handles_after_opening_new_dialog(self):
xul_dialog = "chrome://marionette/content/test_dialog.xul"
new_win = self.open_chrome_window(xul_dialog)

def open_via_js():
self.marionette.execute_script("""
window.openDialog(arguments[0]);
""", script_args=(xul_dialog,))

new_win = self.open_window(trigger=open_via_js)
self.assert_window_handles()
self.assertEqual(len(self.marionette.chrome_window_handles), len(self.start_windows) + 1)
self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
Expand Down Expand Up @@ -167,7 +173,13 @@ def open_with_link():

def test_window_handles_after_opening_new_dialog(self):
xul_dialog = "chrome://marionette/content/test_dialog.xul"
new_win = self.open_chrome_window(xul_dialog)

def open_via_js():
self.marionette.execute_script("""
window.openDialog(arguments[0]);
""", script_args=(xul_dialog,))

new_win = self.open_window(trigger=open_via_js)
self.assert_window_handles()
self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
self.assertEqual(self.marionette.current_window_handle, self.start_tab)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ def open_with_link():

@skip_if_mobile("Fennec doesn't support other chrome windows")
def test_closed_chrome_window_while_in_frame(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)
with self.marionette.using_context("chrome"):
self.marionette.switch_to_frame("iframe")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ def open_with_link():

@skip_if_mobile("Fennec doesn't support other chrome windows")
def test_closed_chrome_window_while_in_frame(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(trigger=open_window_with_js)
self.marionette.switch_to_window(win)
with self.marionette.using_context("chrome"):
self.marionette.switch_to_frame("iframe")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ def tearDown(self):
super(TestWindowTypeChrome, self).tearDown()

def test_get_window_type(self):
win = self.open_chrome_window("chrome://marionette/content/test.xul")

def open_window_with_js():
self.marionette.execute_script("""
window.open('chrome://marionette/content/test.xul',
'foo', 'chrome,centerscreen');
""")

win = self.open_window(open_window_with_js)
self.marionette.switch_to_window(win)

window_type = self.marionette.execute_script(
Expand Down

0 comments on commit 216af16

Please sign in to comment.