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

Unified Diff: components/ukm/ukm_service_unittest.cc

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: MSVC struct initializer Created 3 years, 10 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 | « components/ukm/ukm_service.cc ('k') | ios/chrome/browser/metrics/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ukm/ukm_service_unittest.cc
diff --git a/components/ukm/ukm_service_unittest.cc b/components/ukm/ukm_service_unittest.cc
index cc694e1edfef27f0b622d2cdc820abacfe3bc327..f6b91c0dd1c76961cebb82d29ce4dadb27afcff1 100644
--- a/components/ukm/ukm_service_unittest.cc
+++ b/components/ukm/ukm_service_unittest.cc
@@ -41,6 +41,7 @@ class UkmServiceTest : public testing::Test {
}
Report GetPersistedReport() {
+ EXPECT_GE(GetPersistedLogCount(), 1);
metrics::PersistedLogs result_persisted_logs(
base::MakeUnique<ukm::PersistedLogsMetricsImpl>(), &prefs_,
prefs::kUkmPersistedLogs,
@@ -60,6 +61,14 @@ class UkmServiceTest : public testing::Test {
return report;
}
+ std::unique_ptr<UkmSource> MakeSource(std::string url, int paint_msec) {
+ auto source = base::MakeUnique<UkmSource>();
+ source->set_committed_url(GURL(url));
+ source->set_first_contentful_paint(
+ base::TimeDelta::FromMilliseconds(paint_msec));
+ return source;
+ }
+
protected:
TestingPrefServiceSimple prefs_;
metrics::TestMetricsServiceClient client_;
@@ -80,6 +89,7 @@ TEST_F(UkmServiceTest, EnableDisableSchedule) {
EXPECT_TRUE(task_runner_->HasPendingTask());
// Allow initialization to complete.
task_runner_->RunUntilIdle();
+ service.EnableRecording();
service.EnableReporting();
EXPECT_TRUE(task_runner_->HasPendingTask());
service.DisableReporting();
@@ -92,11 +102,14 @@ TEST_F(UkmServiceTest, PersistAndPurge) {
EXPECT_EQ(GetPersistedLogCount(), 0);
service.Initialize();
task_runner_->RunUntilIdle();
+ service.EnableRecording();
service.EnableReporting();
+ service.RecordSource(MakeSource("https://google.com", 300));
// Should init, generate a log, and start an upload.
task_runner_->RunPendingTasks();
EXPECT_TRUE(client_.uploader()->is_uploading());
// Flushes the generated log to disk and generates a new one.
+ service.RecordSource(MakeSource("https://google.com", 300));
service.Flush();
EXPECT_EQ(GetPersistedLogCount(), 2);
service.Purge();
@@ -108,13 +121,10 @@ TEST_F(UkmServiceTest, SourceSerialization) {
EXPECT_EQ(GetPersistedLogCount(), 0);
service.Initialize();
task_runner_->RunUntilIdle();
+ service.EnableRecording();
service.EnableReporting();
- std::unique_ptr<UkmSource> source = base::WrapUnique(new UkmSource());
- source->set_committed_url(GURL("https://google.com"));
- source->set_first_contentful_paint(base::TimeDelta::FromMilliseconds(300));
-
- service.RecordSource(std::move(source));
+ service.RecordSource(MakeSource("https://google.com", 300));
service.Flush();
EXPECT_EQ(GetPersistedLogCount(), 1);
@@ -140,9 +150,10 @@ TEST_F(UkmServiceTest, MetricsProviderTest) {
EXPECT_FALSE(provider->provide_system_profile_metrics_called());
task_runner_->RunUntilIdle();
+ service.EnableRecording();
service.EnableReporting();
- service.RecordSource(base::WrapUnique(new UkmSource()));
+ service.RecordSource(MakeSource("https://google.com", 300));
service.Flush();
EXPECT_EQ(GetPersistedLogCount(), 1);
@@ -153,4 +164,28 @@ TEST_F(UkmServiceTest, MetricsProviderTest) {
EXPECT_TRUE(provider->provide_system_profile_metrics_called());
}
+TEST_F(UkmServiceTest, LogsUploadedWithSourcesOnly) {
+ UkmService service(&prefs_, &client_);
+ EXPECT_EQ(GetPersistedLogCount(), 0);
+ service.Initialize();
+ task_runner_->RunUntilIdle();
+ service.EnableRecording();
+ service.EnableReporting();
+
+ EXPECT_TRUE(task_runner_->HasPendingTask());
+ // Neither rotation or Flush should generate logs
+ task_runner_->RunPendingTasks();
+ service.Flush();
+ EXPECT_EQ(GetPersistedLogCount(), 0);
+
+ service.RecordSource(MakeSource("https://google.com", 300));
+ // Includes a Source, so will persist.
+ service.Flush();
+ EXPECT_EQ(GetPersistedLogCount(), 1);
+
+ // Current log has no Sources.
+ service.Flush();
+ EXPECT_EQ(GetPersistedLogCount(), 1);
+}
+
} // namespace ukm
« no previous file with comments | « components/ukm/ukm_service.cc ('k') | ios/chrome/browser/metrics/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698