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

Unified Diff: sync/sessions/nudge_tracker_unittest.cc

Issue 13743003: sync: Finish the SyncScheduler refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix AuthErrorTest Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sync_core.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/sessions/nudge_tracker_unittest.cc
diff --git a/sync/sessions/nudge_tracker_unittest.cc b/sync/sessions/nudge_tracker_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..192a737c9369c91004db68e44f361bb92628900f
--- /dev/null
+++ b/sync/sessions/nudge_tracker_unittest.cc
@@ -0,0 +1,112 @@
+// 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 "sync/sessions/nudge_tracker.h"
+
+#include "sync/internal_api/public/base/model_type_invalidation_map.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncer {
+
+namespace {
+
+ModelTypeSet ParamsMeaningAllEnabledTypes() {
+ ModelTypeSet request_params(BOOKMARKS, AUTOFILL);
+ return request_params;
+}
+
+ModelTypeSet ParamsMeaningJustOneEnabledType() {
+ return ModelTypeSet(AUTOFILL);
+}
+
+} // namespace
+
+namespace sessions {
+
+TEST(NudgeTrackerTest, CoalesceSources) {
+ ModelTypeInvalidationMap one_type =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningJustOneEnabledType(),
+ std::string());
+ ModelTypeInvalidationMap all_types =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningAllEnabledTypes(),
+ std::string());
+ sessions::SyncSourceInfo source_one(
+ sync_pb::GetUpdatesCallerInfo::NOTIFICATION, one_type);
+ sessions::SyncSourceInfo source_two(
+ sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
+
+ NudgeTracker tracker;
+ EXPECT_TRUE(tracker.IsEmpty());
+
+ tracker.CoalesceSources(source_one);
+ EXPECT_EQ(source_one.updates_source, tracker.source_info().updates_source);
+
+ tracker.CoalesceSources(source_two);
+ EXPECT_EQ(source_two.updates_source, tracker.source_info().updates_source);
+}
+
+TEST(NudgeTrackerTest, LocallyModifiedTypes_WithInvalidationFirst) {
+ ModelTypeInvalidationMap one_type =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningJustOneEnabledType(),
+ std::string());
+ ModelTypeInvalidationMap all_types =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningAllEnabledTypes(),
+ std::string());
+ sessions::SyncSourceInfo source_one(
+ sync_pb::GetUpdatesCallerInfo::NOTIFICATION, all_types);
+ sessions::SyncSourceInfo source_two(
+ sync_pb::GetUpdatesCallerInfo::LOCAL, one_type);
+
+ NudgeTracker tracker;
+ EXPECT_TRUE(tracker.IsEmpty());
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty());
+
+ tracker.CoalesceSources(source_one);
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty());
+
+ tracker.CoalesceSources(source_two);
+ // TODO: This result is wrong, but that's how the code has always been. A
+ // local invalidation for a single type should mean that we have only one
+ // locally modified source. It should not "inherit" the list of data types
+ // from the previous source.
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Equals(
+ ParamsMeaningAllEnabledTypes()));
+}
+
+TEST(NudgeTrackerTest, LocallyModifiedTypes_WithInvalidationSecond) {
+ ModelTypeInvalidationMap one_type =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningJustOneEnabledType(),
+ std::string());
+ ModelTypeInvalidationMap all_types =
+ ModelTypeSetToInvalidationMap(
+ ParamsMeaningAllEnabledTypes(),
+ std::string());
+ sessions::SyncSourceInfo source_one(
+ sync_pb::GetUpdatesCallerInfo::LOCAL, one_type);
+ sessions::SyncSourceInfo source_two(
+ sync_pb::GetUpdatesCallerInfo::NOTIFICATION, all_types);
+
+ NudgeTracker tracker;
+ EXPECT_TRUE(tracker.IsEmpty());
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty());
+
+ tracker.CoalesceSources(source_one);
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Equals(
+ ParamsMeaningJustOneEnabledType()));
+
+ tracker.CoalesceSources(source_two);
+
+ // TODO: This result is wrong, but that's how the code has always been.
+ // The receipt of an invalidation should have no effect on the set of
+ // locally modified types.
+ EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty());
+}
+
+} // namespace sessions
+} // namespace syncer
« no previous file with comments | « sync/sessions/nudge_tracker.cc ('k') | sync/sync_core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698