multiple_client_dictionary_sync_test.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/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"
10
11class MultipleClientDictionarySyncTest : public SyncTest {
12 public:
13  MultipleClientDictionarySyncTest() : SyncTest(MULTIPLE_CLIENT) {}
14  virtual ~MultipleClientDictionarySyncTest() {}
15
16 private:
17  DISALLOW_COPY_AND_ASSIGN(MultipleClientDictionarySyncTest);
18};
19
20IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddToOne) {
21  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
22  dictionary_helper::LoadDictionaries();
23  ASSERT_TRUE(dictionary_helper::DictionariesMatch());
24
25  ASSERT_TRUE(dictionary_helper::AddWord(0, "foo"));
26  ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
27  ASSERT_TRUE(dictionary_helper::DictionariesMatch());
28}
29
30IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddSameToAll) {
31  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
32  dictionary_helper::LoadDictionaries();
33  ASSERT_TRUE(dictionary_helper::DictionariesMatch());
34
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));
40}
41
42IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, AddDifferentToAll) {
43  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
44  dictionary_helper::LoadDictionaries();
45  ASSERT_TRUE(dictionary_helper::DictionariesMatch());
46
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)));
53}
54
55IN_PROC_BROWSER_TEST_F(MultipleClientDictionarySyncTest, Limit) {
56  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
57  dictionary_helper::LoadDictionaries();
58  ASSERT_TRUE(dictionary_helper::DictionariesMatch());
59
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();
63    for (size_t j = 0;
64         j < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
65         ++j) {
66      ASSERT_TRUE(dictionary_helper::AddWord(
67          i, "foo-" + base::IntToString(i) + "-" + base::Uint64ToString(j)));
68    }
69    ASSERT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS,
70              dictionary_helper::GetDictionarySize(i));
71  }
72
73  // Turn on sync on client #0. The sync server should contain only data from
74  // client #0.
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));
79
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.
89    ASSERT_EQ(
90        chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS * 2,
91        dictionary_helper::GetDictionarySize(i));
92  }
93
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));
98}
99