summaryrefslogtreecommitdiffstats
path: root/sync/sessions/nudge_tracker_unittest.cc
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 04:52:10 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 04:52:10 +0000
commit0248d9208d15bb5d7ae5bb482740e90ee62c8b2a (patch)
treebccfd80b2193bd28f921266b0530c88b84cb2ceb /sync/sessions/nudge_tracker_unittest.cc
parent9df2d09c9b836494e8f83a2a7657ba2a9408a23b (diff)
downloadchromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.zip
chromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.tar.gz
chromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.tar.bz2
sync: Finish the SyncScheduler refactor
This change removes SyncSessionJob entirely. The first step towards this goal was to refactor all functions that depended on SyncSessionJob. All these functions have either been inlined or modified to take different parameters instead. DoSyncSessionJob was split into two separate functions, one for configure jobs and one for nudge jobs, which removes the need for SyncSessionJob's "purpose" member. The SyncScheduler's pending_configure_job_ has been replaced with a ConfigParams member, since that was the only part of the job still being referenced. The pending_nudge_job_ has been replaced with scheduled_nudge_time_ (which is similar to the old scheduled_start_ member of SyncSessionJob) and a new object called a NudgeTracker. The NudgeTracker inherits the SyncSessionJob's responsibilities with respect to coalescing nudge sources. The plan is to extend this class to support more sophisticated nudge coalescing in the future. For now it tries to emulate the old SyncSessionJob behaviour as closely as possible. Some of the refactoring does change behaviour. In particular, the decision-making logic has been updated to fix issues 179515 and 155296. BUG=175024,179515,155296 Review URL: https://chromiumcodereview.appspot.com/13743003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions/nudge_tracker_unittest.cc')
-rw-r--r--sync/sessions/nudge_tracker_unittest.cc112
1 files changed, 112 insertions, 0 deletions
diff --git a/sync/sessions/nudge_tracker_unittest.cc b/sync/sessions/nudge_tracker_unittest.cc
new file mode 100644
index 0000000..192a737
--- /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