OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import re | |
7 | |
8 import pyauto_functional # Must be imported before pyauto | |
9 import pyauto | |
10 import test_utils | |
11 | |
12 | |
13 class SearchEnginesTest(pyauto.PyUITest): | |
14 """TestCase for Search Engines.""" | |
15 | |
16 _localhost_prefix = 'http://localhost:1000/' | |
17 | |
18 def _GetSearchEngineWithKeyword(self, keyword): | |
19 """Get search engine info and return an element that matches keyword. | |
20 | |
21 Args: | |
22 keyword: Search engine keyword field. | |
23 | |
24 Returns: | |
25 A search engine info dict or None. | |
26 """ | |
27 match_list = ([x for x in self.GetSearchEngineInfo() | |
28 if x['keyword'] == keyword]) | |
29 if match_list: | |
30 return match_list[0] | |
31 return None | |
32 | |
33 def Debug(self): | |
34 """Test method for experimentation. | |
35 | |
36 This method will not run automatically. | |
37 """ | |
38 while True: | |
39 raw_input('Interact with the browser and hit <enter>') | |
40 self.pprint(self.GetSearchEngineInfo()) | |
41 | |
42 def testDiscoverSearchEngine(self): | |
43 """Test that chrome discovers youtube search engine after searching.""" | |
44 # Take a snapshot of current search engine info. | |
45 info = self.GetSearchEngineInfo() | |
46 youtube = self._GetSearchEngineWithKeyword('youtube.com') | |
47 self.assertFalse(youtube) | |
48 # Use omnibox to invoke search engine discovery. | |
49 # Navigating using NavigateToURL does not currently invoke this logic. | |
50 self.SetOmniboxText('http://www.youtube.com') | |
51 self.OmniboxAcceptInput() | |
52 def InfoUpdated(old_info): | |
53 new_info = self.GetSearchEngineInfo() | |
54 if len(new_info) > len(old_info): | |
55 return True | |
56 return False | |
57 self.WaitUntil(lambda: InfoUpdated(info)) | |
58 youtube = self._GetSearchEngineWithKeyword('youtube.com') | |
59 self.assertTrue(youtube) | |
60 self.assertTrue(re.search('youtube', youtube['short_name'], | |
61 re.IGNORECASE)) | |
62 self.assertFalse(youtube['in_default_list']) | |
63 self.assertFalse(youtube['is_default']) | |
64 | |
65 def testDeleteSearchEngine(self): | |
66 """Test adding then deleting a search engine.""" | |
67 self.AddSearchEngine(title='foo', | |
68 keyword='foo.com', | |
69 url='http://foo/?q=%s') | |
70 foo = self._GetSearchEngineWithKeyword('foo.com') | |
71 self.assertTrue(foo) | |
72 self.DeleteSearchEngine('foo.com') | |
73 foo = self._GetSearchEngineWithKeyword('foo.com') | |
74 self.assertFalse(foo) | |
75 | |
76 def testMakeSearchEngineDefault(self): | |
77 """Test adding then making a search engine default.""" | |
78 self.AddSearchEngine( | |
79 title='foo', | |
80 keyword='foo.com', | |
81 url=self._localhost_prefix + '?q=%s') | |
82 foo = self._GetSearchEngineWithKeyword('foo.com') | |
83 self.assertTrue(foo) | |
84 self.assertFalse(foo['is_default']) | |
85 self.MakeSearchEngineDefault('foo.com') | |
86 foo = self._GetSearchEngineWithKeyword('foo.com') | |
87 self.assertTrue(foo) | |
88 self.assertTrue(foo['is_default']) | |
89 self.SetOmniboxText('foobar') | |
90 self.OmniboxAcceptInput() | |
91 self.assertEqual(self._localhost_prefix + '?q=foobar', | |
92 self.GetActiveTabURL().spec()) | |
93 | |
94 def testDefaultSearchEngines(self): | |
95 """Test that we have 3 default search options.""" | |
96 info = self.GetSearchEngineInfo() | |
97 self.assertEqual(len(info), 3) | |
98 # Verify that each can be used as the default search provider. | |
99 default_providers = ['google.com', 'yahoo.com', 'bing.com'] | |
100 for keyword in default_providers: | |
101 self.MakeSearchEngineDefault(keyword) | |
102 search_engine = self._GetSearchEngineWithKeyword(keyword) | |
103 self.assertTrue(search_engine['is_default']) | |
104 self.SetOmniboxText('test search') | |
105 self.OmniboxAcceptInput() | |
106 self.assertTrue(re.search(keyword, self.GetActiveTabURL().spec())) | |
107 | |
108 | |
109 if __name__ == '__main__': | |
110 pyauto_functional.Main() | |
OLD | NEW |