Bug 1004089: Allow frame switching in marionette when switching by index and the frame is OOP; r=mdas
authorDavid Burns <dburns@mozilla.com>
Wed, 30 Apr 2014 22:59:25 +0100
changeset 181516 20a18be004c74f7675c0439fc4ba342c28d1b18c
parent 181515 6626b6cdb30ee352129c4f276970de3a997bbc90
child 181517 d411b847239193691525f8451ecb8275c5260a62
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmdas
bugs1004089
milestone32.0a1
Bug 1004089: Allow frame switching in marionette when switching by index and the frame is OOP; r=mdas
testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
testing/marionette/client/marionette/tests/unit/unit-tests.ini
testing/marionette/marionette-listener.js
--- a/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
+++ b/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
@@ -74,16 +74,46 @@ class TestSwitchRemoteFrame(MarionetteTe
         self.assertTrue(main_process)
         self.marionette.switch_to_frame(self.marionette.find_element("id",
                                                                      "remote_iframe"))
         main_process = self.marionette.execute_script("""
             return SpecialPowers.isMainProcess();
             """)
         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("""
                 SpecialPowers.clearUserPref('dom.ipc.browser_frames.oop_by_default');
                 """)
         else:
             self.marionette.execute_script("""
                 SpecialPowers.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s);
--- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini
+++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini
@@ -80,17 +80,16 @@ browser = false
 [test_simpletest_pass.js]
 [test_simpletest_sanity.py]
 [test_simpletest_chrome.js]
 [test_simpletest_timeout.js]
 [test_specialpowers.py]
 [test_switch_frame.py]
 [test_switch_frame_chrome.py]
 [test_switch_remote_frame.py]
-browser = false
 
 [test_pagesource.py]
 b2g = false
 
 [test_visibility.py]
 [test_window_switching.py]
 b2g = false
 [test_window_management.py]
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -1866,19 +1866,28 @@ function switchToFrame(msg) {
             foundFrame = i;
           }
         }
       }
     }
   }
   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) {
     sendError("Unable to locate frame: " + (msg.json.id || msg.json.element), 8, null, command_id);
     return true;
   }
 
   sandbox = null;