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 import urlparse |
10 | 11 |
11 import pyauto_functional # Must be imported before pyauto | 12 import pyauto_functional # Must be imported before pyauto |
12 import pyauto | 13 import pyauto |
13 | 14 |
14 | 15 |
15 class OmniboxTest(pyauto.PyUITest): | 16 class OmniboxTest(pyauto.PyUITest): |
16 """TestCase for Omnibox.""" | 17 """TestCase for Omnibox.""" |
17 | 18 |
18 def Debug(self): | 19 def Debug(self): |
19 """Test method for experimentation. | 20 """Test method for experimentation. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 self.assertTrue(matches) | 207 self.assertTrue(matches) |
207 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) | 208 self.assertTrue([x for x in matches if x['type'] == 'search-suggest']) |
208 # Disable suggest-service | 209 # Disable suggest-service |
209 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) | 210 self.SetPrefs(pyauto.kSearchSuggestEnabled, False) |
210 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) | 211 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kSearchSuggestEnabled)) |
211 matches = self._GetOmniboxMatchesFor('apple') | 212 matches = self._GetOmniboxMatchesFor('apple') |
212 self.assertTrue(matches) | 213 self.assertTrue(matches) |
213 # Verify there are no suggest results | 214 # Verify there are no suggest results |
214 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) | 215 self.assertFalse([x for x in matches if x['type'] == 'search-suggest']) |
215 | 216 |
| 217 def _CheckBookmarkResultForVariousInputs(self, url, title, windex=0): |
| 218 """Check if we get the Bookmark for complete and partial inputs.""" |
| 219 # Check if the complete URL would get the bookmark |
| 220 url_matches = self._GetOmniboxMatchesFor(url, windex=windex) |
| 221 self._VerifyHasBookmarkResult(url_matches) |
| 222 # Check if the complete title would get the bookmark |
| 223 title_matches = self._GetOmniboxMatchesFor(title, windex=windex) |
| 224 self._VerifyHasBookmarkResult(title_matches) |
| 225 # Check if the partial URL would get the bookmark |
| 226 split_url = urlparse.urlsplit(url) |
| 227 search_term = split_url.path |
| 228 partial_url = self._GetOmniboxMatchesFor(search_term, windex=windex) |
| 229 self._VerifyHasBookmarkResult(partial_url) |
| 230 # Check if the partial title would get the bookmark |
| 231 split_title = title.split() |
| 232 search_term = split_title[len(split_title) - 1] |
| 233 partial_title = self._GetOmniboxMatchesFor(search_term, windex=windex) |
| 234 self._VerifyHasBookmarkResult(partial_title) |
| 235 |
| 236 def _VerifyHasBookmarkResult(self, matches): |
| 237 """Verify that we have a bookmark result.""" |
| 238 matches_starred = [result for result in matches if result['starred']] |
| 239 self.assertTrue(matches_starred) |
| 240 self.assertEqual(1, len(matches_starred)) |
| 241 |
| 242 def testBookmarkResultInNewTabAndWindow(self): |
| 243 """Verify that omnibox can recognize bookmark in the search options |
| 244 in new tabs and Windows. |
| 245 """ |
| 246 url = self.GetFileURLForDataPath('title2.html') |
| 247 self.NavigateToURL(url) |
| 248 title = 'This is Awesomeness' |
| 249 bookmarks = self.GetBookmarkModel() |
| 250 bar_id = bookmarks.BookmarkBar()['id'] |
| 251 self.AddBookmarkURL(bar_id, 0, title, url) |
| 252 bookmarks = self.GetBookmarkModel() |
| 253 nodes = bookmarks.FindByTitle(title) |
| 254 self.AppendTab(pyauto.GURL(url)) |
| 255 self._CheckBookmarkResultForVariousInputs(url, title) |
| 256 self.OpenNewBrowserWindow(True) |
| 257 self.assertEqual(2, self.GetBrowserWindowCount()) |
| 258 self.NavigateToURL(url, 1, 0) |
| 259 self._CheckBookmarkResultForVariousInputs(url, title, windex=1) |
| 260 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 261 self.assertEqual(3, self.GetBrowserWindowCount()) |
| 262 self.NavigateToURL(url, 2, 0) |
| 263 self._CheckBookmarkResultForVariousInputs(url, title, windex=2) |
| 264 |
216 | 265 |
217 if __name__ == '__main__': | 266 if __name__ == '__main__': |
218 pyauto_functional.Main() | 267 pyauto_functional.Main() |
OLD | NEW |