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 MultipleClientDictionarySyncTest : public SyncTest { | |
| 12 public: | |
| 13 MultipleClientDictionarySyncTest() : SyncTest(MULTIPLE_CLIENT) {} | |
| 14 virtual ~MultipleClientDictionarySyncTest() {} | |
| 15 | |
| 16 virtual void AddOptionalTypesToCommandLine(CommandLine* cl) OVERRIDE { | |
| 17 dictionary_helper::EnableDictionarySync(cl); | |
| 18 } | |
| 19 | |
| 20 private: | |
| 21 DISALLOW_COPY_AND_ASSIGN(MultipleClientDictionarySyncTest); | |
| 22 }; | |
| 23 | |
| 24 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddToOne) { | |
| 25 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 26 dictionary_helper::LoadDictionaries(); | |
| 27 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 28 | |
| 29 ASSERT_TRUE(dictionary_helper::AddWord(0, "foo")); | |
| 30 ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients())); | |
| 31 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 32 | |
| 33 MessageLoop::current()->RunUntilIdle(); | |
|
Nicolas Zea
2013/01/17 20:14:52
Is the run until idle necessary for correctness on
please use gerrit instead
2013/01/17 22:25:29
It's necessary to prevent crashing in SpellcheckHu
| |
| 34 } | |
| 35 | |
| 36 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddSameToAll) { | |
| 37 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 38 dictionary_helper::LoadDictionaries(); | |
| 39 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 40 | |
| 41 for (int i = 0; i < num_clients(); ++i) | |
| 42 dictionary_helper::AddWord(i, "foo"); | |
| 43 ASSERT_TRUE(AwaitQuiescence()); | |
| 44 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 45 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0)); | |
| 46 | |
| 47 MessageLoop::current()->RunUntilIdle(); | |
| 48 } | |
| 49 | |
| 50 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddDifferentToAll) { | |
| 51 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 52 dictionary_helper::LoadDictionaries(); | |
| 53 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 54 | |
| 55 for (int i = 0; i < num_clients(); ++i) | |
| 56 dictionary_helper::AddWord(i, "foo" + base::IntToString(i)); | |
| 57 ASSERT_TRUE(AwaitQuiescence()); | |
| 58 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 59 ASSERT_EQ(num_clients(), | |
| 60 static_cast<int>(dictionary_helper::GetDictionarySize(0))); | |
| 61 | |
| 62 MessageLoop::current()->RunUntilIdle(); | |
| 63 } | |
| 64 | |
| 65 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, Limit) { | |
| 66 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 67 dictionary_helper::LoadDictionaries(); | |
| 68 ASSERT_TRUE(dictionary_helper::DictionariesMatch()); | |
| 69 | |
| 70 // Add 1300i completely different words to all i clients before sync. | |
|
Nicolas Zea
2013/01/17 20:14:52
1300i?
please use gerrit instead
2013/01/17 22:25:29
Fixed the comment to be "Add 1300 different words
| |
| 71 for (int i = 0; i < num_clients(); ++i) { | |
| 72 GetClient(i)->DisableSyncForAllDatatypes(); | |
| 73 for (size_t j = 0; | |
| 74 j < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | |
| 75 ++j) { | |
| 76 ASSERT_TRUE(dictionary_helper::AddWord( | |
| 77 i, "foo-" + base::IntToString(i) + "-" + base::Uint64ToString(j))); | |
| 78 } | |
| 79 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 80 dictionary_helper::GetDictionarySize(i)); | |
| 81 } | |
| 82 | |
| 83 // Turn on sync on client #0. The sync server should contain only data from | |
| 84 // client #0. | |
| 85 ASSERT_TRUE(GetClient(0)->EnableSyncForAllDatatypes()); | |
| 86 ASSERT_TRUE(AwaitQuiescence()); | |
| 87 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 88 dictionary_helper::GetDictionarySize(0)); | |
| 89 | |
| 90 // Turn on sync in the rest of the clients one-by-one. | |
| 91 for (int i = 1; i < num_clients(); ++i) { | |
| 92 // Client #i has 1300 words before sync. | |
| 93 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 94 dictionary_helper::GetDictionarySize(i)); | |
| 95 ASSERT_TRUE(GetClient(i)->EnableSyncForAllDatatypes()); | |
| 96 ASSERT_TRUE(AwaitQuiescence()); | |
| 97 // Client #i should have 2600 words after sync: 1300 of own original words | |
| 98 // and 1300 words from client #0. | |
| 99 ASSERT_EQ( | |
| 100 chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2, | |
| 101 dictionary_helper::GetDictionarySize(i)); | |
| 102 } | |
| 103 | |
| 104 // Client #0 should still have only 1300 words after syncing all other | |
| 105 // clients, because it has the same data as the sync server. | |
| 106 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | |
| 107 dictionary_helper::GetDictionarySize(0)); | |
| 108 | |
| 109 MessageLoop::current()->RunUntilIdle(); | |
| 110 } | |
| OLD | NEW |