Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: components/update_client/persisted_data_unittest.cc

Issue 1861383004: Add module for counting date-last-roll-call and persisting those counts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ThreadChecker fix Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698