1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_DICTIONARY_HELPER_H_ 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_DICTIONARY_HELPER_H_ 7 8 #include <stddef.h> 9 10 #include <set> 11 #include <string> 12 13 #include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h" 14 #include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" 15 16 namespace dictionary_helper { 17 18 // Returns set of words stored in dictionary for given |profile_index|. 19 const std::set<std::string>& GetDictionaryWords(int profile_index); 20 21 // Synchronously loads the dictionaries across all profiles. Returns only after 22 // the dictionaries have finished to load. 23 void LoadDictionaries(); 24 25 // Used to check the size of the dictionary within a particular sync profile. 26 size_t GetDictionarySize(int index); 27 28 // Adds |word| to the dictionary for profile with index |index|. Returns true 29 // if |word| is valid and not a duplicate. Otherwise returns false. 30 bool AddWord(int index, const std::string& word); 31 32 // Add |n| words with the given |prefix| to the specified client |index|. Return 33 // value is true iff all words are not duplicates and valid. 34 bool AddWords(int index, int n, const std::string& prefix); 35 36 // Removes |word| from the dictionary for profile with index |index|. 37 // Returns true if |word| was found. Otherwise returns false. 38 bool RemoveWord(int index, const std::string& word); 39 40 // Checker to block until all clients have expected dictionaries. 41 class DictionaryChecker : public MultiClientStatusChangeChecker { 42 public: 43 explicit DictionaryChecker(const std::vector<std::string>& expected_words); 44 ~DictionaryChecker() override; 45 46 // StatusChangeChecker implementation. 47 bool IsExitConditionSatisfied(std::ostream* os) override; 48 49 private: 50 std::set<std::string> expected_words_; 51 }; 52 53 // Checker to block until the number of dictionary entries to equal to an 54 // expected count. 55 class NumDictionaryEntriesChecker : public SingleClientStatusChangeChecker { 56 public: 57 NumDictionaryEntriesChecker(int index, size_t num_words); 58 ~NumDictionaryEntriesChecker() override = default; 59 60 // StatusChangeChecker implementation. 61 bool IsExitConditionSatisfied(std::ostream* os) override; 62 63 private: 64 int index_; 65 size_t num_words_; 66 }; 67 68 } // namespace dictionary_helper 69 70 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_DICTIONARY_HELPER_H_ 71