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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/webdriver/webdriver_automation.h" 5 #include "chrome/test/webdriver/webdriver_automation.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 *error = CheckNewExtensionInterfaceSupported(); 790 *error = CheckNewExtensionInterfaceSupported();
791 if (*error) 791 if (*error)
792 return; 792 return;
793 793
794 std::string error_msg; 794 std::string error_msg;
795 if (!SendUninstallExtensionJSONRequest( 795 if (!SendUninstallExtensionJSONRequest(
796 automation(), extension_id, &error_msg)) 796 automation(), extension_id, &error_msg))
797 *error = new Error(kUnknownError, error_msg); 797 *error = new Error(kUnknownError, error_msg);
798 } 798 }
799 799
800 void Automation::SetLocalStatePreference(const std::string& pref,
801 base::Value* value,
802 Error** error) {
803 scoped_ptr<Value> scoped_value(value);
804 bool has_new_local_state_api = false;
805 // In version 927, SetLocalStatePrefs was changed from taking a browser
806 // handle to a browser index.
807 *error = CompareVersion(927, 0, &has_new_local_state_api);
808 if (*error)
809 return;
810
811 if (has_new_local_state_api) {
812 std::string error_msg;
813 if (!SendSetLocalStatePreferenceJSONRequest(
814 automation(), pref, scoped_value.release(), &error_msg))
815 *error = new Error(kUnknownError, error_msg);
816 } else {
817 std::string request, response;
818 DictionaryValue request_dict;
819 request_dict.SetString("command", "SetLocalStatePrefs");
820 request_dict.SetString("path", pref);
821 request_dict.Set("value", scoped_value.release());
822 base::JSONWriter::Write(&request_dict, false, &request);
823 if (!automation()->GetBrowserWindow(0)->SendJSONRequest(
824 request, -1, &response)) {
825 *error = new Error(kUnknownError, base::StringPrintf(
826 "Failed to set local state pref '%s'", pref.c_str()));
827 }
828 }
829 }
830
831 void Automation::SetPreference(const std::string& pref,
832 base::Value* value,
833 Error** error) {
834 scoped_ptr<Value> scoped_value(value);
835 bool has_new_pref_api = false;
836 // Chrome 17 is on the 963 branch. The first released 18 build should have
837 // the new SetPrefs method which uses a browser index instead of handle.
838 *error = CompareVersion(964, 0, &has_new_pref_api);
839 if (*error)
840 return;
841
842 if (has_new_pref_api) {
843 std::string error_msg;
844 if (!SendSetPreferenceJSONRequest(
845 automation(), pref, scoped_value.release(), &error_msg))
846 *error = new Error(kUnknownError, error_msg);
847 } else {
848 std::string request, response;
849 DictionaryValue request_dict;
850 request_dict.SetString("command", "SetPrefs");
851 request_dict.SetInteger("windex", 0);
852 request_dict.SetString("path", pref);
853 request_dict.Set("value", scoped_value.release());
854 base::JSONWriter::Write(&request_dict, false, &request);
855 if (!automation()->GetBrowserWindow(0)->SendJSONRequest(
856 request, -1, &response)) {
857 *error = new Error(kUnknownError, base::StringPrintf(
858 "Failed to set pref '%s'", pref.c_str()));
859 }
860 }
861 }
862
800 AutomationProxy* Automation::automation() const { 863 AutomationProxy* Automation::automation() const {
801 return launcher_->automation(); 864 return launcher_->automation();
802 } 865 }
803 866
804 Error* Automation::ConvertViewIdToLocator( 867 Error* Automation::ConvertViewIdToLocator(
805 const WebViewId& view_id, WebViewLocator* view_locator) { 868 const WebViewId& view_id, WebViewLocator* view_locator) {
806 if (view_id.old_style()) { 869 if (view_id.old_style()) {
807 int browser_index, tab_index; 870 int browser_index, tab_index;
808 std::string error_msg; 871 std::string error_msg;
809 if (!SendGetIndicesFromTabIdJSONRequest( 872 if (!SendGetIndicesFromTabIdJSONRequest(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 return CheckVersion(750, 0, message); 929 return CheckVersion(750, 0, message);
867 } 930 }
868 931
869 Error* Automation::CheckNewExtensionInterfaceSupported() { 932 Error* Automation::CheckNewExtensionInterfaceSupported() {
870 const char* message = 933 const char* message =
871 "Extension interface is not supported for this version of Chrome"; 934 "Extension interface is not supported for this version of Chrome";
872 return CheckVersion(947, 0, message); 935 return CheckVersion(947, 0, message);
873 } 936 }
874 937
875 } // namespace webdriver 938 } // namespace webdriver
OLDNEW
« 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