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.
5 #include "base/strings/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"
11 class MultipleClientDictionarySyncTest : public SyncTest {
13 MultipleClientDictionarySyncTest() : SyncTest(MULTIPLE_CLIENT) {}
14 virtual ~MultipleClientDictionarySyncTest() {}
17 DISALLOW_COPY_AND_ASSIGN(MultipleClientDictionarySyncTest);
20 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddToOne) {
21 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
22 dictionary_helper::LoadDictionaries();
23 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
25 ASSERT_TRUE(dictionary_helper::AddWord(0, "foo"));
26 ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
27 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
30 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddSameToAll) {
31 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
32 dictionary_helper::LoadDictionaries();
33 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
35 for (int i = 0; i < num_clients(); ++i)
36 dictionary_helper::AddWord(i, "foo");
37 ASSERT_TRUE(AwaitQuiescence());
38 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
39 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
42 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddDifferentToAll) {
43 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
44 dictionary_helper::LoadDictionaries();
45 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
47 for (int i = 0; i < num_clients(); ++i)
48 dictionary_helper::AddWord(i, "foo" + base::IntToString(i));
49 ASSERT_TRUE(AwaitQuiescence());
50 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
51 ASSERT_EQ(num_clients(),
52 static_cast<int>(dictionary_helper::GetDictionarySize(0)));
55 IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, Limit) {
56 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
57 dictionary_helper::LoadDictionaries();
58 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
60 // Add 1300 different words to each of the clients before sync.
61 for (int i = 0; i < num_clients(); ++i) {
62 GetClient(i)->DisableSyncForAllDatatypes();
64 j < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
66 ASSERT_TRUE(dictionary_helper::AddWord(
67 i, "foo-" + base::IntToString(i) + "-" + base::Uint64ToString(j)));
69 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
70 dictionary_helper::GetDictionarySize(i));
73 // Turn on sync on client #0. The sync server should contain only data from
75 ASSERT_TRUE(GetClient(0)->EnableSyncForAllDatatypes());
76 ASSERT_TRUE(AwaitQuiescence());
77 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
78 dictionary_helper::GetDictionarySize(0));
80 // Turn on sync in the rest of the clients one-by-one.
81 for (int i = 1; i < num_clients(); ++i) {
82 // Client #i has 1300 words before sync.
83 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
84 dictionary_helper::GetDictionarySize(i));
85 ASSERT_TRUE(GetClient(i)->EnableSyncForAllDatatypes());
86 ASSERT_TRUE(AwaitQuiescence());
87 // Client #i should have 2600 words after sync: 1300 of own original words
88 // and 1300 words from client #0.
90 chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2,
91 dictionary_helper::GetDictionarySize(i));
94 // Client #0 should still have only 1300 words after syncing all other
95 // clients, because it has the same data as the sync server.
96 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
97 dictionary_helper::GetDictionarySize(0));