Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/string_number_conversions.h" | |
| 6 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
| 7 #include "chrome/browser/sync/test/integration/dictionary_helper.h" | |
| 8 #include "chrome/browser/sync/test/integration/sync_test.h" | |
| 9 #include "chrome/common/spellcheck_common.h" | |
| 10 | |
| 11 class TwoClientDictionarySyncTest : public SyncTest { | |
| 12 public: | |
| 13 TwoClientDictionarySyncTest() : SyncTest(TWO_CLIENT) {} | |
| 14 virtual ~TwoClientDictionarySyncTest() {} | |
| 15 | |
| 16 virtual void AddOptionalTypesToCommandLine(CommandLine* cl) OVERRIDE { | |
| 17 dictionary_helper::EnableDictionarySync(cl); | |
| 18 } | |
| 19 | |
| 20 private: | |
| 21 DISALLOW_COPY_AND_ASSIGN(TwoClientDictionarySyncTest); | |
| 22 }; | |
| 23 | |
| 24 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Sanity) { | |
| 25 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 26 dictionary_helper::LoadDictionaries(); | |
| 27 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 28 | |
| 29 std::vector<std::string> words; | |
| 30 words.push_back("foo"); | |
| 31 words.push_back("bar"); | |
| 32 ASSERT_EQ(num_clients(), static_cast<int>(words.size())); | |
| 33 | |
| 34 for (int i = 0; i < num_clients(); ++i) { | |
| 35 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); | |
| 36 ASSERT_TRUE(GetClient(i)->AwaitMutualSyncCycleCompletion( | |
| 37 GetClient((i + 1) % 2))); | |
| 38 } | |
| 39 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 40 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); | |
| 41 | |
| 42 for (int i = 0; i < num_clients(); ++i) { | |
| 43 ASSERT_TRUE(dictionary_helper::RemoveWord(i, words[i])); | |
| 44 ASSERT_TRUE(GetClient(i)->AwaitMutualSyncCycleCompletion( | |
| 45 GetClient((i + 1) % 2))); | |
| 46 } | |
| 47 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 48 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); | |
| 49 | |
| 50 DisableVerifier(); | |
| 51 for (int i = 0; i < num_clients(); ++i) | |
| 52 ASSERT_TRUE(dictionary_helper::AddWord(i, words[i])); | |
| 53 ASSERT_TRUE(AwaitQuiescence()); | |
| 54 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 55 ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0)); | |
| 56 | |
| 57 MessageLoop::current()->RunUntilIdle(); | |
| 58 } | |
| 59 | |
| 60 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, SimultaneousAdd) { | |
| 61 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 62 dictionary_helper::LoadDictionaries(); | |
| 63 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 64 | |
| 65 for (int i = 0; i < num_clients(); ++i) | |
| 66 dictionary_helper::AddWord(i, "foo"); | |
| 67 ASSERT_TRUE(AwaitQuiescence()); | |
| 68 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 69 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | |
| 70 | |
| 71 MessageLoop::current()->RunUntilIdle(); | |
| 72 } | |
| 73 | |
| 74 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, SimultaneousRemove) { | |
| 75 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 76 dictionary_helper::LoadDictionaries(); | |
| 77 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 78 | |
| 79 for (int i = 0; i < num_clients(); ++i) | |
| 80 dictionary_helper::AddWord(i, "foo"); | |
| 81 ASSERT_TRUE(AwaitQuiescence()); | |
| 82 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 83 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | |
| 84 | |
| 85 for (int i = 0; i < num_clients(); ++i) | |
| 86 dictionary_helper::RemoveWord(i, "foo"); | |
| 87 ASSERT_TRUE(AwaitQuiescence()); | |
| 88 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 89 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0)); | |
| 90 | |
| 91 MessageLoop::current()->RunUntilIdle(); | |
| 92 } | |
| 93 | |
| 94 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, RemoveOnAAddOnB) { | |
| 95 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 96 dictionary_helper::LoadDictionaries(); | |
| 97 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 98 | |
| 99 std::string word = "foo"; | |
| 100 // Add on client A | |
| 101 ASSERT_TRUE(dictionary_helper::AddWord(0, word)); | |
| 102 // Remove on client A | |
| 103 ASSERT_TRUE(dictionary_helper::RemoveWord(0, word)); | |
| 104 // Add on client B | |
| 105 ASSERT_TRUE(dictionary_helper::AddWord(1, word)); | |
|
Nicolas Zea
2013/01/17 20:14:52
Without waiting for sync between these events, I s
please use gerrit instead
2013/01/17 22:25:29
Added AwaitQuiescence() between RemoveWord(0, word
| |
| 106 ASSERT_TRUE(AwaitQuiescence()); | |
| 107 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 108 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | |
| 109 | |
| 110 MessageLoop::current()->RunUntilIdle(); | |
| 111 } | |
| 112 | |
| 113 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, DisableSync) { | |
| 114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 115 dictionary_helper::LoadDictionaries(); | |
| 116 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 117 | |
| 118 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes()); | |
| 119 ASSERT_TRUE(dictionary_helper::AddWord(0, "foo")); | |
| 120 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Added a word")); | |
| 121 ASSERT_TRUE(dictionary_helper::DictionaryMatchesVerifier(0)); | |
| 122 ASSERT_FALSE(dictionary_helper::DictionaryMatchesVerifier(1)); | |
| 123 | |
| 124 MessageLoop::current()->RunUntilIdle(); | |
| 125 } | |
| 126 | |
| 127 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Limit) { | |
| 128 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 129 dictionary_helper::LoadDictionaries(); | |
| 130 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 131 | |
| 132 ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes()); | |
| 133 for (size_t i = 0; | |
| 134 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 135 ++i) { | |
| 136 ASSERT_TRUE(dictionary_helper::AddWord( | |
| 137 0, "foo" + base::Uint64ToString(i))); | |
| 138 ASSERT_TRUE(dictionary_helper::AddWord( | |
| 139 1, "bar" + base::Uint64ToString(i))); | |
| 140 } | |
| 141 ASSERT_TRUE(AwaitQuiescence()); | |
| 142 ASSERT_FALSE(dictionary_helper::DictionariesMatch()); | |
| 143 | |
| 144 // Client #0 should have only "foo" set of words. | |
| 145 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 146 dictionary_helper::GetDictionarySize(0)); | |
| 147 | |
| 148 // Client #1 should have only "bar" set of words. | |
| 149 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 150 dictionary_helper::GetDictionarySize(1)); | |
| 151 | |
| 152 ASSERT_TRUE(GetClient(0)->EnableSyncForAllDatatypes()); | |
| 153 ASSERT_TRUE(AwaitQuiescence()); | |
| 154 | |
| 155 // Client #0 should have both "foo" and "bar" sets of words. | |
| 156 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2, | |
| 157 dictionary_helper::GetDictionarySize(0)); | |
| 158 | |
| 159 // The sync server and client #1 should have only "bar" set of words. | |
| 160 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 161 dictionary_helper::GetDictionarySize(1)); | |
| 162 | |
| 163 MessageLoop::current()->RunUntilIdle(); | |
| 164 } | |
| OLD | NEW |