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

Side by Side Diff: chrome/test/automation/browser_proxy.cc

Issue 10736064: Switch to TimeDelta interfaces in chrome automation test infrastructure. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 "chrome/test/automation/browser_proxy.h" 5 #include "chrome/test/automation/browser_proxy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 bool success = false; 193 bool success = false;
194 if (!sender_->Send(new AutomationMsg_WaitForTabCountToBecome( 194 if (!sender_->Send(new AutomationMsg_WaitForTabCountToBecome(
195 handle_, count, &success))) { 195 handle_, count, &success))) {
196 return false; 196 return false;
197 } 197 }
198 198
199 return success; 199 return success;
200 } 200 }
201 201
202 bool BrowserProxy::WaitForTabToBecomeActive(int tab, 202 bool BrowserProxy::WaitForTabToBecomeActive(int tab,
203 int wait_timeout) { 203 base::TimeDelta wait_timeout) {
204 const TimeTicks start = TimeTicks::Now(); 204 const TimeTicks start = TimeTicks::Now();
205 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); 205 while (TimeTicks::Now() - start < wait_timeout) {
206 while (TimeTicks::Now() - start < timeout) {
207 base::PlatformThread::Sleep( 206 base::PlatformThread::Sleep(
208 base::TimeDelta::FromMilliseconds(automation::kSleepTime)); 207 base::TimeDelta::FromMilliseconds(automation::kSleepTime));
209 int active_tab; 208 int active_tab;
210 if (GetActiveTabIndex(&active_tab) && active_tab == tab) 209 if (GetActiveTabIndex(&active_tab) && active_tab == tab)
211 return true; 210 return true;
212 } 211 }
213 // If we get here, the active tab hasn't changed. 212 // If we get here, the active tab hasn't changed.
214 return false; 213 return false;
215 } 214 }
216 215
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (!sender_->Send( 430 if (!sender_->Send(
432 new AutomationMsg_SendJSONRequestWithBrowserHandle(handle_, 431 new AutomationMsg_SendJSONRequestWithBrowserHandle(handle_,
433 request, 432 request,
434 response, 433 response,
435 &result), 434 &result),
436 timeout_ms)) 435 timeout_ms))
437 return false; 436 return false;
438 return result; 437 return result;
439 } 438 }
440 439
441 bool BrowserProxy::GetInitialLoadTimes(int timeout_ms, 440 bool BrowserProxy::GetInitialLoadTimes(base::TimeDelta timeout,
442 float* min_start_time, 441 float* min_start_time,
443 float* max_stop_time, 442 float* max_stop_time,
444 std::vector<float>* stop_times) { 443 std::vector<float>* stop_times) {
445 std::string json_response; 444 std::string json_response;
446 const char* kJSONCommand = "{\"command\": \"GetInitialLoadTimes\"}"; 445 const char* kJSONCommand = "{\"command\": \"GetInitialLoadTimes\"}";
447 446
448 *max_stop_time = 0; 447 *max_stop_time = 0;
449 *min_start_time = -1; 448 *min_start_time = -1;
450 if (!SendJSONRequest(kJSONCommand, timeout_ms, &json_response)) { 449 if (!SendJSONRequest(
450 kJSONCommand, timeout.InMilliseconds(), &json_response)) {
451 // Older browser versions do not support GetInitialLoadTimes. 451 // Older browser versions do not support GetInitialLoadTimes.
452 // Fail gracefully and do not record them in this case. 452 // Fail gracefully and do not record them in this case.
453 return false; 453 return false;
454 } 454 }
455 std::string error; 455 std::string error;
456 scoped_ptr<Value> values(base::JSONReader::ReadAndReturnError( 456 scoped_ptr<Value> values(base::JSONReader::ReadAndReturnError(
457 json_response, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error)); 457 json_response, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error));
458 if (!error.empty() || values->GetType() != Value::TYPE_DICTIONARY) 458 if (!error.empty() || values->GetType() != Value::TYPE_DICTIONARY)
459 return false; 459 return false;
460 460
(...skipping 29 matching lines...) Expand all
490 if (i == 0) 490 if (i == 0)
491 *min_start_time = start_ms; 491 *min_start_time = start_ms;
492 492
493 *min_start_time = std::min(start_ms, *min_start_time); 493 *min_start_time = std::min(start_ms, *min_start_time);
494 *max_stop_time = std::max(stop_ms, *max_stop_time); 494 *max_stop_time = std::max(stop_ms, *max_stop_time);
495 stop_times->push_back(stop_ms); 495 stop_times->push_back(stop_ms);
496 } 496 }
497 std::sort(stop_times->begin(), stop_times->end()); 497 std::sort(stop_times->begin(), stop_times->end());
498 return true; 498 return true;
499 } 499 }
OLDNEW
« no previous file with comments | « chrome/test/automation/browser_proxy.h ('k') | chrome/test/automation/dom_automation_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698