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

Unified Diff: net/reporting/reporting_test_util.cc

Issue 2751883003: Reporting: Implement serializer. (Closed)
Patch Set: rebase Created 3 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
Index: net/reporting/reporting_test_util.cc
diff --git a/net/reporting/reporting_test_util.cc b/net/reporting/reporting_test_util.cc
index 946e1e0bd5e9044575872b59ab96ef497b2e60d8..07e67f98250956215a49308a4c76c5693e8a75fb 100644
--- a/net/reporting/reporting_test_util.cc
+++ b/net/reporting/reporting_test_util.cc
@@ -13,10 +13,13 @@
#include "base/memory/ptr_util.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
+#include "base/timer/mock_timer.h"
+#include "base/timer/timer.h"
#include "net/reporting/reporting_cache.h"
#include "net/reporting/reporting_client.h"
#include "net/reporting/reporting_context.h"
#include "net/reporting/reporting_delegate.h"
+#include "net/reporting/reporting_persister.h"
#include "net/reporting/reporting_policy.h"
#include "net/reporting/reporting_uploader.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -119,21 +122,49 @@ TestReportingContext::TestReportingContext(const ReportingPolicy& policy)
base::MakeUnique<TestReportingDelegate>(),
base::MakeUnique<base::SimpleTestClock>(),
base::MakeUnique<base::SimpleTestTickClock>(),
- base::MakeUnique<TestReportingUploader>()) {}
+ base::MakeUnique<TestReportingUploader>()),
+ persistence_timer_(new base::MockTimer(/* retain_user_task= */ false,
+ /* is_repeating= */ false)) {
+ persister()->SetTimerForTesting(base::WrapUnique(persistence_timer_));
+}
-TestReportingContext::~TestReportingContext() {}
+TestReportingContext::~TestReportingContext() {
+ persistence_timer_ = nullptr;
+}
ReportingTestBase::ReportingTestBase() {
// For tests, disable jitter.
ReportingPolicy policy;
policy.endpoint_backoff_policy.jitter_factor = 0.0;
- UsePolicy(policy);
+
+ CreateAndInitializeContext(policy, std::unique_ptr<const base::Value>(),
+ base::Time::Now(), base::TimeTicks::Now());
}
ReportingTestBase::~ReportingTestBase() {}
-void ReportingTestBase::UsePolicy(const ReportingPolicy& policy) {
+void ReportingTestBase::UsePolicy(const ReportingPolicy& new_policy) {
+ CreateAndInitializeContext(new_policy, delegate()->GetPersistedData(),
+ clock()->Now(), tick_clock()->NowTicks());
+}
+
+void ReportingTestBase::SimulateRestart(base::TimeDelta delta,
+ base::TimeDelta delta_ticks) {
+ CreateAndInitializeContext(policy(), delegate()->GetPersistedData(),
+ clock()->Now() + delta,
+ tick_clock()->NowTicks() + delta_ticks);
+}
+
+void ReportingTestBase::CreateAndInitializeContext(
+ const ReportingPolicy& policy,
+ std::unique_ptr<const base::Value> persisted_data,
+ base::Time now,
+ base::TimeTicks now_ticks) {
context_ = base::MakeUnique<TestReportingContext>(policy);
+ delegate()->PersistData(std::move(persisted_data));
+ clock()->SetNow(now);
+ tick_clock()->SetNowTicks(now_ticks);
+ context_->Initialize();
}
base::TimeTicks ReportingTestBase::yesterday() {
« net/reporting/reporting_persister.cc ('K') | « net/reporting/reporting_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698