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