| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/rappor/rappor_service.h" | 5 #include "components/rappor/rappor_service.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
| 9 #include "components/rappor/byte_vector_utils.h" | 9 #include "components/rappor/byte_vector_utils.h" |
| 10 #include "components/rappor/proto/rappor_metric.pb.h" | 10 #include "components/rappor/proto/rappor_metric.pb.h" |
| 11 #include "components/rappor/rappor_parameters.h" | 11 #include "components/rappor/rappor_parameters.h" |
| 12 #include "components/rappor/rappor_pref_names.h" | 12 #include "components/rappor/rappor_pref_names.h" |
| 13 #include "components/rappor/test_log_uploader.h" | 13 #include "components/rappor/test_log_uploader.h" |
| 14 #include "components/rappor/test_rappor_service.h" | 14 #include "components/rappor/test_rappor_service.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace rappor { | 17 namespace rappor { |
| 18 | 18 |
| 19 TEST(RapporServiceTest, LoadCohort) { | |
| 20 TestRapporService rappor_service; | |
| 21 rappor_service.test_prefs()->SetInteger(prefs::kRapporCohortSeed, 1); | |
| 22 EXPECT_EQ(1, rappor_service.LoadCohortForTesting()); | |
| 23 } | |
| 24 | |
| 25 TEST(RapporServiceTest, LoadSecret) { | |
| 26 TestRapporService rappor_service; | |
| 27 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput(); | |
| 28 std::string secret_base64; | |
| 29 base::Base64Encode(secret, &secret_base64); | |
| 30 rappor_service.test_prefs()->SetString(prefs::kRapporSecret, secret_base64); | |
| 31 EXPECT_EQ(secret, rappor_service.LoadSecretForTesting()); | |
| 32 } | |
| 33 | |
| 34 TEST(RapporServiceTest, Update) { | 19 TEST(RapporServiceTest, Update) { |
| 35 TestRapporService rappor_service; | 20 TestRapporService rappor_service; |
| 36 EXPECT_LT(base::TimeDelta(), rappor_service.next_rotation()); | 21 EXPECT_LT(base::TimeDelta(), rappor_service.next_rotation()); |
| 37 EXPECT_TRUE(rappor_service.test_uploader()->is_running()); | 22 EXPECT_TRUE(rappor_service.test_uploader()->is_running()); |
| 38 | 23 |
| 39 rappor_service.Update(RECORDING_DISABLED, false); | 24 rappor_service.Update(RECORDING_DISABLED, false); |
| 40 EXPECT_EQ(base::TimeDelta(), rappor_service.next_rotation()); | 25 EXPECT_EQ(base::TimeDelta(), rappor_service.next_rotation()); |
| 41 EXPECT_FALSE(rappor_service.test_uploader()->is_running()); | 26 EXPECT_FALSE(rappor_service.test_uploader()->is_running()); |
| 42 | 27 |
| 43 rappor_service.Update(FINE_LEVEL, false); | 28 rappor_service.Update(FINE_LEVEL, false); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 rappor_service.set_is_incognito(true); | 71 rappor_service.set_is_incognito(true); |
| 87 | 72 |
| 88 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo"); | 73 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo"); |
| 89 | 74 |
| 90 RapporReports reports; | 75 RapporReports reports; |
| 91 rappor_service.GetReports(&reports); | 76 rappor_service.GetReports(&reports); |
| 92 EXPECT_EQ(0, reports.report_size()); | 77 EXPECT_EQ(0, reports.report_size()); |
| 93 } | 78 } |
| 94 | 79 |
| 95 } // namespace rappor | 80 } // namespace rappor |
| OLD | NEW |