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

Side by Side Diff: chrome/browser/sync/invalidations/invalidator_storage_unittest.cc

Issue 10451058: sync: move invalidation version prefs out of SyncPrefs into InvalidatorStorage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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
6 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
7
8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h"
10 #include "chrome/test/base/testing_pref_service.h"
11 #include "sync/syncable/model_type.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using sync_notifier::InvalidationVersionMap;
16
17 namespace browser_sync {
18
19 class InvalidatorStorageTest : public testing::Test {
20 protected:
21 TestingPrefService pref_service_;
22
23 private:
24 MessageLoop loop_;
25 };
26
27 TEST_F(InvalidatorStorageTest, MaxInvalidationVersions) {
28 InvalidatorStorage storage(&pref_service_);
29
30 InvalidationVersionMap expected_max_versions;
31 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
32
33 expected_max_versions[syncable::BOOKMARKS] = 2;
34 storage.SetMaxVersion(syncable::BOOKMARKS, 2);
35 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
36
37 expected_max_versions[syncable::PREFERENCES] = 5;
38 storage.SetMaxVersion(syncable::PREFERENCES, 5);
39 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
40
41 expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
42 storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
43 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
44
45 expected_max_versions[syncable::APP_NOTIFICATIONS] = 4;
46 storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 4);
47 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
48 }
49
50 TEST_F(InvalidatorStorageTest, Clear) {
51 InvalidatorStorage storage(&pref_service_);
52 EXPECT_TRUE(storage.GetAllMaxVersions().empty());
53 EXPECT_TRUE(storage.GetInvalidationState().empty());
54
55 storage.SetInvalidationState("test");
56 EXPECT_EQ("test", storage.GetInvalidationState());
57 {
58 InvalidationVersionMap expected_max_versions;
59 expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
60 storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
61 EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
62 }
63
64 storage.Clear();
65
66 EXPECT_TRUE(storage.GetAllMaxVersions().empty());
67 EXPECT_TRUE(storage.GetInvalidationState().empty());
68 }
69
70 TEST_F(InvalidatorStorageTest, SerializeEmptyMap) {
71 InvalidationVersionMap empty_map;
72 base::DictionaryValue dict;
73 InvalidatorStorage::SerializeMap(empty_map, &dict);
74 EXPECT_TRUE(dict.empty());
75 }
76
77 TEST_F(InvalidatorStorageTest, DeserializeOutOfRange) {
78 InvalidationVersionMap map;
79 base::DictionaryValue dict_with_out_of_range_type;
80
81 dict_with_out_of_range_type.SetString(
82 base::IntToString(syncable::TOP_LEVEL_FOLDER), "100");
83 dict_with_out_of_range_type.SetString(
84 base::IntToString(syncable::BOOKMARKS), "5");
85
86 InvalidatorStorage::DeserializeMap(&dict_with_out_of_range_type, &map);
87
88 EXPECT_EQ(1U, map.size());
89 EXPECT_EQ(5, map[syncable::BOOKMARKS]);
90 }
91
92 TEST_F(InvalidatorStorageTest, DeserializeInvalidFormat) {
93 InvalidationVersionMap map;
94 base::DictionaryValue dict_with_invalid_format;
95
96 dict_with_invalid_format.SetString("whoops", "5");
97 dict_with_invalid_format.SetString("ohnoes", "whoops");
98 dict_with_invalid_format.SetString(
99 base::IntToString(syncable::BOOKMARKS), "ohnoes");
100 dict_with_invalid_format.SetString(
101 base::IntToString(syncable::AUTOFILL), "10");
102
103 InvalidatorStorage::DeserializeMap(&dict_with_invalid_format, &map);
104
105 EXPECT_EQ(1U, map.size());
106 EXPECT_EQ(10, map[syncable::AUTOFILL]);
107 }
108
109 TEST_F(InvalidatorStorageTest, DeserializeEmptyDictionary) {
110 InvalidationVersionMap map;
111 base::DictionaryValue dict;
112 InvalidatorStorage::DeserializeMap(&dict, &map);
113 EXPECT_TRUE(map.empty());
114 }
115
116 TEST_F(InvalidatorStorageTest, DeserializeBasic) {
117 InvalidationVersionMap map;
118 base::DictionaryValue dict;
119
120 dict.SetString(base::IntToString(syncable::AUTOFILL), "10");
121 dict.SetString(base::IntToString(syncable::BOOKMARKS), "15");
122
123 InvalidatorStorage::DeserializeMap(&dict, &map);
124 EXPECT_EQ(2U, map.size());
125 EXPECT_EQ(10, map[syncable::AUTOFILL]);
126 EXPECT_EQ(15, map[syncable::BOOKMARKS]);
127 }
128
129 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/invalidations/invalidator_storage.cc ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698