| 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 cgi |
| 7 import os | 8 import os |
| 8 | 9 |
| 9 import pyauto_functional # Must be imported before pyauto | 10 import pyauto_functional # Must be imported before pyauto |
| 10 import pyauto | 11 import pyauto |
| 11 import urlparse | |
| 12 | 12 |
| 13 | 13 |
| 14 class InstantTest(pyauto.PyUITest): | 14 class InstantTest(pyauto.PyUITest): |
| 15 """TestCase for Omnibox Instant feature.""" | 15 """TestCase for Omnibox Instant feature.""" |
| 16 | 16 |
| 17 def setUp(self): | 17 def setUp(self): |
| 18 pyauto.PyUITest.setUp(self) | 18 pyauto.PyUITest.setUp(self) |
| 19 self.SetPrefs(pyauto.kInstantEnabled, True) | 19 self.SetPrefs(pyauto.kInstantEnabled, True) |
| 20 | 20 |
| 21 def _DoneLoading(self): | 21 def _DoneLoading(self): |
| 22 info = self.GetInstantInfo() | 22 info = self.GetInstantInfo() |
| 23 return info.get('current') and not info.get('loading') | 23 return info.get('current') and not info.get('loading') |
| 24 | 24 |
| 25 def _DoneLoadingGoogleQuery(self, query): | 25 def _DoneLoadingGoogleQuery(self, query): |
| 26 """Wait for Omnibox Instant to load Google search result | 26 """Wait for Omnibox Instant to load Google search result |
| 27 and verify location URL contains the specifed query. | 27 and verify location URL contains the specifed query. |
| 28 | 28 |
| 29 Args: | 29 Args: |
| 30 query: Value of query parameter. | 30 query: Value of query parameter. |
| 31 E.g., http://www.google.com?q=hi so query is 'hi'. | 31 E.g., http://www.google.com?q=hi so query is 'hi'. |
| 32 """ | 32 """ |
| 33 self.assertTrue(self.WaitUntil(self._DoneLoading)) | 33 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
| 34 location = self.GetInstantInfo().get('location') | 34 location = self.GetInstantInfo().get('location') |
| 35 if location is not None: | 35 if location is not None: |
| 36 q = urlparse.parse_qs(location).get('q') | 36 q = cgi.parse_qs(location).get('q') |
| 37 if q is not None and query in q: | 37 if q is not None and query in q: |
| 38 return True | 38 return True |
| 39 return False | 39 return False |
| 40 | 40 |
| 41 def testInstantNavigation(self): | 41 def testInstantNavigation(self): |
| 42 """Test that instant navigates based on omnibox input.""" | 42 """Test that instant navigates based on omnibox input.""" |
| 43 self.SetOmniboxText('google.com') | 43 self.SetOmniboxText('google.com') |
| 44 self.assertTrue(self.WaitUntil(self._DoneLoading)) | 44 self.assertTrue(self.WaitUntil(self._DoneLoading)) |
| 45 location = self.GetInstantInfo()['location'] | 45 location = self.GetInstantInfo()['location'] |
| 46 self.assertTrue('google.com' in location, | 46 self.assertTrue('google.com' in location, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 def testInstantLoadsFor100CharsLongQuery(self): | 96 def testInstantLoadsFor100CharsLongQuery(self): |
| 97 """Test that instant loads for search query of 100 characters.""" | 97 """Test that instant loads for search query of 100 characters.""" |
| 98 query = '#' * 100 | 98 query = '#' * 100 |
| 99 self.SetOmniboxText(query) | 99 self.SetOmniboxText(query) |
| 100 self.assertTrue(self.WaitUntil(self._DoneLoadingGoogleQuery, args=[query])) | 100 self.assertTrue(self.WaitUntil(self._DoneLoadingGoogleQuery, args=[query])) |
| 101 | 101 |
| 102 | 102 |
| 103 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 104 pyauto_functional.Main() | 104 pyauto_functional.Main() |
| OLD | NEW |