Bug 1439995 - [marionette] Add user prompt checks for script execution commands. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 26 Jul 2018 22:04:56 +0200
changeset 823378 57169abef0ded7a85f774d022037db38dc8d3256
parent 822981 4e6486b672b32aba075b704c6b1e41e8ccf7a135
child 823379 a42c75bb702bc7a980629db0ef21780df5f68778
push id117653
push userbmo:hskupin@gmail.com
push dateFri, 27 Jul 2018 05:18:40 +0000
bugs1439995
milestone63.0a1
Bug 1439995 - [marionette] Add user prompt checks for script execution commands. WebDriver:{ExecuteScript,ExecuteAsyncScript} were missing user prompt checks. MozReview-Commit-ID: KL8gTBfSTrU
testing/marionette/driver.js
testing/marionette/harness/marionette_harness/tests/unit/test_unhandled_prompt_behavior.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -982,16 +982,17 @@ GeckoDriver.prototype.execute_ = async f
       async = false,
     } = {}) {
 
   if (typeof timeout == "undefined" || timeout === null) {
     timeout = this.timeouts.script;
   }
 
   assert.open(this.getCurrentWindow());
+  this._handleUserPrompts();
 
   assert.string(script, pprint`Expected "script" to be a string: ${script}`);
   assert.array(args, pprint`Expected script args to be an array: ${args}`);
   assert.positiveInteger(timeout, pprint`Expected script timeout to be a positive integer: ${timeout}`);
   if (sandboxName !== null) {
     assert.string(sandboxName, pprint`Expected sandbox name to be a string: ${sandboxName}`);
   }
   assert.boolean(newSandbox, pprint`Expected newSandbox to be boolean: ${newSandbox}`);
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_unhandled_prompt_behavior.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_unhandled_prompt_behavior.py
@@ -49,19 +49,25 @@ class TestUnhandledPromptBehavior(Marion
                 self.marionette.title
             # Bug 1469752 - WebDriverError misses optional data property
             # self.assertEqual(ex.data.text, text)
         else:
             self.marionette.title
 
         self.assertEqual(self.alert_present, not expected_close)
 
-        prompt_result = self.marionette.execute_script(
-            "return window.return_value", new_sandbox=False)
-        self.assertEqual(prompt_result, expected_result)
+        # Close an expected left-over user prompt
+        if not expected_close:
+            alert = self.marionette.switch_to_alert()
+            alert.dismiss()
+
+        else:
+            prompt_result = self.marionette.execute_script(
+                "return window.return_value", new_sandbox=False)
+            self.assertEqual(prompt_result, expected_result)
 
     @parameterized("alert", "alert", None)
     @parameterized("confirm", "confirm", True)
     @parameterized("prompt", "prompt", "")
     def test_accept(self, prompt_type, result):
         self.marionette.start_session({"unhandledPromptBehavior": "accept"})
         self.perform_user_prompt_check(prompt_type, "foo {}".format(prompt_type), result,
                                        expected_notify=False)