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

Side by Side Diff: components/update_client/component_metadata_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: 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/component_metadata.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace update_client {
16
17 class ComponentMetadataTest : public testing::Test {
18 public:
19 ComponentMetadataTest();
20 ~ComponentMetadataTest() override;
21
22 // Overrides from testing::Test.
23 void SetUp() override;
24
25 protected:
26 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
27
28 private:
29 base::MessageLoopForIO used_for_threadtaskrunnerhandle_;
Sorin Jianu 2016/04/07 04:03:19 Do we need base::MessageLoopForIO? I think we've b
waffles 2016/04/07 17:04:44 Done.
30
31 DISALLOW_COPY_AND_ASSIGN(ComponentMetadataTest);
32 };
33
34 void ComponentMetadataTest::SetUp() {
35 task_runner_ = base::ThreadTaskRunnerHandle::Get();
Sorin Jianu 2016/04/07 04:03:19 why not directly initialize in the ctor?
waffles 2016/04/07 17:04:44 Done. (Removed it as a class member, put it in the
36 }
37
38 ComponentMetadataTest::ComponentMetadataTest() {
39 }
40
41 ComponentMetadataTest::~ComponentMetadataTest() {
42 }
43
44 TEST_F(ComponentMetadataTest, InMemory) {
45 scoped_refptr<ComponentMetadata> metadata(new ComponentMetadata(
46 base::FilePath(), task_runner_));
47 base::RunLoop().RunUntilIdle(); // To let Initialize() finish.
48 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid"));
49 std::vector<std::string> items;
50 items.push_back("someappid");
51 metadata->SetDateLastRollCall(items, 3383);
52 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid"));
53 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid"));
54 metadata->SetDateLastRollCall(items, 3386);
55 EXPECT_EQ(3386, metadata->DateLastRollCall("someappid"));
56 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid"));
57 }
58
59 TEST_F(ComponentMetadataTest, InFile) {
60 base::ScopedTempDir dir;
61 EXPECT_TRUE(dir.CreateUniqueTempDir());
62 base::FilePath path = dir.path().AppendASCII("t.json");
63 scoped_refptr<ComponentMetadata> metadata(new ComponentMetadata(
64 path, task_runner_));
65 base::RunLoop().RunUntilIdle(); // To let Initialize() finish.
66 EXPECT_EQ(-2, metadata->DateLastRollCall("someappid"));
67 std::vector<std::string> items;
68 items.push_back("someappid");
69 metadata->SetDateLastRollCall(items, 3383);
70 base::RunLoop().RunUntilIdle();
71
72 // Now, create a new ComponentMetadata reading from the same path, verify
73 // that it loads the value.
74 metadata = new ComponentMetadata(path, task_runner_);
75 base::RunLoop().RunUntilIdle(); // To let Initialize() finish.
76 EXPECT_EQ(3383, metadata->DateLastRollCall("someappid"));
77 EXPECT_EQ(-2, metadata->DateLastRollCall("someotherappid"));
78 }
79
80 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698