Bug 929175: Part 2: Updating frames tests.; r=mdas
☠☠ backed out by 83b46f317e11 ☠ ☠
authorDavid Burns <dburns@mozilla.com>
Fri, 25 Apr 2014 14:41:17 +0100
changeset 180554 6bb03867a3adb440473efb256d7fd91a54a1dbec
parent 180553 bc6ddc5dc31af1f5b0aeb56bb39030611f7a3767
child 180555 a3e1f186d06ab4fe67206a879a67b58209b16142
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmdas
bugs929175
milestone31.0a1
Bug 929175: Part 2: Updating frames tests.; r=mdas
testing/marionette/client/marionette/tests/unit/test_switch_frame.py
testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
testing/marionette/client/marionette/tests/unit/unit-tests.ini
testing/marionette/client/marionette/www/frameset.html
testing/marionette/client/marionette/www/framesetPage2.html
testing/marionette/client/marionette/www/test_iframe.html
--- a/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
+++ b/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
@@ -1,77 +1,121 @@
 # 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/.
 
-import os
 from marionette_test import MarionetteTestCase
 from marionette import JavascriptException
 
-# boiler plate for the initial navigation and frame switch
-def switch_to_window_verify(test, start_url, frame, verify_title, verify_url):
-    test.assertTrue(test.marionette.execute_script("window.location.href = 'about:blank'; return true;"))
-    test.assertEqual("about:blank", test.marionette.execute_script("return window.location.href;"))
-    test_html = test.marionette.absolute_url(start_url)
-    test.marionette.navigate(test_html)
-    test.assertEqual(test.marionette.get_active_frame(), None)
-    test.assertNotEqual("about:blank", test.marionette.execute_script("return window.location.href;"))
-    test.assertEqual(verify_title, test.marionette.title)
-    test.marionette.switch_to_default_content()
-    test.marionette.switch_to_frame(frame)
-    test.assertTrue(verify_url in test.marionette.get_url())
-    inner_frame_element = test.marionette.get_active_frame()
-    # test that we can switch back to main frame, then switch back to the
-    # inner frame with the value we got from get_active_frame
-    test.marionette.switch_to_frame()
-    test.assertEqual(verify_title, test.marionette.title)
-    test.marionette.switch_to_frame(inner_frame_element)
-    test.assertTrue(verify_url in test.marionette.get_url())
 
 class TestSwitchFrame(MarionetteTestCase):
     def test_switch_simple(self):
-        switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html")
+        start_url = "test_iframe.html"
+        verify_title = "Marionette IFrame Test"
+        verify_url = "test.html"
+        test_html = self.marionette.absolute_url(start_url)
+        self.marionette.navigate(test_html)
+        self.assertEqual(self.marionette.get_active_frame(), None)
+        frame = self.marionette.find_element("id", "test_iframe")
+        self.marionette.switch_to_frame(frame)
+        self.assertTrue(verify_url in self.marionette.get_url())
+        inner_frame_element = self.marionette.get_active_frame()
+        # test that we can switch back to main frame, then switch back to the
+        # inner frame with the value we got from get_active_frame
+        self.marionette.switch_to_frame()
+        self.assertEqual(verify_title, self.marionette.title)
+        self.marionette.switch_to_frame(inner_frame_element)
+        self.assertTrue(verify_url in self.marionette.get_url())
 
     def test_switch_nested(self):
-        switch_to_window_verify(self, "test_nested_iframe.html", "test_iframe", "Marionette IFrame Test", "test_inner_iframe.html")
-        self.marionette.switch_to_frame("inner_frame")
+        start_url = "test_nested_iframe.html"
+        verify_title = "Marionette IFrame Test"
+        verify_url = "test_inner_iframe.html"
+        test_html = self.marionette.absolute_url(start_url)
+        self.marionette.navigate(test_html)
+        frame = self.marionette.find_element("id", "test_iframe")
+        self.assertEqual(self.marionette.get_active_frame(), None)
+        self.marionette.switch_to_frame(frame)
+        self.assertTrue(verify_url in self.marionette.get_url())
+        inner_frame_element = self.marionette.get_active_frame()
+        # test that we can switch back to main frame, then switch back to the
+        # inner frame with the value we got from get_active_frame
+        self.marionette.switch_to_frame()
+        self.assertEqual(verify_title, self.marionette.title)
+        self.marionette.switch_to_frame(inner_frame_element)
+        self.assertTrue(verify_url in self.marionette.get_url())
+        inner_frame = self.marionette.find_element('id', 'inner_frame')
+        self.marionette.switch_to_frame(inner_frame)
         self.assertTrue("test.html" in self.marionette.get_url())
         self.marionette.switch_to_frame() # go back to main frame
         self.assertTrue("test_nested_iframe.html" in self.marionette.get_url())
         #test that we're using the right window object server-side
         self.assertTrue("test_nested_iframe.html" in self.marionette.execute_script("return window.location.href;"))
 
     def test_stack_trace(self):
-        switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html")
+        start_url = "test_iframe.html"
+        verify_title = "Marionette IFrame Test"
+        verify_url = "test.html"
+        test_html = self.marionette.absolute_url(start_url)
+        self.marionette.navigate(test_html)
+        frame = self.marionette.find_element("id", "test_iframe")
+        self.assertEqual(self.marionette.get_active_frame(), None)
+        self.marionette.switch_to_frame(frame)
+        self.assertTrue(verify_url in self.marionette.get_url())
+        inner_frame_element = self.marionette.get_active_frame()
+        # test that we can switch back to main frame, then switch back to the
+        # inner frame with the value we got from get_active_frame
+        self.marionette.switch_to_frame()
+        self.assertEqual(verify_title, self.marionette.title)
+        self.marionette.switch_to_frame(inner_frame_element)
+        self.assertTrue(verify_url in self.marionette.get_url())
+
         #can't use assertRaises in context manager with python2.6
         self.assertRaises(JavascriptException, self.marionette.execute_async_script, "foo();")
         try:
             self.marionette.execute_async_script("foo();")
         except JavascriptException as e:
             self.assertTrue("foo" in e.msg)
 
