diff --git a/testing/marionette/client/marionette/tests/unit/test_switch_frame.py b/testing/marionette/client/marionette/tests/unit/test_switch_frame.py index e38cb050dbb6..fe938c2d5668 100644 --- a/testing/marionette/client/marionette/tests/unit/test_switch_frame.py +++ b/testing/marionette/client/marionette/tests/unit/test_switch_frame.py @@ -2,48 +2,37 @@ # 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): - 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()) + switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html") def test_switch_nested(self): - 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) + 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") 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()) @@ -51,23 +40,7 @@ class TestSwitchFrame(MarionetteTestCase): self.assertTrue("test_nested_iframe.html" in self.marionette.execute_script("return window.location.href;")) def test_stack_trace(self): - 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()) - + switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html") #can't use assertRaises in context manager with python2.6 self.assertRaises(JavascriptException, self.marionette.execute_async_script, "foo();") try: @@ -75,13 +48,12 @@ class TestSwitchFrame(MarionetteTestCase): except JavascriptException as e: self.assertTrue("foo" in e.msg) - def test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us(self): + def testShouldBeAbleToCarryOnWorkingIfTheFrameIsDeletedFromUnderUs(self): test_html = self.marionette.absolute_url("deletingFrame.html") self.marionette.navigate(test_html) - self.marionette.switch_to_frame(self.marionette.find_element('id', - 'iframe1')) - killIframe = self.marionette.find_element("id", "killIframe") + self.marionette.switch_to_frame("iframe1"); + killIframe = self.marionette.find_element("id" ,"killIframe") killIframe.click() self.marionette.switch_to_frame() @@ -91,12 +63,11 @@ class TestSwitchFrame(MarionetteTestCase): addIFrame.click() self.marionette.find_element("id", "iframe1") - self.marionette.switch_to_frame(self.marionette.find_element("id", - "iframe1")) + self.marionette.switch_to_frame("iframe1"); self.marionette.find_element("id", "checkbox") - def test_should_allow_a_user_to_switch_from_an_iframe_back_to_the_main_content_of_the_page(self): + def testShouldAllowAUserToSwitchFromAnIframeBackToTheMainContentOfThePage(self): test_iframe = self.marionette.absolute_url("test_iframe.html") self.marionette.navigate(test_iframe) self.marionette.switch_to_frame(0) @@ -104,18 +75,3 @@ class TestSwitchFrame(MarionetteTestCase): 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")) 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..df5c1e86ce5f 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 @@ -40,8 +40,7 @@ class TestSwitchRemoteFrame(MarionetteTestCase): iframe.src = "%s"; document.body.appendChild(iframe); """ % self.marionette.absolute_url("test.html")) - remote_iframe = self.marionette.find_element("id", "remote_iframe") - self.marionette.switch_to_frame(remote_iframe) + self.marionette.switch_to_frame("remote_iframe") main_process = self.marionette.execute_script(""" return SpecialPowers.isMainProcess(); """) @@ -61,8 +60,7 @@ class TestSwitchRemoteFrame(MarionetteTestCase): iframe.src = "%s"; document.body.appendChild(iframe); """ % self.marionette.absolute_url("test.html")) - self.marionette.switch_to_frame(self.marionette.find_element("id", - "remote_iframe")) + self.marionette.switch_to_frame("remote_iframe") main_process = self.marionette.execute_script(""" return SpecialPowers.isMainProcess(); """) @@ -72,8 +70,7 @@ class TestSwitchRemoteFrame(MarionetteTestCase): return SpecialPowers.isMainProcess(); """) self.assertTrue(main_process) - self.marionette.switch_to_frame(self.marionette.find_element("id", - "remote_iframe")) + self.marionette.switch_to_frame("remote_iframe") main_process = self.marionette.execute_script(""" return SpecialPowers.isMainProcess(); """) diff --git a/testing/marionette/client/marionette/tests/unit/unit-tests.ini b/testing/marionette/client/marionette/tests/unit/unit-tests.ini index 343fa8582f60..5a8962992bfc 100644 --- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini +++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini @@ -85,7 +85,7 @@ browser = false [test_switch_frame.py] [test_switch_frame_chrome.py] [test_switch_remote_frame.py] -browser = false + [test_pagesource.py] [test_visibility.py] diff --git a/testing/marionette/client/marionette/www/frameset.html b/testing/marionette/client/marionette/www/frameset.html deleted file mode 100644 index 1136b35b3994..000000000000 --- a/testing/marionette/client/marionette/www/frameset.html +++ /dev/null @@ -1,14 +0,0 @@ - - - Unique title - - - - - - - - - - - \ No newline at end of file diff --git a/testing/marionette/client/marionette/www/framesetPage2.html b/testing/marionette/client/marionette/www/framesetPage2.html deleted file mode 100644 index 4ea35ff71b7f..000000000000 --- a/testing/marionette/client/marionette/www/framesetPage2.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/testing/marionette/client/marionette/www/test_iframe.html b/testing/marionette/client/marionette/www/test_iframe.html index 7ed88665c5db..4cdb33382c2a 100644 --- a/testing/marionette/client/marionette/www/test_iframe.html +++ b/testing/marionette/client/marionette/www/test_iframe.html @@ -11,6 +11,5 @@

This is the heading

-