diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 21:27:58 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 21:27:58 +0000 |
commit | f91f6a90a41df66264740c9d158855649b38caf7 (patch) | |
tree | a0fee127d23fc15aba01f3b521b897dabd531005 /chrome/browser/automation | |
parent | aa06595d090165c9b41f936424629e55b3063a6a (diff) | |
download | chromium_src-f91f6a90a41df66264740c9d158855649b38caf7.zip chromium_src-f91f6a90a41df66264740c9d158855649b38caf7.tar.gz chromium_src-f91f6a90a41df66264740c9d158855649b38caf7.tar.bz2 |
Add pyauto commands to access local state.
BUG=83766
TEST=forthcoming
Review URL: http://codereview.chromium.org/7067033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 46 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 12 |
2 files changed, 58 insertions, 0 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 46d08e6..f087b5f 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -2311,6 +2311,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle, browser_handler_map["PerformActionOnSearchEngine"] = &TestingAutomationProvider::PerformActionOnSearchEngine; + browser_handler_map["GetLocalStatePrefsInfo"] = + &TestingAutomationProvider::GetLocalStatePrefsInfo; + browser_handler_map["SetLocalStatePrefs"] = + &TestingAutomationProvider::SetLocalStatePrefs; browser_handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; @@ -3128,6 +3132,48 @@ void TestingAutomationProvider::PerformActionOnSearchEngine( } } +// Sample json input: { "command": "GetLocalStatePrefsInfo" } +// Refer chrome/test/pyautolib/prefs_info.py for sample json output. +void TestingAutomationProvider::GetLocalStatePrefsInfo( + Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + DictionaryValue* items = g_browser_process->local_state()-> + GetPreferenceValues(); + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + return_value->Set("prefs", items); // return_value owns items. + AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); +} + +// Sample json input: { "command": "SetLocalStatePrefs", "path": path, +// "value": value } +void TestingAutomationProvider::SetLocalStatePrefs(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + std::string path; + Value* val; + AutomationJSONReply reply(this, reply_message); + if (args->GetString("path", &path) && args->Get("value", &val)) { + PrefService* pref_service = g_browser_process->local_state(); + const PrefService::Preference* pref = + pref_service->FindPreference(path.c_str()); + if (!pref) { // Not a registered pref. + reply.SendError("pref not registered."); + return; + } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. + reply.SendError("pref is managed. cannot be changed."); + return; + } else { // Set the pref. + pref_service->Set(path.c_str(), *val); + } + } else { + reply.SendError("no pref path or value given."); + return; + } + + reply.SendSuccess(NULL); +} + // Sample json input: { "command": "GetPrefsInfo" } // Refer chrome/test/pyautolib/prefs_info.py for sample json output. void TestingAutomationProvider::GetPrefsInfo(Browser* browser, diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index f2dbb72..66769d7 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -476,6 +476,18 @@ class TestingAutomationProvider : public AutomationProvider, DictionaryValue* args, IPC::Message* reply_message); + // Get info about preferences stored in Local State. + // Uses the JSON interface for input/output. + void GetLocalStatePrefsInfo(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + + // Set local state prefs. + // Uses the JSON interface for input/output. + void SetLocalStatePrefs(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + // Get info about preferences. // Uses the JSON interface for input/output. void GetPrefsInfo(Browser* browser, |