| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/message_box_flags.h" | 7 #include "app/message_box_flags.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/blocked_content_container.h" | 33 #include "chrome/browser/blocked_content_container.h" |
| 34 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
| 35 #include "chrome/browser/browser_shutdown.h" | 35 #include "chrome/browser/browser_shutdown.h" |
| 36 #include "chrome/browser/browser_window.h" | 36 #include "chrome/browser/browser_window.h" |
| 37 #include "chrome/browser/debugger/devtools_manager.h" | 37 #include "chrome/browser/debugger/devtools_manager.h" |
| 38 #include "chrome/browser/download/download_prefs.h" | 38 #include "chrome/browser/download/download_prefs.h" |
| 39 #include "chrome/browser/download/download_shelf.h" | 39 #include "chrome/browser/download/download_shelf.h" |
| 40 #include "chrome/browser/extensions/extension_host.h" | 40 #include "chrome/browser/extensions/extension_host.h" |
| 41 #include "chrome/browser/extensions/extensions_service.h" | 41 #include "chrome/browser/extensions/extensions_service.h" |
| 42 #include "chrome/browser/find_bar.h" | 42 #include "chrome/browser/find_bar.h" |
| 43 #include "chrome/browser/history/top_sites.h" |
| 43 #include "chrome/browser/location_bar.h" | 44 #include "chrome/browser/location_bar.h" |
| 44 #include "chrome/browser/login_prompt.h" | 45 #include "chrome/browser/login_prompt.h" |
| 45 #include "chrome/browser/native_app_modal_dialog.h" | 46 #include "chrome/browser/native_app_modal_dialog.h" |
| 46 #include "chrome/browser/profile.h" | 47 #include "chrome/browser/profile.h" |
| 47 #include "chrome/browser/platform_util.h" | 48 #include "chrome/browser/platform_util.h" |
| 48 #include "chrome/browser/prefs/pref_service.h" | 49 #include "chrome/browser/prefs/pref_service.h" |
| 49 #include "chrome/browser/profile_manager.h" | 50 #include "chrome/browser/profile_manager.h" |
| 50 #include "chrome/browser/renderer_host/render_process_host.h" | 51 #include "chrome/browser/renderer_host/render_process_host.h" |
| 51 #include "chrome/browser/renderer_host/render_view_host.h" | 52 #include "chrome/browser/renderer_host/render_view_host.h" |
| 52 #include "chrome/browser/search_engines/keyword_editor_controller.h" | 53 #include "chrome/browser/search_engines/keyword_editor_controller.h" |
| (...skipping 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 | 2135 |
| 2135 handler_map["SignInToSync"] = &TestingAutomationProvider::SignInToSync; | 2136 handler_map["SignInToSync"] = &TestingAutomationProvider::SignInToSync; |
| 2136 handler_map["GetSyncInfo"] = &TestingAutomationProvider::GetSyncInfo; | 2137 handler_map["GetSyncInfo"] = &TestingAutomationProvider::GetSyncInfo; |
| 2137 handler_map["AwaitSyncCycleCompletion"] = | 2138 handler_map["AwaitSyncCycleCompletion"] = |
| 2138 &TestingAutomationProvider::AwaitSyncCycleCompletion; | 2139 &TestingAutomationProvider::AwaitSyncCycleCompletion; |
| 2139 handler_map["EnableSyncForDatatypes"] = | 2140 handler_map["EnableSyncForDatatypes"] = |
| 2140 &TestingAutomationProvider::EnableSyncForDatatypes; | 2141 &TestingAutomationProvider::EnableSyncForDatatypes; |
| 2141 handler_map["DisableSyncForDatatypes"] = | 2142 handler_map["DisableSyncForDatatypes"] = |
| 2142 &TestingAutomationProvider::DisableSyncForDatatypes; | 2143 &TestingAutomationProvider::DisableSyncForDatatypes; |
| 2143 | 2144 |
| 2145 handler_map["GetNTPInfo"] = |
| 2146 &TestingAutomationProvider::GetNTPInfo; |
| 2147 handler_map["MoveNTPMostVisitedThumbnail"] = |
| 2148 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail; |
| 2149 handler_map["RemoveNTPMostVisitedThumbnail"] = |
| 2150 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; |
| 2151 handler_map["UnpinNTPMostVisitedThumbnail"] = |
| 2152 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; |
| 2153 handler_map["RestoreAllNTPMostVisitedThumbnails"] = |
| 2154 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; |
| 2155 |
| 2144 if (handler_map.find(std::string(command)) != handler_map.end()) { | 2156 if (handler_map.find(std::string(command)) != handler_map.end()) { |
| 2145 (this->*handler_map[command])(browser, dict_value, reply_message); | 2157 (this->*handler_map[command])(browser, dict_value, reply_message); |
| 2146 } else { | 2158 } else { |
| 2147 std::string error_string = "Unknown command. Options: "; | 2159 std::string error_string = "Unknown command. Options: "; |
| 2148 for (std::map<std::string, JsonHandler>::const_iterator it = | 2160 for (std::map<std::string, JsonHandler>::const_iterator it = |
| 2149 handler_map.begin(); it != handler_map.end(); ++it) { | 2161 handler_map.begin(); it != handler_map.end(); ++it) { |
| 2150 error_string += it->first + ", "; | 2162 error_string += it->first + ", "; |
| 2151 } | 2163 } |
| 2152 AutomationJSONReply(this, reply_message).SendError(error_string); | 2164 AutomationJSONReply(this, reply_message).SendError(error_string); |
| 2153 } | 2165 } |
| (...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4298 const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons(); | 4310 const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons(); |
| 4299 if (static_cast<int>(balloons.size()) == count) { | 4311 if (static_cast<int>(balloons.size()) == count) { |
| 4300 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 4312 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 4301 return; | 4313 return; |
| 4302 } | 4314 } |
| 4303 // This will delete itself when finished. | 4315 // This will delete itself when finished. |
| 4304 new OnNotificationBalloonCountObserver( | 4316 new OnNotificationBalloonCountObserver( |
| 4305 this, reply_message, collection, count); | 4317 this, reply_message, collection, count); |
| 4306 } | 4318 } |
| 4307 | 4319 |
| 4320 // Sample JSON input: { "command": "GetNTPInfo" } |
| 4321 // For output, refer to chrome/test/pyautolib/ntp_model.py. |
| 4322 void TestingAutomationProvider::GetNTPInfo( |
| 4323 Browser* browser, |
| 4324 DictionaryValue* args, |
| 4325 IPC::Message* reply_message) { |
| 4326 // This observer will delete itself. |
| 4327 new NTPInfoObserver(this, reply_message, &consumer_); |
| 4328 } |
| 4329 |
| 4330 void TestingAutomationProvider::MoveNTPMostVisitedThumbnail( |
| 4331 Browser* browser, |
| 4332 DictionaryValue* args, |
| 4333 IPC::Message* reply_message) { |
| 4334 AutomationJSONReply reply(this, reply_message); |
| 4335 std::string url, error; |
| 4336 int index, old_index; |
| 4337 if (!args->GetString("url", &url)) { |
| 4338 reply.SendError("Missing or invalid 'url' key."); |
| 4339 return; |
| 4340 } |
| 4341 if (!args->GetInteger("index", &index)) { |
| 4342 reply.SendError("Missing or invalid 'index' key."); |
| 4343 return; |
| 4344 } |
| 4345 if (!args->GetInteger("old_index", &old_index)) { |
| 4346 reply.SendError("Missing or invalid 'old_index' key"); |
| 4347 return; |
| 4348 } |
| 4349 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
| 4350 if (!top_sites) { |
| 4351 reply.SendError("TopSites service is not initialized."); |
| 4352 return; |
| 4353 } |
| 4354 GURL swapped; |
| 4355 // If thumbnail A is switching positions with a pinned thumbnail B, B |
| 4356 // should be pinned in the old index of A. |
| 4357 if (top_sites->GetPinnedURLAtIndex(index, &swapped)) { |
| 4358 top_sites->AddPinnedURL(swapped, old_index); |
| 4359 } |
| 4360 top_sites->AddPinnedURL(GURL(url), index); |
| 4361 reply.SendSuccess(NULL); |
| 4362 } |
| 4363 |
| 4364 void TestingAutomationProvider::RemoveNTPMostVisitedThumbnail( |
| 4365 Browser* browser, |
| 4366 DictionaryValue* args, |
| 4367 IPC::Message* reply_message) { |
| 4368 AutomationJSONReply reply(this, reply_message); |
| 4369 std::string url; |
| 4370 if (!args->GetString("url", &url)) { |
| 4371 reply.SendError("Missing or invalid 'url' key."); |
| 4372 return; |
| 4373 } |
| 4374 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
| 4375 if (!top_sites) { |
| 4376 reply.SendError("TopSites service is not initialized."); |
| 4377 return; |
| 4378 } |
| 4379 top_sites->AddBlacklistedURL(GURL(url)); |
| 4380 reply.SendSuccess(NULL); |
| 4381 } |
| 4382 |
| 4383 void TestingAutomationProvider::UnpinNTPMostVisitedThumbnail( |
| 4384 Browser* browser, |
| 4385 DictionaryValue* args, |
| 4386 IPC::Message* reply_message) { |
| 4387 AutomationJSONReply reply(this, reply_message); |
| 4388 std::string url; |
| 4389 if (!args->GetString("url", &url)) { |
| 4390 reply.SendError("Missing or invalid 'url' key."); |
| 4391 return; |
| 4392 } |
| 4393 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
| 4394 if (!top_sites) { |
| 4395 reply.SendError("TopSites service is not initialized."); |
| 4396 return; |
| 4397 } |
| 4398 top_sites->RemovePinnedURL(GURL(url)); |
| 4399 reply.SendSuccess(NULL); |
| 4400 } |
| 4401 |
| 4402 void TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails( |
| 4403 Browser* browser, |
| 4404 DictionaryValue* args, |
| 4405 IPC::Message* reply_message) { |
| 4406 AutomationJSONReply reply(this, reply_message); |
| 4407 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
| 4408 if (!top_sites) { |
| 4409 reply.SendError("TopSites service is not initialized."); |
| 4410 return; |
| 4411 } |
| 4412 top_sites->ClearBlacklistedURLs(); |
| 4413 reply.SendSuccess(NULL); |
| 4414 } |
| 4415 |
| 4308 void TestingAutomationProvider::WaitForTabCountToBecome( | 4416 void TestingAutomationProvider::WaitForTabCountToBecome( |
| 4309 int browser_handle, | 4417 int browser_handle, |
| 4310 int target_tab_count, | 4418 int target_tab_count, |
| 4311 IPC::Message* reply_message) { | 4419 IPC::Message* reply_message) { |
| 4312 if (!browser_tracker_->ContainsHandle(browser_handle)) { | 4420 if (!browser_tracker_->ContainsHandle(browser_handle)) { |
| 4313 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, | 4421 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, |
| 4314 false); | 4422 false); |
| 4315 Send(reply_message); | 4423 Send(reply_message); |
| 4316 return; | 4424 return; |
| 4317 } | 4425 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4453 DCHECK(type == NotificationType::SESSION_END); | 4561 DCHECK(type == NotificationType::SESSION_END); |
| 4454 // OnBrowserRemoved does a ReleaseLater. When session end is received we exit | 4562 // OnBrowserRemoved does a ReleaseLater. When session end is received we exit |
| 4455 // before the task runs resulting in this object not being deleted. This | 4563 // before the task runs resulting in this object not being deleted. This |
| 4456 // Release balance out the Release scheduled by OnBrowserRemoved. | 4564 // Release balance out the Release scheduled by OnBrowserRemoved. |
| 4457 Release(); | 4565 Release(); |
| 4458 } | 4566 } |
| 4459 | 4567 |
| 4460 void TestingAutomationProvider::OnRemoveProvider() { | 4568 void TestingAutomationProvider::OnRemoveProvider() { |
| 4461 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4569 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 4462 } | 4570 } |
| OLD | NEW |