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/test/integration/dictionary_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
9 #include "chrome/common/spellcheck_common.h"
11 class TwoClientDictionarySyncTest
: public SyncTest
{
13 TwoClientDictionarySyncTest() : SyncTest(TWO_CLIENT
) {}
14 virtual ~TwoClientDictionarySyncTest() {}
17 DISALLOW_COPY_AND_ASSIGN(TwoClientDictionarySyncTest
);
20 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, Sanity
) {
21 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
22 dictionary_helper::LoadDictionaries();
23 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
25 std::vector
<std::string
> words
;
26 words
.push_back("foo");
27 words
.push_back("bar");
28 ASSERT_EQ(num_clients(), static_cast<int>(words
.size()));
30 for (int i
= 0; i
< num_clients(); ++i
) {
31 ASSERT_TRUE(dictionary_helper::AddWord(i
, words
[i
]));
32 ASSERT_TRUE(GetClient(i
)->AwaitMutualSyncCycleCompletion(
33 GetClient((i
+ 1) % 2)));
35 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
36 ASSERT_EQ(words
.size(), dictionary_helper::GetDictionarySize(0));
38 for (int i
= 0; i
< num_clients(); ++i
) {
39 ASSERT_TRUE(dictionary_helper::RemoveWord(i
, words
[i
]));
40 ASSERT_TRUE(GetClient(i
)->AwaitMutualSyncCycleCompletion(
41 GetClient((i
+ 1) % 2)));
43 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
44 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0));
47 for (int i
= 0; i
< num_clients(); ++i
)
48 ASSERT_TRUE(dictionary_helper::AddWord(i
, words
[i
]));
49 ASSERT_TRUE(AwaitQuiescence());
50 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
51 ASSERT_EQ(words
.size(), dictionary_helper::GetDictionarySize(0));
54 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, SimultaneousAdd
) {
55 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
56 dictionary_helper::LoadDictionaries();
57 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
59 for (int i
= 0; i
< num_clients(); ++i
)
60 dictionary_helper::AddWord(i
, "foo");
61 ASSERT_TRUE(AwaitQuiescence());
62 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
63 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
66 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, SimultaneousRemove
) {
67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
68 dictionary_helper::LoadDictionaries();
69 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
71 for (int i
= 0; i
< num_clients(); ++i
)
72 dictionary_helper::AddWord(i
, "foo");
73 ASSERT_TRUE(AwaitQuiescence());
74 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
75 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
77 for (int i
= 0; i
< num_clients(); ++i
)
78 dictionary_helper::RemoveWord(i
, "foo");
79 ASSERT_TRUE(AwaitQuiescence());
80 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
81 ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0));
84 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, RemoveOnAAddOnB
) {
85 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
86 dictionary_helper::LoadDictionaries();
87 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
89 std::string word
= "foo";
91 ASSERT_TRUE(dictionary_helper::AddWord(0, word
));
93 ASSERT_TRUE(dictionary_helper::RemoveWord(0, word
));
94 ASSERT_TRUE(AwaitQuiescence());
96 ASSERT_TRUE(dictionary_helper::AddWord(1, word
));
97 ASSERT_TRUE(AwaitQuiescence());
98 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
99 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
102 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, DisableSync
) {
103 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
104 dictionary_helper::LoadDictionaries();
105 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
107 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
108 ASSERT_TRUE(dictionary_helper::AddWord(0, "foo"));
109 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
110 ASSERT_TRUE(dictionary_helper::DictionaryMatchesVerifier(0));
111 ASSERT_FALSE(dictionary_helper::DictionaryMatchesVerifier(1));
114 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest
, Limit
) {
115 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
116 dictionary_helper::LoadDictionaries();
117 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
119 ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes());
121 i
< chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS
;
123 ASSERT_TRUE(dictionary_helper::AddWord(
124 0, "foo" + base::Uint64ToString(i
)));
125 ASSERT_TRUE(dictionary_helper::AddWord(
126 1, "bar" + base::Uint64ToString(i
)));
128 ASSERT_TRUE(AwaitQuiescence());
129 ASSERT_FALSE(dictionary_helper::DictionariesMatch());
131 // Client #0 should have only "foo" set of words.
132 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS
,
133 dictionary_helper::GetDictionarySize(0));
135 // Client #1 should have only "bar" set of words.
136 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS
,
137 dictionary_helper::GetDictionarySize(1));
139 ASSERT_TRUE(GetClient(0)->EnableSyncForAllDatatypes());
140 ASSERT_TRUE(AwaitQuiescence());
142 // Client #0 should have both "foo" and "bar" sets of words.
143 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS
* 2,
144 dictionary_helper::GetDictionarySize(0));
146 // The sync server and client #1 should have only "bar" set of words.
147 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS
,
148 dictionary_helper::GetDictionarySize(1));