Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / dictionary_helper.cc
index 9418339..2d43a56 100644 (file)
@@ -6,11 +6,15 @@
 
 #include <algorithm>
 
+#include "base/format_macros.h"
+#include "base/strings/stringprintf.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/spellchecker/spellcheck_factory.h"
 #include "chrome/browser/spellchecker/spellcheck_service.h"
 #include "chrome/browser/sync/test/integration/dictionary_load_observer.h"
+#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
+#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
 #include "chrome/browser/sync/test/integration/sync_test.h"
 #include "chrome/common/chrome_switches.h"
@@ -94,6 +98,79 @@ bool DictionariesMatch() {
   return true;
 }
 
+namespace {
+
+// Helper class used in the implementation of AwaitDictionariesMatch.
+class DictionaryMatchStatusChecker : public MultiClientStatusChangeChecker {
+ public:
+  DictionaryMatchStatusChecker();
+  virtual ~DictionaryMatchStatusChecker();
+
+  virtual bool IsExitConditionSatisfied() OVERRIDE;
+  virtual std::string GetDebugMessage() const OVERRIDE;
+};
+
+DictionaryMatchStatusChecker::DictionaryMatchStatusChecker()
+    : MultiClientStatusChangeChecker(
+        sync_datatype_helper::test()->GetSyncServices()) {}
+
+DictionaryMatchStatusChecker::~DictionaryMatchStatusChecker() {}
+
+bool DictionaryMatchStatusChecker::IsExitConditionSatisfied() {
+  return DictionariesMatch();
+}
+
+std::string DictionaryMatchStatusChecker::GetDebugMessage() const {
+  return "Waiting for matching dictionaries";
+}
+
+// Helper class used in the implementation of AwaitNumDictionaryEntries.
+class NumDictionaryEntriesStatusChecker
+    : public SingleClientStatusChangeChecker {
+ public:
+  NumDictionaryEntriesStatusChecker(int index, size_t num_words);
+  virtual ~NumDictionaryEntriesStatusChecker();
+
+  virtual bool IsExitConditionSatisfied() OVERRIDE;
+  virtual std::string GetDebugMessage() const OVERRIDE;
+ private:
+  int index_;
+  size_t num_words_;
+};
+
+NumDictionaryEntriesStatusChecker::NumDictionaryEntriesStatusChecker(
+    int index, size_t num_words)
+  : SingleClientStatusChangeChecker(
+      sync_datatype_helper::test()->GetSyncService(index)),
+  index_(index),
+  num_words_(num_words) {}
+
+NumDictionaryEntriesStatusChecker::~NumDictionaryEntriesStatusChecker() {}
+
+bool NumDictionaryEntriesStatusChecker::IsExitConditionSatisfied() {
+  return GetDictionarySize(index_) == num_words_;
+}
+
+std::string NumDictionaryEntriesStatusChecker::GetDebugMessage() const {
+  return base::StringPrintf(
+      "Waiting for client %d: %" PRIuS " / %" PRIuS " words downloaded",
+      index_, GetDictionarySize(index_), num_words_);
+}
+
+}  // namespace
+
+bool AwaitDictionariesMatch() {
+  DictionaryMatchStatusChecker checker;
+  checker.Wait();
+  return !checker.TimedOut();
+}
+
+bool AwaitNumDictionaryEntries(int index, size_t num_words) {
+  NumDictionaryEntriesStatusChecker checker(index, num_words);
+  checker.Wait();
+  return !checker.TimedOut();
+}
+
 bool DictionaryMatchesVerifier(int index) {
   const chrome::spellcheck_common::WordSet& expected =
       GetVerifierDictionary()->GetWords();