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

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

Issue 1899043002: Implement ping_freshness for update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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
« no previous file with comments | « components/update_client/persisted_data.cc ('k') | components/update_client/update_checker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "components/prefs/testing_pref_service.h" 8 #include "components/prefs/testing_pref_service.h"
9 #include "components/update_client/persisted_data.h" 9 #include "components/update_client/persisted_data.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace update_client { 12 namespace update_client {
13 13
14 TEST(PersistedDataTest, Simple) { 14 TEST(PersistedDataTest, Simple) {
15 std::unique_ptr<TestingPrefServiceSimple> pref( 15 std::unique_ptr<TestingPrefServiceSimple> pref(
16 new TestingPrefServiceSimple()); 16 new TestingPrefServiceSimple());
17 PersistedData::RegisterPrefs(pref->registry()); 17 PersistedData::RegisterPrefs(pref->registry());
18 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get())); 18 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get()));
19 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid")); 19 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid"));
20 std::vector<std::string> items; 20 std::vector<std::string> items;
21 items.push_back("someappid"); 21 items.push_back("someappid");
22 metadata->SetDateLastRollCall(items, 3383); 22 metadata->SetDateLastRollCall(items, 3383);
23 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); 23 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid"));
24 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); 24 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid"));
25 const std::string pf1 = metadata->GetPingFreshness("someappid");
26 EXPECT_FALSE(pf1.empty());
25 metadata->SetDateLastRollCall(items, 3386); 27 metadata->SetDateLastRollCall(items, 3386);
26 EXPECT_EQ(3386, metadata->GetDateLastRollCall("someappid")); 28 EXPECT_EQ(3386, metadata->GetDateLastRollCall("someappid"));
27 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); 29 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid"));
30 const std::string pf2 = metadata->GetPingFreshness("someappid");
31 EXPECT_FALSE(pf2.empty());
32 // The following has a 1 / 2^128 chance of being flaky.
33 EXPECT_NE(pf1, pf2);
28 } 34 }
29 35
30 TEST(PersistedDataTest, SharedPref) { 36 TEST(PersistedDataTest, SharedPref) {
31 std::unique_ptr<TestingPrefServiceSimple> pref( 37 std::unique_ptr<TestingPrefServiceSimple> pref(
32 new TestingPrefServiceSimple()); 38 new TestingPrefServiceSimple());
33 PersistedData::RegisterPrefs(pref->registry()); 39 PersistedData::RegisterPrefs(pref->registry());
34 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get())); 40 std::unique_ptr<PersistedData> metadata(new PersistedData(pref.get()));
35 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid")); 41 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someappid"));
36 std::vector<std::string> items; 42 std::vector<std::string> items;
37 items.push_back("someappid"); 43 items.push_back("someappid");
38 metadata->SetDateLastRollCall(items, 3383); 44 metadata->SetDateLastRollCall(items, 3383);
39 45
40 // Now, create a new PersistedData reading from the same path, verify 46 // Now, create a new PersistedData reading from the same path, verify
41 // that it loads the value. 47 // that it loads the value.
42 metadata.reset(new PersistedData(pref.get())); 48 metadata.reset(new PersistedData(pref.get()));
43 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid")); 49 EXPECT_EQ(3383, metadata->GetDateLastRollCall("someappid"));
44 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid")); 50 EXPECT_EQ(-2, metadata->GetDateLastRollCall("someotherappid"));
45 } 51 }
46 52
47 } // namespace update_client 53 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/persisted_data.cc ('k') | components/update_client/update_checker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698