Bug 772835: changing get_window and get_windows to match Selenium; r=jgriffin
authorDavid Burns <dburns@mozilla.com>
Wed, 11 Jul 2012 12:31:07 -0700
changeset 101822 f25cba119ef99aaf3990b0cd923bd53d5835f2c7
parent 101821 322ef042e1d227966b440c7533a53bbc38198fc7
child 101823 83e30b5c8dbaeb939dc23a8c07af084eacba1936
push id1729
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 20:02:43 +0000
treeherdermozilla-aurora@f4e75e148951 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs772835
milestone16.0a1
Bug 772835: changing get_window and get_windows to match Selenium; r=jgriffin
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/test_protocol.py
testing/marionette/client/marionette/tests/unit/test_click.py
testing/marionette/client/marionette/tests/unit/test_elementState.py
testing/marionette/client/marionette/tests/unit/test_findelement.py
testing/marionette/client/marionette/tests/unit/test_getattr.py
testing/marionette/client/marionette/tests/unit/test_selected.py
testing/marionette/client/marionette/tests/unit/test_switch_frame.py
testing/marionette/client/marionette/tests/unit/test_text.py
testing/marionette/client/marionette/tests/unit/test_window_management.py
testing/marionette/client/marionette/tests/unit/test_window_switching.py
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -236,32 +236,34 @@ class Marionette(object):
     def set_script_timeout(self, timeout):
         response = self._send_message('setScriptTimeout', 'ok', value=timeout)
         return response
 
     def set_search_timeout(self, timeout):
         response = self._send_message('setSearchTimeout', 'ok', value=timeout)
         return response
 
-    def get_window(self):
+    @property
+    def current_window_handle(self):
         self.window = self._send_message('getWindow', 'value')
         return self.window
     
     @property
     def title(self):
         response = self._send_message('getTitle', 'value') 
         return response
 
-    def get_windows(self):
+    @property
+    def window_handles(self):
         response = self._send_message('getWindows', 'value')
         return response
 
     def close_window(self, window_id=None):
         if not window_id:
-            window_id = self.get_window()
+            window_id = self.current_window_handle
         response = self._send_message('closeWindow', 'ok', value=window_id)
         return response
 
     def set_context(self, context):
         assert(context == self.CONTEXT_CHROME or context == self.CONTEXT_CONTENT)
         return self._send_message('setContext', 'ok', value=context)
 
     def switch_to_window(self, window_id):
--- a/testing/marionette/client/marionette/test_protocol.py
+++ b/testing/marionette/client/marionette/test_protocol.py
@@ -14,19 +14,19 @@ if __name__ == '__main__':
     thread.daemon = True
     thread.start()
 
     # run some trivial unit tests which just verify the protocol
     m = Marionette(host='localhost', port=2626)
     assert(m.status()['os']['arch'] == 'x86')
     assert(m.start_session())
     assert(m.get_session_capabilities()['javascriptEnabled'] == True)
-    assert(m.get_window() == server.TEST_CURRENT_WINDOW)
+    assert(m.current_window_handle == server.TEST_CURRENT_WINDOW)
     assert(m.window == server.TEST_CURRENT_WINDOW)
-    assert(m.get_windows() == server.TEST_WINDOW_LIST)
+    assert(m.window_handles == server.TEST_WINDOW_LIST)
     assert(m.switch_to_window('window2'))
     assert(m.window == 'window2')
     assert(m.close_window('window2'))
     assert(m.set_script_timeout(1000))
     assert(m.set_search_timeout(500))
     assert(m.get_url() == server.TEST_URL)
     assert(m.navigate(server.TEST_URL))
     assert(m.go_back())
@@ -55,11 +55,11 @@ if __name__ == '__main__':
     assert(m.find_element(HTMLElement.ID, 'id3').get_attribute('value') == server.TEST_GET_VALUE)
     assert(m.delete_session())
 
     # verify a session is started automatically for us if needed
     assert(m.switch_to_frame('frame1'))
     assert(m.switch_to_frame(1))
     assert(m.switch_to_frame(m.find_element(HTMLElement.ID, 'frameid')))
     assert(m.switch_to_frame())
