Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 7067033: Add pyauto commands to access local state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/testing_automation_provider.cc
===================================================================
--- chrome/browser/automation/testing_automation_provider.cc (revision 86289)
+++ chrome/browser/automation/testing_automation_provider.cc (working copy)
@@ -2311,6 +2311,10 @@
browser_handler_map["PerformActionOnSearchEngine"] =
&TestingAutomationProvider::PerformActionOnSearchEngine;
+ browser_handler_map["GetLocalStatePrefsInfo"] =
+ &TestingAutomationProvider::GetLocalStatePrefsInfo;
+ browser_handler_map["SetLocalState"] =
+ &TestingAutomationProvider::SetLocalState;
browser_handler_map["GetPrefsInfo"] =
&TestingAutomationProvider::GetPrefsInfo;
browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs;
@@ -3128,6 +3132,48 @@
}
}
+// 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": "SetLocalState", "path": path,
+// "value": value }
+void TestingAutomationProvider::SetLocalState(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,

Powered by Google App Engine
This is Rietveld 408576698