| 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 re | 7 import re |
| 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 | 11 |
| 12 | 12 |
| 13 class SearchEnginesTest(pyauto.PyUITest): | 13 class SearchEnginesTest(pyauto.PyUITest): |
| 14 """TestCase for Search Engines.""" | 14 """TestCase for Search Engines.""" |
| 15 | 15 |
| 16 _localhost_prefix = 'http://localhost:1000/' |
| 17 |
| 16 def _GetSearchEngineWithKeyword(self, keyword): | 18 def _GetSearchEngineWithKeyword(self, keyword): |
| 17 """Get search engine info and return an element that matches keyword. | 19 """Get search engine info and return an element that matches keyword. |
| 18 | 20 |
| 19 Args: | 21 Args: |
| 20 keyword: Search engine keyword field. | 22 keyword: Search engine keyword field. |
| 21 | 23 |
| 22 Returns: | 24 Returns: |
| 23 A search engine info dict or None. | 25 A search engine info dict or None. |
| 24 """ | 26 """ |
| 25 match_list = ([x for x in self.GetSearchEngineInfo() | 27 match_list = ([x for x in self.GetSearchEngineInfo() |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 self.assertTrue(youtube) | 61 self.assertTrue(youtube) |
| 60 self.assertTrue(re.search('youtube', youtube['short_name'], | 62 self.assertTrue(re.search('youtube', youtube['short_name'], |
| 61 re.IGNORECASE)) | 63 re.IGNORECASE)) |
| 62 self.assertFalse(youtube['in_default_list']) | 64 self.assertFalse(youtube['in_default_list']) |
| 63 self.assertFalse(youtube['is_default']) | 65 self.assertFalse(youtube['is_default']) |
| 64 | 66 |
| 65 def testAddSearchEngine(self): | 67 def testAddSearchEngine(self): |
| 66 """Test searching using keyword of user-added search engine.""" | 68 """Test searching using keyword of user-added search engine.""" |
| 67 self.AddSearchEngine(title='foo', | 69 self.AddSearchEngine(title='foo', |
| 68 keyword='foo.com', | 70 keyword='foo.com', |
| 69 url='http://localhost/?q=%s') | 71 url=self._localhost_prefix + '?q=%s') |
| 70 self.SetOmniboxText('foo.com foobar') | 72 self.SetOmniboxText('foo.com foobar') |
| 71 self.OmniboxAcceptInput() | 73 self.OmniboxAcceptInput() |
| 72 self.assertEqual('http://localhost/?q=foobar', | 74 self.assertEqual(self._localhost_prefix + '?q=foobar', |
| 73 self.GetActiveTabURL().spec()) | 75 self.GetActiveTabURL().spec()) |
| 74 | 76 |
| 75 def testEditSearchEngine(self): | 77 def testEditSearchEngine(self): |
| 76 """Test editing a search engine's properties.""" | 78 """Test editing a search engine's properties.""" |
| 77 self.AddSearchEngine(title='foo', | 79 self.AddSearchEngine(title='foo', |
| 78 keyword='foo.com', | 80 keyword='foo.com', |
| 79 url='http://foo/?q=%s') | 81 url='http://foo/?q=%s') |
| 80 self.EditSearchEngine(keyword='foo.com', | 82 self.EditSearchEngine(keyword='foo.com', |
| 81 new_title='bar', | 83 new_title='bar', |
| 82 new_keyword='bar.com', | 84 new_keyword='bar.com', |
| 83 new_url='http://localhost/?bar=true&q=%s') | 85 new_url=self._localhost_prefix + '?bar=true&q=%s') |
| 84 self.assertTrue(self._GetSearchEngineWithKeyword('bar.com')) | 86 self.assertTrue(self._GetSearchEngineWithKeyword('bar.com')) |
| 85 self.assertFalse(self._GetSearchEngineWithKeyword('foo.com')) | 87 self.assertFalse(self._GetSearchEngineWithKeyword('foo.com')) |
| 86 self.SetOmniboxText('bar.com foobar') | 88 self.SetOmniboxText('bar.com foobar') |
| 87 self.OmniboxAcceptInput() | 89 self.OmniboxAcceptInput() |
| 88 self.assertEqual('http://localhost/?bar=true&q=foobar', | 90 self.assertEqual(self._localhost_prefix + '?bar=true&q=foobar', |
| 89 self.GetActiveTabURL().spec()) | 91 self.GetActiveTabURL().spec()) |
| 90 | 92 |
| 91 def testDeleteSearchEngine(self): | 93 def testDeleteSearchEngine(self): |
| 92 """Test adding then deleting a search engine.""" | 94 """Test adding then deleting a search engine.""" |
| 93 self.AddSearchEngine(title='foo', | 95 self.AddSearchEngine(title='foo', |
| 94 keyword='foo.com', | 96 keyword='foo.com', |
| 95 url='http://foo/?q=%s') | 97 url='http://foo/?q=%s') |
| 96 foo = self._GetSearchEngineWithKeyword('foo.com') | 98 foo = self._GetSearchEngineWithKeyword('foo.com') |
| 97 self.assertTrue(foo) | 99 self.assertTrue(foo) |
| 98 self.DeleteSearchEngine('foo.com') | 100 self.DeleteSearchEngine('foo.com') |
| 99 foo = self._GetSearchEngineWithKeyword('foo.com') | 101 foo = self._GetSearchEngineWithKeyword('foo.com') |
| 100 self.assertFalse(foo) | 102 self.assertFalse(foo) |
| 101 | 103 |
| 102 def testMakeSearchEngineDefault(self): | 104 def testMakeSearchEngineDefault(self): |
| 103 """Test adding then making a search engine default.""" | 105 """Test adding then making a search engine default.""" |
| 104 self.AddSearchEngine( | 106 self.AddSearchEngine( |
| 105 title='foo', | 107 title='foo', |
| 106 keyword='foo.com', | 108 keyword='foo.com', |
| 107 url='http://localhost/?q=%s') | 109 url=self._localhost_prefix + '?q=%s') |
| 108 foo = self._GetSearchEngineWithKeyword('foo.com') | 110 foo = self._GetSearchEngineWithKeyword('foo.com') |
| 109 self.assertTrue(foo) | 111 self.assertTrue(foo) |
| 110 self.assertFalse(foo['is_default']) | 112 self.assertFalse(foo['is_default']) |
| 111 self.MakeSearchEngineDefault('foo.com') | 113 self.MakeSearchEngineDefault('foo.com') |
| 112 foo = self._GetSearchEngineWithKeyword('foo.com') | 114 foo = self._GetSearchEngineWithKeyword('foo.com') |
| 113 self.assertTrue(foo) | 115 self.assertTrue(foo) |
| 114 self.assertTrue(foo['is_default']) | 116 self.assertTrue(foo['is_default']) |
| 115 self.SetOmniboxText('foobar') | 117 self.SetOmniboxText('foobar') |
| 116 self.OmniboxAcceptInput() | 118 self.OmniboxAcceptInput() |
| 117 self.assertEqual('http://localhost/?q=foobar', | 119 self.assertEqual(self._localhost_prefix + '?q=foobar', |
| 118 self.GetActiveTabURL().spec()) | 120 self.GetActiveTabURL().spec()) |
| 119 | 121 |
| 120 def testTabToSearch(self): | 122 def testTabToSearch(self): |
| 121 """Test to verify that tab to search feature works.""" | 123 """Test to verify that tab to search feature works.""" |
| 122 # Verify tab to search with tab, space, and keyord variants | 124 # Verify tab to search with tab, space, and keyord variants |
| 123 omnibox_inputs = ['google.com test', | 125 omnibox_inputs = ['google.com test', |
| 124 'google.com\ttest', | 126 'google.com\ttest', |
| 125 'http://www.google.com\ttest'] | 127 'http://www.google.com\ttest'] |
| 126 for omnibox_input in omnibox_inputs: | 128 for omnibox_input in omnibox_inputs: |
| 127 self.SetOmniboxText(omnibox_input) | 129 self.SetOmniboxText(omnibox_input) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 self.MakeSearchEngineDefault(keyword) | 151 self.MakeSearchEngineDefault(keyword) |
| 150 search_engine = self._GetSearchEngineWithKeyword(keyword) | 152 search_engine = self._GetSearchEngineWithKeyword(keyword) |
| 151 self.assertTrue(search_engine['is_default']) | 153 self.assertTrue(search_engine['is_default']) |
| 152 self.SetOmniboxText('test search') | 154 self.SetOmniboxText('test search') |
| 153 self.OmniboxAcceptInput() | 155 self.OmniboxAcceptInput() |
| 154 self.assertTrue(re.search(keyword, self.GetActiveTabURL().spec())) | 156 self.assertTrue(re.search(keyword, self.GetActiveTabURL().spec())) |
| 155 | 157 |
| 156 | 158 |
| 157 if __name__ == '__main__': | 159 if __name__ == '__main__': |
| 158 pyauto_functional.Main() | 160 pyauto_functional.Main() |
| OLD | NEW |