Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: omnibox.py

Issue 7043026: Added 3 more functions in popups.py (Closed) Base URL: http://src.chromium.org/svn/trunk/src/chrome/test/functional/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « PYAUTO_TESTS ('k') | popups.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import glob 6 import glob
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import tempfile 10 import tempfile
11 import urlparse 11 import urlparse
12 12
13 import pyauto_functional # Must be imported before pyauto 13 import pyauto_functional # Must be imported before pyauto
14 import pyauto 14 import pyauto
15 import test_utils
15 16
16 17
17 class OmniboxTest(pyauto.PyUITest): 18 class OmniboxTest(pyauto.PyUITest):
18 """TestCase for Omnibox.""" 19 """TestCase for Omnibox."""
19 20
20 def Debug(self): 21 def Debug(self):
21 """Test method for experimentation. 22 """Test method for experimentation.
22 23
23 This method will not run automatically. 24 This method will not run automatically.
24 """ 25 """
25 import pprint 26 import pprint
26 import time 27 import time
27 pp = pprint.PrettyPrinter(indent=2) 28 pp = pprint.PrettyPrinter(indent=2)
28 while True: 29 while True:
29 pp.pprint(self.GetOmniboxInfo().omniboxdict) 30 pp.pprint(self.GetOmniboxInfo().omniboxdict)
30 time.sleep(1) 31 time.sleep(1)
31 32
32 def testFocusOnStartup(self): 33 def testFocusOnStartup(self):
33 """Verify that omnibox has focus on startup.""" 34 """Verify that omnibox has focus on startup."""
34 self.WaitUntilOmniboxReadyHack() 35 self.WaitUntilOmniboxReadyHack()
35 self.assertTrue(self.GetOmniboxInfo().Properties('has_focus')) 36 self.assertTrue(self.GetOmniboxInfo().Properties('has_focus'))
36 37
37 def _GetOmniboxMatchesFor(self, text, windex=0, attr_dict=None):
38 """Fetch omnibox matches with the given attributes for the given query.
39
40 Args:
41 text: the query text to use
42 windex: the window index to work on. Defaults to 0 (first window)
43 attr_dict: the dictionary of properties to be satisfied
44
45 Returns:
46 a list of match items
47 """
48 self.SetOmniboxText(text, windex=windex)
49 self.WaitUntilOmniboxQueryDone(windex=windex)
50 if not attr_dict:
51 matches = self.GetOmniboxInfo(windex=windex).Matches()
52 else:
53 matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes(
54 attr_dict=attr_dict)
55 return matches
56
57 def testHistoryResult(self): 38 def testHistoryResult(self):
58 """Verify that omnibox can fetch items from history.""" 39 """Verify that omnibox can fetch items from history."""
59 url = self.GetFileURLForDataPath('title2.html') 40 url = self.GetFileURLForDataPath('title2.html')
60 title = 'Title Of Awesomeness' 41 title = 'Title Of Awesomeness'
61 self.AppendTab(pyauto.GURL(url)) 42 self.AppendTab(pyauto.GURL(url))
62 def _VerifyHistoryResult(query_list, description, windex=0): 43 def _VerifyHistoryResult(query_list, description, windex=0):
63 """Verify result matching given description for given list of queries.""" 44 """Verify result matching given description for given list of queries."""
64 for query_text in query_list: 45 for query_text in query_list:
65 matches = self._GetOmniboxMatchesFor( 46 matches = test_utils.GetOmniboxMatchesFor(self,
66 query_text, windex=windex, attr_dict={'description': description}) 47 query_text, windex=windex, attr_dict={'description': description})
67 self.assertTrue(matches) 48 self.assertTrue(matches)
68 self.assertEqual(1, len(matches)) 49 self.assertEqual(1, len(matches))
69 item = matches[0] 50 item = matches[0]
70 self.assertEqual(url, item['destination_url']) 51 self.assertEqual(url, item['destination_url'])
71 # Query using URL & title 52 # Query using URL & title
72 _VerifyHistoryResult([url, title], title) 53 _VerifyHistoryResult([url, title], title)
73 # Verify results in another tab 54 # Verify results in another tab
74 self.AppendTab(pyauto.GURL()) 55 self.AppendTab(pyauto.GURL())
75 _VerifyHistoryResult([url, title], title) 56 _VerifyHistoryResult([url, title], title)
76 # Verify results in another window 57 # Verify results in another window
77 self.OpenNewBrowserWindow(True) 58 self.OpenNewBrowserWindow(True)
78 self.WaitUntilOmniboxReadyHack(windex=1) 59 self.WaitUntilOmniboxReadyHack(windex=1)
79 _VerifyHistoryResult([url, title], title, windex=1) 60 _VerifyHistoryResult([url, title], title, windex=1)
80 # Verify results in an incognito window 61 # Verify results in an incognito window
81 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) 62 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
82 self.WaitUntilOmniboxReadyHack(windex=2) 63 self.WaitUntilOmniboxReadyHack(windex=2)
83 _VerifyHistoryResult([url, title], title, windex=2) 64 _VerifyHistoryResult([url, title], title, windex=2)
84 65
85 def _VerifyOmniboxURLMatches(self, url, description, windex=0): 66 def _VerifyOmniboxURLMatches(self, url, description, windex=0):
86 """Verify URL match results from the Omnibox. 67 """Verify URL match results from the Omnibox.
87 68
88 Args: 69 Args:
89 url: the url to use 70 url: the url to use
90 description: the string description within history page and google search 71 description: the string description within history page and google search
91 to match against 72 to match against
92 windex: the window index to work on. Defaults to 0 (first window) 73 windex: the window index to work on. Defaults to 0 (first window)
93 """ 74 """
94 matches_description = self._GetOmniboxMatchesFor( 75 matches_description = test_utils.GetOmniboxMatchesFor(self,
95 url, windex=windex, attr_dict={'description': description}) 76 url, windex=windex, attr_dict={'description': description})
96 self.assertEqual(1, len(matches_description)) 77 self.assertEqual(1, len(matches_description))
97 if description == 'Google Search': 78 if description == 'Google Search':
98 self.assertTrue(re.match('http://www.google.com/search.+', 79 self.assertTrue(re.match('http://www.google.com/search.+',
99 matches_description[0]['destination_url'])) 80 matches_description[0]['destination_url']))
100 else: 81 else:
101 self.assertEqual(url, matches_description[0]['destination_url']) 82 self.assertEqual(url, matches_description[0]['destination_url'])
102 83
103 def testFetchHistoryResultItems(self): 84 def testFetchHistoryResultItems(self):
104 """Verify omnibox fetches history items in second tab, win and Incognito.""" 85 """Verify omnibox fetches history items in second tab, win and Incognito."""
(...skipping 12 matching lines...) Expand all
117 self.NavigateToURL(url, 2, 0) 98 self.NavigateToURL(url, 2, 0)
118 self._VerifyOmniboxURLMatches(url, desc, windex=2) 99 self._VerifyOmniboxURLMatches(url, desc, windex=2)
119 100
120 def testSelect(self): 101 def testSelect(self):
121 """Verify omnibox popup selection.""" 102 """Verify omnibox popup selection."""
122 url1 = self.GetFileURLForDataPath('title2.html') 103 url1 = self.GetFileURLForDataPath('title2.html')
123 url2 = self.GetFileURLForDataPath('title1.html') 104 url2 = self.GetFileURLForDataPath('title1.html')
124 title1 = 'Title Of Awesomeness' 105 title1 = 'Title Of Awesomeness'
125 self.NavigateToURL(url1) 106 self.NavigateToURL(url1)
126 self.NavigateToURL(url2) 107 self.NavigateToURL(url2)
127 matches = self._GetOmniboxMatchesFor('file://') 108 matches = test_utils.GetOmniboxMatchesFor(self, 'file://')
128 self.assertTrue(matches) 109 self.assertTrue(matches)
129 # Find the index of match for url1 110 # Find the index of match for url1
130 index = None 111 index = None
131 for i, match in enumerate(matches): 112 for i, match in enumerate(matches):
132 if match['description'] == title1: 113 if match['description'] == title1:
133 index = i 114 index = i
134 self.assertTrue(index is not None) 115 self.assertTrue(index is not None)
135 self.OmniboxMovePopupSelection(index) # Select url1 line in popup 116 self.OmniboxMovePopupSelection(index) # Select url1 line in popup
136 self.assertEqual(url1, self.GetOmniboxInfo().Text()) 117 self.assertEqual(url1, self.GetOmniboxInfo().Text())
137 self.OmniboxAcceptInput() 118 self.OmniboxAcceptInput()
138 self.assertEqual(title1, self.GetActiveTabTitle()) 119 self.assertEqual(title1, self.GetActiveTabTitle())
139 120
140 def testGoogleSearch(self): 121 def testGoogleSearch(self):
141 """Verify Google search item in omnibox results.""" 122 """Verify Google search item in omnibox results."""
142 search_text = 'hello world' 123 search_text = 'hello world'
143 verify_str = 'Google Search' 124 verify_str = 'Google Search'
144 url_re = 'http://www.google.com/search\?.*q=hello\+world.*' 125 url_re = 'http://www.google.com/search\?.*q=hello\+world.*'
145 matches_description = self._GetOmniboxMatchesFor( 126 matches_description = test_utils.GetOmniboxMatchesFor(self,
146 search_text, attr_dict={'description': verify_str}) 127 search_text, attr_dict={'description': verify_str})
147 self.assertTrue(matches_description) 128 self.assertTrue(matches_description)
148 self.assertEqual(1, len(matches_description)) 129 self.assertEqual(1, len(matches_description))
149 item = matches_description[0] 130 item = matches_description[0]
150 self.assertTrue(re.search(url_re, item['destination_url'])) 131 self.assertTrue(re.search(url_re, item['destination_url']))
151 self.assertEqual('search-what-you-typed', item['type']) 132 self.assertEqual('search-what-you-typed', item['type'])
152 133
153 def testInlinAutoComplete(self): 134 def testInlinAutoComplete(self):
154 """Verify inline autocomplete for a pre-visited url.""" 135 """Verify inline autocomplete for a pre-visited url."""
155 self.NavigateToURL('http://www.google.com') 136 self.NavigateToURL('http://www.google.com')
156 matches = self._GetOmniboxMatchesFor('goog') 137 matches = test_utils.GetOmniboxMatchesFor(self, 'goog')
157 self.assertTrue(matches) 138 self.assertTrue(matches)
158 # Omnibox should suggest auto completed url as the first item 139 # Omnibox should suggest auto completed url as the first item
159 matches_description = matches[0] 140 matches_description = matches[0]
160 self.assertTrue('www.google.com' in matches_description['contents']) 141 self.assertTrue('www.google.com' in matches_description['contents'])
161 self.assertEqual('history-url', matches_description['type']) 142 self.assertEqual('history-url', matches_description['type'])
162 # The url should be inline-autocompleted in the omnibox 143 # The url should be inline-autocompleted in the omnibox
163 self.assertTrue('google.com' in self.GetOmniboxInfo().Text()) 144 self.assertTrue('google.com' in self.GetOmniboxInfo().Text())
164 145
165 def testCrazyFilenames(self): 146 def testCrazyFilenames(self):
166 """Test omnibox query with filenames containing special chars. 147 """Test omnibox query with filenames containing special chars.
(...skipping 27 matching lines...) Expand all
194 try: 175 try:
195 for filename in crazy_filenames: # filename is unicode. 176 for filename in crazy_filenames: # filename is unicode.
196 file_path = os.path.join(temp_dir, filename.encode('utf-8')) 177 file_path = os.path.join(temp_dir, filename.encode('utf-8'))
197 _CreateFile(os.path.join(temp_dir, filename)) 178 _CreateFile(os.path.join(temp_dir, filename))
198 file_url = self.GetFileURLForPath(file_path) 179 file_url = self.GetFileURLForPath(file_path)
199 crazy_fileurls.append(file_url) 180 crazy_fileurls.append(file_url)
200 self.NavigateToURL(file_url) 181 self.NavigateToURL(file_url)
201 182
202 # Verify omnibox queries. 183 # Verify omnibox queries.
203 for file_url in crazy_fileurls: 184 for file_url in crazy_fileurls:
204 matches = self._GetOmniboxMatchesFor( 185 matches = test_utils.GetOmniboxMatchesFor(self,
205 file_url, attr_dict={'type': 'url-what-you-typed', 186 file_url, attr_dict={'type': 'url-what-you-typed',
206 'description': title}) 187 'description': title})
207 self.assertTrue(matches) 188 self.assertTrue(matches)
208 self.assertEqual(1, len(matches)) 189 self.assertEqual(1, len(matches))
209 self.assertTrue(os.path.basename(file_url) in 190 self.assertTrue(os.path.basename(file_url) in
210 matches[0]['destination_url']) 191 matches[0]['destination_url'])
211 finally: 192 finally:
212 shutil.rmtree(unicode(temp_dir)) # unicode so that win treats nicely. 193 shutil.rmtree(unicode(temp_dir)) # unicode so that win treats nicely.
213 194
214 def testSuggest(self): 195 def testSuggest(self):
215 """Verify suggested results in omnibox.""" 196 """Verify suggested results in omnibox."""
216 matches = self._GetOmniboxMatchesFor('apple') 197 matches = test_utils.GetOmniboxMatchesFor(self, 'apple')
217 self.assertTrue(matches) 198 self.assertTrue(matches)
218 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) 199 self.assertTrue([x for x in matches if x['type'] == 'search-suggest'])
219 200
220 def testDifferentTypesOfResults(self): 201 def testDifferentTypesOfResults(self):
221 """Verify different types of results from omnibox. 202 """Verify different types of results from omnibox.
222 203
223 This includes history result, bookmark result, suggest results. 204 This includes history result, bookmark result, suggest results.
224 """ 205 """
225 url = 'http://www.google.com/' 206 url = 'http://www.google.com/'
226 title = 'Google' 207 title = 'Google'
227 search_string = 'google' 208 search_string = 'google'
228 self.AddBookmarkURL( # Add a bookmark 209 self.AddBookmarkURL( # Add a bookmark
229 self.GetBookmarkModel().BookmarkBar()['id'], 0, title, url) 210 self.GetBookmarkModel().BookmarkBar()['id'], 0, title, url)
230 self.NavigateToURL(url) # Build up history 211 self.NavigateToURL(url) # Build up history
231 matches = self._GetOmniboxMatchesFor(search_string) 212 matches = test_utils.GetOmniboxMatchesFor(self, search_string)
232 self.assertTrue(matches) 213 self.assertTrue(matches)
233 # Verify starred result (indicating bookmarked url) 214 # Verify starred result (indicating bookmarked url)
234 self.assertTrue([x for x in matches if x['starred'] == True]) 215 self.assertTrue([x for x in matches if x['starred'] == True])
235 for item_type in ('history-url', 'search-what-you-typed', 216 for item_type in ('history-url', 'search-what-you-typed',
236 'search-suggest',): 217 'search-suggest',):
237 self.assertTrue([x for x in matches if x['type'] == item_type]) 218 self.assertTrue([x for x in matches if x['type'] == item_type])
238 219
239 def testSuggestPref(self): 220 def testSuggestPref(self):
240 """Verify no suggests for omnibox when suggested-services disabled.""" 221 """Verify no suggests for omnibox when suggested-services disabled."""
241 search_string = 'apple' 222 search_string = 'apple'
242 self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) 223 self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled))
243 matches = self._GetOmniboxMatchesFor(search_string) 224 matches = test_utils.GetOmniboxMatchesFor(self, search_string)
244 self.assertTrue(matches) 225 self.assertTrue(matches)
245 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) 226 self.assertTrue([x for x in matches if x['type'] == 'search-suggest'])
246 # Disable suggest-service 227 # Disable suggest-service
247 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) 228 self.SetPrefs(pyauto.kSearchSuggestEnabled, False)
248 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) 229 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled))
249 matches = self._GetOmniboxMatchesFor(search_string) 230 matches = test_utils.GetOmniboxMatchesFor(self, search_string)
250 self.assertTrue(matches) 231 self.assertTrue(matches)
251 # Verify there are no suggest results 232 # Verify there are no suggest results
252 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) 233 self.assertFalse([x for x in matches if x['type'] == 'search-suggest'])
253 234
254 def testAutoCompleteForSearch(self): 235 def testAutoCompleteForSearch(self):
255 """Verify omnibox autocomplete for search.""" 236 """Verify omnibox autocomplete for search."""
256 search_string = 'youtu' 237 search_string = 'youtu'
257 verify_string = 'youtube' 238 verify_string = 'youtube'
258 matches = self._GetOmniboxMatchesFor(search_string) 239 matches = test_utils.GetOmniboxMatchesFor(self, search_string)
259 # retrieve last contents element. 240 # retrieve last contents element.
260 matches_description = matches[-1]['contents'].split() 241 matches_description = matches[-1]['contents'].split()
261 self.assertEqual(verify_string, matches_description[0]) 242 self.assertEqual(verify_string, matches_description[0])
262 243
263 def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0): 244 def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0):
264 """Check if we get the Bookmark for complete and partial inputs.""" 245 """Check if we get the Bookmark for complete and partial inputs."""
265 # Check if the complete URL would get the bookmark. 246 # Check if the complete URL would get the bookmark.
266 url_matches = self._GetOmniboxMatchesFor(url, windex=windex) 247 url_matches = test_utils.GetOmniboxMatchesFor(self, url, windex=windex)
267 self._VerifyHasBookmarkResult(url_matches) 248 self._VerifyHasBookmarkResult(url_matches)
268 # Check if the complete title would get the bookmark. 249 # Check if the complete title would get the bookmark.
269 title_matches = self._GetOmniboxMatchesFor(title, windex=windex) 250 title_matches = test_utils.GetOmniboxMatchesFor(self, title, windex=windex)
270 self._VerifyHasBookmarkResult(title_matches) 251 self._VerifyHasBookmarkResult(title_matches)
271 # Check if the partial URL would get the bookmark. 252 # Check if the partial URL would get the bookmark.
272 split_url = urlparse.urlsplit(url) 253 split_url = urlparse.urlsplit(url)
273 partial_url = self._GetOmniboxMatchesFor(split_url.scheme, windex=windex) 254 partial_url = test_utils.GetOmniboxMatchesFor(self,
255 split_url.scheme, windex=windex)
274 self._VerifyHasBookmarkResult(partial_url) 256 self._VerifyHasBookmarkResult(partial_url)
275 # Check if the partial title would get the bookmark. 257 # Check if the partial title would get the bookmark.
276 split_title = title.split() 258 split_title = title.split()
277 search_term = split_title[len(split_title) - 1] 259 search_term = split_title[len(split_title) - 1]
278 partial_title = self._GetOmniboxMatchesFor(search_term, windex=windex) 260 partial_title = test_utils.GetOmniboxMatchesFor(self,
261 search_term, windex=windex)
279 self._VerifyHasBookmarkResult(partial_title) 262 self._VerifyHasBookmarkResult(partial_title)
280 263
281 def _GotContentHistory(self, search_text, url): 264 def _GotContentHistory(self, search_text, url):
282 """Determines if omnibox returns a previously visited page for given 265 """Determines if omnibox returns a previously visited page for given
283 search text 266 search text
284 """ 267 """
285 # Omnibox doesn't change results if searching the same text repeatedly. 268 # Omnibox doesn't change results if searching the same text repeatedly.
286 # So setting '' in omnibox before the next repeated search. 269 # So setting '' in omnibox before the next repeated search.
287 self.SetOmniboxText('') 270 self.SetOmniboxText('')
288 matches = self._GetOmniboxMatchesFor(search_text) 271 matches = test_utils.GetOmniboxMatchesFor(self, search_text)
289 matches_description = [x for x in matches if x['destination_url'] == url] 272 matches_description = [x for x in matches if x['destination_url'] == url]
290 return 1 == len(matches_description) 273 return 1 == len(matches_description)
291 274
292 def testContentHistory(self): 275 def testContentHistory(self):
293 """Verify omnibox results when entering page content 276 """Verify omnibox results when entering page content
294 277
295 Test verifies that visited page shows up in omnibox on entering page 278 Test verifies that visited page shows up in omnibox on entering page
296 content. 279 content.
297 """ 280 """
298 url = self.GetFileURLForPath( 281 url = self.GetFileURLForPath(
(...skipping 26 matching lines...) Expand all
325 self.NavigateToURL(url, 1, 0) 308 self.NavigateToURL(url, 1, 0)
326 self._CheckBookmarkResultForVariousInputs(url, title, windex=1) 309 self._CheckBookmarkResultForVariousInputs(url, title, windex=1)
327 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) 310 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
328 self.assertEqual(3, self.GetBrowserWindowCount()) 311 self.assertEqual(3, self.GetBrowserWindowCount())
329 self.NavigateToURL(url, 2, 0) 312 self.NavigateToURL(url, 2, 0)
330 self._CheckBookmarkResultForVariousInputs(url, title, windex=2) 313 self._CheckBookmarkResultForVariousInputs(url, title, windex=2)
331 314
332 315
333 if __name__ == '__main__': 316 if __name__ == '__main__':
334 pyauto_functional.Main() 317 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « PYAUTO_TESTS ('k') | popups.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698