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

Side by Side Diff: chrome/test/pyautolib/pyautolib.cc

Issue 10703040: Revert 144610 (speculative; possibly caused http://crbug.com/135059) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/common/automation_messages.h"
15 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/automation/automation_proxy.h" 15 #include "chrome/test/automation/automation_proxy.h"
17 #include "chrome/test/automation/tab_proxy.h" 16 #include "chrome/test/automation/tab_proxy.h"
18 #include "chrome/test/pyautolib/pyautolib.h" 17 #include "chrome/test/pyautolib/pyautolib.h"
19 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
20 19
21 static int64 StringToId(const std::wstring& str) { 20 static int64 StringToId(const std::wstring& str) {
22 int64 id; 21 int64 id;
23 base::StringToInt64(WideToUTF8(str), &id); 22 base::StringToInt64(WideToUTF8(str), &id);
24 return id; 23 return id;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 363
365 364
366 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { 365 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
367 return automation()->GetBrowserWindow(window_index); 366 return automation()->GetBrowserWindow(window_index);
368 } 367 }
369 368
370 std::string PyUITestBase::_SendJSONRequest(int window_index, 369 std::string PyUITestBase::_SendJSONRequest(int window_index,
371 const std::string& request, 370 const std::string& request,
372 int timeout) { 371 int timeout) {
373 std::string response; 372 std::string response;
374 bool success; 373 base::TimeTicks time;
375 AutomationMessageSender* automation_sender = automation(); 374 if (window_index < 0) { // Do not need to target a browser window.
376 base::TimeTicks time = base::TimeTicks::Now(); 375 time = base::TimeTicks::Now();
377 376 if (!automation()->SendJSONRequest(request, timeout, &response)) {
378 if (!automation_sender) { 377 LOG(WARNING) << "SendJSONRequest returned false after "
379 ErrorResponse("The automation proxy does not exist", request, &response); 378 << (base::TimeTicks::Now() - time).InSeconds()
380 } else if (!automation_sender->Send( 379 << " seconds: " << request;
381 new AutomationMsg_SendJSONRequest(window_index, request, &response, 380 }
382 &success), 381 } else {
383 timeout)) { 382 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
384 RequestFailureResponse(request, base::TimeTicks::Now() - time, 383 if (!browser_proxy.get()) {
385 base::TimeDelta::FromMilliseconds(timeout), 384 base::DictionaryValue error_dict;
386 &response); 385 std::string error_string = StringPrintf(
386 "No browser at windex=%d for %s", window_index, request.c_str());
387 LOG(WARNING) << error_string;
388 error_dict.SetString("error", error_string);
389 base::JSONWriter::Write(&error_dict, &response);
390 } else {
391 time = base::TimeTicks::Now();
392 if (!browser_proxy->SendJSONRequest(request, timeout, &response)) {
393 LOG(WARNING) << "SendJSONRequest returned false after "
394 << (base::TimeTicks::Now() - time).InSeconds()
395 << " seconds: " << request;
396 }
397 }
387 } 398 }
388 return response; 399 return response;
389 } 400 }
390 401
391 void PyUITestBase::ErrorResponse(
392 const std::string& error_string,
393 const std::string& request,
394 std::string* response) {
395 base::DictionaryValue error_dict;
396 LOG(ERROR) << "Error during automation: " << response;
397 error_dict.SetString("error",
398 StringPrintf("%s for %s",
399 error_string.c_str(),
400 request.c_str()));
401 base::JSONWriter::Write(&error_dict, response);
402 }
403
404 void PyUITestBase::RequestFailureResponse(
405 const std::string& request,
406 const base::TimeDelta& duration,
407 const base::TimeDelta& timeout,
408 std::string* response) {
409 // TODO(craigdh): Determine timeout directly from IPC's Send().
410 if (duration >= timeout) {
411 ErrorResponse(
412 StringPrintf("Request timed out after %d seconds",
413 static_cast<int>(duration.InSeconds())),
414 request, response);
415 } else {
416 // TODO(craigdh): Determine specific cause.
417 ErrorResponse("Chrome failed to respond", request, response);
418 }
419 }
420
421 bool PyUITestBase::ResetToDefaultTheme() { 402 bool PyUITestBase::ResetToDefaultTheme() {
422 return automation()->ResetToDefaultTheme(); 403 return automation()->ResetToDefaultTheme();
423 } 404 }
424 405
425 bool PyUITestBase::SetCookie(const GURL& cookie_url, 406 bool PyUITestBase::SetCookie(const GURL& cookie_url,
426 const std::string& value, 407 const std::string& value,
427 int window_index, 408 int window_index,
428 int tab_index) { 409 int tab_index) {
429 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 410 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
430 EXPECT_TRUE(browser_proxy.get()); 411 EXPECT_TRUE(browser_proxy.get());
(...skipping 15 matching lines...) Expand all
446 // TODO(phadjan.jr): figure out a way to unambiguously report error. 427 // TODO(phadjan.jr): figure out a way to unambiguously report error.
447 if (!browser_proxy.get()) 428 if (!browser_proxy.get())
448 return cookie_val; 429 return cookie_val;
449 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index); 430 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
450 EXPECT_TRUE(tab_proxy.get()); 431 EXPECT_TRUE(tab_proxy.get());
451 if (!tab_proxy.get()) 432 if (!tab_proxy.get())
452 return cookie_val; 433 return cookie_val;
453 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val)); 434 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val));
454 return cookie_val; 435 return cookie_val;
455 } 436 }
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698