metricsd: Add test case for the upload service.
This test case ensures that we can log a metric with the metrics library and upload it with the upload service. BUG: 22879646 TEST: unit tests. Change-Id: Idf4a1240d41745ebf7835089230608082eed19f5
This commit is contained in:
parent
1df10c43ea
commit
4c8a8ad3bf
3 changed files with 19 additions and 1 deletions
|
|
@ -123,6 +123,7 @@ class MetricsLibrary : public MetricsLibraryInterface {
|
|||
private:
|
||||
friend class CMetricsLibraryTest;
|
||||
friend class MetricsLibraryTest;
|
||||
friend class UploadServiceTest;
|
||||
FRIEND_TEST(MetricsLibraryTest, AreMetricsEnabled);
|
||||
FRIEND_TEST(MetricsLibraryTest, FormatChromeMessage);
|
||||
FRIEND_TEST(MetricsLibraryTest, FormatChromeMessageTooLong);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ class UploadService : public base::HistogramFlattener {
|
|||
FRIEND_TEST(UploadServiceTest, LogContainsAggregatedValues);
|
||||
FRIEND_TEST(UploadServiceTest, LogEmptyAfterUpload);
|
||||
FRIEND_TEST(UploadServiceTest, LogEmptyByDefault);
|
||||
FRIEND_TEST(UploadServiceTest, LogFromTheMetricsLibrary);
|
||||
FRIEND_TEST(UploadServiceTest, LogKernelCrash);
|
||||
FRIEND_TEST(UploadServiceTest, LogUncleanShutdown);
|
||||
FRIEND_TEST(UploadServiceTest, LogUserCrash);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class UploadServiceTest : public testing::Test {
|
|||
CHECK(dir_.CreateUniqueTempDir());
|
||||
chromeos_metrics::PersistentInteger::SetMetricsDirectory(
|
||||
dir_.path().value());
|
||||
metrics_lib_.InitForTest(dir_.path());
|
||||
upload_service_.reset(new UploadService(new MockSystemProfileSetter(),
|
||||
&metrics_lib_, "", true));
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ class UploadServiceTest : public testing::Test {
|
|||
|
||||
base::ScopedTempDir dir_;
|
||||
scoped_ptr<UploadService> upload_service_;
|
||||
MetricsLibraryMock metrics_lib_;
|
||||
MetricsLibrary metrics_lib_;
|
||||
|
||||
scoped_ptr<base::AtExitManager> exit_manager_;
|
||||
};
|
||||
|
|
@ -274,3 +275,18 @@ TEST_F(UploadServiceTest, SessionIdIncrementedAtInitialization) {
|
|||
cache.Initialize();
|
||||
EXPECT_EQ(cache.profile_.session_id, session_id + 1);
|
||||
}
|
||||
|
||||
// Test that we can log metrics from the metrics library and have the uploader
|
||||
// upload them.
|
||||
TEST_F(UploadServiceTest, LogFromTheMetricsLibrary) {
|
||||
SenderMock* sender = new SenderMock();
|
||||
upload_service_->sender_.reset(sender);
|
||||
|
||||
upload_service_->UploadEvent();
|
||||
EXPECT_EQ(0, sender->send_call_count());
|
||||
|
||||
metrics_lib_.SendEnumToUMA("testname", 2, 10);
|
||||
upload_service_->UploadEvent();
|
||||
|
||||
EXPECT_EQ(1, sender->send_call_count());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue