• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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_integration_test_util.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
10 #include "chrome/common/spellcheck_common.h"
11 
12 using sync_integration_test_util::AwaitCommitActivityCompletion;
13 
14 class TwoClientDictionarySyncTest : public SyncTest {
15  public:
TwoClientDictionarySyncTest()16   TwoClientDictionarySyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientDictionarySyncTest()17   virtual ~TwoClientDictionarySyncTest() {}
18 
TestUsesSelfNotifications()19   virtual bool TestUsesSelfNotifications() OVERRIDE {
20     return false;
21   }
22 
23  private:
24   DISALLOW_COPY_AND_ASSIGN(TwoClientDictionarySyncTest);
25 };
26 
IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest,Sanity)27 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, Sanity) {
28   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
29   dictionary_helper::LoadDictionaries();
30   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
31 
32   std::vector<std::string> words;
33   words.push_back("foo");
34   words.push_back("bar");
35   ASSERT_EQ(num_clients(), static_cast<int>(words.size()));
36 
37   for (int i = 0; i < num_clients(); ++i) {
38     ASSERT_TRUE(dictionary_helper::AddWord(i, words[i]));
39   }
40   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
41   ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0));
42 
43   for (int i = 0; i < num_clients(); ++i) {
44     ASSERT_TRUE(dictionary_helper::RemoveWord(i, words[i]));
45   }
46   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
47   ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0));
48 
49   DisableVerifier();
50   for (int i = 0; i < num_clients(); ++i)
51     ASSERT_TRUE(dictionary_helper::AddWord(i, words[i]));
52   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
53   ASSERT_EQ(words.size(), dictionary_helper::GetDictionarySize(0));
54 }
55 
IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest,SimultaneousAdd)56 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, SimultaneousAdd) {
57   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
58   dictionary_helper::LoadDictionaries();
59   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
60 
61   for (int i = 0; i < num_clients(); ++i)
62     dictionary_helper::AddWord(i, "foo");
63   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
64   ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
65 }
66 
IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest,SimultaneousRemove)67 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, SimultaneousRemove) {
68   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
69   dictionary_helper::LoadDictionaries();
70   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
71 
72   for (int i = 0; i < num_clients(); ++i)
73     dictionary_helper::AddWord(i, "foo");
74   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
75   ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
76 
77   for (int i = 0; i < num_clients(); ++i)
78     dictionary_helper::RemoveWord(i, "foo");
79   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
80   ASSERT_EQ(0UL, dictionary_helper::GetDictionarySize(0));
81 }
82 
IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest,RemoveOnAAddOnB)83 IN_PROC_BROWSER_TEST_F(TwoClientDictionarySyncTest, RemoveOnAAddOnB) {
84   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
85   dictionary_helper::LoadDictionaries();
86   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
87 
88   std::string word = "foo";
89   // Add on client A, check it appears on B.
90   ASSERT_TRUE(dictionary_helper::AddWord(0, word));
91   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
92   // Remove on client A, check it disappears on B.
93   ASSERT_TRUE(dictionary_helper::RemoveWord(0, word));
94   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
95   // Add on client B, check it appears on A.
96   ASSERT_TRUE(dictionary_helper::AddWord(1, word));
97   ASSERT_TRUE(dictionary_helper::AwaitDictionariesMatch());
98   ASSERT_EQ(1UL, dictionary_helper::GetDictionarySize(0));
99 }
100 
101