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/browser/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 } | 2249 } |
2250 | 2250 |
2251 // Map json commands to their handlers. | 2251 // Map json commands to their handlers. |
2252 std::map<std::string, JsonHandler> handler_map; | 2252 std::map<std::string, JsonHandler> handler_map; |
2253 handler_map["WaitForAllTabsToStopLoading"] = | 2253 handler_map["WaitForAllTabsToStopLoading"] = |
2254 &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 2254 &TestingAutomationProvider::WaitForAllTabsToStopLoading; |
2255 handler_map["GetIndicesFromTab"] = | 2255 handler_map["GetIndicesFromTab"] = |
2256 &TestingAutomationProvider::GetIndicesFromTab; | 2256 &TestingAutomationProvider::GetIndicesFromTab; |
2257 handler_map["NavigateToURL"] = | 2257 handler_map["NavigateToURL"] = |
2258 &TestingAutomationProvider::NavigateToURL; | 2258 &TestingAutomationProvider::NavigateToURL; |
| 2259 handler_map["GetLocalStatePrefsInfo"] = |
| 2260 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
| 2261 handler_map["SetLocalStatePrefs"] = |
| 2262 &TestingAutomationProvider::SetLocalStatePrefs; |
2259 handler_map["ExecuteJavascript"] = | 2263 handler_map["ExecuteJavascript"] = |
2260 &TestingAutomationProvider::ExecuteJavascriptJSON; | 2264 &TestingAutomationProvider::ExecuteJavascriptJSON; |
2261 handler_map["ExecuteJavascriptInRenderView"] = | 2265 handler_map["ExecuteJavascriptInRenderView"] = |
2262 &TestingAutomationProvider::ExecuteJavascriptInRenderView; | 2266 &TestingAutomationProvider::ExecuteJavascriptInRenderView; |
2263 handler_map["GoForward"] = | 2267 handler_map["GoForward"] = |
2264 &TestingAutomationProvider::GoForward; | 2268 &TestingAutomationProvider::GoForward; |
2265 handler_map["GoBack"] = | 2269 handler_map["GoBack"] = |
2266 &TestingAutomationProvider::GoBack; | 2270 &TestingAutomationProvider::GoBack; |
2267 handler_map["Reload"] = | 2271 handler_map["Reload"] = |
2268 &TestingAutomationProvider::ReloadJSON; | 2272 &TestingAutomationProvider::ReloadJSON; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2425 | 2429 |
2426 browser_handler_map["LoadSearchEngineInfo"] = | 2430 browser_handler_map["LoadSearchEngineInfo"] = |
2427 &TestingAutomationProvider::LoadSearchEngineInfo; | 2431 &TestingAutomationProvider::LoadSearchEngineInfo; |
2428 browser_handler_map["GetSearchEngineInfo"] = | 2432 browser_handler_map["GetSearchEngineInfo"] = |
2429 &TestingAutomationProvider::GetSearchEngineInfo; | 2433 &TestingAutomationProvider::GetSearchEngineInfo; |
2430 browser_handler_map["AddOrEditSearchEngine"] = | 2434 browser_handler_map["AddOrEditSearchEngine"] = |
2431 &TestingAutomationProvider::AddOrEditSearchEngine; | 2435 &TestingAutomationProvider::AddOrEditSearchEngine; |
2432 browser_handler_map["PerformActionOnSearchEngine"] = | 2436 browser_handler_map["PerformActionOnSearchEngine"] = |
2433 &TestingAutomationProvider::PerformActionOnSearchEngine; | 2437 &TestingAutomationProvider::PerformActionOnSearchEngine; |
2434 | 2438 |
2435 browser_handler_map["GetLocalStatePrefsInfo"] = | |
2436 &TestingAutomationProvider::GetLocalStatePrefsInfo; | |
2437 browser_handler_map["SetLocalStatePrefs"] = | |
2438 &TestingAutomationProvider::SetLocalStatePrefs; | |
2439 browser_handler_map["GetPrefsInfo"] = | 2439 browser_handler_map["GetPrefsInfo"] = |
2440 &TestingAutomationProvider::GetPrefsInfo; | 2440 &TestingAutomationProvider::GetPrefsInfo; |
2441 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; | 2441 browser_handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
2442 | 2442 |
2443 browser_handler_map["SetWindowDimensions"] = | 2443 browser_handler_map["SetWindowDimensions"] = |
2444 &TestingAutomationProvider::SetWindowDimensions; | 2444 &TestingAutomationProvider::SetWindowDimensions; |
2445 | 2445 |
2446 browser_handler_map["GetDownloadsInfo"] = | 2446 browser_handler_map["GetDownloadsInfo"] = |
2447 &TestingAutomationProvider::GetDownloadsInfo; | 2447 &TestingAutomationProvider::GetDownloadsInfo; |
2448 browser_handler_map["WaitForAllDownloadsToComplete"] = | 2448 browser_handler_map["WaitForAllDownloadsToComplete"] = |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3339 url_model->SetDefaultSearchProvider(template_url); | 3339 url_model->SetDefaultSearchProvider(template_url); |
3340 } else { | 3340 } else { |
3341 AutomationJSONReply(this, reply_message) | 3341 AutomationJSONReply(this, reply_message) |
3342 .SendError(StringPrintf("Invalid action: %s", action.c_str())); | 3342 .SendError(StringPrintf("Invalid action: %s", action.c_str())); |
3343 } | 3343 } |
3344 } | 3344 } |
3345 | 3345 |
3346 // Sample json input: { "command": "GetLocalStatePrefsInfo" } | 3346 // Sample json input: { "command": "GetLocalStatePrefsInfo" } |
3347 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. | 3347 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
3348 void TestingAutomationProvider::GetLocalStatePrefsInfo( | 3348 void TestingAutomationProvider::GetLocalStatePrefsInfo( |
3349 Browser* browser, | |
3350 DictionaryValue* args, | 3349 DictionaryValue* args, |
3351 IPC::Message* reply_message) { | 3350 IPC::Message* reply_message) { |
3352 DictionaryValue* items = g_browser_process->local_state()-> | 3351 DictionaryValue* items = g_browser_process->local_state()-> |
3353 GetPreferenceValues(); | 3352 GetPreferenceValues(); |
3354 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3353 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
3355 return_value->Set("prefs", items); // return_value owns items. | 3354 return_value->Set("prefs", items); // return_value owns items. |
3356 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 3355 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
3357 } | 3356 } |
3358 | 3357 |
3359 // Sample json input: { "command": "SetLocalStatePrefs", "path": path, | 3358 // Sample json input: { "command": "SetLocalStatePrefs", "path": path, |
3360 // "value": value } | 3359 // "value": value } |
3361 void TestingAutomationProvider::SetLocalStatePrefs(Browser* browser, | 3360 void TestingAutomationProvider::SetLocalStatePrefs( |
3362 DictionaryValue* args, | 3361 DictionaryValue* args, |
3363 IPC::Message* reply_message) { | 3362 IPC::Message* reply_message) { |
3364 std::string path; | 3363 std::string path; |
3365 Value* val; | 3364 Value* val; |
3366 AutomationJSONReply reply(this, reply_message); | 3365 AutomationJSONReply reply(this, reply_message); |
3367 if (args->GetString("path", &path) && args->Get("value", &val)) { | 3366 if (args->GetString("path", &path) && args->Get("value", &val)) { |
3368 PrefService* pref_service = g_browser_process->local_state(); | 3367 PrefService* pref_service = g_browser_process->local_state(); |
3369 const PrefService::Preference* pref = | 3368 const PrefService::Preference* pref = |
3370 pref_service->FindPreference(path.c_str()); | 3369 pref_service->FindPreference(path.c_str()); |
3371 if (!pref) { // Not a registered pref. | 3370 if (!pref) { // Not a registered pref. |
(...skipping 3161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6533 | 6532 |
6534 Send(reply_message_); | 6533 Send(reply_message_); |
6535 redirect_query_ = 0; | 6534 redirect_query_ = 0; |
6536 reply_message_ = NULL; | 6535 reply_message_ = NULL; |
6537 } | 6536 } |
6538 | 6537 |
6539 void TestingAutomationProvider::OnRemoveProvider() { | 6538 void TestingAutomationProvider::OnRemoveProvider() { |
6540 if (g_browser_process) | 6539 if (g_browser_process) |
6541 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6540 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6542 } | 6541 } |
OLD | NEW |