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 class PersistedDataTest : public testing::Test { |
| 15 public: |
| 16 PersistedDataTest(); |
| 17 ~PersistedDataTest() override; |
| 18 |
| 19 private: |
| 20 DISALLOW_COPY_AND_ASSIGN(PersistedDataTest); |
| 21 }; |
| 22 |
| 23 PersistedDataTest::PersistedDataTest() { |
| 24 } |
| 25 |
| 26 PersistedDataTest::~PersistedDataTest() { |
| 27 } |
| 28 |
| 29 TEST_F(PersistedDataTest, Simple) { |
| 30 TestingPrefServiceSimple* pref = new TestingPrefServiceSimple(); |
| 31 RegisterPersistedDataPreferences(pref->registry()); |
| 32 scoped_refptr<PersistedData> metadata(new PersistedData(pref)); |
| 33 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid")); |
| 34 std::vector<std::string> items; |
| 35 items.push_back("someappid"); |
| 36 metadata->SetDateLastRollCall(items, 3383); |
| 37 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid")); |
| 38 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 39 metadata->SetDateLastRollCall(items, 3386); |
| 40 EXPECT_EQ(3386, metadata->DateLastRollCall("someappid")); |
| 41 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 42 } |
| 43 |
| 44 TEST_F(PersistedDataTest, SharedPref) { |
| 45 TestingPrefServiceSimple* pref = new TestingPrefServiceSimple(); |
| 46 RegisterPersistedDataPreferences(pref->registry()); |
| 47 scoped_refptr<PersistedData> metadata(new PersistedData(pref)); |
| 48 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid")); |
| 49 std::vector<std::string> items; |
| 50 items.push_back("someappid"); |
| 51 metadata->SetDateLastRollCall(items, 3383); |
| 52 |
| 53 // Now, create a new PersistedData reading from the same path, verify |
| 54 // that it loads the value. |
| 55 metadata = new PersistedData(pref); |
| 56 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid")); |
| 57 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 58 } |
| 59 |
| 60 } // namespace update_client |
OLD | NEW |