-    assert(m.get_window() == server.TEST_CURRENT_WINDOW)
+    assert(m.current_window_handle == server.TEST_CURRENT_WINDOW)
     assert(m.set_context(m.CONTEXT_CHROME))
     assert(m.delete_session())
--- a/testing/marionette/client/marionette/tests/unit/test_click.py
+++ b/testing/marionette/client/marionette/tests/unit/test_click.py
@@ -18,25 +18,25 @@ class TestClick(MarionetteTestCase):
         self.marionette.navigate(test_html)
         self.marionette.find_element("link text", "333333").click()
         self.assertEqual(self.marionette.title, "XHTML Test Page")
 
 class TestClickChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_click(self):
-        wins = self.marionette.get_windows()
+        wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
         box = self.marionette.find_element("id", "testBox")
         self.assertFalse(self.marionette.execute_script("return arguments[0].checked;", [box]))
         box.click()
         self.assertTrue(self.marionette.execute_script("return arguments[0].checked;", [box]))
--- a/testing/marionette/client/marionette/tests/unit/test_elementState.py
+++ b/testing/marionette/client/marionette/tests/unit/test_elementState.py
@@ -21,17 +21,17 @@ class TestState(MarionetteTestCase):
         self.assertTrue(l.is_displayed())
         self.marionette.execute_script("arguments[0].hidden = true;", [l])
         self.assertFalse(l.is_displayed())
 
 class TestStateChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_isEnabled(self):
--- a/testing/marionette/client/marionette/tests/unit/test_findelement.py
+++ b/testing/marionette/client/marionette/tests/unit/test_findelement.py
@@ -122,17 +122,17 @@ class TestElements(MarionetteTestCase):
         self.assertTrue(True, self.marionette.set_search_timeout(4000))
         self.marionette.navigate(test_html)
         self.assertEqual(HTMLElement, type(self.marionette.find_element("id", "newDiv")))
 
 class TestElementsChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_id(self):
