OLD | NEW |
---|---|
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 os | 7 import os |
7 import re | 8 import re |
8 import shutil | 9 import shutil |
9 import tempfile | 10 import tempfile |
10 import urlparse | 11 import urlparse |
11 | 12 |
12 import pyauto_functional # Must be imported before pyauto | 13 import pyauto_functional # Must be imported before pyauto |
13 import pyauto | 14 import pyauto |
14 | 15 |
15 | 16 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 matches = self._GetOmniboxMatchesFor('apple') | 207 matches = self._GetOmniboxMatchesFor('apple') |
207 self.assertTrue(matches) | 208 self.assertTrue(matches) |
208 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) | 209 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) |
209 # Disable suggest-service | 210 # Disable suggest-service |
210 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) | 211 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) |
211 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) | 212 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) |
212 matches = self._GetOmniboxMatchesFor('apple') | 213 matches = self._GetOmniboxMatchesFor('apple') |
213 self.assertTrue(matches) | 214 self.assertTrue(matches) |
214 # Verify there are no suggest results | 215 # Verify there are no suggest results |
215 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) | 216 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) |
216 | 217 |
Nirnimesh
2010/12/22 19:32:51
remove stray whitespace chars
| |
217 def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0): | 218 def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0): |
218 """Check if we get the Bookmark for complete and partial inputs.""" | 219 """Check if we get the Bookmark for complete and partial inputs.""" |
219 # Check if the complete URL would get the bookmark | 220 # Check if the complete URL would get the bookmark |
220 url_matches = self._GetOmniboxMatchesFor(url, windex=windex) | 221 url_matches = self._GetOmniboxMatchesFor(url, windex=windex) |
221 self._VerifyHasBookmarkResult(url_matches) | 222 self._VerifyHasBookmarkResult(url_matches) |
222 # Check if the complete title would get the bookmark | 223 # Check if the complete title would get the bookmark |
223 title_matches = self._GetOmniboxMatchesFor(title, windex=windex) | 224 title_matches = self._GetOmniboxMatchesFor(title, windex=windex) |
224 self._VerifyHasBookmarkResult(title_matches) | 225 self._VerifyHasBookmarkResult(title_matches) |
225 # Check if the partial URL would get the bookmark | 226 # Check if the partial URL would get the bookmark |
226 split_url = urlparse.urlsplit(url) | 227 split_url = urlparse.urlsplit(url) |
227 partial_url = self._GetOmniboxMatchesFor(split_url.scheme, windex=windex) | 228 partial_url = self._GetOmniboxMatchesFor(split_url.scheme, windex=windex) |
228 self._VerifyHasBookmarkResult(partial_url) | 229 self._VerifyHasBookmarkResult(partial_url) |
229 # Check if the partial title would get the bookmark | 230 # Check if the partial title would get the bookmark |
230 split_title = title.split() | 231 split_title = title.split() |
231 search_term = split_title[len(split_title) - 1] | 232 search_term = split_title[len(split_title) - 1] |
232 partial_title = self._GetOmniboxMatchesFor(search_term, windex=windex) | 233 partial_title = self._GetOmniboxMatchesFor(search_term, windex=windex) |
233 self._VerifyHasBookmarkResult(partial_title) | 234 self._VerifyHasBookmarkResult(partial_title) |
234 | 235 |
236 def _CheckMatches(self, old_matches_len, search_text): | |
Nirnimesh
2010/12/22 19:32:51
Be more descriptive with the name.
Or at least pro
| |
237 new_matches = self._GetOmniboxMatchesFor(search_text) | |
238 if len(new_matches) > old_matches_len: | |
239 return True | |
240 return False | |
241 | |
242 def testContentHisotry(self): | |
243 """Verify omnibox results when entering page content | |
244 | |
245 Test verifies that visited page shows up in omnibox on entering page | |
246 content. | |
247 """ | |
248 search_text = 'British throne' | |
249 old_matches = self._GetOmniboxMatchesFor(search_text) | |
250 url = self.GetFileURLForPath( | |
251 os.path.join(self.DataDir(), 'find_in_page', 'largepage.html')) | |
252 self.AppendTab(pyauto.GURL(url)) | |
253 self.WaitUntil(lambda: self._CheckMatches(len(old_matches), search_text)) | |
Nirnimesh
2010/12/22 19:32:51
wrap this inside self.assertTrue()
Be aware that
| |
254 matches = self._GetOmniboxMatchesFor(search_text) | |
255 matches_description = [x for x in matches if x['destination_url'] == url] | |
256 self.assertEqual(1, len(matches_description)) | |
257 | |
258 def testRecentPageHistory(self): | |
Nirnimesh
2010/12/22 19:32:51
In the interest of saving time it might be useful
| |
259 """Verify that omnibox shows recent history option in the visited | |
260 url list.""" | |
261 search_text = 'file' | |
262 sites = glob.glob(os.path.join(self.DataDir(), 'find_in_page', '*.html')) | |
263 for site in sites: | |
264 self.NavigateToURL(self.GetFileURLForPath(site)) | |
265 old_matches = self._GetOmniboxMatchesFor(search_text) | |
266 # Using max timeout as 40 seconds, since expected page only shows up | |
267 # after 40 seconds and default timeout is less than that. | |
268 self.WaitUntil(lambda: self._CheckMatches(len(old_matches), search_text), | |
Nirnimesh
2010/12/22 19:32:51
wrap inside self.assertTrue
| |
269 timeout=40) | |
270 matches = self._GetOmniboxMatchesFor(search_text) | |
271 matches_description = [x for x in matches if x['type'] == | |
272 'open-history-page'] | |
273 self.assertEqual(1, len(matches_description)) | |
274 | |
235 def _VerifyHasBookmarkResult(self, matches): | 275 def _VerifyHasBookmarkResult(self, matches): |
236 """Verify that we have a bookmark result.""" | 276 """Verify that we have a bookmark result.""" |
237 matches_starred = [result for result in matches if result['starred']] | 277 matches_starred = [result for result in matches if result['starred']] |
238 self.assertTrue(matches_starred) | 278 self.assertTrue(matches_starred) |
239 self.assertEqual(1, len(matches_starred)) | 279 self.assertEqual(1, len(matches_starred)) |
240 | 280 |
241 def testBookmarkResultInNewTabAndWindow(self): | 281 def testBookmarkResultInNewTabAndWindow(self): |
242 """Verify that omnibox can recognize bookmark in the search options | 282 """Verify that omnibox can recognize bookmark in the search options |
243 in new tabs and Windows. | 283 in new tabs and Windows. |
244 """ | 284 """ |
(...skipping 12 matching lines...) Expand all Loading... | |
257 self.NavigateToURL(url, 1, 0) | 297 self.NavigateToURL(url, 1, 0) |
258 self._CheckBookmarkResultForVariousInputs(url, title, windex=1) | 298 self._CheckBookmarkResultForVariousInputs(url, title, windex=1) |
259 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 299 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
260 self.assertEqual(3, self.GetBrowserWindowCount()) | 300 self.assertEqual(3, self.GetBrowserWindowCount()) |
261 self.NavigateToURL(url, 2, 0) | 301 self.NavigateToURL(url, 2, 0) |
262 self._CheckBookmarkResultForVariousInputs(url, title, windex=2) | 302 self._CheckBookmarkResultForVariousInputs(url, title, windex=2) |
263 | 303 |
264 | 304 |
265 if __name__ == '__main__': | 305 if __name__ == '__main__': |
266 pyauto_functional.Main() | 306 pyauto_functional.Main() |
OLD | NEW |