Chromium Code Reviews| 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 os | 6 import os |
| 7 import re | 7 import re |
| 8 import shutil | 8 import shutil |
| 9 import tempfile | 9 import tempfile |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 """ | 45 """ |
| 46 self.SetOmniboxText(text, windex=windex) | 46 self.SetOmniboxText(text, windex=windex) |
| 47 self.WaitUntilOmniboxQueryDone(windex=windex) | 47 self.WaitUntilOmniboxQueryDone(windex=windex) |
| 48 if not attr_dict: | 48 if not attr_dict: |
| 49 matches = self.GetOmniboxInfo(windex=windex).Matches() | 49 matches = self.GetOmniboxInfo(windex=windex).Matches() |
| 50 else: | 50 else: |
| 51 matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes( | 51 matches = self.GetOmniboxInfo(windex=windex).MatchesWithAttributes( |
| 52 attr_dict=attr_dict) | 52 attr_dict=attr_dict) |
| 53 return matches | 53 return matches |
| 54 | 54 |
| 55 def _AddBookmark(self, url, title): | |
|
Nirnimesh
2010/12/09 00:52:21
Move this closer to where it's actually used
deepakg
2010/12/09 01:59:50
Done.
| |
| 56 """Adds a new bookmark with the given URL and title.""" | |
| 57 bookmarks = self.GetBookmarkModel() | |
| 58 bar_id = bookmarks.BookmarkBar()['id'] | |
| 59 self.AddBookmarkURL(bar_id, 0, title, url) | |
| 60 bookmarks = self.GetBookmarkModel() | |
| 61 nodes = bookmarks.FindByTitle(title) | |
| 62 self.assertEqual(1, len(nodes)) | |
|
Nirnimesh
2010/12/09 00:52:21
Remove the asserts
deepakg
2010/12/09 01:59:50
Done.
| |
| 63 self.assertTrue(nodes[0]['name'] == title) | |
| 64 | |
| 55 def testHistoryResult(self): | 65 def testHistoryResult(self): |
| 56 """Verify that omnibox can fetch items from history.""" | 66 """Verify that omnibox can fetch items from history.""" |
| 57 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) | 67 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) |
| 58 title = 'Title Of Awesomeness' | 68 title = 'Title Of Awesomeness' |
| 59 self.AppendTab(pyauto.GURL(url)) | 69 self.AppendTab(pyauto.GURL(url)) |
| 60 def _VerifyHistoryResult(query_list, description, windex=0): | 70 def _VerifyHistoryResult(query_list, description, windex=0): |
| 61 """Verify result matching given description for given list of queries.""" | 71 """Verify result matching given description for given list of queries.""" |
| 62 for query_text in query_list: | 72 for query_text in query_list: |
| 63 matches = self._GetOmniboxMatchesFor( | 73 matches = self._GetOmniboxMatchesFor( |
| 64 query_text, windex=windex, attr_dict={'description': description}) | 74 query_text, windex=windex, attr_dict={'description': description}) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 self.assertTrue(matches) | 216 self.assertTrue(matches) |
| 207 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) | 217 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) |
| 208 # Disable suggest-service | 218 # Disable suggest-service |
| 209 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) | 219 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) |
| 210 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) | 220 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) |
| 211 matches = self._GetOmniboxMatchesFor('apple') | 221 matches = self._GetOmniboxMatchesFor('apple') |
| 212 self.assertTrue(matches) | 222 self.assertTrue(matches) |
| 213 # Verify there are no suggest results | 223 # Verify there are no suggest results |
| 214 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) | 224 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) |
| 215 | 225 |
| 226 def _CheckBookmarkResultForVariousInputs(self, url, title, windex): | |
| 227 """Check if we get the Bookmark for complete and partial inputs.""" | |
| 228 # Check if the complete URL would get the bookmark | |
| 229 urlMatches = self._GetOmniboxMatchesFor(url, windex) | |
|
Nirnimesh
2010/12/09 00:52:21
use named arg wherever possible.
windex=windex
Nirnimesh
2010/12/09 00:52:21
camelCase var names not allowed.
rename: url_match
deepakg
2010/12/09 01:59:50
Done.
deepakg
2010/12/09 01:59:50
Done.
| |
| 230 self._CheckIfBookmarkMatches(urlMatches) | |
| 231 # Check if the complete title would get the bookmark | |
| 232 titleMatches = self._GetOmniboxMatchesFor(title, windex) | |
|
Nirnimesh
2010/12/09 00:52:21
use named arg
windex=windex
deepakg
2010/12/09 01:59:50
Done.
| |
| 233 self._CheckIfBookmarkMatches(titleMatches) | |
| 234 # Check if the partial URL would get the bookmark | |
| 235 split_url = url.split('/') | |
|
Nirnimesh
2010/12/09 00:52:21
use split* family of functions in urllib
deepakg
2010/12/09 01:59:50
Done.
Have done this but urlparse.urlsplit would
| |
| 236 term = split_url[len(split_url) - 1] | |
| 237 search_term = term.split('.') # we don't need the .html extension | |
| 238 partialURL = self._GetOmniboxMatchesFor(search_term[0], windex) | |
|
Nirnimesh
2010/12/09 00:52:21
use named arg
windex=windex
deepakg
2010/12/09 01:59:50
Done.
| |
| 239 self._CheckIfBookmarkMatches(partialURL) | |
| 240 # Check if the partial title would get the bookmark | |
| 241 split_title = title.split() | |
| 242 search_term = split_title[len(split_title) -1] | |
|
Nirnimesh
2010/12/09 00:52:21
need space after -
deepakg
2010/12/09 01:59:50
Done.
| |
| 243 partialTitle = self._GetOmniboxMatchesFor(search_term, windex) | |
|
Nirnimesh
2010/12/09 00:52:21
use named arg
windex=windex
deepakg
2010/12/09 01:59:50
Done.
| |
| 244 self._CheckIfBookmarkMatches(partialTitle) | |
| 245 | |
| 246 def _CheckIfBookmarkMatches(self, matches): | |
|
Nirnimesh
2010/12/09 00:52:21
Rename: _VerifyHasBookmarkResult
deepakg
2010/12/09 01:59:50
Done.
| |
| 247 """Verify that the Omnibox options have the bookmark.""" | |
|
Nirnimesh
2010/12/09 00:52:21
Verify that we have a bookmark result
deepakg
2010/12/09 01:59:50
Done.
| |
| 248 matches_starred = [result for result in matches if result['starred']] | |
| 249 self.assertTrue(matches_starred) | |
| 250 self.assertEqual(1, len(matches_starred)) | |
| 251 | |
| 252 def testBookmarkResultInNewTab(self): | |
| 253 """Verify that omnibox can recognize bookmark in the search options | |
| 254 for multiple tabs. | |
| 255 """ | |
| 256 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) | |
|
Nirnimesh
2010/12/09 00:52:21
use self.GetFileURLForDataPath('title2.html')
deepakg
2010/12/09 01:59:50
Done.
| |
| 257 self.NavigateToURL(url) | |
| 258 title = 'This is Awesomeness' | |
| 259 self._AddBookmark(url, title) | |
| 260 # Check in a new tab | |
| 261 self.AppendTab(pyauto.GURL(url)) | |
| 262 self._CheckBookmarkResultForVariousInputs(url, title, 0) | |
|
Nirnimesh
2010/12/09 00:52:21
use named arg. tab_index=0
deepakg
2010/12/09 01:59:50
Done.
| |
| 263 | |
| 264 def testBookmarkResultInNewWindow(self): | |
|
Nirnimesh
2010/12/09 00:52:21
Most of this test is similar to the last one.
Mer
deepakg
2010/12/09 01:59:50
Done.
| |
| 265 """Verify the bookmarks title are found in a normal and | |
| 266 incognito window. | |
| 267 """ | |
| 268 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) | |
| 269 title = 'This is Awesomeness' | |
| 270 self._AddBookmark(url, title) | |
| 271 self.OpenNewBrowserWindow(True) | |
| 272 self.assertEqual(2, self.GetBrowserWindowCount()) | |
| 273 self.NavigateToURL(url, 1, 0) | |
| 274 self._CheckBookmarkResultForVariousInputs(url, title, 1) | |
| 275 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
| 276 self.assertEqual(3, self.GetBrowserWindowCount()) | |
| 277 self.NavigateToURL(url, 2, 0) | |
| 278 self._CheckBookmarkResultForVariousInputs(url, title, 2) | |
| 279 | |
| 216 | 280 |
| 217 if __name__ == '__main__': | 281 if __name__ == '__main__': |
| 218 pyauto_functional.Main() | 282 pyauto_functional.Main() |
| OLD | NEW |