OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 #include <vector> |
| 7 |
| 8 #include "components/prefs/testing_pref_service.h" |
| 9 #include "components/update_client/persisted_data.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace update_client { |
| 13 |
| 14 TEST(PersistedDataTest, Simple) { |
| 15 std::unique_ptr<TestingPrefServiceSimple> pref( |
| 16 new TestingPrefServiceSimple()); |
| 17 PersistedData::RegisterPrefs(pref->registry()); |
| 18 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get())); |
| 19 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid")); |
| 20 std::vector<std::string> items; |
| 21 items.push_back("someappid"); |
| 22 metadata->SetDateLastRollCall(items, 3383); |
| 23 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); |
| 24 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); |
| 25 metadata->SetDateLastRollCall(items, 3386); |
| 26 EXPECT_EQ(3386, metadata->GetDateLastRollCall("someappid")); |
| 27 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); |
| 28 } |
| 29 |
| 30 TEST(PersistedDataTest, SharedPref) { |
| 31 std::unique_ptr<TestingPrefServiceSimple> pref( |
| 32 new TestingPrefServiceSimple()); |
| 33 PersistedData::RegisterPrefs(pref->registry()); |
| 34 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get())); |
| 35 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid")); |
| 36 std::vector<std::string> items; |
| 37 items.push_back("someappid"); |
| 38 metadata->SetDateLastRollCall(items, 3383); |
| 39 |
| 40 // Now, create a new PersistedData reading from the same path, verify |
| 41 // that it loads the value. |
| 42 metadata.reset(new PersistedData(pref.get())); |
| 43 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); |
| 44 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); |
| 45 } |
| 46 |
| 47 } // namespace update_client |
OLD | NEW |