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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 5755003: Fix pyauto flakiness by waiting for notification that the renderer process' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 10 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) 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"
11 #include "base/json/string_escape.h" 11 #include "base/json/string_escape.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/process.h"
14 #include "base/process_util.h"
13 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
14 #include "base/thread_restrictions.h" 16 #include "base/thread_restrictions.h"
15 #include "base/time.h" 17 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 19 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/autocomplete/autocomplete.h" 20 #include "chrome/browser/autocomplete/autocomplete.h"
19 #include "chrome/browser/autocomplete/autocomplete_edit.h" 21 #include "chrome/browser/autocomplete/autocomplete_edit.h"
20 #include "chrome/browser/autocomplete/autocomplete_match.h" 22 #include "chrome/browser/autocomplete/autocomplete_match.h"
21 #include "chrome/browser/autofill/autofill_manager.h" 23 #include "chrome/browser/autofill/autofill_manager.h"
22 #include "chrome/browser/automation/automation_autocomplete_edit_tracker.h" 24 #include "chrome/browser/automation/automation_autocomplete_edit_tracker.h"
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 &TestingAutomationProvider::GetNTPInfo; 2127 &TestingAutomationProvider::GetNTPInfo;
2126 handler_map["MoveNTPMostVisitedThumbnail"] = 2128 handler_map["MoveNTPMostVisitedThumbnail"] =
2127 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail; 2129 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail;
2128 handler_map["RemoveNTPMostVisitedThumbnail"] = 2130 handler_map["RemoveNTPMostVisitedThumbnail"] =
2129 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; 2131 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail;
2130 handler_map["UnpinNTPMostVisitedThumbnail"] = 2132 handler_map["UnpinNTPMostVisitedThumbnail"] =
2131 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; 2133 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail;
2132 handler_map["RestoreAllNTPMostVisitedThumbnails"] = 2134 handler_map["RestoreAllNTPMostVisitedThumbnails"] =
2133 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; 2135 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails;
2134 2136
2137 handler_map["KillRendererProcess"] =
2138 &TestingAutomationProvider::KillRendererProcess;
2139
2135 if (handler_map.find(std::string(command)) != handler_map.end()) { 2140 if (handler_map.find(std::string(command)) != handler_map.end()) {
2136 (this->*handler_map[command])(browser, dict_value, reply_message); 2141 (this->*handler_map[command])(browser, dict_value, reply_message);
2137 } else { 2142 } else {
2138 std::string error_string = "Unknown command. Options: "; 2143 std::string error_string = "Unknown command. Options: ";
2139 for (std::map<std::string, JsonHandler>::const_iterator it = 2144 for (std::map<std::string, JsonHandler>::const_iterator it =
2140 handler_map.begin(); it != handler_map.end(); ++it) { 2145 handler_map.begin(); it != handler_map.end(); ++it) {
2141 error_string += it->first + ", "; 2146 error_string += it->first + ", ";
2142 } 2147 }
2143 AutomationJSONReply(this, reply_message).SendError(error_string); 2148 AutomationJSONReply(this, reply_message).SendError(error_string);
2144 } 2149 }
(...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 AutomationJSONReply reply(this, reply_message); 4375 AutomationJSONReply reply(this, reply_message);
4371 history::TopSites* top_sites = browser->profile()->GetTopSites(); 4376 history::TopSites* top_sites = browser->profile()->GetTopSites();
4372 if (!top_sites) { 4377 if (!top_sites) {
4373 reply.SendError("TopSites service is not initialized."); 4378 reply.SendError("TopSites service is not initialized.");
4374 return; 4379 return;
4375 } 4380 }
4376 top_sites->ClearBlacklistedURLs(); 4381 top_sites->ClearBlacklistedURLs();
4377 reply.SendSuccess(NULL); 4382 reply.SendSuccess(NULL);
4378 } 4383 }
4379 4384
4385 void TestingAutomationProvider::KillRendererProcess(
4386 Browser* browser,
4387 DictionaryValue* args,
4388 IPC::Message* reply_message) {
4389 int pid;
4390 if (!args->GetInteger("pid", &pid)) {
4391 AutomationJSONReply(this, reply_message).
4392 SendError("'pid' key missing or invalid.");
4393 return;
4394 }
4395 base::ProcessHandle process;
4396 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) {
4397 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf(
4398 "Failed to open process handle for pid %d", pid));
4399 return;
4400 }
4401 new RendererProcessClosedObserver(this, reply_message);
4402 base::KillProcess(process, 0, false);
4403 base::CloseProcessHandle(process);
4404 }
4405
4380 void TestingAutomationProvider::WaitForTabCountToBecome( 4406 void TestingAutomationProvider::WaitForTabCountToBecome(
4381 int browser_handle, 4407 int browser_handle,
4382 int target_tab_count, 4408 int target_tab_count,
4383 IPC::Message* reply_message) { 4409 IPC::Message* reply_message) {
4384 if (!browser_tracker_->ContainsHandle(browser_handle)) { 4410 if (!browser_tracker_->ContainsHandle(browser_handle)) {
4385 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, 4411 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message,
4386 false); 4412 false);
4387 Send(reply_message); 4413 Send(reply_message);
4388 return; 4414 return;
4389 } 4415 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
4515 // If you change this, update Observer for NotificationType::SESSION_END 4541 // If you change this, update Observer for NotificationType::SESSION_END
4516 // below. 4542 // below.
4517 MessageLoop::current()->PostTask(FROM_HERE, 4543 MessageLoop::current()->PostTask(FROM_HERE,
4518 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 4544 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
4519 } 4545 }
4520 } 4546 }
4521 4547
4522 void TestingAutomationProvider::OnRemoveProvider() { 4548 void TestingAutomationProvider::OnRemoveProvider() {
4523 AutomationProviderList::GetInstance()->RemoveProvider(this); 4549 AutomationProviderList::GetInstance()->RemoveProvider(this);
4524 } 4550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698