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

Unified Diff: content/browser/service_worker/foreign_fetch_request_handler_unittest.cc

Issue 2555333006: Deflake origin trial token validator tests (Closed)
Patch Set: Add a clock for testing to serviceworkerversion Created 3 years, 4 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
Index: content/browser/service_worker/foreign_fetch_request_handler_unittest.cc
diff --git a/content/browser/service_worker/foreign_fetch_request_handler_unittest.cc b/content/browser/service_worker/foreign_fetch_request_handler_unittest.cc
index cdf3bc48a5fadb166da6f4c30b85660ee1629112..b03a983cbf126782c70befd9b37450c8425fef9c 100644
--- a/content/browser/service_worker/foreign_fetch_request_handler_unittest.cc
+++ b/content/browser/service_worker/foreign_fetch_request_handler_unittest.cc
@@ -6,6 +6,7 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
+#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
@@ -50,6 +51,10 @@ int kMockProviderId = 1;
const char* kValidUrl = "https://valid.example.com/foo/bar";
+// This timestamp is set to a time after the expiry timestamp of the expired
+// tokens in this test, but before the expiry timestamp of the valid ones.
+double kNowTimestamp = 1500000000;
+
void EmptyCallback() {}
} // namespace
@@ -79,6 +84,11 @@ class ForeignFetchRequestHandlerTest : public testing::Test {
kVersionId, context()->AsWeakPtr());
version_->set_foreign_fetch_scopes({kScope});
+ // Fix the time for testing to kNowTimestamp
+ base::SimpleTestClock* clock = new base::SimpleTestClock();
+ clock->SetNow(base::Time::FromDoubleT(kNowTimestamp));
+ version_->SetClockForTesting(base::WrapUnique(clock));
Marijn Kruisselbrink 2017/08/02 19:57:25 why WrapUnique here, and not simply base::MakeUniq
iclelland 2017/08/02 20:22:05 Because I need to call SetNow() on it -- if I make
Marijn Kruisselbrink 2017/08/02 20:34:20 Yeah, that's what I meant. std::unique_ptr<Foo> is
+
context()->storage()->LazyInitialize(base::Bind(&EmptyCallback));
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698