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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/invalidations/invalidator_storage_unittest.cc
diff --git a/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc b/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..765f3322233a467ce794852f083301005d435f36
--- /dev/null
+++ b/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc
@@ -0,0 +1,129 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
+
+#include "base/message_loop.h"
+#include "base/string_number_conversions.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "sync/syncable/model_type.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_notifier::InvalidationVersionMap;
+
+namespace browser_sync {
+
+class InvalidatorStorageTest : public testing::Test {
+ protected:
+ TestingPrefService pref_service_;
+
+ private:
+ MessageLoop loop_;
+};
+
+TEST_F(InvalidatorStorageTest, MaxInvalidationVersions) {
+ InvalidatorStorage storage(&pref_service_);
+
+ InvalidationVersionMap expected_max_versions;
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::BOOKMARKS] = 2;
+ storage.SetMaxVersion(syncable::BOOKMARKS, 2);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::PREFERENCES] = 5;
+ storage.SetMaxVersion(syncable::PREFERENCES, 5);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 4;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 4);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+}
+
+TEST_F(InvalidatorStorageTest, Clear) {
+ InvalidatorStorage storage(&pref_service_);
+ EXPECT_TRUE(storage.GetAllMaxVersions().empty());
+ EXPECT_TRUE(storage.GetInvalidationState().empty());
+
+ storage.SetInvalidationState("test");
+ EXPECT_EQ("test", storage.GetInvalidationState());
+ {
+ InvalidationVersionMap expected_max_versions;
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+ }
+
+ storage.Clear();
+
+ EXPECT_TRUE(storage.GetAllMaxVersions().empty());
+ EXPECT_TRUE(storage.GetInvalidationState().empty());
+}
+
+TEST_F(InvalidatorStorageTest, SerializeEmptyMap) {
+ InvalidationVersionMap empty_map;
+ base::DictionaryValue dict;
+ InvalidatorStorage::SerializeMap(empty_map, &dict);
+ EXPECT_TRUE(dict.empty());
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeOutOfRange) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict_with_out_of_range_type;
+
+ dict_with_out_of_range_type.SetString(
+ base::IntToString(syncable::TOP_LEVEL_FOLDER), "100");
+ dict_with_out_of_range_type.SetString(
+ base::IntToString(syncable::BOOKMARKS), "5");
+
+ InvalidatorStorage::DeserializeMap(&dict_with_out_of_range_type, &map);
+
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ(5, map[syncable::BOOKMARKS]);
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeInvalidFormat) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict_with_invalid_format;
+
+ dict_with_invalid_format.SetString("whoops", "5");
+ dict_with_invalid_format.SetString("ohnoes", "whoops");
+ dict_with_invalid_format.SetString(
+ base::IntToString(syncable::BOOKMARKS), "ohnoes");
+ dict_with_invalid_format.SetString(
+ base::IntToString(syncable::AUTOFILL), "10");
+
+ InvalidatorStorage::DeserializeMap(&dict_with_invalid_format, &map);
+
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ(10, map[syncable::AUTOFILL]);
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeEmptyDictionary) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict;
+ InvalidatorStorage::DeserializeMap(&dict, &map);
+ EXPECT_TRUE(map.empty());
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeBasic) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict;
+
+ dict.SetString(base::IntToString(syncable::AUTOFILL), "10");
+ dict.SetString(base::IntToString(syncable::BOOKMARKS), "15");
+
+ InvalidatorStorage::DeserializeMap(&dict, &map);
+ EXPECT_EQ(2U, map.size());
+ EXPECT_EQ(10, map[syncable::AUTOFILL]);
+ EXPECT_EQ(15, map[syncable::BOOKMARKS]);
+}
+
+} // namespace browser_sync
« 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