More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / sessions / status_controller_unittest.cc
blob619e1fae34cdb0c9bdf018d10b6a890528315db3
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.
5 #include "sync/sessions/sync_session.h"
6 #include "sync/test/engine/test_id_factory.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace syncer {
10 namespace sessions {
12 class StatusControllerTest : public testing::Test {
13 public:
14 virtual void SetUp() {
15 routes_[BOOKMARKS] = GROUP_UI;
17 protected:
18 ModelSafeRoutingInfo routes_;
21 // This test is useful, as simple as it sounds, due to the copy-paste prone
22 // nature of status_controller.cc (we have had bugs in the past where a set_foo
23 // method was actually setting |bar_| instead!).
24 TEST_F(StatusControllerTest, ReadYourWrites) {
25 StatusController status(routes_);
26 status.set_num_server_changes_remaining(13);
27 EXPECT_EQ(13, status.num_server_changes_remaining());
29 EXPECT_FALSE(status.conflicts_resolved());
30 status.update_conflicts_resolved(true);
31 EXPECT_TRUE(status.conflicts_resolved());
33 status.set_last_download_updates_result(SYNCER_OK);
34 EXPECT_EQ(SYNCER_OK,
35 status.model_neutral_state().last_download_updates_result);
37 status.set_commit_result(SYNC_AUTH_ERROR);
38 EXPECT_EQ(SYNC_AUTH_ERROR, status.model_neutral_state().commit_result);
40 for (int i = 0; i < 14; i++)
41 status.increment_num_successful_commits();
42 EXPECT_EQ(14, status.model_neutral_state().num_successful_commits);
45 TEST_F(StatusControllerTest, HasConflictingUpdates) {
46 StatusController status(routes_);
47 EXPECT_FALSE(status.HasConflictingUpdates());
49 ScopedModelSafeGroupRestriction r(&status, GROUP_UI);
50 EXPECT_FALSE(status.update_progress());
51 status.mutable_update_progress()->AddAppliedUpdate(SUCCESS,
52 syncable::Id());
53 status.mutable_update_progress()->AddAppliedUpdate(CONFLICT_SIMPLE,
54 syncable::Id());
55 EXPECT_TRUE(status.update_progress()->HasConflictingUpdates());
58 EXPECT_TRUE(status.HasConflictingUpdates());
61 ScopedModelSafeGroupRestriction r(&status, GROUP_PASSIVE);
62 EXPECT_FALSE(status.update_progress());
66 TEST_F(StatusControllerTest, HasConflictingUpdates_NonBlockingUpdates) {
67 StatusController status(routes_);
68 EXPECT_FALSE(status.HasConflictingUpdates());
70 ScopedModelSafeGroupRestriction r(&status, GROUP_UI);
71 EXPECT_FALSE(status.update_progress());
72 status.mutable_update_progress()->AddAppliedUpdate(SUCCESS,
73 syncable::Id());
74 status.mutable_update_progress()->AddAppliedUpdate(CONFLICT_HIERARCHY,
75 syncable::Id());
76 EXPECT_TRUE(status.update_progress()->HasConflictingUpdates());
79 EXPECT_TRUE(status.HasConflictingUpdates());
82 TEST_F(StatusControllerTest, CountUpdates) {
83 StatusController status(routes_);
84 EXPECT_EQ(0, status.CountUpdates());
85 sync_pb::ClientToServerResponse* response(status.mutable_updates_response());
86 sync_pb::SyncEntity* entity1 = response->mutable_get_updates()->add_entries();
87 sync_pb::SyncEntity* entity2 = response->mutable_get_updates()->add_entries();
88 ASSERT_TRUE(entity1 != NULL && entity2 != NULL);
89 EXPECT_EQ(2, status.CountUpdates());
92 // Test TotalNumConflictingItems
93 TEST_F(StatusControllerTest, TotalNumConflictingItems) {
94 StatusController status(routes_);
95 TestIdFactory f;
97 ScopedModelSafeGroupRestriction r(&status, GROUP_UI);
98 status.mutable_simple_conflict_ids()->insert(f.NewLocalId());
99 status.mutable_simple_conflict_ids()->insert(f.NewLocalId());
100 EXPECT_EQ(static_cast<size_t>(2), status.simple_conflict_ids()->size());
102 EXPECT_EQ(2, status.TotalNumConflictingItems());
104 ScopedModelSafeGroupRestriction r(&status, GROUP_DB);
105 status.mutable_simple_conflict_ids()->insert(f.NewLocalId());
106 status.mutable_simple_conflict_ids()->insert(f.NewLocalId());
107 EXPECT_EQ(static_cast<size_t>(2), status.simple_conflict_ids()->size());
109 EXPECT_EQ(4, status.TotalNumConflictingItems());
111 status.increment_num_server_conflicts();
112 status.set_num_hierarchy_conflicts(3);
113 EXPECT_EQ(8, status.TotalNumConflictingItems());
116 // Basic test that non group-restricted state accessors don't cause violations.
117 TEST_F(StatusControllerTest, Unrestricted) {
118 StatusController status(routes_);
119 const UpdateProgress* progress =
120 status.GetUnrestrictedUpdateProgress(GROUP_UI);
121 EXPECT_FALSE(progress);
122 status.model_neutral_state();
123 status.download_updates_succeeded();
124 status.ServerSaysNothingMoreToDownload();
125 status.group_restriction();
128 } // namespace sessions
129 } // namespace syncer