--- a/testing/marionette/client/marionette/tests/unit/test_getattr.py
+++ b/testing/marionette/client/marionette/tests/unit/test_getattr.py
@@ -11,21 +11,20 @@ class TestGetAttribute(MarionetteTestCas
         self.marionette.navigate(test_html)
         l = self.marionette.find_element("id", "mozLink")
         self.assertEqual("mozLink", l.get_attribute("id"))
 
 class TestGetAttributeChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_getAttribute(self):
         el = self.marionette.execute_script("return window.document.getElementById('textInput');")
-        found_el = self.marionette.find_element("id", "textInput")
         self.assertEqual(el.get_attribute("id"), "textInput")
 
--- a/testing/marionette/client/marionette/tests/unit/test_selected.py
+++ b/testing/marionette/client/marionette/tests/unit/test_selected.py
@@ -13,25 +13,25 @@ class TestSelected(MarionetteTestCase):
         self.assertFalse(box.selected())
         box.click()
         self.assertTrue(box.selected())
 
 class TestSelectedChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_selected(self):
-        wins = self.marionette.get_windows()
+        wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
         box = self.marionette.find_element("id", "testBox")
         self.assertFalse(box.selected())
         self.assertFalse(self.marionette.execute_script("arguments[0].checked = true;", [box]))
         self.assertTrue(box.selected())
--- a/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
+++ b/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
@@ -31,17 +31,17 @@ class TestSwitchFrame(MarionetteTestCase
         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;"))
 
 class TestSwitchFrameChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_switch_simple(self):
--- a/testing/marionette/client/marionette/tests/unit/test_text.py
+++ b/testing/marionette/client/marionette/tests/unit/test_text.py
@@ -27,43 +27,43 @@ class TestText(MarionetteTestCase):
         self.assertEqual("asdf", self.marionette.execute_script("return arguments[0].value;", [l]))
         l.send_keys("o")
         self.assertEqual("asdfo", self.marionette.execute_script("return arguments[0].value;", [l]))
 
 class TestTextChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
-        self.win = self.marionette.get_window()
+        self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
 
     def tearDown(self):
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_getText(self):
-        wins = self.marionette.get_windows()
+        wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
         box = self.marionette.find_element("id", "textInput")
         self.assertEqual("test", box.text())
 
     def test_clearText(self):
-        wins = self.marionette.get_windows()
+        wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
         box = self.marionette.find_element("id", "textInput")
         self.assertEqual("test", box.text())
         box.clear()
         self.assertEqual("", box.text())
 
     def test_sendKeys(self):
-        wins = self.marionette.get_windows()
+        wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
         box = self.marionette.find_element("id", "textInput")
         self.assertEqual("test", box.text())
         box.send_keys("at")
         self.assertEqual("attest", box.text())
--- a/testing/marionette/client/marionette/tests/unit/test_window_management.py
+++ b/testing/marionette/client/marionette/tests/unit/test_window_management.py
@@ -27,35 +27,35 @@ class TestSwitchWindow(MarionetteTestCas
                                                  .getService(Components.interfaces.nsIWindowWatcher); 
                                         var win = ww.getWindowByName("testWin", null);
                                         if (win != null)
                                           win.close();
                                         """)
         self.marionette.set_context("content")
 
     def test_windows(self):
-        orig_win = self.marionette.get_window()
-        orig_available = self.marionette.get_windows()
+        orig_win = self.marionette.current_window_handle
+        orig_available = self.marionette.window_handles
         self.open_new_window()
         #assert we're still in the original window
-        self.assertEqual(self.marionette.get_window(), orig_win)
-        now_available = self.marionette.get_windows()
+        self.assertEqual(self.marionette.current_window_handle, orig_win)
+        now_available = self.marionette.window_handles
         #assert we can find the new window
         self.assertEqual(len(now_available), len(orig_available) + 1) 
         #assert that our window is there
         self.assertTrue(orig_win in now_available)
         new_win = None
         for win in now_available:
             if win != orig_win:
                 new_win = orig_win
         #switch to another window
         self.marionette.switch_to_window(new_win)
-        self.assertEqual(self.marionette.get_window(), new_win)
+        self.assertEqual(self.marionette.current_window_handle, new_win)
         #switch back
         self.marionette.switch_to_window(orig_win)
         self.close_new_window()
-        self.assertEqual(self.marionette.get_window(), orig_win)
-        self.assertEqual(len(self.marionette.get_windows()), len(orig_available))
+        self.assertEqual(self.marionette.current_window_handle, orig_win)
+        self.assertEqual(len(self.marionette.window_handles), len(orig_available))
 
     def tearDown(self):
         #ensure that we close the window, regardless of pass/failure
         self.close_new_window()
         MarionetteTestCase.tearDown(self)
--- a/testing/marionette/client/marionette/tests/unit/test_window_switching.py
+++ b/testing/marionette/client/marionette/tests/unit/test_window_switching.py
@@ -6,40 +6,40 @@ import os
 import time
 from marionette_test import MarionetteTestCase
 
 class TestWindowSwitching(MarionetteTestCase):
     def testJSWindowCreationAndSwitching(self):
         test_html = self.marionette.absolute_url("test_windows.html")
         self.marionette.navigate(test_html)
 
-        current_window = self.marionette.get_window()
+        current_window = self.marionette.current_window_handle
         link = self.marionette.find_element("link text", "Open new window")
         link.click()
 
-        windows = self.marionette.get_windows()
+        windows = self.marionette.window_handles
         windows.remove(current_window)
         self.marionette.switch_to_window(windows[0])
 
         title = self.marionette.execute_script("return document.title")
         results_page = self.marionette.absolute_url("resultPage.html")
         self.assertEqual(self.marionette.get_url(), results_page)
         self.assertEqual(title, "We Arrive Here")
 
         #ensure navigate works in our current window
         other_page = self.marionette.absolute_url("test.html")
         self.marionette.navigate(other_page)
-        other_window = self.marionette.get_window()
+        other_window = self.marionette.current_window_handle
 
         #try to access its dom
         #since Bug 720714 stops us from checking DOMContentLoaded, we wait a bit
         for i in range(30):
             try:
                 self.marionette.find_element("id", "mozLink")
                 break
             except:
                 pass
             time.sleep(1)
 
-        self.assertEqual(other_window, self.marionette.get_window())
+        self.assertEqual(other_window, self.marionette.current_window_handle)
         self.marionette.switch_to_window(current_window)
-        self.assertEqual(current_window, self.marionette.get_window())
+        self.assertEqual(current_window, self.marionette.current_window_handle)