diff options
author | ace@chromium.org <ace@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 04:47:44 +0000 |
---|---|---|
committer | ace@chromium.org <ace@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 04:47:44 +0000 |
commit | 88efa012201af24b14072298d7a24b64fc1c02a1 (patch) | |
tree | 8268a64f6826da53e2610f7c46bc4dc7e2dc99d2 /chrome/test | |
parent | 077851be33ef19822a8ac6497f6618894c30da56 (diff) | |
download | chromium_src-88efa012201af24b14072298d7a24b64fc1c02a1.zip chromium_src-88efa012201af24b14072298d7a24b64fc1c02a1.tar.gz chromium_src-88efa012201af24b14072298d7a24b64fc1c02a1.tar.bz2 |
Adding automation hooks for editing search engines.
Refactored automation hook for getting search engine info.
BUG=52009
Review URL: http://codereview.chromium.org/3581003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/functional/search_engines.py | 78 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 101 |
2 files changed, 152 insertions, 27 deletions
diff --git a/chrome/test/functional/search_engines.py b/chrome/test/functional/search_engines.py index ed90bb2..5d1082d 100644 --- a/chrome/test/functional/search_engines.py +++ b/chrome/test/functional/search_engines.py @@ -13,6 +13,21 @@ import pyauto class SearchEnginesTest(pyauto.PyUITest): """TestCase for Search Engines.""" + def _GetSearchEngineWithKeyword(self, keyword): + """Get search engine info and return an element that matches keyword. + + Args: + keyword: Search engine keyword field. + + Returns: + A search engine info dict or None. + """ + match_list = ([x for x in self.GetSearchEngineInfo() + if x['keyword'] == keyword]) + if match_list: + return match_list[0] + return None + def Debug(self): """Test method for experimentation. @@ -47,20 +62,59 @@ class SearchEnginesTest(pyauto.PyUITest): self.assertFalse(youtube['in_default_list']) self.assertFalse(youtube['is_default']) - def _GetSearchEngineWithKeyword(self, keyword): - """Get search engine info and return an element that matches keyword. + def testAddSearchEngine(self): + """Test searching using keyword of user-added search engine.""" + self.AddSearchEngine(title='foo', + keyword='foo.com', + url='http://foo/?q=%s') + self.SetOmniboxText('foo.com foobar') + self.OmniboxAcceptInput() + self.assertEqual('http://foo/?q=foobar', self.GetActiveTabURL().spec()) - Args: - keyword: Search engine keyword field. + def testEditSearchEngine(self): + """Test editing a search engine's properties.""" + self.AddSearchEngine(title='foo', + keyword='foo.com', + url='http://foo/?q=%s') + self.EditSearchEngine(keyword='foo.com', + new_title='bar', + new_keyword='bar.com', + new_url='http://foo/?bar=true&q=%s') + self.assertTrue(self._GetSearchEngineWithKeyword('bar.com')) + self.assertFalse(self._GetSearchEngineWithKeyword('foo.com')) + self.SetOmniboxText('bar.com foobar') + self.OmniboxAcceptInput() + self.assertEqual('http://foo/?bar=true&q=foobar', + self.GetActiveTabURL().spec()) - Returns: - A search engine info dict or None. - """ - match_list = ([x for x in self.GetSearchEngineInfo() - if x['keyword'] == 'youtube.com']) - if match_list: - return match_list[0] - return None + def testDeleteSearchEngine(self): + """Test adding then deleting a search engine.""" + self.AddSearchEngine(title='foo', + keyword='foo.com', + url='http://foo/?q=%s') + foo = self._GetSearchEngineWithKeyword('foo.com') + self.assertTrue(foo) + self.DeleteSearchEngine('foo.com') + foo = self._GetSearchEngineWithKeyword('foo.com') + self.assertFalse(foo) + + def testMakeSearchEngineDefault(self): + """Test adding then making a search engine default.""" + self.AddSearchEngine( + title='foo', + keyword='foo.com', + url='http://foo/?q=%s') + foo = self._GetSearchEngineWithKeyword('foo.com') + self.assertTrue(foo) + self.assertFalse(foo['is_default']) + self.MakeSearchEngineDefault('foo.com') + foo = self._GetSearchEngineWithKeyword('foo.com') + self.assertTrue(foo) + self.assertTrue(foo['is_default']) + self.SetOmniboxText('foobar') + self.OmniboxAcceptInput() + self.assertEqual('http://foo/?q=foobar', + self.GetActiveTabURL().spec()) if __name__ == '__main__': diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index f51c11d..9c52c34 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -398,6 +398,9 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): windex: the index of the browser window to work on. Default: 0 (first window) """ + # Ensure that keyword data is loaded from the profile. + # This would normally be triggered by the user inputting this text. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) cmd_dict = { 'command': 'SetOmniboxText', 'text': text, @@ -454,25 +457,93 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): An ordered list of dictionaries describing info about each search engine. Example: - [ { u'description': u'', - u'in_default_list': True, - u'is_default': True, - u'keyword': u'google.com', - u'short_name': u'Google'}, - { u'description': u'', - u'in_default_list': True, - u'is_default': False, - u'keyword': u'yahoo.com', - u'short_name': u'Yahoo!'}, - { u'description': u'', - u'in_default_list': True, - u'is_default': False, - u'keyword': u'bing.com', - u'short_name': u'Bing'}] + [ { u'description': u'', + u'display_url': u'{google:baseURL}search?q=%s', + u'host': u'www.google.com', + u'in_default_list': True, + u'is_default': True, + u'is_valid': True, + u'keyword': u'google.com', + u'path': u'/search', + u'short_name': u'Google', + u'supports_replacement': True, + u'url': u'{google:baseURL}search?q={searchTerms}'}, + { u'description': u'', + u'display_url': u'http://search.yahoo.com/search?p=%s', + u'host': u'search.yahoo.com', + u'in_default_list': True, + u'is_default': False, + u'is_valid': True, + u'keyword': u'yahoo.com', + u'path': u'/search', + u'short_name': u'Yahoo!', + u'supports_replacement': True, + u'url': u'http://search.yahoo.com/search?p={searchTerms}'}, """ + # Ensure that the search engine profile is loaded into data model. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) cmd_dict = {'command': 'GetSearchEngineInfo'} return self._GetResultFromJSONRequest(cmd_dict)['search_engines'] + def AddSearchEngine(self, title, keyword, url): + """Add a search engine, as done through the search engines UI. + + Args: + title: name for search engine. + keyword: keyword, used to initiate a custom search from omnibox. + url: url template for this search engine's query. + '%s' is replaced by search query string when used to search. + """ + # Ensure that the search engine profile is loaded into data model. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) + cmd_dict = {'command': 'AddOrEditSearchEngine', + 'new_title': title, + 'new_keyword': keyword, + 'new_url': url} + self._GetResultFromJSONRequest(cmd_dict) + + def EditSearchEngine(self, keyword, new_title, new_keyword, new_url): + """Edit info for existing search engine. + + Args: + keyword: existing search engine keyword. + new_title: new name for this search engine. + new_keyword: new keyword for this search engine. + new_url: new url for this search engine. + """ + # Ensure that the search engine profile is loaded into data model. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) + cmd_dict = {'command': 'AddOrEditSearchEngine', + 'keyword': keyword, + 'new_title': new_title, + 'new_keyword': new_keyword, + 'new_url': new_url} + self._GetResultFromJSONRequest(cmd_dict) + + def DeleteSearchEngine(self, keyword): + """Delete search engine with given keyword. + + Args: + keyword: the keyword string of the search engine to delete. + """ + # Ensure that the search engine profile is loaded into data model. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) + cmd_dict = {'command': 'PerformActionOnSearchEngine', 'keyword': keyword, + 'action': 'delete'} + self._GetResultFromJSONRequest(cmd_dict) + + def MakeSearchEngineDefault(self, keyword): + """Make search engine with given keyword the default search. + + Args: + keyword: the keyword string of the search engine to make default. + """ + # Ensure that the search engine profile is loaded into data model. + self._GetResultFromJSONRequest({'command': 'LoadSearchEngineInfo'}) + cmd_dict = {'command': 'PerformActionOnSearchEngine', 'keyword': keyword, + 'action': 'default'} + self._GetResultFromJSONRequest(cmd_dict) + def GetPrefsInfo(self): """Return info about preferences. |