summaryrefslogtreecommitdiffstats
path: root/chrome/test/functional
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 21:47:45 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 21:47:45 +0000
commitea4dbc90144ad244f4520ac78d87040f0ee84221 (patch)
treeaf0a3654767755b8dab2c5c3fd26283055a98e8d /chrome/test/functional
parente4832a5322e8343ae2128c0e29a16d8709441fc2 (diff)
downloadchromium_src-ea4dbc90144ad244f4520ac78d87040f0ee84221.zip
chromium_src-ea4dbc90144ad244f4520ac78d87040f0ee84221.tar.gz
chromium_src-ea4dbc90144ad244f4520ac78d87040f0ee84221.tar.bz2
Add new omnibox functional tests
TEST=python chrome/test/functional/omnibox.py Review URL: http://codereview.chromium.org/2091011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/functional')
-rw-r--r--chrome/test/functional/downloads.py17
-rw-r--r--chrome/test/functional/omnibox.py110
2 files changed, 103 insertions, 24 deletions
diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py
index 84f3af7..1f2f49b 100644
--- a/chrome/test/functional/downloads.py
+++ b/chrome/test/functional/downloads.py
@@ -86,27 +86,14 @@ class DownloadsTest(pyauto.PyUITest):
self.assertTrue(os.path.exists(filename))
os.path.exists(filename) and os.remove(filename)
- def _EvalDataFrom(self, filename):
- """Return eval of python code from given file.
-
- The datastructure used in the file will be preserved.
- """
- data_file = os.path.join(self.DataDir(), 'downloads', filename)
- contents = open(data_file).read()
- try:
- ret = eval(contents, {'__builtins__': None}, None)
- except:
- print >>sys.stderr, '%s is an invalid data file.' % data_file
- raise
- return ret
-
def testCrazyFilenames(self):
"""Test downloading with filenames containing special chars.
The files are created on the fly and cleaned after use.
"""
download_dir = self.GetDownloadDirectory().value()
- crazy_filenames = self._EvalDataFrom('crazy_filenames.txt')
+ filename = os.path.join(self.DataDir(), 'downloads', 'crazy_filenames.txt')
+ crazy_filenames = self.EvalDataFrom(filename)
logging.info('Testing with %d crazy filenames' % len(crazy_filenames))
def _CreateFile(name):
diff --git a/chrome/test/functional/omnibox.py b/chrome/test/functional/omnibox.py
index b7797c5..f6b3dd4 100644
--- a/chrome/test/functional/omnibox.py
+++ b/chrome/test/functional/omnibox.py
@@ -4,6 +4,9 @@
# found in the LICENSE file.
import os
+import re
+import shutil
+import tempfile
import pyauto_functional # Must be imported before pyauto
import pyauto
@@ -24,6 +27,31 @@ class OmniboxTest(pyauto.PyUITest):
pp.pprint(self.GetOmniboxInfo().omniboxdict)
time.sleep(1)
+ def testFocusOnStartup(self):
+ """Verify that omnibox has focus on startup."""
+ self.assertTrue(self.GetOmniboxInfo().Properties('has_focus'))
+
+ def _GetOmniboxMatchesFor(self, text, windex=0, attr_dict=None):
+ """Fetch omnibox matches for the given query with the given properties.
+
+ Args:
+ text: the query text to use
+ windex: the window index to work on. Defaults to 0 (first window)
+ attr_dict: the dictionary of properties to be satisfied
+
+ Returns:
+ a list of match items
+ """
+ self.SetOmniboxText(text, windex=windex)
+ self.WaitUntilOmniboxQueryDone(windex=windex)
+ if not attr_dict:
+ matches = self.GetOmniboxInfo(windex=windex).Matches()
+ else:
+ matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes(
+ attr_dict=attr_dict)
+ self.assertTrue(matches)
+ return matches
+
def testHistoryResult(self):
"""Verify that omnibox can fetch items from history."""
url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html'))
@@ -31,12 +59,8 @@ class OmniboxTest(pyauto.PyUITest):
self.AppendTab(pyauto.GURL(url))
def _VerifyResult(query_text, description):
"""Verify result matching given description for given query_text."""
- self.SetOmniboxText(query_text)
- self.WaitUntilOmniboxQueryDone()
- info = self.GetOmniboxInfo()
- self.assertTrue(info.Matches())
- matches = info.MatchesWithAttributes({'description': description})
- self.assertTrue(matches)
+ matches = self._GetOmniboxMatchesFor(
+ query_text, attr_dict={'description': description})
self.assertEqual(1, len(matches))
item = matches[0]
self.assertEqual(url, item['destination_url'])
@@ -52,9 +76,7 @@ class OmniboxTest(pyauto.PyUITest):
title1 = 'Title Of Awesomeness'
self.NavigateToURL(url1)
self.NavigateToURL(url2)
- self.SetOmniboxText('file://')
- self.WaitUntilOmniboxQueryDone()
- matches = self.GetOmniboxInfo().Matches()
+ matches = self._GetOmniboxMatchesFor('file://')
# Find the index of match for url1
index = None
for i, match in enumerate(matches):
@@ -66,6 +88,76 @@ class OmniboxTest(pyauto.PyUITest):
self.OmniboxAcceptInput()
self.assertEqual(title1, self.GetActiveTabTitle())
+ def testGoogleSearch(self):
+ """Verify Google search item in omnibox results."""
+ search_text = 'hello world'
+ verify_str = 'Google Search'
+ url_re = 'http://www.google.com/search\?.*q=hello\+world.*'
+ matches_description = self._GetOmniboxMatchesFor(
+ search_text, attr_dict={'description': verify_str})
+ self.assertEqual(1, len(matches_description))
+ item = matches_description[0]
+ self.assertTrue(re.search(url_re, item['destination_url']))
+ self.assertEqual('search-what-you-typed', item['type'])
+
+ def testInlinAutoComplete(self):
+ """Verify inline autocomplete for a pre-visited url."""
+ self.NavigateToURL('http://www.google.com')
+ matches = self._GetOmniboxMatchesFor('goog')
+ # Omnibox should suggest auto completed url as the first item
+ matches_description = matches[0]
+ self.assertTrue('www.google.com' in matches_description['contents'])
+ self.assertEqual('history-url', matches_description['type'])
+ # The url should be inline-autocompleted in the omnibox
+ self.assertEqual('google.com/', self.GetOmniboxInfo().Text())
+
+ def testCrazyFilenames(self):
+ """Test omnibox query with filenames containing special chars.
+
+ The files are created on the fly and cleaned after use.
+ """
+ filename = os.path.join(self.DataDir(), 'downloads', 'crazy_filenames.txt')
+ zip_names = self.EvalDataFrom(filename)
+ # We got .zip filenames. Change them to .html
+ crazy_filenames = [x.replace('.zip', '.html') for x in zip_names]
+ title = 'given title'
+
+ def _CreateFile(name):
+ """Create the given html file."""
+ fp = open(name, 'w') # name could be unicode
+ print >>fp, '<html><title>%s</title><body>' % title
+ print >>fp, 'This is a junk file named <h2>%s</h2>' % repr(name)
+ print >>fp, '</body></html>'
+ fp.close()
+
+ crazy_fileurls = []
+ # Temp dir for hosting crazy filenames.
+ temp_dir = tempfile.mkdtemp(prefix='omnibox')
+ # Windows has a dual nature dealing with unicode filenames.
+ # While the files are internally saved as unicode, there's a non-unicode
+ # aware API that returns a locale-dependent coding on the true unicode
+ # filenames. This messes up things.
+ # Filesystem-interfacing functions like os.listdir() need to
+ # be given unicode strings to "do the right thing" on win.
+ # Ref: http://boodebr.org/main/python/all-about-python-and-unicode
+ try:
+ for filename in crazy_filenames: # filename is unicode.
+ file_path = os.path.join(temp_dir, filename.encode('utf-8'))
+ _CreateFile(os.path.join(temp_dir, filename))
+ file_url = self.GetFileURLForPath(file_path)
+ crazy_fileurls.append(file_url)
+ self.NavigateToURL(file_url)
+
+ # Verify omnibox queries.
+ for file_url in crazy_fileurls:
+ matches = self._GetOmniboxMatchesFor(
+ file_url, attr_dict={'type': 'url-what-you-typed',
+ 'destination_url': file_url,
+ 'description': title})
+ self.assertEqual(1, len(matches))
+ finally:
+ shutil.rmtree(unicode(temp_dir)) # unicode so that win treats nicely.
+
if __name__ == '__main__':
pyauto_functional.Main()