Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 return CheckForChromeExe(browser_exes, locations, browser_exe) || | 178 return CheckForChromeExe(browser_exes, locations, browser_exe) || |
| 179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); | 179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace | 182 } // namespace |
| 183 | 183 |
| 184 namespace webdriver { | 184 namespace webdriver { |
| 185 | 185 |
| 186 Automation::BrowserOptions::BrowserOptions() | 186 Automation::BrowserOptions::BrowserOptions() |
| 187 : command(CommandLine::NO_PROGRAM), | 187 : command(CommandLine::NO_PROGRAM), |
| 188 detach_process(false) {} | 188 detach_process(false), |
| 189 cert_revocation_checking(true) {} | |
| 189 | 190 |
| 190 Automation::BrowserOptions::~BrowserOptions() {} | 191 Automation::BrowserOptions::~BrowserOptions() {} |
| 191 | 192 |
| 192 Automation::Automation() {} | 193 Automation::Automation() {} |
| 193 | 194 |
| 194 Automation::~Automation() {} | 195 Automation::~Automation() {} |
| 195 | 196 |
| 196 void Automation::Init(const BrowserOptions& options, Error** error) { | 197 void Automation::Init(const BrowserOptions& options, Error** error) { |
| 197 // Prepare Chrome's command line. | 198 // Prepare Chrome's command line. |
| 198 CommandLine command(CommandLine::NO_PROGRAM); | 199 CommandLine command(CommandLine::NO_PROGRAM); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 *error = CheckNewExtensionInterfaceSupported(); | 737 *error = CheckNewExtensionInterfaceSupported(); |
| 737 if (*error) | 738 if (*error) |
| 738 return; | 739 return; |
| 739 | 740 |
| 740 std::string error_msg; | 741 std::string error_msg; |
| 741 if (!SendInstallExtensionJSONRequest( | 742 if (!SendInstallExtensionJSONRequest( |
| 742 automation(), path, false /* with_ui */, extension_id, &error_msg)) | 743 automation(), path, false /* with_ui */, extension_id, &error_msg)) |
| 743 *error = new Error(kUnknownError, error_msg); | 744 *error = new Error(kUnknownError, error_msg); |
| 744 } | 745 } |
| 745 | 746 |
| 747 void Automation::SetLocalStatePreference(const std::string& pref, | |
| 748 base::Value* value, | |
| 749 Error** error) { | |
| 750 scoped_ptr<Value> scoped_value(value); | |
| 751 bool has_new_local_state_api = false; | |
| 752 *error = CompareVersion(927, 0, &has_new_local_state_api); | |
|
Huyen
2011/12/09 23:56:55
maybe move the version # out into a constant and/o
kkania
2011/12/10 00:37:44
Done.
| |
| 753 if (*error) | |
| 754 return; | |
| 755 | |
| 756 if (has_new_local_state_api) { | |
| 757 std::string error_msg; | |
| 758 if (!SendSetLocalStatePreferenceJSONRequest( | |
| 759 automation(), pref, scoped_value.release(), &error_msg)) | |
| 760 *error = new Error(kUnknownError, error_msg); | |
| 761 } else { | |
| 762 std::string request, response; | |
| 763 DictionaryValue request_dict; | |
| 764 request_dict.SetString("command", "SetLocalStatePrefs"); | |
| 765 request_dict.SetString("path", pref); | |
| 766 request_dict.Set("value", scoped_value.release()); | |
| 767 base::JSONWriter::Write(&request_dict, false, &request); | |
| 768 if (!automation()->GetBrowserWindow(0)->SendJSONRequest( | |
| 769 request, -1, &response)) { | |
| 770 *error = new Error(kUnknownError, base::StringPrintf( | |
| 771 "Failed to set local state pref '%s'", pref.c_str())); | |
| 772 } | |
| 773 } | |
| 774 } | |
| 775 | |
| 776 void Automation::SetPreference(const std::string& pref, | |
| 777 base::Value* value, | |
| 778 Error** error) { | |
| 779 scoped_ptr<Value> scoped_value(value); | |
| 780 bool has_new_pref_api = false; | |
| 781 *error = CompareVersion(964, 0, &has_new_pref_api); | |
|
Huyen
2011/12/09 23:56:55
same comment as above
kkania
2011/12/10 00:37:44
Done.
| |
| 782 if (*error) | |
| 783 return; | |
| 784 | |
| 785 if (has_new_pref_api) { | |
| 786 std::string error_msg; | |
| 787 if (!SendSetPreferenceJSONRequest( | |
| 788 automation(), pref, scoped_value.release(), &error_msg)) | |
| 789 *error = new Error(kUnknownError, error_msg); | |
| 790 } else { | |
| 791 std::string request, response; | |
| 792 DictionaryValue request_dict; | |
| 793 request_dict.SetString("command", "SetPrefs"); | |
| 794 request_dict.SetString("path", pref); | |
| 795 request_dict.Set("value", scoped_value.release()); | |
| 796 base::JSONWriter::Write(&request_dict, false, &request); | |
| 797 if (!automation()->GetBrowserWindow(0)->SendJSONRequest( | |
| 798 request, -1, &response)) { | |
| 799 *error = new Error(kUnknownError, base::StringPrintf( | |
| 800 "Failed to set pref '%s'", pref.c_str())); | |
| 801 } | |
| 802 } | |
| 803 } | |
| 804 | |
| 746 AutomationProxy* Automation::automation() const { | 805 AutomationProxy* Automation::automation() const { |
| 747 return launcher_->automation(); | 806 return launcher_->automation(); |
| 748 } | 807 } |
| 749 | 808 |
| 750 Error* Automation::GetIndicesForTab( | 809 Error* Automation::GetIndicesForTab( |
| 751 int tab_id, int* browser_index, int* tab_index) { | 810 int tab_id, int* browser_index, int* tab_index) { |
| 752 std::string error_msg; | 811 std::string error_msg; |
| 753 if (!SendGetIndicesFromTabIdJSONRequest( | 812 if (!SendGetIndicesFromTabIdJSONRequest( |
| 754 automation(), tab_id, browser_index, tab_index, &error_msg)) { | 813 automation(), tab_id, browser_index, tab_index, &error_msg)) { |
| 755 return new Error(kUnknownError, error_msg); | 814 return new Error(kUnknownError, error_msg); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 return CheckVersion(750, 0, message); | 865 return CheckVersion(750, 0, message); |
| 807 } | 866 } |
| 808 | 867 |
| 809 Error* Automation::CheckNewExtensionInterfaceSupported() { | 868 Error* Automation::CheckNewExtensionInterfaceSupported() { |
| 810 const char* message = | 869 const char* message = |
| 811 "Extension interface is not supported for this version of Chrome"; | 870 "Extension interface is not supported for this version of Chrome"; |
| 812 return CheckVersion(947, 0, message); | 871 return CheckVersion(947, 0, message); |
| 813 } | 872 } |
| 814 | 873 |
| 815 } // namespace webdriver | 874 } // namespace webdriver |
| OLD | NEW |