OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import os | 7 import os |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
| 11 import urlparse |
11 | 12 |
12 | 13 |
13 class InstantTest(pyauto.PyUITest): | 14 class InstantTest(pyauto.PyUITest): |
14 """TestCase for Omnibox Instant feature.""" | 15 """TestCase for Omnibox Instant feature.""" |
15 | 16 |
16 def setUp(self): | 17 def setUp(self): |
17 pyauto.PyUITest.setUp(self) | 18 pyauto.PyUITest.setUp(self) |
18 self.SetPrefs(pyauto.kInstantEnabled, True) | 19 self.SetPrefs(pyauto.kInstantEnabled, True) |
19 | 20 |
20 def _DoneLoading(self): | 21 def _DoneLoading(self): |
21 info = self.GetInstantInfo() | 22 info = self.GetInstantInfo() |
22 return info.get('current') and not info.get('loading') | 23 return info.get('current') and not info.get('loading') |
23 | 24 |
| 25 def _DoneLoadingGoogleQuery(self, query): |
| 26 """Wait for Omnibox Instant to load Google search result |
| 27 and verify location URL contains the specifed query. |
| 28 |
| 29 Args: |
| 30 query: Value of query parameter. |
| 31 E.g., http://www.google.com?q=hi so query is 'hi'. |
| 32 """ |
| 33 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
| 34 location = self.GetInstantInfo().get('location') |
| 35 if location is not None: |
| 36 q = urlparse.parse_qs(location).get('q') |
| 37 if q is not None and query in q: |
| 38 return True |
| 39 return False |
| 40 |
24 def testInstantNavigation(self): | 41 def testInstantNavigation(self): |
25 """Test that instant navigates based on omnibox input.""" | 42 """Test that instant navigates based on omnibox input.""" |
26 self.SetOmniboxText('google.com') | 43 self.SetOmniboxText('google.com') |
27 self.assertTrue(self.WaitUntil(self._DoneLoading)) | 44 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
28 location = self.GetInstantInfo()['location'] | 45 location = self.GetInstantInfo()['location'] |
29 self.assertTrue('google.com' in location, | 46 self.assertTrue('google.com' in location, |
30 msg='No google.com in %s' % location) | 47 msg='No google.com in %s' % location) |
31 | 48 |
32 self.SetOmniboxText('google.es') | 49 self.SetOmniboxText('google.es') |
33 self.assertTrue(self.WaitUntil(self._DoneLoading)) | 50 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
(...skipping 22 matching lines...) Expand all Loading... |
56 self.assertTrue(self.WaitUntil(self._DoneLoading)) | 73 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
57 history = self.GetHistoryInfo().History() | 74 history = self.GetHistoryInfo().History() |
58 self.assertEqual(0, len(history)) | 75 self.assertEqual(0, len(history)) |
59 | 76 |
60 def testInstantDisabledForJavaScript(self): | 77 def testInstantDisabledForJavaScript(self): |
61 """Test that instant is disabled for javascript URLs.""" | 78 """Test that instant is disabled for javascript URLs.""" |
62 self.SetOmniboxText('javascript:') | 79 self.SetOmniboxText('javascript:') |
63 self.assertFalse(self.GetInstantInfo()['active'], | 80 self.assertFalse(self.GetInstantInfo()['active'], |
64 'Instant enabled for javascript URL.') | 81 'Instant enabled for javascript URL.') |
65 | 82 |
| 83 def testInstantDisablesPopupsOnPrefetch(self): |
| 84 """Test that instant disables popups when prefetching.""" |
| 85 file_url = self.GetFileURLForPath(os.path.join( |
| 86 self.DataDir(), 'popup_blocker', 'popup-blocked-to-post-blank.html')) |
| 87 self.SetOmniboxText(file_url) |
| 88 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
| 89 location = self.GetInstantInfo()['location'] |
| 90 self.assertTrue(file_url in location, |
| 91 msg='Prefetched page is not %s' % file_url) |
| 92 blocked_popups = self.GetBlockedPopupsInfo() |
| 93 self.assertEqual(0, len(blocked_popups), |
| 94 msg='Unexpected popup in instant preview.') |
| 95 |
| 96 def testInstantLoadsFor100CharsLongQuery(self): |
| 97 """Test that instant loads for search query of 100 characters.""" |
| 98 query = '#' * 100 |
| 99 self.SetOmniboxText(query) |
| 100 self.assertTrue(self.WaitUntil(self._DoneLoadingGoogleQuery, args=[query])) |
| 101 |
66 | 102 |
67 if __name__ == '__main__': | 103 if __name__ == '__main__': |
68 pyauto_functional.Main() | 104 pyauto_functional.Main() |
OLD | NEW |