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

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

Issue 7866026: Added trace query code and wired tracing through BrowserProxy so tests can run traces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 3 months 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) 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void TestingAutomationProvider::Observe(int type, 244 void TestingAutomationProvider::Observe(int type,
245 const NotificationSource& source, 245 const NotificationSource& source,
246 const NotificationDetails& details) { 246 const NotificationDetails& details) {
247 DCHECK(type == chrome::NOTIFICATION_SESSION_END); 247 DCHECK(type == chrome::NOTIFICATION_SESSION_END);
248 // OnBrowserRemoved does a ReleaseLater. When session end is received we exit 248 // OnBrowserRemoved does a ReleaseLater. When session end is received we exit
249 // before the task runs resulting in this object not being deleted. This 249 // before the task runs resulting in this object not being deleted. This
250 // Release balance out the Release scheduled by OnBrowserRemoved. 250 // Release balance out the Release scheduled by OnBrowserRemoved.
251 Release(); 251 Release();
252 } 252 }
253 253
254 void TestingAutomationProvider::OnEndTracingComplete() {
255 IPC::Message* reply_message = tracing_data_.reply_message.release();
256 if (reply_message) {
257 // Finish off JSON string.
258 if (tracing_data_.json_output.empty())
259 tracing_data_.json_output.push_back("[]");
260 else
261 tracing_data_.json_output.push_back("]");
262 AutomationMsg_EndTracing::WriteReplyParams(reply_message, true);
263 Send(reply_message);
264 }
265 }
266
267 void TestingAutomationProvider::OnTraceDataCollected(
268 const std::string& json_events) {
269 // |json_events| should start with '[' and end with ']'.
270 if (json_events.size() > 2) {
271 std::string chunk;
272 // If this is the first chunk, JSON starts with '['.
273 if (tracing_data_.json_output.empty())
274 chunk += '[';
275 else
276 chunk += ',';
277 chunk += json_events.substr(1, json_events.size() - 2);
278 // Append without the leading and trailing brackets.
279 tracing_data_.json_output.push_back(chunk);
280 }
281 }
282
254 bool TestingAutomationProvider::OnMessageReceived( 283 bool TestingAutomationProvider::OnMessageReceived(
255 const IPC::Message& message) { 284 const IPC::Message& message) {
256 bool handled = true; 285 bool handled = true;
257 bool deserialize_success = true; 286 bool deserialize_success = true;
258 IPC_BEGIN_MESSAGE_MAP_EX(TestingAutomationProvider, 287 IPC_BEGIN_MESSAGE_MAP_EX(TestingAutomationProvider,
259 message, 288 message,
260 deserialize_success) 289 deserialize_success)
261 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) 290 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
262 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, 291 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
263 CloseBrowserAsync) 292 CloseBrowserAsync)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) 333 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds)
305 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) 334 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds)
306 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) 335 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible)
307 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) 336 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
308 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) 337 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove)
309 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) 338 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
310 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) 339 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount)
311 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) 340 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType)
312 IPC_MESSAGE_HANDLER(AutomationMsg_IsBrowserInApplicationMode, 341 IPC_MESSAGE_HANDLER(AutomationMsg_IsBrowserInApplicationMode,
313 IsBrowserInApplicationMode) 342 IsBrowserInApplicationMode)
343 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing)
344 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing)
345 IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput)
314 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) 346 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
315 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) 347 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID)
316 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) 348 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
317 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) 349 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
318 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) 350 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
319 IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) 351 IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility)
320 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) 352 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen)
321 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, 353 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible,
322 GetFullscreenBubbleVisibility) 354 GetFullscreenBubbleVisibility)
323 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, 355 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 1222
1191 if (browser_tracker_->ContainsHandle(handle)) { 1223 if (browser_tracker_->ContainsHandle(handle)) {
1192 Browser* browser = browser_tracker_->GetResource(handle); 1224 Browser* browser = browser_tracker_->GetResource(handle);
1193 if (browser) { 1225 if (browser) {
1194 *success = true; 1226 *success = true;
1195 *is_application = browser->is_app(); 1227 *is_application = browser->is_app();
1196 } 1228 }
1197 } 1229 }
1198 } 1230 }
1199 1231
1232 void TestingAutomationProvider::BeginTracing(
1233 const std::vector<std::string>& included_categories,
1234 const std::vector<std::string>& excluded_categories,
1235 bool* result) {
1236 tracing_data_.json_output.clear();
1237 *result = TraceController::GetInstance()->BeginTracing(this,
1238 included_categories,
1239 excluded_categories);
1240 }
1241
1242 void TestingAutomationProvider::EndTracing(IPC::Message* reply_message) {
1243 bool success = false;
1244 if (!tracing_data_.reply_message.get()) {
1245 success = TraceController::GetInstance()->EndTracingAsync(this);
1246 }
1247 // If failed to call EndTracingAsync, need to reply with failure now.
1248 if (!success) {
1249 AutomationMsg_EndTracing::WriteReplyParams(reply_message, false);
1250 Send(reply_message);
1251 } else {
1252 // Defer EndTracing reply until the we are notified by TraceController.
1253 tracing_data_.reply_message.reset(reply_message);
1254 }
1255 }
1256
1257 void TestingAutomationProvider::GetTracingOutput(std::string* chunk,
1258 int* remaining_chunks) {
1259 // The JSON data is sent back to the test in chunks, because IPC sends will
1260 // fail if they are too large.
1261 if (tracing_data_.json_output.empty()) {
1262 *chunk = "";
1263 *remaining_chunks = -1;
1264 } else {
1265 *chunk = tracing_data_.json_output.front();
1266 tracing_data_.json_output.pop_front();
1267 *remaining_chunks = tracing_data_.json_output.size();
1268 }
1269 }
1270
1200 void TestingAutomationProvider::GetTab(int win_handle, 1271 void TestingAutomationProvider::GetTab(int win_handle,
1201 int tab_index, 1272 int tab_index,
1202 int* tab_handle) { 1273 int* tab_handle) {
1203 *tab_handle = 0; 1274 *tab_handle = 0;
1204 if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { 1275 if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) {
1205 Browser* browser = browser_tracker_->GetResource(win_handle); 1276 Browser* browser = browser_tracker_->GetResource(win_handle);
1206 if (tab_index < browser->tab_count()) { 1277 if (tab_index < browser->tab_count()) {
1207 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); 1278 TabContents* tab_contents = browser->GetTabContentsAt(tab_index);
1208 *tab_handle = tab_tracker_->Add(&tab_contents->controller()); 1279 *tab_handle = tab_tracker_->Add(&tab_contents->controller());
1209 } 1280 }
(...skipping 5131 matching lines...) Expand 10 before | Expand all | Expand 10 after
6341 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); 6412 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl);
6342 6413
6343 Send(reply_message_); 6414 Send(reply_message_);
6344 redirect_query_ = 0; 6415 redirect_query_ = 0;
6345 reply_message_ = NULL; 6416 reply_message_ = NULL;
6346 } 6417 }
6347 6418
6348 void TestingAutomationProvider::OnRemoveProvider() { 6419 void TestingAutomationProvider::OnRemoveProvider() {
6349 AutomationProviderList::GetInstance()->RemoveProvider(this); 6420 AutomationProviderList::GetInstance()->RemoveProvider(this);
6350 } 6421 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/common/automation_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698