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

Unified Diff: chrome/test/chromedriver/net/timeout.cc

Issue 1669453002: [chromedriver] Apply page load timeout to slow cross-process navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pure virtual Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/net/timeout.h ('k') | chrome/test/chromedriver/net/timeout_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/net/timeout.cc
diff --git a/chrome/test/chromedriver/net/timeout.cc b/chrome/test/chromedriver/net/timeout.cc
new file mode 100644
index 0000000000000000000000000000000000000000..391a63f64ebe3c3b805229ed39ead62c299edc4f
--- /dev/null
+++ b/chrome/test/chromedriver/net/timeout.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/chromedriver/net/timeout.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+
+Timeout::Timeout() : start_(base::TimeTicks::Now()) {
+}
+
+Timeout::Timeout(const base::TimeDelta& duration) : Timeout() {
+ SetDuration(duration);
+}
+
+Timeout::Timeout(const base::TimeDelta& duration, const Timeout* outer)
+ : Timeout(duration) {
+ if (outer && !outer->deadline_.is_null())
+ deadline_ = std::min(outer->deadline_, deadline_);
+}
+
+void Timeout::SetDuration(const base::TimeDelta& duration) {
+ DCHECK(!start_.is_null());
+ if (deadline_.is_null()) {
+ deadline_ = start_ + duration;
+ } else if (deadline_ - start_ != duration) {
+ LOG(ERROR) << "Timeout::SetDuration was called with a duration different"
+ " from what was already set: " << duration << " vs. "
+ << deadline_ - start_ << " (original).";
+ NOTREACHED();
+ }
+}
+
+bool Timeout::IsExpired() const {
+ return GetRemainingTime() <= base::TimeDelta();
+}
+
+base::TimeDelta Timeout::GetDuration() const {
+ return !deadline_.is_null() ? deadline_ - start_
+ : base::TimeDelta::Max();
+}
+
+base::TimeDelta Timeout::GetRemainingTime() const {
+ return !deadline_.is_null() ? deadline_ - base::TimeTicks::Now()
+ : base::TimeDelta::Max();
+}
« no previous file with comments | « chrome/test/chromedriver/net/timeout.h ('k') | chrome/test/chromedriver/net/timeout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698