Bug 1487358 - [marionette] "Accept Alert" and "Dismiss Alert" should check for remaining user prompts. r=webdriver-reviewers,maja_zf

Workaround until we have a sane dynamic user prompt implementation
(see bug 1477977). At least for now this patch will give us the
opportunity to handle multiple open user prompts.

Differential Revision: https://phabricator.services.mozilla.com/D32666

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2019-05-27 19:54:21 +00:00
Родитель dc948a87d9
Коммит 21e28757a5
3 изменённых файлов: 84 добавлений и 112 удалений

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

@ -3171,7 +3171,7 @@ GeckoDriver.prototype.dismissDialog = async function() {
await dialogClosed;
this.dialog = null;
this.dialog = modal.findModalDialogs(this.curBrowser);
};
/**
@ -3189,7 +3189,7 @@ GeckoDriver.prototype.acceptDialog = async function() {
await dialogClosed;
this.dialog = null;
this.dialog = modal.findModalDialogs(this.curBrowser);
};
/**

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

@ -1,7 +1,3 @@
# 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/.
from __future__ import absolute_import
from marionette_driver.by import By
@ -10,7 +6,7 @@ from marionette_driver import errors
from marionette_driver.marionette import Alert
from marionette_driver.wait import Wait
from marionette_harness import MarionetteTestCase, WindowManagerMixin
from marionette_harness import MarionetteTestCase, parameterized, WindowManagerMixin
class BaseAlertTestCase(WindowManagerMixin, MarionetteTestCase):
@ -27,10 +23,6 @@ class BaseAlertTestCase(WindowManagerMixin, MarionetteTestCase):
Wait(self.marionette, timeout=timeout).until(
lambda _: self.alert_present)
def wait_for_alert_closed(self, timeout=None):
Wait(self.marionette, timeout=timeout).until(
lambda _: not self.alert_present)
class TestTabModalAlerts(BaseAlertTestCase):
@ -43,13 +35,12 @@ class TestTabModalAlerts(BaseAlertTestCase):
self.marionette.navigate(self.test_page)
def tearDown(self):
# Ensure to close a possible remaining tab modal dialog
# Ensure to close all possible remaining tab modal dialogs
try:
while True:
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.wait_for_alert_closed()
except:
except errors.NoAlertPresentException:
pass
super(TestTabModalAlerts, self).tearDown()
@ -60,50 +51,6 @@ class TestTabModalAlerts(BaseAlertTestCase):
with self.assertRaises(errors.NoAlertPresentException):
Alert(self.marionette).dismiss()
def test_alert_accept(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
def test_alert_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
def test_confirm_accept(self):
self.marionette.find_element(By.ID, "tab-modal-confirm").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "confirm-result").text == "true")
def test_confirm_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-confirm").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "confirm-result").text == "false")
def test_prompt_accept(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "prompt-result").text == "")
def test_prompt_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "prompt-result").text == "null")
def test_alert_opened_before_session_starts(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
@ -115,40 +62,45 @@ class TestTabModalAlerts(BaseAlertTestCase):
alert = self.marionette.switch_to_alert()
alert.dismiss()
def test_alert_text(self):
@parameterized("alert", "alert", "undefined")
@parameterized("confirm", "confirm", "true")
@parameterized("prompt", "prompt", "")
def test_accept(self, value, result):
self.marionette.find_element(By.ID, "tab-modal-{}".format(value)).click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.accept()
self.assertEqual(self.marionette.find_element(By.ID, "text").text, result)
@parameterized("alert", "alert", "undefined")
@parameterized("confirm", "confirm", "false")
@parameterized("prompt", "prompt", "null")
def test_dismiss(self, value, result):
self.marionette.find_element(By.ID, "tab-modal-{}".format(value)).click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.assertEqual(self.marionette.find_element(By.ID, "text").text, result)
@parameterized("alert", "alert", "Marionette alert")
@parameterized("confirm", "confirm", "Marionette confirm")
@parameterized("prompt", "prompt", "Marionette prompt")
def test_text(self, value, text):
with self.assertRaises(errors.NoAlertPresentException):
alert = self.marionette.switch_to_alert()
alert.text
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.marionette.find_element(By.ID, "tab-modal-{}".format(value)).click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
self.assertEqual(alert.text, "Marionette alert")
self.assertEqual(alert.text, text)
alert.accept()
def test_prompt_text(self):
with self.assertRaises(errors.NoAlertPresentException):
alert = self.marionette.switch_to_alert()
alert.text
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
self.assertEqual(alert.text, "Marionette prompt")
alert.accept()
def test_confirm_text(self):
with self.assertRaises(errors.NoAlertPresentException):
alert = self.marionette.switch_to_alert()
alert.text
self.marionette.find_element(By.ID, "tab-modal-confirm").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
self.assertEqual(alert.text, "Marionette confirm")
alert.accept()
def test_set_text_throws(self):
@parameterized("alert", "alert")
@parameterized("confirm", "confirm")
def test_set_text_throws(self, value):
with self.assertRaises(errors.NoAlertPresentException):
Alert(self.marionette).send_keys("Foo")
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.marionette.find_element(By.ID, "tab-modal-{}".format(value)).click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
with self.assertRaises(errors.ElementNotInteractableException):
@ -159,10 +111,9 @@ class TestTabModalAlerts(BaseAlertTestCase):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
self.wait_for_alert()
alert = self.marionette.switch_to_alert()
alert.send_keys("Some text!")
alert.send_keys("Foo bar")
alert.accept()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "prompt-result").text == "Some text!")
self.assertEqual(self.marionette.find_element(By.ID, "text").text, "Foo bar")
def test_set_text_dismiss(self):
self.marionette.find_element(By.ID, "tab-modal-prompt").click()
@ -170,35 +121,51 @@ class TestTabModalAlerts(BaseAlertTestCase):
alert = self.marionette.switch_to_alert()
alert.send_keys("Some text!")
alert.dismiss()
self.wait_for_condition(
lambda mn: mn.find_element(By.ID, "prompt-result").text == "null")
self.assertEqual(self.marionette.find_element(By.ID, "text").text, "null")
def test_unrelated_command_when_alert_present(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
with self.assertRaises(errors.UnexpectedAlertOpen):
self.marionette.find_element(By.ID, "click-result")
self.marionette.find_element(By.ID, "text")
def test_modal_is_dismissed_after_unexpected_alert(self):
self.marionette.find_element(By.ID, "tab-modal-alert").click()
self.wait_for_alert()
with self.assertRaises(errors.UnexpectedAlertOpen):
self.marionette.find_element(By.ID, "click-result")
self.marionette.find_element(By.ID, "text")
assert not self.alert_present
def test_handle_two_modal_dialogs(self):
self.marionette.find_element(By.ID, "open-two-dialogs").click()
self.wait_for_alert()
alert1 = self.marionette.switch_to_alert()
alert1.send_keys("foo")
alert1.accept()
alert2 = self.marionette.switch_to_alert()
alert2.send_keys("bar")
alert2.accept()
self.assertEqual(self.marionette.find_element(By.ID, "text1").text, "foo")
self.assertEqual(self.marionette.find_element(By.ID, "text2").text, "bar")
class TestModalAlerts(BaseAlertTestCase):
def setUp(self):
super(TestModalAlerts, self).setUp()
self.marionette.set_pref("network.auth.non-web-content-triggered-resources-http-auth-allow",
self.marionette.set_pref(
"network.auth.non-web-content-triggered-resources-http-auth-allow",
True)
def tearDown(self):
# Ensure to close a possible remaining modal dialog
self.close_all_windows()
self.marionette.clear_pref("network.auth.non-web-content-triggered-resources-http-auth-allow")
self.marionette.clear_pref(
"network.auth.non-web-content-triggered-resources-http-auth-allow")
super(TestModalAlerts, self).tearDown()
@ -209,8 +176,6 @@ class TestModalAlerts(BaseAlertTestCase):
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.wait_for_alert_closed()
status = Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
element_present(By.ID, "status")
)
@ -226,5 +191,3 @@ class TestModalAlerts(BaseAlertTestCase):
alert = self.marionette.switch_to_alert()
alert.dismiss()
self.wait_for_alert_closed()

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

@ -7,18 +7,25 @@
<head>
<title>Dialog Test</title>
<script type="text/javascript">
function setInnerText(id, value) {
document.getElementById(id).innerHTML = "<p>" + value + "</p>";
}
function handleAlert () {
window.alert('Marionette alert');
setInnerText("text", alert("Marionette alert"));
}
function handleConfirm () {
var alertAccepted = window.confirm('Marionette confirm');
document.getElementById('confirm-result').innerHTML = alertAccepted;
setInnerText("text", confirm("Marionette confirm"));
}
function handlePrompt () {
var promptText = window.prompt('Marionette prompt');
document.getElementById('prompt-result').innerHTML = promptText === null ? 'null' : promptText;
setInnerText("text", prompt("Marionette prompt"));
}
function handleTwoDialogs() {
setInnerText("text1", prompt("First"));
setInnerText("text2", prompt("Second"));
}
</script>
</head>
@ -26,9 +33,11 @@
<a href="#" id="tab-modal-alert" onclick="handleAlert()">Open an alert dialog.</a>
<a href="#" id="tab-modal-confirm" onclick="handleConfirm()">Open a confirm dialog.</a>
<a href="#" id="tab-modal-prompt" onclick="handlePrompt()">Open a prompt dialog.</a>
<a href="#" id="click-handler" onclick="document.getElementById('click-result').innerHTML='result';">Make text appear.</a>
<div id="confirm-result"></div>
<div id="prompt-result"></div>
<div id="click-result"></div>
<a href="#" id="open-two-dialogs" onclick="handleTwoDialogs()">Open two prompts.</a>
<a href="#" id="click-handler" onclick="document.getElementById('text').innerHTML='result';">Make text appear.</a>
<div id="text"></div>
<div id="text1"></div>
<div id="text2"></div>
</body>
</html>