| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/test/integration/dictionary_helper.h" | 5 #include "chrome/browser/sync/test/integration/dictionary_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 8 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 9 #include "chrome/browser/spellchecker/spellcheck_service.h" | 9 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_harness.h" | 10 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 11 #include "chrome/browser/sync/test/integration/dictionary_load_observer.h" | 11 #include "chrome/browser/sync/test/integration/dictionary_load_observer.h" |
| 12 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 12 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 13 #include "chrome/browser/sync/test/integration/sync_test.h" | 13 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/spellcheck_common.h" | 15 #include "chrome/common/spellcheck_common.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 | 17 |
| 18 class DictionarySyncIntegrationTestHelper { | 18 class DictionarySyncIntegrationTestHelper { |
| 19 public: | 19 public: |
| 20 // Same as SpellcheckCustomDictionary::AddWord/RemoveWord, except does not | 20 // Same as SpellcheckCustomDictionary::AddWord/RemoveWord, except does not |
| 21 // write to disk. | 21 // write to disk. |
| 22 static bool ApplyChange( | 22 static bool ApplyChange( |
| 23 SpellcheckCustomDictionary* dictionary, | 23 SpellcheckCustomDictionary* dictionary, |
| 24 SpellcheckCustomDictionary::Change& change) { | 24 SpellcheckCustomDictionary::Change& change) { |
| 25 std::sort(dictionary->words_.begin(), dictionary->words_.end()); | |
| 26 int result = change.Sanitize(dictionary->GetWords()); | 25 int result = change.Sanitize(dictionary->GetWords()); |
| 27 dictionary->Apply(change); | 26 dictionary->Apply(change); |
| 28 dictionary->Notify(change); | 27 dictionary->Notify(change); |
| 29 dictionary->Sync(change); | 28 dictionary->Sync(change); |
| 30 return !result; | 29 return !result; |
| 31 } | 30 } |
| 32 | 31 |
| 33 DISALLOW_COPY_AND_ASSIGN(DictionarySyncIntegrationTestHelper); | 32 DISALLOW_COPY_AND_ASSIGN(DictionarySyncIntegrationTestHelper); |
| 34 }; | 33 }; |
| 35 | 34 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 98 |
| 100 size_t GetDictionarySize(int index) { | 99 size_t GetDictionarySize(int index) { |
| 101 return GetDictionary(index)->GetWords().size(); | 100 return GetDictionary(index)->GetWords().size(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 size_t GetVerifierDictionarySize() { | 103 size_t GetVerifierDictionarySize() { |
| 105 return GetVerifierDictionary()->GetWords().size(); | 104 return GetVerifierDictionary()->GetWords().size(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 bool DictionariesMatch() { | 107 bool DictionariesMatch() { |
| 109 chrome::spellcheck_common::WordList reference = | 108 chrome::spellcheck_common::WordSet reference = |
| 110 sync_datatype_helper::test()->use_verifier() ? | 109 sync_datatype_helper::test()->use_verifier() ? |
| 111 GetVerifierDictionary()->GetWords() : GetDictionary(0)->GetWords(); | 110 GetVerifierDictionary()->GetWords() : GetDictionary(0)->GetWords(); |
| 112 for (int i = 0; i < sync_datatype_helper::test()->num_clients(); ++i) { | 111 for (int i = 0; i < sync_datatype_helper::test()->num_clients(); ++i) { |
| 113 if (reference.size() != GetDictionary(i)->GetWords().size()) | 112 if (reference.size() != GetDictionary(i)->GetWords().size()) |
| 114 return false; | 113 return false; |
| 115 } | 114 } |
| 116 for (chrome::spellcheck_common::WordList::iterator it = reference.begin(); | 115 for (chrome::spellcheck_common::WordSet::iterator it = reference.begin(); |
| 117 it != reference.end(); | 116 it != reference.end(); |
| 118 ++it) { | 117 ++it) { |
| 119 if (!HaveWordMatches(*it)) | 118 if (!HaveWordMatches(*it)) |
| 120 return false; | 119 return false; |
| 121 } | 120 } |
| 122 return true; | 121 return true; |
| 123 } | 122 } |
| 124 | 123 |
| 125 bool DictionaryMatchesVerifier(int index) { | 124 bool DictionaryMatchesVerifier(int index) { |
| 126 chrome::spellcheck_common::WordList expected = | 125 chrome::spellcheck_common::WordSet expected = |
| 127 GetVerifierDictionary()->GetWords(); | 126 GetVerifierDictionary()->GetWords(); |
| 128 chrome::spellcheck_common::WordList actual = GetDictionary(index)->GetWords(); | 127 chrome::spellcheck_common::WordSet actual = GetDictionary(index)->GetWords(); |
| 129 if (expected.size() != actual.size()) | 128 if (expected.size() != actual.size()) |
| 130 return false; | 129 return false; |
| 131 for (chrome::spellcheck_common::WordList::iterator it = expected.begin(); | 130 for (chrome::spellcheck_common::WordSet::iterator it = expected.begin(); |
| 132 it != expected.end(); | 131 it != expected.end(); |
| 133 ++it) { | 132 ++it) { |
| 134 if (actual.end() == std::find(actual.begin(), actual.end(), *it)) | 133 if (actual.end() == std::find(actual.begin(), actual.end(), *it)) |
| 135 return false; | 134 return false; |
| 136 } | 135 } |
| 137 return true; | 136 return true; |
| 138 } | 137 } |
| 139 | 138 |
| 140 bool AddWord(int index, const std::string& word) { | 139 bool AddWord(int index, const std::string& word) { |
| 141 SpellcheckCustomDictionary::Change dictionary_change; | 140 SpellcheckCustomDictionary::Change dictionary_change; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 bool result = DictionarySyncIntegrationTestHelper::ApplyChange( | 154 bool result = DictionarySyncIntegrationTestHelper::ApplyChange( |
| 156 GetDictionary(index), dictionary_change); | 155 GetDictionary(index), dictionary_change); |
| 157 if (sync_datatype_helper::test()->use_verifier()) { | 156 if (sync_datatype_helper::test()->use_verifier()) { |
| 158 result &= DictionarySyncIntegrationTestHelper::ApplyChange( | 157 result &= DictionarySyncIntegrationTestHelper::ApplyChange( |
| 159 GetVerifierDictionary(), dictionary_change); | 158 GetVerifierDictionary(), dictionary_change); |
| 160 } | 159 } |
| 161 return result; | 160 return result; |
| 162 } | 161 } |
| 163 | 162 |
| 164 } // namespace dictionary_helper | 163 } // namespace dictionary_helper |
| OLD | NEW |