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 "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "components/update_client/persisted_data.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace update_client { |
| 16 |
| 17 class PersistedDataTest : public testing::Test { |
| 18 public: |
| 19 PersistedDataTest(); |
| 20 ~PersistedDataTest() override; |
| 21 |
| 22 private: |
| 23 base::MessageLoop used_for_threadtaskrunnerhandle_; |
| 24 |
| 25 DISALLOW_COPY_AND_ASSIGN(PersistedDataTest); |
| 26 }; |
| 27 |
| 28 PersistedDataTest::PersistedDataTest() { |
| 29 } |
| 30 |
| 31 PersistedDataTest::~PersistedDataTest() { |
| 32 } |
| 33 |
| 34 TEST_F(PersistedDataTest, InMemory) { |
| 35 scoped_refptr<PersistedData> metadata(new PersistedData( |
| 36 base::FilePath(), base::ThreadTaskRunnerHandle::Get())); |
| 37 base::RunLoop().RunUntilIdle(); // To let Initialize() finish. |
| 38 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid")); |
| 39 std::vector<std::string> items; |
| 40 items.push_back("someappid"); |
| 41 metadata->SetDateLastRollCall(items, 3383); |
| 42 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid")); |
| 43 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 44 metadata->SetDateLastRollCall(items, 3386); |
| 45 EXPECT_EQ(3386, metadata->DateLastRollCall("someappid")); |
| 46 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 47 } |
| 48 |
| 49 TEST_F(PersistedDataTest, InFile) { |
| 50 base::ScopedTempDir dir; |
| 51 EXPECT_TRUE(dir.CreateUniqueTempDir()); |
| 52 base::FilePath path = dir.path().AppendASCII("t.json"); |
| 53 scoped_refptr<PersistedData> metadata(new PersistedData( |
| 54 path, base::ThreadTaskRunnerHandle::Get())); |
| 55 base::RunLoop().RunUntilIdle(); // To let Initialize() finish. |
| 56 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid")); |
| 57 std::vector<std::string> items; |
| 58 items.push_back("someappid"); |
| 59 metadata->SetDateLastRollCall(items, 3383); |
| 60 base::RunLoop().RunUntilIdle(); |
| 61 |
| 62 // Now, create a new PersistedData reading from the same path, verify |
| 63 // that it loads the value. |
| 64 metadata = new PersistedData(path, base::ThreadTaskRunnerHandle::Get()); |
| 65 base::RunLoop().RunUntilIdle(); // To let Initialize() finish. |
| 66 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid")); |
| 67 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid")); |
| 68 } |
| 69 |
| 70 } // namespace update_client |
OLD | NEW |