diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 21:34:33 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 21:34:33 +0000 |
commit | b71ae4d211f9c911b3d6f6c051c8375f62794ca6 (patch) | |
tree | 85ab391b6d734ea7de185601f40b44315bd4083c /chrome/test | |
parent | 92fa5b98619fb7edaa39b31a4f0473e72ae5d11e (diff) | |
download | chromium_src-b71ae4d211f9c911b3d6f6c051c8375f62794ca6.zip chromium_src-b71ae4d211f9c911b3d6f6c051c8375f62794ca6.tar.gz chromium_src-b71ae4d211f9c911b3d6f6c051c8375f62794ca6.tar.bz2 |
Fix extension automation hooks to use the right profile.
Extension automation hooks used to rely on the default profile saved in the
AutomationProvider at initialization. This profile is not valid in
multi-profile scenarios, or when the profile changes as after login in
chromeos. Fix these to use the right profile every time.
BUG=chromium-os:18249, chromium-os:17609
TEST=The following tests:
1. pyauto functional tests
python chrome/test/functional/pyauto_functional.py extensions
python chrome/test/functional/pyauto_functional.py themes
2. chromedriver tests
python chrome/test/webdriver/test/run_chromedriver_tests.py --f="chromedriver_tests.ExtensionTest*"
python chrome/test/webdriver/test/run_chromedriver_tests.py --f=chromedriver_tests.DesiredCapabilitiesTest.testInstallExtensions
Review URL: https://chromiumcodereview.appspot.com/9963078
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/automation/automation_json_requests.cc | 12 | ||||
-rwxr-xr-x | chrome/test/pyautolib/pyauto.py | 169 |
2 files changed, 106 insertions, 75 deletions
diff --git a/chrome/test/automation/automation_json_requests.cc b/chrome/test/automation/automation_json_requests.cc index 7430cc7..bc2fbc8 100644 --- a/chrome/test/automation/automation_json_requests.cc +++ b/chrome/test/automation/automation_json_requests.cc @@ -760,6 +760,8 @@ bool SendInstallExtensionJSONRequest( dict.SetString("command", "InstallExtension"); dict.SetString("path", path.value()); dict.SetBoolean("with_ui", with_ui); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. + dict.SetInteger("windex", 0); DictionaryValue reply_dict; if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error)) return false; @@ -776,6 +778,8 @@ bool SendGetExtensionsInfoJSONRequest( Error* error) { DictionaryValue dict; dict.SetString("command", "GetExtensionsInfo"); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. + dict.SetInteger("windex", 0); DictionaryValue reply_dict; if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error)) return false; @@ -798,6 +802,8 @@ bool SendIsPageActionVisibleJSONRequest( dict.SetString("command", "IsPageActionVisible"); tab_id.UpdateDictionary(&dict, "auto_id"); dict.SetString("extension_id", extension_id); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. + dict.SetInteger("windex", 0); DictionaryValue reply_dict; if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error)) return false; @@ -819,6 +825,8 @@ bool SendSetExtensionStateJSONRequest( dict.SetString("id", extension_id); dict.SetBoolean("enable", enable); dict.SetBoolean("allow_in_incognito", allow_in_incognito); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. + dict.SetInteger("windex", 0); DictionaryValue reply_dict; return SendAutomationJSONRequest(sender, dict, &reply_dict, error); } @@ -834,6 +842,7 @@ bool SendClickExtensionButtonJSONRequest( else dict.SetString("command", "TriggerPageActionById"); dict.SetString("id", extension_id); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. dict.SetInteger("windex", 0); dict.SetInteger("tab_index", 0); DictionaryValue reply_dict; @@ -847,6 +856,8 @@ bool SendUninstallExtensionJSONRequest( DictionaryValue dict; dict.SetString("command", "UninstallExtensionById"); dict.SetString("id", extension_id); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. + dict.SetInteger("windex", 0); DictionaryValue reply_dict; if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error)) return false; @@ -882,6 +893,7 @@ bool SendSetPreferenceJSONRequest( Error* error) { DictionaryValue dict; dict.SetString("command", "SetPrefs"); + // TODO(kkania): Set correct auto_id instead of hardcoding windex. dict.SetInteger("windex", 0); dict.SetString("path", pref); dict.Set("value", value); diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index f106294..673c21d 100755 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -1890,7 +1890,75 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): return self._GetResultFromJSONRequest( cmd_dict, windex=window_index)['translation_success'] - def InstallExtension(self, extension_path, with_ui=False): + def SelectTranslateOption(self, option, tab_index=0, window_index=0): + """Selects one of the options in the drop-down menu for the translate bar. + + Args: + option: One of 'never_translate_language', 'never_translate_site', or + 'toggle_always_translate'. See notes on each below. + tab_index: The index of the tab, default is 0. + window_index: The index of the window, default is 0. + + *Notes* + never_translate_language: Selecting this means that no sites in this + language will be translated. This dismisses the infobar. + never_translate_site: Selecting this means that this site will never be + translated, regardless of the language. This dismisses the infobar. + toggle_always_translate: This does not dismiss the infobar or translate the + page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do + those. If a language is selected to be always translated, then whenver + the user visits a page with that language, the infobar will show the + 'This page has been translated...' message. + decline_translation: Equivalent to selecting 'Nope' on the translate bar. + click_never_translate_lang_button: This button appears when the user has + declined translation of this language several times. Selecting it causes + the language to never be translated. Look at GetTranslateInfo to + determine if the button is showing. + click_always_translate_lang_button: This button appears when the user has + accepted translation of this language several times. Selecting it causes + the language to always be translated. Look at GetTranslateInfo to + determine if the button is showing. + + Raises: + pyauto_errors.JSONInterfaceError if the automation returns an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'SelectTranslateOption', + 'option': option, + 'tab_index': tab_index + } + self._GetResultFromJSONRequest(cmd_dict, windex=window_index) + + def WaitUntilTranslateComplete(self, tab_index=0, window_index=0): + """Waits until an attempted translation has finished. + + This should be called after navigating to a page that should be translated + automatically (because the language always-translate is on). It does not + need to be called after 'ClickTranslateBarTranslate'. + + Do not call this function if you are not expecting a page translation - it + will hang. If you call it when there is no translate bar, it will return + False. + + Args: + tab_index: The tab index, default is 0. + window_index: The window index, default is 0. + + Returns: + True if the translation was successful, False if there was an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'WaitUntilTranslateComplete', + 'tab_index': tab_index + } + # TODO(phajdan.jr): We need a solid automation infrastructure to handle + # these cases. See crbug.com/53647. + return self.WaitUntil( + lambda tab_index, window_index: self.GetTranslateInfo( + tab_index=tab_index, window_index=window_index)['page_translated'], + args=[tab_index, window_index]) + + def InstallExtension(self, extension_path, with_ui=False, windex=0): """Installs an extension from the given path. The path must be absolute and may be a crx file or an unpacked extension @@ -1901,6 +1969,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): extension_path: The absolute path to the extension to install. If the extension is packed, it must have a .crx extension. with_ui: Whether the extension install confirmation UI should be shown. + windex: Integer index of the browser window to use; defaults to 0 + (first window). Returns: The ID of the installed extension. @@ -1911,13 +1981,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): cmd_dict = { 'command': 'InstallExtension', 'path': extension_path, - 'with_ui': with_ui + 'with_ui': with_ui, + 'windex': windex, } return self._GetResultFromJSONRequest(cmd_dict, windex=None)['id'] - def GetExtensionsInfo(self): + def GetExtensionsInfo(self, windex=0): """Returns information about all installed extensions. + Args: + windex: Integer index of the browser window to use; defaults to 0 + (first window). + Returns: A list of dictionaries representing each of the installed extensions. Example: @@ -1955,15 +2030,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): u'allowed_in_incognito': True} ] """ cmd_dict = { # Prepare command for the json interface - 'command': 'GetExtensionsInfo' + 'command': 'GetExtensionsInfo', + 'windex': windex, } return self._GetResultFromJSONRequest(cmd_dict, windex=None)['extensions'] - def UninstallExtensionById(self, id): + def UninstallExtensionById(self, id, windex=0): """Uninstall the extension with the given id. Args: id: The string id of the extension. + windex: Integer index of the browser window to use; defaults to 0 + (first window). Returns: True, if the extension was successfully uninstalled, or @@ -1972,22 +2050,26 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): cmd_dict = { # Prepare command for the json interface 'command': 'UninstallExtensionById', 'id': id, + 'windex': windex, } return self._GetResultFromJSONRequest(cmd_dict, windex=None)['success'] - def SetExtensionStateById(self, id, enable, allow_in_incognito): + def SetExtensionStateById(self, id, enable, allow_in_incognito, windex=0): """Set extension state: enable/disable, allow/disallow in incognito mode. Args: id: The string id of the extension. enable: A boolean, enable extension. allow_in_incognito: A boolean, allow extension in incognito. + windex: Integer index of the browser window to use; defaults to 0 + (first window). """ cmd_dict = { # Prepare command for the json interface 'command': 'SetExtensionStateById', 'id': id, 'enable': enable, 'allow_in_incognito': allow_in_incognito, + 'windex': windex, } self._GetResultFromJSONRequest(cmd_dict, windex=None) @@ -2027,18 +2109,23 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } self._GetResultFromJSONRequest(cmd_dict, windex=None) - def UpdateExtensionsNow(self): + def UpdateExtensionsNow(self, windex=0): """Auto-updates installed extensions. Waits until all extensions are updated, loaded, and ready for use. This is equivalent to clicking the "Update extensions now" button on the chrome://extensions page. + Args: + windex: Integer index of the browser window to use; defaults to 0 + (first window). + Raises: pyauto_errors.JSONInterfaceError if the automation returns an error. """ cmd_dict = { # Prepare command for the json interface. 'command': 'UpdateExtensionsNow', + 'windex': windex, } self._GetResultFromJSONRequest(cmd_dict, windex=None) @@ -2105,74 +2192,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): return self.WaitUntil(lambda: _IsExtensionViewClosed()) - def SelectTranslateOption(self, option, tab_index=0, window_index=0): - """Selects one of the options in the drop-down menu for the translate bar. - - Args: - option: One of 'never_translate_language', 'never_translate_site', or - 'toggle_always_translate'. See notes on each below. - tab_index: The index of the tab, default is 0. - window_index: The index of the window, default is 0. - - *Notes* - never_translate_language: Selecting this means that no sites in this - language will be translated. This dismisses the infobar. - never_translate_site: Selecting this means that this site will never be - translated, regardless of the language. This dismisses the infobar. - toggle_always_translate: This does not dismiss the infobar or translate the - page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do - those. If a language is selected to be always translated, then whenver - the user visits a page with that language, the infobar will show the - 'This page has been translated...' message. - decline_translation: Equivalent to selecting 'Nope' on the translate bar. - click_never_translate_lang_button: This button appears when the user has - declined translation of this language several times. Selecting it causes - the language to never be translated. Look at GetTranslateInfo to - determine if the button is showing. - click_always_translate_lang_button: This button appears when the user has - accepted translation of this language several times. Selecting it causes - the language to always be translated. Look at GetTranslateInfo to - determine if the button is showing. - - Raises: - pyauto_errors.JSONInterfaceError if the automation returns an error. - """ - cmd_dict = { # Prepare command for the json interface - 'command': 'SelectTranslateOption', - 'option': option, - 'tab_index': tab_index - } - self._GetResultFromJSONRequest(cmd_dict, windex=window_index) - - def WaitUntilTranslateComplete(self, tab_index=0, window_index=0): - """Waits until an attempted translation has finished. - - This should be called after navigating to a page that should be translated - automatically (because the language always-translate is on). It does not - need to be called after 'ClickTranslateBarTranslate'. - - Do not call this function if you are not expecting a page translation - it - will hang. If you call it when there is no translate bar, it will return - False. - - Args: - tab_index: The tab index, default is 0. - window_index: The window index, default is 0. - - Returns: - True if the translation was successful, False if there was an error. - """ - cmd_dict = { # Prepare command for the json interface - 'command': 'WaitUntilTranslateComplete', - 'tab_index': tab_index - } - # TODO(phajdan.jr): We need a solid automation infrastructure to handle - # these cases. See crbug.com/53647. - return self.WaitUntil( - lambda tab_index, window_index: self.GetTranslateInfo( - tab_index=tab_index, window_index=window_index)['page_translated'], - args=[tab_index, window_index]) - def FillAutofillProfile(self, profiles=None, credit_cards=None, tab_index=0, window_index=0): """Set the autofill profile to contain the given profiles and credit cards. |