diff options
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 5 | ||||
-rw-r--r-- | chrome/test/functional/navigation.py | 102 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.cc | 6 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.h | 3 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 4 |
5 files changed, 118 insertions, 2 deletions
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 585870d..c556fc0 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -19,11 +19,12 @@ { 'all': [ 'bookmarks', - 'history', - 'test_basic.SimpleTest.testCanOpenGoogle', 'downloads', + 'history', + 'navigation', 'prefs', 'special_tabs', + 'test_basic.SimpleTest.testCanOpenGoogle', ], 'win': [ diff --git a/chrome/test/functional/navigation.py b/chrome/test/functional/navigation.py new file mode 100644 index 0000000..9abcc38 --- /dev/null +++ b/chrome/test/functional/navigation.py @@ -0,0 +1,102 @@ +#!/usr/bin/python +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os + +import pyauto_functional # Must be imported before pyauto +import pyauto + + +class NavigationTest(pyauto.PyUITest): + """TestCase for Navigation.""" + + def _ObtainURLList(self): + """Get a list of file:// urls for use in this test case.""" + urls = [] + for fname in ['title1.html', 'title2.html', 'title3.html']: + urls.append(self.GetFileURLForPath(os.path.join(self.DataDir(), fname))) + return urls + + def _OpenTabsInWindow(self, urls, windex): + """Open, verify given urls in the window at the given index.""" + for url in self._ObtainURLList(): + self.AppendTab(pyauto.GURL(url), windex) + self.assertEqual(url, self.GetActiveTabURL(windex).spec()) + self.assertEqual(len(urls) + 1, self.GetTabCount(windex)) + for i in range(len(urls)): + self.ActivateTab(i + 1, windex) # ignore first tab + self.assertEqual(self.GetActiveTabURL(windex).spec(), urls[i]) + + def testMultipleTabsAndWindows(self): + """Verify multiple tabs and windows.""" + self.assertEqual(1, self.GetBrowserWindowCount()) + urls = self._ObtainURLList() + self._OpenTabsInWindow(urls, 0) + more_windows = 3 + for windex in range(1, more_windows + 1): + self.OpenNewBrowserWindow(True) + self.assertEqual(1 + windex, self.GetBrowserWindowCount()) + self._OpenTabsInWindow(urls, windex) + + def testTabsOpenClose(self): + """Verify tabs open/close.""" + urls = self._ObtainURLList() + def _OpenCloseTabsInWindow(windex): + """Open/close tabs in window at given index.""" + self.AppendTab(pyauto.GURL(urls[0]), windex) + self.assertEqual(2, self.GetTabCount(windex)) + self.AppendTab(pyauto.GURL(urls[1]), windex) + self.assertEqual(3, self.GetTabCount(windex)) + self.GetBrowserWindow(windex).GetTab(2).Close(True) + self.assertEqual(2, self.GetTabCount(windex)) + self.GetBrowserWindow(windex).GetTab(1).Close(True) + self.assertEqual(1, self.GetTabCount(windex)) + _OpenCloseTabsInWindow(0) + self.OpenNewBrowserWindow(True) + _OpenCloseTabsInWindow(1) + + def testForwardBackward(self): + """Verify forward/backward actions.""" + urls = self._ObtainURLList() + assert len(urls) >= 3, 'Need at least 3 urls.' + for url in urls: + self.NavigateToURL(url) + tab = self.GetBrowserWindow(0).GetTab(0) + self.assertEqual(self.GetActiveTabURL().spec(), urls[-1]) + for i in [-2, -3]: + tab.GoBack() + self.assertEqual(self.GetActiveTabURL().spec(), urls[i]) + for i in [-2, -1]: + tab.GoForward() + self.assertEqual(self.GetActiveTabURL().spec(), urls[i]) + + def testCanDuplicateTab(self): + """Open a page, duplicate it and make sure the new tab was duplicated""" + urls = self._ObtainURLList() + assert len(urls) >= 3, 'Need at least 3 urls.' + self.NavigateToURL(urls[0]) + self.ApplyAccelerator(pyauto.IDC_DUPLICATE_TAB) + self.assertEqual(self.GetTabCount(), 2) + self.assertEqual(urls[0], self.GetActiveTabURL().spec()) + + def testBrutalTabsAndWindows(self): + """Open "many" windows and tabs.""" + urls = self._ObtainURLList() + num_windows = 10 + orig_num_windows = self.GetBrowserWindowCount() + for windex in range(1, num_windows): + self.OpenNewBrowserWindow(True) + self.assertEqual(orig_num_windows + windex, self.GetBrowserWindowCount()) + # Open many tabs in 1st window + num_tabs = 20 + orig_num_tabs = self.GetTabCount(windex) + print 'orig_num_tabs', orig_num_tabs + for tindex in range(1, num_tabs): + self.AppendTab(pyauto.GURL(urls[0])) + self.assertEqual(orig_num_tabs + tindex, self.GetTabCount()) + + +if __name__ == '__main__': + pyauto_functional.Main() diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index fab3832..452727b 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -156,6 +156,12 @@ bool PyUITestBase::OpenNewBrowserWindow(bool show) { return automation()->OpenNewBrowserWindow(Browser::TYPE_NORMAL, show); } +int PyUITestBase::GetBrowserWindowCount() { + int num_windows = 0; + EXPECT_TRUE(automation()->GetBrowserWindowCount(&num_windows)); + return num_windows; +} + bool PyUITestBase::InstallExtension(const FilePath& crx_file, bool with_ui) { scoped_refptr<ExtensionProxy> proxy = automation()->InstallExtension(crx_file, with_ui); diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index 321cfde..d293370 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -98,6 +98,9 @@ class PyUITestBase : public UITestBase { // Open a new browser window. Returns false on failure. bool OpenNewBrowserWindow(bool show); + // Fetch the number of browser windows. Includes popups. + int GetBrowserWindowCount(); + // Installs the extension crx. Returns true only if extension was installed // and loaded successfully. Overinstalls will fail. bool InstallExtension(const FilePath& crx_file, bool with_ui); diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 626303f..63ec51f 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -276,6 +276,10 @@ class PyUITestBase { %feature("docstring", "Open a new browser window.") OpenNewBrowserWindow; bool OpenNewBrowserWindow(bool show); + %feature("docstring", "Fetch the number of browser windows. Includes popups.") + GetBrowserWindowCount; + int GetBrowserWindowCount(); + %feature("docstring", "Get the index of the active tab in the given or " "first window. Indexes are zero-based.") GetActiveTabIndex; int GetActiveTabIndex(int window_index=0); |