diff options
author | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 19:00:07 +0000 |
---|---|---|
committer | alyssad@chromium.org <alyssad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 19:00:07 +0000 |
commit | c5aa5321a9bbc18daef554c8fe60030d193d1360 (patch) | |
tree | 051c43c8edaf5bc420f6ecdab6039e3a2a0df06d | |
parent | 196562021d98360096a71ad3b6e6f5e1181278a4 (diff) | |
download | chromium_src-c5aa5321a9bbc18daef554c8fe60030d193d1360.zip chromium_src-c5aa5321a9bbc18daef554c8fe60030d193d1360.tar.gz chromium_src-c5aa5321a9bbc18daef554c8fe60030d193d1360.tar.bz2 |
Adding a new PyAuto hook for importing settings.
BUG=43231
Review URL: http://codereview.chromium.org/2923010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52508 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 84 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 6 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 8 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.h | 20 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 35 |
5 files changed, 153 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 95b524f..fb8c7a1 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -62,6 +62,8 @@ #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/find_notification_details.h" #include "chrome/browser/host_content_settings_map.h" +#include "chrome/browser/importer/importer.h" +#include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/login_prompt.h" @@ -2349,6 +2351,86 @@ void AutomationProvider::SaveTabContents(Browser* browser, Send(reply_message); } +// Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample +// json input. +// Sample json output: "{}" +void AutomationProvider::ImportSettings(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + std::string json_return = "{}"; + + // Map from the json string passed over to the import item masks. + std::map<std::string, ImportItem> string_to_import_item; + string_to_import_item["HISTORY"] = importer::HISTORY; + string_to_import_item["FAVORITES"] = importer::FAVORITES; + string_to_import_item["COOKIES"] = importer::COOKIES; + string_to_import_item["PASSWORDS"] = importer::PASSWORDS; + string_to_import_item["SEARCH_ENGINES"] = importer::SEARCH_ENGINES; + string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; + string_to_import_item["ALL"] = importer::ALL; + + std::wstring browser_name; + int import_items = 0; + ListValue* import_items_list = NULL; + bool first_run; + + if (!args->GetString(L"import_from", &browser_name) || + !args->GetBoolean(L"first_run", &first_run) || + !args->GetList(L"import_items", &import_items_list)) { + std::string json_return = + JSONErrorString("Incorrect type for one or more of the arguments."); + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message, json_return, false); + Send(reply_message); + return; + } + + int num_items = import_items_list->GetSize(); + for (int i = 0; i < num_items; i++) { + std::string item; + import_items_list->GetString(i, &item); + // If the provided string is not part of the map, error out. + if (!ContainsKey(string_to_import_item, item)) { + json_return = + JSONErrorString("Invalid item string found in import_items."); + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message, json_return, false); + Send(reply_message); + return; + } + import_items |= string_to_import_item[item]; + } + + ImporterHost* importer_host = new ImporterHost(); + // Get the correct ProfileInfo based on the browser they user provided. + importer::ProfileInfo profile_info; + int num_browsers = importer_host->GetAvailableProfileCount(); + int i = 0; + for ( ; i < num_browsers; i++) { + std::wstring name = importer_host->GetSourceProfileNameAt(i); + if (name == browser_name) { + profile_info = importer_host->GetSourceProfileInfoAt(i); + break; + } + } + // If we made it to the end of the loop, then the input was bad. + if (i == num_browsers) { + json_return = + JSONErrorString("Invalid browser name string found."); + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message, json_return, false); + Send(reply_message); + return; + } + + Profile* profile = browser->profile(); + + importer_host->SetObserver( + new AutomationProviderImportSettingsObserver(this, reply_message)); + importer_host->StartImportSettings(profile_info, profile, import_items, + new ProfileWriter(profile), first_run); +} + // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample // json input. // Sample json output: {} @@ -2772,6 +2854,8 @@ void AutomationProvider::SendJSONRequest(int handle, handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; + handler_map["ImportSettings"] = &AutomationProvider::ImportSettings; + handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData; // SetTheme() implemented using InstallExtension(). diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index b4782c3..45c8abd 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -460,6 +460,12 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DictionaryValue* args, IPC::Message* reply_message); + // Import the given settings from the given browser. + // Uses the JSON interface for input/output. + void ImportSettings(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + // Fill in an AutoFillProfile with the given profile information. // Uses the JSON interface for input/output. void FillAutoFillProfile(Browser* browser, diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index a8c441d..0076047 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1012,6 +1012,14 @@ void AutomationProviderHistoryObserver::HistoryQueryComplete( delete this; } +void AutomationProviderImportSettingsObserver::ImportEnded() { + // Send back an empty success message. + AutomationMsg_SendJSONRequest::WriteReplyParams( + reply_message_, std::string("{}"), true); + provider_->Send(reply_message_); + delete this; +} + void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() { // Send back an empty success message AutomationMsg_SendJSONRequest::WriteReplyParams( diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 72147c6..8bb100a 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -12,6 +12,8 @@ #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/importer/importer.h" +#include "chrome/browser/importer/importer_data_types.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_type.h" @@ -612,6 +614,24 @@ class AutomationProviderHistoryObserver { IPC::Message* reply_message_; }; +// Allows the automation provider to wait for import queries to finish. +class AutomationProviderImportSettingsObserver : + public ImporterHost::Observer { + public: + AutomationProviderImportSettingsObserver( + AutomationProvider* provider, + IPC::Message* reply_message) + : provider_(provider), + reply_message_(reply_message) {} + void ImportStarted() {} + void ImportItemStarted(importer::ImportItem item) {} + void ImportItemEnded(importer::ImportItem item) {} + void ImportEnded(); + private: + AutomationProvider* provider_; + IPC::Message* reply_message_; +}; + // Allows the automation provider to wait for clearing browser data to finish. class AutomationProviderBrowsingDataObserver : public BrowsingDataRemover::Observer { diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index c25b893..72304d5 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -757,6 +757,41 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): finally: shutil.rmtree(tempdir) + def ImportSettings(self, import_from, first_run, import_items): + """Import the specified import items from the specified browser. + + Implements the features available in the "Import Settings" part of the + first-run UI dialog. + + Args: + import_from: A string indicating which browser to import from. Possible + strings (depending on which browsers are installed on the + machine) are: 'Mozilla Firefox', 'Google Toolbar', + 'Microsoft Internet Explorer', 'Safari' + first_run: A boolean indicating whether this is the first run of + the browser. + If it is not the first run then: + 1) Bookmarks are only imported to the bookmarks bar if there + aren't already bookmarks. + 2) The bookmark bar is shown. + import_items: A list of strings indicating which items to import. + Strings that can be in the list are: + HISTORY, FAVORITES, PASSWORDS, SEARCH_ENGINES, HOME_PAGE, + ALL (note: COOKIES is not supported by the browser yet) + Raises: + pyauto_errors.JSONInterfaceError if the automation call returns an error. + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'ImportSettings', + 'import_from': import_from, + 'first_run': first_run, + 'import_items': import_items + } + ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) + if ret_dict.has_key('error'): + raise JSONInterfaceError(ret_dict['error']) + return ret_dict + def ClearBrowsingData(self, to_remove, time_period): """Clear the specified browsing data. Implements the features available in the "ClearBrowsingData" UI. |