Commit f91f6a90 authored by mirandac@chromium.org's avatar mirandac@chromium.org

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
parent aa06595d
......@@ -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,
......
......@@ -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,
......
......@@ -6,7 +6,8 @@
"""Python representation for Chromium Preferences.
Obtain one of these from PyUITestSuite::GetPrefsInfo() call.
Obtain one of these from a call to PyUITest::GetPrefsInfo() or
PyUITest::GetLocalStatePrefsInfo().
Example:
class MyTest(pyauto.PyUITest):
......
......@@ -816,6 +816,51 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
'action': 'default'}
self._GetResultFromJSONRequest(cmd_dict)
def GetLocalStatePrefsInfo(self):
"""Return info about preferences.
This represents a snapshot of the local state preferences. If you expect
local state preferences to have changed, you need to call this method again
to get a fresh snapshot.
Returns:
an instance of prefs_info.PrefsInfo
"""
return prefs_info.PrefsInfo(
self._SendJSONRequest(0,
json.dumps({'command': 'GetLocalStatePrefsInfo'}),
self.action_max_timeout_ms()))
def SetLocalStatePrefs(self, path, value):
"""Set local state preference for the given path.
Preferences are stored by Chromium as a hierarchical dictionary.
dot-separated paths can be used to refer to a particular preference.
example: "session.restore_on_startup"
Some preferences are managed, that is, they cannot be changed by the
user. It's up to the user to know which ones can be changed. Typically,
the options available via Chromium preferences can be changed.
Args:
path: the path the preference key that needs to be changed
example: "session.restore_on_startup"
One of the equivalent names in chrome/common/pref_names.h could
also be used.
value: the value to be set. It could be plain values like int, bool,
string or complex ones like list.
The user has to ensure that the right value is specified for the
right key. It's useful to dump the preferences first to determine
what type is expected for a particular preference path.
"""
cmd_dict = {
'command': 'SetLocalStatePrefs',
'path': path,
'value': value,
}
self._GetResultFromJSONRequest(cmd_dict)
def GetPrefsInfo(self):
"""Return info about preferences.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment