| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/sessions/sync_session.h" | 5 #include "sync/sessions/sync_session.h" |
| 6 #include "sync/test/engine/test_id_factory.h" | 6 #include "sync/test/engine/test_id_factory.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace syncer { | 9 namespace syncer { |
| 10 namespace sessions { | 10 namespace sessions { |
| 11 | 11 |
| 12 class StatusControllerTest : public testing::Test { | 12 class StatusControllerTest : public testing::Test { |
| 13 public: | 13 public: |
| 14 virtual void SetUp() { | 14 virtual void SetUp() { |
| 15 routes_[BOOKMARKS] = GROUP_UI; | 15 routes_[BOOKMARKS] = GROUP_UI; |
| 16 } | 16 } |
| 17 protected: | 17 protected: |
| 18 ModelSafeRoutingInfo routes_; | 18 ModelSafeRoutingInfo routes_; |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 // This test is useful, as simple as it sounds, due to the copy-paste prone | 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 | 22 // nature of status_controller.cc (we have had bugs in the past where a set_foo |
| 23 // method was actually setting |bar_| instead!). | 23 // method was actually setting |bar_| instead!). |
| 24 TEST_F(StatusControllerTest, ReadYourWrites) { | 24 TEST_F(StatusControllerTest, ReadYourWrites) { |
| 25 StatusController status(routes_); | 25 StatusController status(routes_); |
| 26 status.set_num_server_changes_remaining(13); | 26 status.set_num_server_changes_remaining(13); |
| 27 EXPECT_EQ(13, status.num_server_changes_remaining()); | 27 EXPECT_EQ(13, status.num_server_changes_remaining()); |
| 28 | 28 |
| 29 EXPECT_FALSE(status.conflicts_resolved()); | |
| 30 status.update_conflicts_resolved(true); | |
| 31 EXPECT_TRUE(status.conflicts_resolved()); | |
| 32 | |
| 33 status.set_last_download_updates_result(SYNCER_OK); | 29 status.set_last_download_updates_result(SYNCER_OK); |
| 34 EXPECT_EQ(SYNCER_OK, | 30 EXPECT_EQ(SYNCER_OK, |
| 35 status.model_neutral_state().last_download_updates_result); | 31 status.model_neutral_state().last_download_updates_result); |
| 36 | 32 |
| 37 status.set_commit_result(SYNC_AUTH_ERROR); | 33 status.set_commit_result(SYNC_AUTH_ERROR); |
| 38 EXPECT_EQ(SYNC_AUTH_ERROR, status.model_neutral_state().commit_result); | 34 EXPECT_EQ(SYNC_AUTH_ERROR, status.model_neutral_state().commit_result); |
| 39 | 35 |
| 40 for (int i = 0; i < 14; i++) | 36 for (int i = 0; i < 14; i++) |
| 41 status.increment_num_successful_commits(); | 37 status.increment_num_successful_commits(); |
| 42 EXPECT_EQ(14, status.model_neutral_state().num_successful_commits); | 38 EXPECT_EQ(14, status.model_neutral_state().num_successful_commits); |
| 43 } | 39 } |
| 44 | 40 |
| 45 TEST_F(StatusControllerTest, HasConflictingUpdates) { | |
| 46 StatusController status(routes_); | |
| 47 EXPECT_FALSE(status.HasConflictingUpdates()); | |
| 48 { | |
| 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()); | |
| 56 } | |
| 57 | |
| 58 EXPECT_TRUE(status.HasConflictingUpdates()); | |
| 59 | |
| 60 { | |
| 61 ScopedModelSafeGroupRestriction r(&status, GROUP_PASSIVE); | |
| 62 EXPECT_FALSE(status.update_progress()); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 TEST_F(StatusControllerTest, HasConflictingUpdates_NonBlockingUpdates) { | |
| 67 StatusController status(routes_); | |
| 68 EXPECT_FALSE(status.HasConflictingUpdates()); | |
| 69 { | |
| 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()); | |
| 77 } | |
| 78 | |
| 79 EXPECT_TRUE(status.HasConflictingUpdates()); | |
| 80 } | |
| 81 | |
| 82 TEST_F(StatusControllerTest, CountUpdates) { | 41 TEST_F(StatusControllerTest, CountUpdates) { |
| 83 StatusController status(routes_); | 42 StatusController status(routes_); |
| 84 EXPECT_EQ(0, status.CountUpdates()); | 43 EXPECT_EQ(0, status.CountUpdates()); |
| 85 sync_pb::ClientToServerResponse* response(status.mutable_updates_response()); | 44 sync_pb::ClientToServerResponse* response(status.mutable_updates_response()); |
| 86 sync_pb::SyncEntity* entity1 = response->mutable_get_updates()->add_entries(); | 45 sync_pb::SyncEntity* entity1 = response->mutable_get_updates()->add_entries(); |
| 87 sync_pb::SyncEntity* entity2 = response->mutable_get_updates()->add_entries(); | 46 sync_pb::SyncEntity* entity2 = response->mutable_get_updates()->add_entries(); |
| 88 ASSERT_TRUE(entity1 != NULL && entity2 != NULL); | 47 ASSERT_TRUE(entity1 != NULL && entity2 != NULL); |
| 89 EXPECT_EQ(2, status.CountUpdates()); | 48 EXPECT_EQ(2, status.CountUpdates()); |
| 90 } | 49 } |
| 91 | 50 |
| 92 // Test TotalNumConflictingItems | 51 // Test TotalNumConflictingItems |
| 93 TEST_F(StatusControllerTest, TotalNumConflictingItems) { | 52 TEST_F(StatusControllerTest, TotalNumConflictingItems) { |
| 94 StatusController status(routes_); | 53 StatusController status(routes_); |
| 95 TestIdFactory f; | 54 EXPECT_EQ(0, status.TotalNumConflictingItems()); |
| 96 { | 55 |
| 97 ScopedModelSafeGroupRestriction r(&status, GROUP_UI); | 56 status.increment_num_server_conflicts(); |
| 98 EXPECT_FALSE(status.conflict_progress()); | 57 status.increment_num_hierarchy_conflicts_by(3); |
| 99 status.mutable_conflict_progress()-> | 58 status.increment_num_encryption_conflicts_by(2); |
| 100 AddSimpleConflictingItemById(f.NewLocalId()); | 59 EXPECT_EQ(6, status.TotalNumConflictingItems()); |
| 101 status.mutable_conflict_progress()-> | |
| 102 AddSimpleConflictingItemById(f.NewLocalId()); | |
| 103 EXPECT_EQ(2, status.conflict_progress()->SimpleConflictingItemsSize()); | |
| 104 } | |
| 105 EXPECT_EQ(2, status.TotalNumConflictingItems()); | |
| 106 { | |
| 107 ScopedModelSafeGroupRestriction r(&status, GROUP_DB); | |
| 108 EXPECT_FALSE(status.conflict_progress()); | |
| 109 status.mutable_conflict_progress()-> | |
| 110 AddSimpleConflictingItemById(f.NewLocalId()); | |
| 111 status.mutable_conflict_progress()-> | |
| 112 AddSimpleConflictingItemById(f.NewLocalId()); | |
| 113 EXPECT_EQ(2, status.conflict_progress()->SimpleConflictingItemsSize()); | |
| 114 } | |
| 115 EXPECT_EQ(4, status.TotalNumConflictingItems()); | |
| 116 } | 60 } |
| 117 | 61 |
| 118 // Basic test that non group-restricted state accessors don't cause violations. | 62 // Basic test that non group-restricted state accessors don't cause violations. |
| 119 TEST_F(StatusControllerTest, Unrestricted) { | 63 TEST_F(StatusControllerTest, Unrestricted) { |
| 120 StatusController status(routes_); | 64 StatusController status(routes_); |
| 121 const UpdateProgress* progress = | |
| 122 status.GetUnrestrictedUpdateProgress(GROUP_UI); | |
| 123 EXPECT_FALSE(progress); | |
| 124 status.model_neutral_state(); | 65 status.model_neutral_state(); |
| 125 status.download_updates_succeeded(); | 66 status.download_updates_succeeded(); |
| 126 status.ServerSaysNothingMoreToDownload(); | 67 status.ServerSaysNothingMoreToDownload(); |
| 127 status.group_restriction(); | 68 status.group_restriction(); |
| 128 } | 69 } |
| 129 | 70 |
| 130 } // namespace sessions | 71 } // namespace sessions |
| 131 } // namespace syncer | 72 } // namespace syncer |
| OLD | NEW |