Bug 1107336: correct loop imports for marionette; r=jgriffin draft
authorDavid Burns <dburns@mozilla.com>
Tue, 10 Feb 2015 00:49:24 +0000
changeset 241848 6ff685c82442d523bf11480c6e95b1fbdde7dba0
parent 241847 50dd5a7217a69da45dd2404eabc5c68ba73b3823
child 241849 4af31415d74b5f44425df5db2d0152813098c9ac
push id624
push userdburns@mozilla.com
push dateTue, 10 Feb 2015 13:30:25 +0000
reviewersjgriffin
bugs1107336
milestone38.0a1
Bug 1107336: correct loop imports for marionette; r=jgriffin
browser/components/loop/test/functional/test_1_browser_call.py
browser/components/loop/test/shared/frontend_tester.py
testing/marionette/client/marionette/tests/unit/test_navigation.py
testing/marionette/client/marionette/tests/unit/test_window_handles.py
--- a/browser/components/loop/test/functional/test_1_browser_call.py
+++ b/browser/components/loop/test/functional/test_1_browser_call.py
@@ -1,17 +1,23 @@
 from marionette_test import MarionetteTestCase
-from by import By
-import urlparse
-from errors import NoSuchElementException, StaleElementException
-# noinspection PyUnresolvedReferences
-from wait import Wait
+try:
+    from by import By
+    from errors import NoSuchElementException, StaleElementException
+    # noinspection PyUnresolvedReferences
+    from wait import Wait
+except ImportError:
+    from marionette_driver.by import By
+    from marionette_driver.errors import NoSuchElementException, StaleElementException
+    # noinspection PyUnresolvedReferences
+    from marionette_driver import Wait
 
 import os
 import sys
+import urlparse
 sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))
 
 import pyperclip
 
 from serversetup import LoopTestServers
 from config import *
 
 
--- a/browser/components/loop/test/shared/frontend_tester.py
+++ b/browser/components/loop/test/shared/frontend_tester.py
@@ -1,10 +1,10 @@
 from marionette_test import MarionetteTestCase
-from errors import NoSuchElementException
+from marionette_driver.errors import NoSuchElementException
 import threading
 import SimpleHTTPServer
 import SocketServer
 import BaseHTTPServer
 import socket
 import urllib
 import urlparse
 import os
--- a/testing/marionette/client/marionette/tests/unit/test_navigation.py
+++ b/testing/marionette/client/marionette/tests/unit/test_navigation.py
@@ -1,13 +1,12 @@
 # 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/.
 
-from marionette_test import MarionetteTestCase, skip_if_b2g, skip_if_e10s
 from errors import MarionetteException, TimeoutException
 
 class TestNavigate(MarionetteTestCase):
     def test_navigate(self):
         self.assertTrue(self.marionette.execute_script("window.location.href = 'about:blank'; return true;"))
         self.assertEqual("about:blank", self.marionette.execute_script("return window.location.href;"))
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
--- a/testing/marionette/client/marionette/tests/unit/test_window_handles.py
+++ b/testing/marionette/client/marionette/tests/unit/test_window_handles.py
@@ -1,16 +1,19 @@
 # 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/.
 
-from marionette import Keys
+from marionette_test import MarionetteTestCase, skip_if_e10s
+from marionette_driver.keys import Keys
 
 
+class TestWindowHandles(MarionetteTestCase):
 
+    @skip_if_e10s # Interactions with about: pages need e10s support (bug 1096488).
     def test_new_tab_window_handles(self):
         keys = [Keys.SHIFT]
         if self.marionette.session_capabilities['platformName'] == 'DARWIN':
             keys.append(Keys.META)
         else:
             keys.append(Keys.CONTROL)
         keys.append('a')
 
@@ -84,10 +87,71 @@ from marionette import Keys
             self.wait_for_condition(lambda mn: len(mn.window_handles) == i + 3)
             self.assertEqual(len(self.marionette.chrome_window_handles), 2)
 
         self.marionette.close_chrome_window()
         self.assertEqual(len(self.marionette.chrome_window_handles), 1)
         self.assertEqual(len(self.marionette.window_handles), 1)
         self.marionette.switch_to_window(start_tab)
 
+    # This sequence triggers an exception in Marionette:register with e10s on (bug 1120809).
+    @skip_if_e10s
     def test_tab_and_window_handles(self):
+        start_tab = self.marionette.current_window_handle
+        start_chrome_window = self.marionette.current_chrome_window_handle
+        tab_open_page = self.marionette.absolute_url("windowHandles.html")
+        window_open_page = self.marionette.absolute_url("test_windows.html")
 
+        # Open a new tab and switch to it.
+        self.marionette.navigate(tab_open_page)
+        link = self.marionette.find_element("id", "new-tab")
+        link.click()
+
+        self.wait_for_condition(lambda mn: len(mn.window_handles) == 2)
+        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
+        self.assertEqual(self.marionette.current_chrome_window_handle, start_chrome_window)
+
+        handles = self.marionette.window_handles
+        handles.remove(start_tab)
+
+        new_tab = handles.pop()
+        self.marionette.switch_to_window(new_tab)
+        self.assertEqual(self.marionette.get_url(), "about:blank")
+
+        # Open a new window from the new tab.
+        self.marionette.navigate(window_open_page)
+
+        link = self.marionette.find_element("link text", "Open new window")
+        link.click()
+        self.wait_for_condition(lambda mn: len(mn.window_handles) == 3)
+
+        self.assertEqual(len(self.marionette.chrome_window_handles), 2)
+        self.assertEqual(self.marionette.current_chrome_window_handle, start_chrome_window)
+
+        # Find the new window and switch to it.
+        handles = self.marionette.window_handles
+        handles.remove(start_tab)
+        handles.remove(new_tab)
+        new_window = handles.pop()
+
+        self.marionette.switch_to_window(new_window)
+        results_page = self.marionette.absolute_url("resultPage.html")
+        self.assertEqual(self.marionette.get_url(), results_page)
+
+        self.assertEqual(len(self.marionette.chrome_window_handles), 2)
+        self.assertNotEqual(self.marionette.current_chrome_window_handle, start_chrome_window)
+
+        # Return to our original tab and close it.
+        self.marionette.switch_to_window(start_tab)
+        self.marionette.close()
+        self.assertEquals(len(self.marionette.window_handles), 2)
+
+        # Close the opened window and carry on in our new tab.
+        self.marionette.switch_to_window(new_window)
+        self.marionette.close()
+        self.assertEqual(len(self.marionette.window_handles), 1)
+
+        self.marionette.switch_to_window(new_tab)
+        self.assertEqual(self.marionette.get_url(), results_page)
+        self.marionette.navigate("about:blank")
+
+        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
+        self.assertEqual(self.marionette.current_chrome_window_handle, start_chrome_window)