OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "chrome/browser/sync/test/integration/dictionary_helper.h" | 7 #include "chrome/browser/sync/test/integration/dictionary_helper.h" |
8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
10 #include "chrome/browser/sync/test/integration/sync_test.h" | 10 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 11 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h
" |
11 #include "components/spellcheck/common/spellcheck_common.h" | 12 #include "components/spellcheck/common/spellcheck_common.h" |
12 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
13 | 14 |
14 using spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; | 15 using spellcheck::MAX_SYNCABLE_DICTIONARY_WORDS; |
15 using dictionary_helper::AwaitNumDictionaryEntries; | |
16 using sync_integration_test_util::AwaitCommitActivityCompletion; | |
17 using sync_integration_test_util::AwaitServerCount; | |
18 | 16 |
19 class TwoClientDictionarySyncTest : public SyncTest { | 17 class TwoClientDictionarySyncTest : public SyncTest { |
20 public: | 18 public: |
21 TwoClientDictionarySyncTest() : SyncTest(TWO_CLIENT) {} | 19 TwoClientDictionarySyncTest() : SyncTest(TWO_CLIENT) {} |
22 ~TwoClientDictionarySyncTest() override {} | 20 ~TwoClientDictionarySyncTest() override {} |
23 | 21 |
24 bool TestUsesSelfNotifications() override { return false; } | 22 bool TestUsesSelfNotifications() override { return false; } |
25 | 23 |
26 private: | 24 private: |
27 DISALLOW_COPY_AND_ASSIGN(TwoClientDictionarySyncTest); | 25 DISALLOW_COPY_AND_ASSIGN(TwoClientDictionarySyncTest); |
28 }; | 26 }; |
29 | 27 |
30 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, E2E_ENABLED(Sanity)) { | 28 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, E2E_ENABLED(Sanity)) { |
31 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 29 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
32 dictionary_helper::LoadDictionaries(); | 30 dictionary_helper::LoadDictionaries(); |
33 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 31 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
34 | 32 |
35 std::vector<std::string> words; | 33 std::vector<std::string> words; |
36 words.push_back("foo"); | 34 words.push_back("foo"); |
37 words.push_back("bar"); | 35 words.push_back("bar"); |
38 ASSERT_EQ(num_clients(), static_cast<int>(words.size())); | 36 ASSERT_EQ(num_clients(), static_cast<int>(words.size())); |
39 | 37 |
40 for (int i = 0; i < num_clients(); ++i) { | 38 for (int i = 0; i < num_clients(); ++i) { |
41 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); | 39 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); |
42 } | 40 } |
43 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 41 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
44 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); | 42 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); |
45 | 43 |
46 for (int i = 0; i < num_clients(); ++i) { | 44 for (int i = 0; i < num_clients(); ++i) { |
47 ASSERT_TRUE(dictionary_helper::RemoveWord(i, words[i])); | 45 ASSERT_TRUE(dictionary_helper::RemoveWord(i, words[i])); |
48 } | 46 } |
49 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 47 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
50 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); | 48 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); |
51 | 49 |
52 DisableVerifier(); | 50 DisableVerifier(); |
53 for (int i = 0; i < num_clients(); ++i) | 51 for (int i = 0; i < num_clients(); ++i) |
54 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); | 52 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); |
55 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 53 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
56 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); | 54 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); |
57 } | 55 } |
58 | 56 |
59 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, | 57 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, |
60 E2E_ENABLED(SimultaneousAdd)) { | 58 E2E_ENABLED(SimultaneousAdd)) { |
61 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 59 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
62 dictionary_helper::LoadDictionaries(); | 60 dictionary_helper::LoadDictionaries(); |
63 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 61 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
64 | 62 |
65 for (int i = 0; i < num_clients(); ++i) | 63 for (int i = 0; i < num_clients(); ++i) |
66 dictionary_helper::AddWord(i, "foo"); | 64 dictionary_helper::AddWord(i, "foo"); |
67 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 65 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
68 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | 66 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); |
69 } | 67 } |
70 | 68 |
71 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, | 69 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, |
72 E2E_ENABLED(SimultaneousRemove)) { | 70 E2E_ENABLED(SimultaneousRemove)) { |
73 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 71 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
74 dictionary_helper::LoadDictionaries(); | 72 dictionary_helper::LoadDictionaries(); |
75 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 73 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
76 | 74 |
77 for (int i = 0; i < num_clients(); ++i) | 75 for (int i = 0; i < num_clients(); ++i) |
78 dictionary_helper::AddWord(i, "foo"); | 76 dictionary_helper::AddWord(i, "foo"); |
79 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 77 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
80 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | 78 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); |
81 | 79 |
82 for (int i = 0; i < num_clients(); ++i) | 80 for (int i = 0; i < num_clients(); ++i) |
83 dictionary_helper::RemoveWord(i, "foo"); | 81 dictionary_helper::RemoveWord(i, "foo"); |
84 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 82 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
85 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); | 83 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); |
86 } | 84 } |
87 | 85 |
88 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, | 86 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, |
89 E2E_ENABLED(AddDifferentToEach)) { | 87 E2E_ENABLED(AddDifferentToEach)) { |
90 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
91 dictionary_helper::LoadDictionaries(); | 89 dictionary_helper::LoadDictionaries(); |
92 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 90 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
93 | 91 |
94 for (int i = 0; i < num_clients(); ++i) | 92 for (int i = 0; i < num_clients(); ++i) |
95 dictionary_helper::AddWord(i, "foo" + base::IntToString(i)); | 93 dictionary_helper::AddWord(i, "foo" + base::IntToString(i)); |
96 | 94 |
97 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 95 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
98 ASSERT_EQ(num_clients(), | 96 ASSERT_EQ(num_clients(), |
99 static_cast<int>(dictionary_helper::GetDictionarySize(0))); | 97 static_cast<int>(dictionary_helper::GetDictionarySize(0))); |
100 } | 98 } |
101 | 99 |
102 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, | 100 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, |
103 E2E_ENABLED(RemoveOnAAddOnB)) { | 101 E2E_ENABLED(RemoveOnAAddOnB)) { |
104 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
105 dictionary_helper::LoadDictionaries(); | 103 dictionary_helper::LoadDictionaries(); |
106 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 104 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
107 | 105 |
108 std::string word = "foo"; | 106 std::string word = "foo"; |
109 // Add on client A, check it appears on B. | 107 // Add on client A, check it appears on B. |
110 ASSERT_TRUE(dictionary_helper::AddWord(0, word)); | 108 ASSERT_TRUE(dictionary_helper::AddWord(0, word)); |
111 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 109 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
112 // Remove on client A, check it disappears on B. | 110 // Remove on client A, check it disappears on B. |
113 ASSERT_TRUE(dictionary_helper::RemoveWord(0, word)); | 111 ASSERT_TRUE(dictionary_helper::RemoveWord(0, word)); |
114 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 112 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
115 // Add on client B, check it appears on A. | 113 // Add on client B, check it appears on A. |
116 ASSERT_TRUE(dictionary_helper::AddWord(1, word)); | 114 ASSERT_TRUE(dictionary_helper::AddWord(1, word)); |
117 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 115 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
118 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | 116 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); |
119 } | 117 } |
120 | 118 |
121 // Tests the case where a client has more words added than the | 119 // Tests the case where a client has more words added than the |
122 // MAX_SYNCABLE_DICTIONARY_WORDS limit. | 120 // MAX_SYNCABLE_DICTIONARY_WORDS limit. |
123 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Limit) { | 121 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Limit) { |
124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 122 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
125 dictionary_helper::LoadDictionaries(); | 123 dictionary_helper::LoadDictionaries(); |
126 ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch()); | 124 ASSERT_TRUE(DictionaryMatchChecker().Wait()); |
127 | 125 |
128 // Disable client #1 before client #0 starts adding anything. | 126 // Disable client #1 before client #0 starts adding anything. |
129 GetClient(1)->DisableSyncForAllDatatypes(); | 127 GetClient(1)->DisableSyncForAllDatatypes(); |
130 | 128 |
131 // Pick a size between 1/2 and 1/3 of MAX_SYNCABLE_DICTIONARY_WORDS. This will | 129 // Pick a size between 1/2 and 1/3 of MAX_SYNCABLE_DICTIONARY_WORDS. This will |
132 // allow the test to verify that while we crossed the limit the client not | 130 // allow the test to verify that while we crossed the limit the client not |
133 // actively making changes is still recieving sync updates but stops exactly | 131 // actively making changes is still recieving sync updates but stops exactly |
134 // on the limit. | 132 // on the limit. |
135 size_t chunk_size = MAX_SYNCABLE_DICTIONARY_WORDS * 2 / 5; | 133 size_t chunk_size = MAX_SYNCABLE_DICTIONARY_WORDS * 2 / 5; |
136 | 134 |
137 ASSERT_TRUE(dictionary_helper::AddWords(0, chunk_size, "foo-0-")); | 135 ASSERT_TRUE(dictionary_helper::AddWords(0, chunk_size, "foo-0-")); |
138 ASSERT_EQ(chunk_size, dictionary_helper::GetDictionarySize(0)); | 136 ASSERT_EQ(chunk_size, dictionary_helper::GetDictionarySize(0)); |
139 | 137 |
140 // We must wait for the server here. This test was originally an n-client test | 138 // We must wait for the server here. This test was originally an n-client test |
141 // where n-1 clients waited to have the same state. We cannot do that on 2 | 139 // where n-1 clients waited to have the same state. We cannot do that on 2 |
142 // clients because one needs to be disconnected during this process, because | 140 // clients because one needs to be disconnected during this process, because |
143 // part of what we're testing is that when it comes online it pulls remote | 141 // part of what we're testing is that when it comes online it pulls remote |
144 // changes before pushing local changes, with the limit in mind. So we check | 142 // changes before pushing local changes, with the limit in mind. So we check |
145 // the server count here to make sure client #0 is done pushing its changes | 143 // the server count here to make sure client #0 is done pushing its changes |
146 // out. In there real world there's a race condition here, if multiple clients | 144 // out. In there real world there's a race condition here, if multiple clients |
147 // are adding words simultaneously then we're go over the limit slightly, | 145 // are adding words simultaneously then we're go over the limit slightly, |
148 // though we'd expect this to be relatively small. | 146 // though we'd expect this to be relatively small. |
149 AwaitServerCount(syncer::DICTIONARY, chunk_size); | 147 ASSERT_TRUE( |
| 148 ServerCountMatchStatusChecker(syncer::DICTIONARY, chunk_size).Wait()); |
150 | 149 |
151 ASSERT_TRUE(dictionary_helper::AddWords(1, 2 * chunk_size, "foo-1-")); | 150 ASSERT_TRUE(dictionary_helper::AddWords(1, 2 * chunk_size, "foo-1-")); |
152 ASSERT_EQ(2 * chunk_size, dictionary_helper::GetDictionarySize(1)); | 151 ASSERT_EQ(2 * chunk_size, dictionary_helper::GetDictionarySize(1)); |
153 | 152 |
154 // Client #1 should first pull remote changes, apply them, without capping at | 153 // Client #1 should first pull remote changes, apply them, without capping at |
155 // any sort of limit. This will cause client #1 to have 3 * chunk_size. When | 154 // any sort of limit. This will cause client #1 to have 3 * chunk_size. When |
156 // client #1 then tries to commit changes, that is when it obeys the limit | 155 // client #1 then tries to commit changes, that is when it obeys the limit |
157 // and will cause client #0 to only see the limit worth of words. | 156 // and will cause client #0 to only see the limit worth of words. |
158 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); | 157 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); |
159 ASSERT_TRUE(AwaitNumDictionaryEntries(1, 3 * chunk_size)); | 158 ASSERT_TRUE(NumDictionaryEntriesChecker(1, 3 * chunk_size).Wait()); |
| 159 ASSERT_TRUE(ServerCountMatchStatusChecker(syncer::DICTIONARY, |
| 160 MAX_SYNCABLE_DICTIONARY_WORDS) |
| 161 .Wait()); |
160 ASSERT_TRUE( | 162 ASSERT_TRUE( |
161 AwaitServerCount(syncer::DICTIONARY, MAX_SYNCABLE_DICTIONARY_WORDS)); | 163 NumDictionaryEntriesChecker(0, MAX_SYNCABLE_DICTIONARY_WORDS).Wait()); |
162 ASSERT_TRUE(AwaitNumDictionaryEntries(0, MAX_SYNCABLE_DICTIONARY_WORDS)); | |
163 } | 164 } |
OLD | NEW |