OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #include "chrome/browser/search_engines/template_url_service_factory.h" | 84 #include "chrome/browser/search_engines/template_url_service_factory.h" |
85 #include "chrome/browser/sessions/session_service_factory.h" | 85 #include "chrome/browser/sessions/session_service_factory.h" |
86 #include "chrome/browser/sessions/session_tab_helper.h" | 86 #include "chrome/browser/sessions/session_tab_helper.h" |
87 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 87 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
88 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 88 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
89 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 89 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
90 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 90 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
91 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | 91 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
92 #include "chrome/browser/ui/browser_commands.h" | 92 #include "chrome/browser/ui/browser_commands.h" |
93 #include "chrome/browser/ui/browser_finder.h" | 93 #include "chrome/browser/ui/browser_finder.h" |
94 #include "chrome/browser/ui/browser_instant_controller.h" | |
95 #include "chrome/browser/ui/browser_iterator.h" | 94 #include "chrome/browser/ui/browser_iterator.h" |
96 #include "chrome/browser/ui/browser_list_impl.h" | 95 #include "chrome/browser/ui/browser_list_impl.h" |
97 #include "chrome/browser/ui/browser_tabstrip.h" | 96 #include "chrome/browser/ui/browser_tabstrip.h" |
98 #include "chrome/browser/ui/browser_window.h" | 97 #include "chrome/browser/ui/browser_window.h" |
99 #include "chrome/browser/ui/extensions/application_launch.h" | 98 #include "chrome/browser/ui/extensions/application_launch.h" |
100 #include "chrome/browser/ui/find_bar/find_bar.h" | 99 #include "chrome/browser/ui/find_bar/find_bar.h" |
101 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 100 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
102 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 101 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
103 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" | 102 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" |
104 #include "chrome/browser/ui/host_desktop.h" | 103 #include "chrome/browser/ui/host_desktop.h" |
(...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1747 handler_map_["TriggerBrowserActionById"] = | 1746 handler_map_["TriggerBrowserActionById"] = |
1748 &TestingAutomationProvider::TriggerBrowserActionById; | 1747 &TestingAutomationProvider::TriggerBrowserActionById; |
1749 handler_map_["UpdateExtensionsNow"] = | 1748 handler_map_["UpdateExtensionsNow"] = |
1750 &TestingAutomationProvider::UpdateExtensionsNow; | 1749 &TestingAutomationProvider::UpdateExtensionsNow; |
1751 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 1750 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
1752 handler_map_["HeapProfilerDump"] = | 1751 handler_map_["HeapProfilerDump"] = |
1753 &TestingAutomationProvider::HeapProfilerDump; | 1752 &TestingAutomationProvider::HeapProfilerDump; |
1754 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 1753 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
1755 handler_map_["OverrideGeoposition"] = | 1754 handler_map_["OverrideGeoposition"] = |
1756 &TestingAutomationProvider::OverrideGeoposition; | 1755 &TestingAutomationProvider::OverrideGeoposition; |
1757 handler_map_["AppendSwitchASCIIToCommandLine"] = | |
1758 &TestingAutomationProvider::AppendSwitchASCIIToCommandLine; | |
1759 handler_map_["SimulateAsanMemoryBug"] = | 1756 handler_map_["SimulateAsanMemoryBug"] = |
1760 &TestingAutomationProvider::SimulateAsanMemoryBug; | 1757 &TestingAutomationProvider::SimulateAsanMemoryBug; |
1761 | 1758 |
1762 #if defined(OS_CHROMEOS) | 1759 #if defined(OS_CHROMEOS) |
1763 handler_map_["AcceptOOBENetworkScreen"] = | 1760 handler_map_["AcceptOOBENetworkScreen"] = |
1764 &TestingAutomationProvider::AcceptOOBENetworkScreen; | 1761 &TestingAutomationProvider::AcceptOOBENetworkScreen; |
1765 handler_map_["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; | 1762 handler_map_["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; |
1766 handler_map_["CancelOOBEUpdate"] = | 1763 handler_map_["CancelOOBEUpdate"] = |
1767 &TestingAutomationProvider::CancelOOBEUpdate; | 1764 &TestingAutomationProvider::CancelOOBEUpdate; |
1768 handler_map_["PickUserImage"] = &TestingAutomationProvider::PickUserImage; | 1765 handler_map_["PickUserImage"] = &TestingAutomationProvider::PickUserImage; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 | 1861 |
1865 browser_handler_map_["GetOmniboxInfo"] = | 1862 browser_handler_map_["GetOmniboxInfo"] = |
1866 &TestingAutomationProvider::GetOmniboxInfo; | 1863 &TestingAutomationProvider::GetOmniboxInfo; |
1867 browser_handler_map_["SetOmniboxText"] = | 1864 browser_handler_map_["SetOmniboxText"] = |
1868 &TestingAutomationProvider::SetOmniboxText; | 1865 &TestingAutomationProvider::SetOmniboxText; |
1869 browser_handler_map_["OmniboxAcceptInput"] = | 1866 browser_handler_map_["OmniboxAcceptInput"] = |
1870 &TestingAutomationProvider::OmniboxAcceptInput; | 1867 &TestingAutomationProvider::OmniboxAcceptInput; |
1871 browser_handler_map_["OmniboxMovePopupSelection"] = | 1868 browser_handler_map_["OmniboxMovePopupSelection"] = |
1872 &TestingAutomationProvider::OmniboxMovePopupSelection; | 1869 &TestingAutomationProvider::OmniboxMovePopupSelection; |
1873 | 1870 |
1874 browser_handler_map_["GetInstantInfo"] = | |
1875 &TestingAutomationProvider::GetInstantInfo; | |
1876 | |
1877 browser_handler_map_["LoadSearchEngineInfo"] = | 1871 browser_handler_map_["LoadSearchEngineInfo"] = |
1878 &TestingAutomationProvider::LoadSearchEngineInfo; | 1872 &TestingAutomationProvider::LoadSearchEngineInfo; |
1879 browser_handler_map_["GetSearchEngineInfo"] = | 1873 browser_handler_map_["GetSearchEngineInfo"] = |
1880 &TestingAutomationProvider::GetSearchEngineInfo; | 1874 &TestingAutomationProvider::GetSearchEngineInfo; |
1881 browser_handler_map_["AddOrEditSearchEngine"] = | 1875 browser_handler_map_["AddOrEditSearchEngine"] = |
1882 &TestingAutomationProvider::AddOrEditSearchEngine; | 1876 &TestingAutomationProvider::AddOrEditSearchEngine; |
1883 browser_handler_map_["PerformActionOnSearchEngine"] = | 1877 browser_handler_map_["PerformActionOnSearchEngine"] = |
1884 &TestingAutomationProvider::PerformActionOnSearchEngine; | 1878 &TestingAutomationProvider::PerformActionOnSearchEngine; |
1885 | 1879 |
1886 browser_handler_map_["SetWindowDimensions"] = | 1880 browser_handler_map_["SetWindowDimensions"] = |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3075 LocationBar* loc_bar = browser->window()->GetLocationBar(); | 3069 LocationBar* loc_bar = browser->window()->GetLocationBar(); |
3076 if (!loc_bar) { | 3070 if (!loc_bar) { |
3077 AutomationJSONReply(this, reply_message).SendError( | 3071 AutomationJSONReply(this, reply_message).SendError( |
3078 "The specified browser does not have a location bar."); | 3072 "The specified browser does not have a location bar."); |
3079 return; | 3073 return; |
3080 } | 3074 } |
3081 new OmniboxAcceptNotificationObserver(&controller, this, reply_message); | 3075 new OmniboxAcceptNotificationObserver(&controller, this, reply_message); |
3082 loc_bar->AcceptInput(); | 3076 loc_bar->AcceptInput(); |
3083 } | 3077 } |
3084 | 3078 |
3085 // Sample json input: { "command": "GetInstantInfo" } | |
3086 void TestingAutomationProvider::GetInstantInfo(Browser* browser, | |
3087 DictionaryValue* args, | |
3088 IPC::Message* reply_message) { | |
3089 DictionaryValue* info = new DictionaryValue; | |
3090 if (chrome::BrowserInstantController::IsInstantEnabled(browser->profile()) && | |
3091 browser->instant_controller()) { | |
3092 InstantController* instant = browser->instant_controller()->instant(); | |
3093 info->SetBoolean("enabled", true); | |
3094 info->SetBoolean("active", (instant->GetPreviewContents() != NULL)); | |
3095 info->SetBoolean("current", instant->IsPreviewingSearchResults()); | |
3096 if (instant->GetPreviewContents()) { | |
3097 WebContents* contents = instant->GetPreviewContents(); | |
3098 info->SetBoolean("loading", contents->IsLoading()); | |
3099 info->SetString("location", contents->GetURL().spec()); | |
3100 info->SetString("title", contents->GetTitle()); | |
3101 } | |
3102 } else { | |
3103 info->SetBoolean("enabled", false); | |
3104 } | |
3105 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
3106 return_value->Set("instant", info); | |
3107 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | |
3108 } | |
3109 | |
3110 // Sample json input: { "command": "GetInitialLoadTimes" } | 3079 // Sample json input: { "command": "GetInitialLoadTimes" } |
3111 // Refer to InitialLoadObserver::GetTimingInformation() for sample output. | 3080 // Refer to InitialLoadObserver::GetTimingInformation() for sample output. |
3112 void TestingAutomationProvider::GetInitialLoadTimes( | 3081 void TestingAutomationProvider::GetInitialLoadTimes( |
3113 Browser*, | 3082 Browser*, |
3114 DictionaryValue*, | 3083 DictionaryValue*, |
3115 IPC::Message* reply_message) { | 3084 IPC::Message* reply_message) { |
3116 scoped_ptr<DictionaryValue> return_value( | 3085 scoped_ptr<DictionaryValue> return_value( |
3117 initial_load_observer_->GetTimingInformation()); | 3086 initial_load_observer_->GetTimingInformation()); |
3118 | 3087 |
3119 std::string json_return; | 3088 std::string json_return; |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4147 position.latitude = latitude; | 4116 position.latitude = latitude; |
4148 position.longitude = longitude; | 4117 position.longitude = longitude; |
4149 position.altitude = altitude; | 4118 position.altitude = altitude; |
4150 position.accuracy = 0.; | 4119 position.accuracy = 0.; |
4151 position.timestamp = base::Time::Now(); | 4120 position.timestamp = base::Time::Now(); |
4152 content::OverrideLocationForTesting( | 4121 content::OverrideLocationForTesting( |
4153 position, | 4122 position, |
4154 base::Bind(&SendSuccessIfAlive, AsWeakPtr(), reply_message)); | 4123 base::Bind(&SendSuccessIfAlive, AsWeakPtr(), reply_message)); |
4155 } | 4124 } |
4156 | 4125 |
4157 // Sample json input: | |
4158 // { "command": "AppendSwitchASCIIToCommandLine", | |
4159 // "switch": "instant-field-trial", | |
4160 // "value": "disabled" } | |
4161 void TestingAutomationProvider::AppendSwitchASCIIToCommandLine( | |
4162 DictionaryValue* args, IPC::Message* reply_message) { | |
4163 AutomationJSONReply reply(this, reply_message); | |
4164 std::string switch_name, switch_value; | |
4165 if (!args->GetString("switch", &switch_name) || | |
4166 !args->GetString("value", &switch_value)) { | |
4167 reply.SendError("Missing or invalid command line switch"); | |
4168 return; | |
4169 } | |
4170 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_name, | |
4171 switch_value); | |
4172 reply.SendSuccess(NULL); | |
4173 } | |
4174 | |
4175 // Refer to GetAllNotifications() in chrome/test/pyautolib/pyauto.py for | 4126 // Refer to GetAllNotifications() in chrome/test/pyautolib/pyauto.py for |
4176 // sample json input/output. | 4127 // sample json input/output. |
4177 void TestingAutomationProvider::GetAllNotifications( | 4128 void TestingAutomationProvider::GetAllNotifications( |
4178 Browser* browser, | 4129 Browser* browser, |
4179 DictionaryValue* args, | 4130 DictionaryValue* args, |
4180 IPC::Message* reply_message) { | 4131 IPC::Message* reply_message) { |
4181 new GetAllNotificationsObserver(this, reply_message); | 4132 new GetAllNotificationsObserver(this, reply_message); |
4182 } | 4133 } |
4183 | 4134 |
4184 // Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for | 4135 // Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for |
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5966 if (g_browser_process) | 5917 if (g_browser_process) |
5967 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5918 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
5968 } | 5919 } |
5969 | 5920 |
5970 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5921 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
5971 WebContents* tab) { | 5922 WebContents* tab) { |
5972 TabStripModel* tab_strip = browser->tab_strip_model(); | 5923 TabStripModel* tab_strip = browser->tab_strip_model(); |
5973 if (tab_strip->GetActiveWebContents() != tab) | 5924 if (tab_strip->GetActiveWebContents() != tab) |
5974 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5925 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
5975 } | 5926 } |
OLD | NEW |