Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/browser/sync/test/integration/two_client_dictionary_sync_test.cc

Issue 11445002: Sync user's custom spellcheck dictionary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge master Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 ASSERT_TRUE(AwaitQuiescence());
105 // Add on client B
106 ASSERT_TRUE(dictionary_helper::AddWord(1, word));
107 ASSERT_TRUE(AwaitQuiescence());
108 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
109 ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
110
111 MessageLoop::current()->RunUntilIdle();
112 }
113
114 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, DisableSync) {
115 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
116 dictionary_helper::LoadDictionaries();
117 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
118
119 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
120 ASSERT_TRUE(dictionary_helper::AddWord(0, "foo"));
121 ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion("Added a word"));
122 ASSERT_TRUE(dictionary_helper::DictionaryMatchesVerifier(0));
123 ASSERT_FALSE(dictionary_helper::DictionaryMatchesVerifier(1));
124
125 MessageLoop::current()->RunUntilIdle();
126 }
127
128 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Limit) {
129 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
130 dictionary_helper::LoadDictionaries();
131 ASSERT_TRUE(dictionary_helper::DictionariesMatch());
132
133 ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes());
134 for (size_t i = 0;
135 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
136 ++i) {
137 ASSERT_TRUE(dictionary_helper::AddWord(
138 0, "foo" + base::Uint64ToString(i)));
139 ASSERT_TRUE(dictionary_helper::AddWord(
140 1, "bar" + base::Uint64ToString(i)));
141 }
142 ASSERT_TRUE(AwaitQuiescence());
143 ASSERT_FALSE(dictionary_helper::DictionariesMatch());
144
145 // Client #0 should have only "foo" set of words.
146 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
147 dictionary_helper::GetDictionarySize(0));
148
149 // Client #1 should have only "bar" set of words.
150 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
151 dictionary_helper::GetDictionarySize(1));
152
153 ASSERT_TRUE(GetClient(0)->EnableSyncForAllDatatypes());
154 ASSERT_TRUE(AwaitQuiescence());
155
156 // Client #0 should have both "foo" and "bar" sets of words.
157 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2,
158 dictionary_helper::GetDictionarySize(0));
159
160 // The sync server and client #1 should have only "bar" set of words.
161 ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
162 dictionary_helper::GetDictionarySize(1));
163
164 MessageLoop::current()->RunUntilIdle();
165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698