From 8ac5a891232e20ea1316ea91e8cda4ce1e2408d3 Mon Sep 17 00:00:00 2001 From: David Burns Date: Wed, 30 Apr 2014 22:59:25 +0100 Subject: [PATCH] Bug 1004089: Allow frame switching in marionette when switching by index and the frame is OOP; r=mdas --- .../tests/unit/test_switch_remote_frame.py | 30 +++++++++++++++++++ .../marionette/tests/unit/unit-tests.ini | 1 - testing/marionette/marionette-listener.js | 15 ++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) 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 64d6a8bd1f7..0c2fb6cddff 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 fcbcc9f46f2..1bf4c06ba7a 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 9db68535e8c..0527f6a8439 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) {