| 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 browser_sync { | 9 namespace browser_sync { |
| 10 namespace sessions { | 10 namespace sessions { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 EXPECT_TRUE(status.TestAndClearIsDirty()); | 32 EXPECT_TRUE(status.TestAndClearIsDirty()); |
| 33 status.increment_num_successful_commits(); | 33 status.increment_num_successful_commits(); |
| 34 EXPECT_TRUE(status.TestAndClearIsDirty()); | 34 EXPECT_TRUE(status.TestAndClearIsDirty()); |
| 35 | 35 |
| 36 { | 36 { |
| 37 ScopedModelSafeGroupRestriction r(&status, GROUP_UI); | 37 ScopedModelSafeGroupRestriction r(&status, GROUP_UI); |
| 38 status.mutable_conflict_progress()-> | 38 status.mutable_conflict_progress()-> |
| 39 AddSimpleConflictingItemById(syncable::Id()); | 39 AddSimpleConflictingItemById(syncable::Id()); |
| 40 } | 40 } |
| 41 EXPECT_TRUE(status.TestAndClearIsDirty()); | 41 EXPECT_TRUE(status.TestAndClearIsDirty()); |
| 42 | |
| 43 std::vector<int64> v; | |
| 44 v.push_back(1); | |
| 45 status.set_unsynced_handles(v); | |
| 46 EXPECT_TRUE(status.TestAndClearIsDirty()); | |
| 47 std::vector<int64> v2; | |
| 48 v2.push_back(1); | |
| 49 status.set_unsynced_handles(v2); | |
| 50 EXPECT_FALSE(status.TestAndClearIsDirty()); // Test for deep comparison. | |
| 51 } | 42 } |
| 52 | 43 |
| 53 TEST_F(StatusControllerTest, StaysClean) { | 44 TEST_F(StatusControllerTest, StaysClean) { |
| 54 StatusController status(routes_); | 45 StatusController status(routes_); |
| 55 status.update_conflicts_resolved(true); | 46 status.update_conflicts_resolved(true); |
| 56 EXPECT_FALSE(status.TestAndClearIsDirty()); | 47 EXPECT_FALSE(status.TestAndClearIsDirty()); |
| 57 | |
| 58 status.set_items_committed(); | |
| 59 EXPECT_FALSE(status.TestAndClearIsDirty()); | |
| 60 | |
| 61 OrderedCommitSet commits(routes_); | |
| 62 commits.AddCommitItem(0, syncable::Id(), syncable::BOOKMARKS); | |
| 63 status.set_commit_set(commits); | |
| 64 EXPECT_FALSE(status.TestAndClearIsDirty()); | |
| 65 } | 48 } |
| 66 | 49 |
| 67 // This test is useful, as simple as it sounds, due to the copy-paste prone | 50 // This test is useful, as simple as it sounds, due to the copy-paste prone |
| 68 // nature of status_controller.cc (we have had bugs in the past where a set_foo | 51 // nature of status_controller.cc (we have had bugs in the past where a set_foo |
| 69 // method was actually setting |bar_| instead!). | 52 // method was actually setting |bar_| instead!). |
| 70 TEST_F(StatusControllerTest, ReadYourWrites) { | 53 TEST_F(StatusControllerTest, ReadYourWrites) { |
| 71 StatusController status(routes_); | 54 StatusController status(routes_); |
| 72 status.set_num_server_changes_remaining(13); | 55 status.set_num_server_changes_remaining(13); |
| 73 EXPECT_EQ(13, status.num_server_changes_remaining()); | 56 EXPECT_EQ(13, status.num_server_changes_remaining()); |
| 74 | 57 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 status.set_last_post_commit_result(SYNC_AUTH_ERROR); | 69 status.set_last_post_commit_result(SYNC_AUTH_ERROR); |
| 87 EXPECT_EQ(SYNC_AUTH_ERROR, status.error().last_post_commit_result); | 70 EXPECT_EQ(SYNC_AUTH_ERROR, status.error().last_post_commit_result); |
| 88 | 71 |
| 89 status.set_last_process_commit_response_result(SYNC_SERVER_ERROR); | 72 status.set_last_process_commit_response_result(SYNC_SERVER_ERROR); |
| 90 EXPECT_EQ(SYNC_SERVER_ERROR, | 73 EXPECT_EQ(SYNC_SERVER_ERROR, |
| 91 status.error().last_process_commit_response_result); | 74 status.error().last_process_commit_response_result); |
| 92 | 75 |
| 93 for (int i = 0; i < 14; i++) | 76 for (int i = 0; i < 14; i++) |
| 94 status.increment_num_successful_commits(); | 77 status.increment_num_successful_commits(); |
| 95 EXPECT_EQ(14, status.syncer_status().num_successful_commits); | 78 EXPECT_EQ(14, status.syncer_status().num_successful_commits); |
| 96 | |
| 97 std::vector<int64> v; | |
| 98 v.push_back(16); | |
| 99 status.set_unsynced_handles(v); | |
| 100 EXPECT_EQ(16, v[0]); | |
| 101 } | 79 } |
| 102 | 80 |
| 103 TEST_F(StatusControllerTest, HasConflictingUpdates) { | 81 TEST_F(StatusControllerTest, HasConflictingUpdates) { |
| 104 StatusController status(routes_); | 82 StatusController status(routes_); |
| 105 EXPECT_FALSE(status.HasConflictingUpdates()); | 83 EXPECT_FALSE(status.HasConflictingUpdates()); |
| 106 { | 84 { |
| 107 ScopedModelSafeGroupRestriction r(&status, GROUP_UI); | 85 ScopedModelSafeGroupRestriction r(&status, GROUP_UI); |
| 108 EXPECT_FALSE(status.update_progress()); | 86 EXPECT_FALSE(status.update_progress()); |
| 109 status.mutable_update_progress()->AddAppliedUpdate(SUCCESS, | 87 status.mutable_update_progress()->AddAppliedUpdate(SUCCESS, |
| 110 syncable::Id()); | 88 syncable::Id()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 150 } |
| 173 EXPECT_EQ(4, status.TotalNumConflictingItems()); | 151 EXPECT_EQ(4, status.TotalNumConflictingItems()); |
| 174 } | 152 } |
| 175 | 153 |
| 176 // Basic test that non group-restricted state accessors don't cause violations. | 154 // Basic test that non group-restricted state accessors don't cause violations. |
| 177 TEST_F(StatusControllerTest, Unrestricted) { | 155 TEST_F(StatusControllerTest, Unrestricted) { |
| 178 StatusController status(routes_); | 156 StatusController status(routes_); |
| 179 const UpdateProgress* progress = | 157 const UpdateProgress* progress = |
| 180 status.GetUnrestrictedUpdateProgress(GROUP_UI); | 158 status.GetUnrestrictedUpdateProgress(GROUP_UI); |
| 181 EXPECT_FALSE(progress); | 159 EXPECT_FALSE(progress); |
| 182 status.mutable_commit_message(); | |
| 183 status.commit_response(); | |
| 184 status.mutable_commit_response(); | |
| 185 status.updates_response(); | |
| 186 status.mutable_updates_response(); | |
| 187 status.error(); | 160 status.error(); |
| 188 status.syncer_status(); | 161 status.syncer_status(); |
| 189 status.num_server_changes_remaining(); | 162 status.num_server_changes_remaining(); |
| 190 status.commit_ids(); | |
| 191 status.HasBookmarkCommitActivity(); | |
| 192 status.download_updates_succeeded(); | 163 status.download_updates_succeeded(); |
| 193 status.ServerSaysNothingMoreToDownload(); | 164 status.ServerSaysNothingMoreToDownload(); |
| 194 status.group_restriction(); | 165 status.group_restriction(); |
| 195 } | 166 } |
| 196 | 167 |
| 197 } // namespace sessions | 168 } // namespace sessions |
| 198 } // namespace browser_sync | 169 } // namespace browser_sync |
| OLD | NEW |