-    def testShouldBeAbleToCarryOnWorkingIfTheFrameIsDeletedFromUnderUs(self):
+    def test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us(self):
         test_html = self.marionette.absolute_url("deletingFrame.html")
         self.marionette.navigate(test_html)
 
-        self.marionette.switch_to_frame("iframe1");
-        killIframe = self.marionette.find_element("id" ,"killIframe")
+        self.marionette.switch_to_frame(self.marionette.find_element('id',
+                                                                     'iframe1'))
+        killIframe = self.marionette.find_element("id", "killIframe")
         killIframe.click()
         self.marionette.switch_to_frame()
 
         self.assertEqual(0, len(self.marionette.find_elements("id", "iframe1")))
 
         addIFrame = self.marionette.find_element("id", "addBackFrame")
         addIFrame.click()
         self.marionette.find_element("id", "iframe1")
 
-        self.marionette.switch_to_frame("iframe1");
+        self.marionette.switch_to_frame(self.marionette.find_element("id",
+                                                                     "iframe1"))
 
         self.marionette.find_element("id", "checkbox")
 
-    def testShouldAllowAUserToSwitchFromAnIframeBackToTheMainContentOfThePage(self):
+    def test_should_allow_a_user_to_switch_from_an_iframe_back_to_the_main_content_of_the_page(self):
         test_iframe = self.marionette.absolute_url("test_iframe.html")
         self.marionette.navigate(test_iframe)
         self.marionette.switch_to_frame(0)
         self.marionette.switch_to_default_content()
         header = self.marionette.find_element("id", "iframe_page_heading")
         self.assertEqual(header.text, "This is the heading")
 
+    def test_should_be_able_to_switch_to_a_frame_by_its_index(self):
+        test_html = self.marionette.absolute_url("frameset.html")
+        self.marionette.navigate(test_html)
+        self.marionette.switch_to_frame(2)
+        element = self.marionette.find_element("id", "email")
+        self.assertEquals("email", element.get_attribute("type"))
+
+    def test_should_be_able_to_switch_to_a_frame_using_a_previously_located_element(self):
+        test_html = self.marionette.absolute_url("frameset.html")
+        self.marionette.navigate(test_html)
+        frame = self.marionette.find_element("name", "third")
+        self.marionette.switch_to_frame(frame)
+
+        element = self.marionette.find_element("id", "email")
+        self.assertEquals("email", element.get_attribute("type"))
--- a/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
+++ b/testing/marionette/client/marionette/tests/unit/test_switch_remote_frame.py
@@ -35,17 +35,18 @@ class TestSwitchRemoteFrame(MarionetteTe
             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("remote_iframe")
+        remote_iframe = self.marionette.find_element("id", "remote_iframe")
+        self.marionette.switch_to_frame(remote_iframe)
         main_process = self.marionette.execute_script("""
             return SpecialPowers.isMainProcess();
             """)
         self.assertFalse(main_process)
 
     def test_remote_frame_revisit(self):
         # test if we can revisit a remote frame (this takes a different codepath)
         self.marionette.navigate(self.marionette.absolute_url("test.html"))
@@ -55,27 +56,29 @@ class TestSwitchRemoteFrame(MarionetteTe
             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("remote_iframe")
+        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)
         self.marionette.switch_to_frame()
         main_process = self.marionette.execute_script("""
             return SpecialPowers.isMainProcess();
             """)
         self.assertTrue(main_process)
-        self.marionette.switch_to_frame("remote_iframe")
+        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 tearDown(self):
         if self.oop_by_default is None:
             self.marionette.execute_script("""
--- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini
+++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini
@@ -80,17 +80,17 @@ 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]
 
 [test_visibility.py]
 [test_window_switching.py]
 b2g = false
 [test_window_management.py]
 b2g = false
 
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/frameset.html
@@ -0,0 +1,14 @@
+<html>
+  <head>
+    <title>Unique title</title>
+  </head>
+<frameset cols="*, *, *, *, *, *, *">
+    <frame name="first" src="page/1"/>
+    <frame name="second" src="page/2?title=Fish"/>
+    <frame name="third" src="formPage.html"/>
+    <frame name="fourth" src="framesetPage2.html"/>
+    <frame id="fifth" src="xhtmlTest.html"/>
+    <frame id="sixth" src="iframes.html"/>
+    <frame id="sixth.iframe1" src="page/3"/>
+</frameset>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/framesetPage2.html
@@ -0,0 +1,7 @@
+<html>
+<head></head>
+<frameset cols="*, *">
+    <frame name="child1" src="page/10"/>
+    <frame name="child2" src="page/11"/>
+</frameset>
+</html>
\ No newline at end of file
--- a/testing/marionette/client/marionette/www/test_iframe.html
+++ b/testing/marionette/client/marionette/www/test_iframe.html
@@ -6,10 +6,11 @@
 <html>
 <head>
 <title>Marionette IFrame Test</title>
 </head>
 <body>
   <h1 id="iframe_page_heading">This is the heading</h1>
 
   <iframe src="test.html" id="test_iframe"></iframe>
+  <iframe src="test.html" id="test_iframe" name="test_iframe_name"></iframe>
 </body>
 </html>