| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> |
| 5 #include <string> | 6 #include <string> |
| 6 #include <vector> | 7 #include <vector> |
| 7 | 8 |
| 8 #include "components/prefs/testing_pref_service.h" | 9 #include "components/prefs/testing_pref_service.h" |
| 9 #include "components/update_client/persisted_data.h" | 10 #include "components/update_client/persisted_data.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace update_client { | 13 namespace update_client { |
| 13 | 14 |
| 14 TEST(PersistedDataTest, Simple) { | 15 TEST(PersistedDataTest, Simple) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 43 items.push_back("someappid"); | 44 items.push_back("someappid"); |
| 44 metadata->SetDateLastRollCall(items, 3383); | 45 metadata->SetDateLastRollCall(items, 3383); |
| 45 | 46 |
| 46 // Now, create a new PersistedData reading from the same path, verify | 47 // Now, create a new PersistedData reading from the same path, verify |
| 47 // that it loads the value. | 48 // that it loads the value. |
| 48 metadata.reset(new PersistedData(pref.get())); | 49 metadata.reset(new PersistedData(pref.get())); |
| 49 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); | 50 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); |
| 50 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); | 51 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); |
| 51 } | 52 } |
| 52 | 53 |
| 54 TEST(PersistedDataTest, SimpleCohort) { |
| 55 std::unique_ptr<TestingPrefServiceSimple> pref( |
| 56 new TestingPrefServiceSimple()); |
| 57 PersistedData::RegisterPrefs(pref->registry()); |
| 58 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get())); |
| 59 EXPECT_EQ("", metadata->GetCohort("someappid")); |
| 60 EXPECT_EQ("", metadata->GetCohort("someotherappid")); |
| 61 EXPECT_EQ("", metadata->GetCohortHint("someappid")); |
| 62 EXPECT_EQ("", metadata->GetCohortHint("someotherappid")); |
| 63 EXPECT_EQ("", metadata->GetCohortName("someappid")); |
| 64 EXPECT_EQ("", metadata->GetCohortName("someotherappid")); |
| 65 metadata->SetCohort("someappid", "c1"); |
| 66 metadata->SetCohort("someotherappid", "c2"); |
| 67 metadata->SetCohortHint("someappid", "ch1"); |
| 68 metadata->SetCohortHint("someotherappid", "ch2"); |
| 69 metadata->SetCohortName("someappid", "cn1"); |
| 70 metadata->SetCohortName("someotherappid", "cn2"); |
| 71 EXPECT_EQ("c1", metadata->GetCohort("someappid")); |
| 72 EXPECT_EQ("c2", metadata->GetCohort("someotherappid")); |
| 73 EXPECT_EQ("ch1", metadata->GetCohortHint("someappid")); |
| 74 EXPECT_EQ("ch2", metadata->GetCohortHint("someotherappid")); |
| 75 EXPECT_EQ("cn1", metadata->GetCohortName("someappid")); |
| 76 EXPECT_EQ("cn2", metadata->GetCohortName("someotherappid")); |
| 77 metadata->SetCohort("someappid", "oc1"); |
| 78 metadata->SetCohort("someotherappid", "oc2"); |
| 79 metadata->SetCohortHint("someappid", "och1"); |
| 80 metadata->SetCohortHint("someotherappid", "och2"); |
| 81 metadata->SetCohortName("someappid", "ocn1"); |
| 82 metadata->SetCohortName("someotherappid", "ocn2"); |
| 83 EXPECT_EQ("oc1", metadata->GetCohort("someappid")); |
| 84 EXPECT_EQ("oc2", metadata->GetCohort("someotherappid")); |
| 85 EXPECT_EQ("och1", metadata->GetCohortHint("someappid")); |
| 86 EXPECT_EQ("och2", metadata->GetCohortHint("someotherappid")); |
| 87 EXPECT_EQ("ocn1", metadata->GetCohortName("someappid")); |
| 88 EXPECT_EQ("ocn2", metadata->GetCohortName("someotherappid")); |
| 89 } |
| 90 |
| 53 } // namespace update_client | 91 } // namespace update_client |
| OLD | NEW |