diff --git a/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py b/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py index 64d6a8bd1f73..0c2fb6cddffe 100644 --- a/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py +++ b/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py @@ -79,6 +79,36 @@ class TestSwitchRemoteFrame(MarionetteTestCase): """) self.assertFalse(main_process) + def test_we_can_switch_to_a_remote_frame_by_index(self): + # test if we can revisit a remote frame (this takes a different codepath) + self.marionette.navigate(self.marionette.absolute_url("test.html")) + self.marionette.execute_script("SpecialPowers.addPermission('browser', true, document)") + self.marionette.execute_script(""" + let iframe = document.createElement("iframe"); + SpecialPowers.wrap(iframe).mozbrowser = true; + SpecialPowers.wrap(iframe).remote = true; + iframe.id = "remote_iframe"; + iframe.style.height = "100px"; + iframe.style.width = "100%%"; + iframe.src = "%s"; + document.body.appendChild(iframe); + """ % self.marionette.absolute_url("test.html")) + self.marionette.switch_to_frame(0) + main_process = self.marionette.execute_script(""" + return SpecialPowers.isMainProcess(); + """) + self.assertFalse(main_process) + self.marionette.switch_to_frame() + main_process = self.marionette.execute_script(""" + return SpecialPowers.isMainProcess(); + """) + self.assertTrue(main_process) + self.marionette.switch_to_frame(0) + main_process = self.marionette.execute_script(""" + return SpecialPowers.isMainProcess(); + """) + self.assertFalse(main_process) + def tearDown(self): if self.oop_by_default is None: self.marionette.execute_script(""" diff --git a/testing/marionette/client/marionette/tests/unit/unit-tests.ini b/testing/marionette/client/marionette/tests/unit/unit-tests.ini index fcbcc9f46f2c..1bf4c06ba7ac 100644 --- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini +++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini @@ -85,7 +85,6 @@ browser = false [test_switch_frame.py] [test_switch_frame_chrome.py] [test_switch_remote_frame.py] -browser = false [test_pagesource.py] b2g = false diff --git a/testing/marionette/marionette-listener.js b/testing/marionette/marionette-listener.js index 9db68535e8c1..0527f6a8439f 100644 --- a/testing/marionette/marionette-listener.js +++ b/testing/marionette/marionette-listener.js @@ -1871,9 +1871,18 @@ function switchToFrame(msg) { } if (foundFrame == null) { if (typeof(msg.json.id) === 'number') { - foundFrame = frames[msg.json.id].frameElement; - curFrame = foundFrame; - foundFrame = elementManager.addToKnownElements(curFrame); + try { + foundFrame = frames[msg.json.id].frameElement; + curFrame = foundFrame; + foundFrame = elementManager.addToKnownElements(curFrame); + } catch (e) { + // Since window.frames does not return OOP frames it will throw + // and we land up here. Let's not give up and check if there are + // iframes and switch to the indexed frame there + let iframes = curFrame.document.getElementsByTagName("iframe"); + curFrame = iframes[msg.json.id]; + foundFrame = msg.json.id + } } } if (foundFrame == null) {