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

Unified Diff: chrome/test/webdriver/webdriver_automation.cc

Issue 8890026: Allow chromedriver to set local state preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years 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
« no previous file with comments | « chrome/test/webdriver/webdriver_automation.h ('k') | chrome/test/webdriver/webdriver_capabilities_parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/webdriver_automation.cc
diff --git a/chrome/test/webdriver/webdriver_automation.cc b/chrome/test/webdriver/webdriver_automation.cc
index 579f5d49d1b7a9cc41e7d6203f340b5ea8885b72..36033481a65bc960c1d27f42b8d5c02bbc6408c5 100644
--- a/chrome/test/webdriver/webdriver_automation.cc
+++ b/chrome/test/webdriver/webdriver_automation.cc
@@ -797,6 +797,69 @@ void Automation::UninstallExtension(
*error = new Error(kUnknownError, error_msg);
}
+void Automation::SetLocalStatePreference(const std::string& pref,
+ base::Value* value,
+ Error** error) {
+ scoped_ptr<Value> scoped_value(value);
+ bool has_new_local_state_api = false;
+ // In version 927, SetLocalStatePrefs was changed from taking a browser
+ // handle to a browser index.
+ *error = CompareVersion(927, 0, &has_new_local_state_api);
+ if (*error)
+ return;
+
+ if (has_new_local_state_api) {
+ std::string error_msg;
+ if (!SendSetLocalStatePreferenceJSONRequest(
+ automation(), pref, scoped_value.release(), &error_msg))
+ *error = new Error(kUnknownError, error_msg);
+ } else {
+ std::string request, response;
+ DictionaryValue request_dict;
+ request_dict.SetString("command", "SetLocalStatePrefs");
+ request_dict.SetString("path", pref);
+ request_dict.Set("value", scoped_value.release());
+ base::JSONWriter::Write(&request_dict, false, &request);
+ if (!automation()->GetBrowserWindow(0)->SendJSONRequest(
+ request, -1, &response)) {
+ *error = new Error(kUnknownError, base::StringPrintf(
+ "Failed to set local state pref '%s'", pref.c_str()));
+ }
+ }
+}
+
+void Automation::SetPreference(const std::string& pref,
+ base::Value* value,
+ Error** error) {
+ scoped_ptr<Value> scoped_value(value);
+ bool has_new_pref_api = false;
+ // Chrome 17 is on the 963 branch. The first released 18 build should have
+ // the new SetPrefs method which uses a browser index instead of handle.
+ *error = CompareVersion(964, 0, &has_new_pref_api);
+ if (*error)
+ return;
+
+ if (has_new_pref_api) {
+ std::string error_msg;
+ if (!SendSetPreferenceJSONRequest(
+ automation(), pref, scoped_value.release(), &error_msg))
+ *error = new Error(kUnknownError, error_msg);
+ } else {
+ std::string request, response;
+ DictionaryValue request_dict;
+ request_dict.SetString("command", "SetPrefs");
+ request_dict.SetInteger("windex", 0);
+ request_dict.SetString("path", pref);
+ request_dict.Set("value", scoped_value.release());
+ base::JSONWriter::Write(&request_dict, false, &request);
+ if (!automation()->GetBrowserWindow(0)->SendJSONRequest(
+ request, -1, &response)) {
+ *error = new Error(kUnknownError, base::StringPrintf(
+ "Failed to set pref '%s'", pref.c_str()));
+ }
+ }
+}
+
AutomationProxy* Automation::automation() const {
return launcher_->automation();
}
« no previous file with comments | « chrome/test/webdriver/webdriver_automation.h ('k') | chrome/test/webdriver/webdriver_capabilities_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698