| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/metrics/histogram.h" | |
| 10 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 11 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 12 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | 11 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
| 14 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 12 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 13 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 16 #include "chrome/browser/spellchecker/spellcheck_service.h" | 14 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 17 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/common/spellcheck_common.h" | 16 #include "chrome/common/spellcheck_common.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 20 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "net/url_request/test_url_fetcher_factory.h" |
| 21 #include "sync/api/sync_change.h" | 20 #include "sync/api/sync_change.h" |
| 22 #include "sync/api/sync_data.h" | 21 #include "sync/api/sync_data.h" |
| 23 #include "sync/api/sync_error_factory.h" | 22 #include "sync/api/sync_error_factory.h" |
| 24 #include "sync/api/sync_error_factory_mock.h" | 23 #include "sync/api/sync_error_factory_mock.h" |
| 25 #include "sync/protocol/sync.pb.h" | 24 #include "sync/protocol/sync.pb.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 27 |
| 29 using base::HistogramBase; | 28 using base::HistogramBase; |
| 30 using base::HistogramSamples; | 29 using base::HistogramSamples; |
| 31 using base::StatisticsRecorder; | 30 using base::StatisticsRecorder; |
| 32 using content::BrowserThread; | |
| 33 using chrome::spellcheck_common::WordList; | 31 using chrome::spellcheck_common::WordList; |
| 34 using chrome::spellcheck_common::WordSet; | 32 using chrome::spellcheck_common::WordSet; |
| 35 | 33 |
| 36 namespace { | 34 namespace { |
| 37 | 35 |
| 38 // Get all sync data for the custom dictionary without limiting to maximum | 36 // Get all sync data for the custom dictionary without limiting to maximum |
| 39 // number of syncable words. | 37 // number of syncable words. |
| 40 syncer::SyncDataList GetAllSyncDataNoLimit( | 38 syncer::SyncDataList GetAllSyncDataNoLimit( |
| 41 const SpellcheckCustomDictionary* dictionary) { | 39 const SpellcheckCustomDictionary* dictionary) { |
| 42 syncer::SyncDataList data; | 40 syncer::SyncDataList data; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 | 51 |
| 54 } // namespace | 52 } // namespace |
| 55 | 53 |
| 56 static BrowserContextKeyedService* BuildSpellcheckService( | 54 static BrowserContextKeyedService* BuildSpellcheckService( |
| 57 content::BrowserContext* profile) { | 55 content::BrowserContext* profile) { |
| 58 return new SpellcheckService(static_cast<Profile*>(profile)); | 56 return new SpellcheckService(static_cast<Profile*>(profile)); |
| 59 } | 57 } |
| 60 | 58 |
| 61 class SpellcheckCustomDictionaryTest : public testing::Test { | 59 class SpellcheckCustomDictionaryTest : public testing::Test { |
| 62 protected: | 60 protected: |
| 63 SpellcheckCustomDictionaryTest() | |
| 64 : ui_thread_(BrowserThread::UI, &message_loop_), | |
| 65 file_thread_(BrowserThread::FILE, &message_loop_), | |
| 66 profile_(new TestingProfile) { | |
| 67 } | |
| 68 | |
| 69 virtual void SetUp() OVERRIDE { | 61 virtual void SetUp() OVERRIDE { |
| 70 // Use SetTestingFactoryAndUse to force creation and initialization. | 62 // Use SetTestingFactoryAndUse to force creation and initialization. |
| 71 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 63 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 72 profile_.get(), &BuildSpellcheckService); | 64 &profile_, &BuildSpellcheckService); |
| 73 | 65 |
| 74 StatisticsRecorder::Initialize(); | 66 StatisticsRecorder::Initialize(); |
| 75 } | 67 } |
| 76 | 68 |
| 77 virtual void TearDown() OVERRIDE { | |
| 78 base::MessageLoop::current()->RunUntilIdle(); | |
| 79 } | |
| 80 | |
| 81 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private | 69 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private |
| 82 // function to avoid a large number of FRIEND_TEST declarations in | 70 // function to avoid a large number of FRIEND_TEST declarations in |
| 83 // SpellcheckCustomDictionary. | 71 // SpellcheckCustomDictionary. |
| 84 chrome::spellcheck_common::WordList LoadDictionaryFile( | 72 chrome::spellcheck_common::WordList LoadDictionaryFile( |
| 85 const base::FilePath& path) { | 73 const base::FilePath& path) { |
| 86 return SpellcheckCustomDictionary::LoadDictionaryFile(path); | 74 return SpellcheckCustomDictionary::LoadDictionaryFile(path); |
| 87 } | 75 } |
| 88 | 76 |
| 89 // A wrapper around SpellcheckCustomDictionary::UpdateDictionaryFile private | 77 // A wrapper around SpellcheckCustomDictionary::UpdateDictionaryFile private |
| 90 // function to avoid a large number of FRIEND_TEST declarations in | 78 // function to avoid a large number of FRIEND_TEST declarations in |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 } | 93 } |
| 106 | 94 |
| 107 // A wrapper around SpellcheckCustomDictionary::Apply private method to avoid | 95 // A wrapper around SpellcheckCustomDictionary::Apply private method to avoid |
| 108 // a large number of FRIEND_TEST declarations in SpellcheckCustomDictionary. | 96 // a large number of FRIEND_TEST declarations in SpellcheckCustomDictionary. |
| 109 void Apply( | 97 void Apply( |
| 110 SpellcheckCustomDictionary& dictionary, | 98 SpellcheckCustomDictionary& dictionary, |
| 111 const SpellcheckCustomDictionary::Change& change) { | 99 const SpellcheckCustomDictionary::Change& change) { |
| 112 return dictionary.Apply(change); | 100 return dictionary.Apply(change); |
| 113 } | 101 } |
| 114 | 102 |
| 115 base::MessageLoop message_loop_; | 103 content::TestBrowserThreadBundle thread_bundle_; |
| 116 content::TestBrowserThread ui_thread_; | |
| 117 content::TestBrowserThread file_thread_; | |
| 118 | 104 |
| 119 scoped_ptr<TestingProfile> profile_; | 105 TestingProfile profile_; |
| 106 net::TestURLFetcherFactory fetcher_factory_; |
| 120 }; | 107 }; |
| 121 | 108 |
| 122 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped | 109 // A wrapper around SpellcheckCustomDictionary that does not own the wrapped |
| 123 // object. An instance of this class can be inside of a scoped pointer safely | 110 // object. An instance of this class can be inside of a scoped pointer safely |
| 124 // while the dictionary is managed by another scoped pointer. | 111 // while the dictionary is managed by another scoped pointer. |
| 125 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { | 112 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { |
| 126 public: | 113 public: |
| 127 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary) | 114 explicit SyncChangeProcessorDelegate(SpellcheckCustomDictionary* dictionary) |
| 128 : dictionary_(dictionary) {} | 115 : dictionary_(dictionary) {} |
| 129 virtual ~SyncChangeProcessorDelegate() {} | 116 virtual ~SyncChangeProcessorDelegate() {} |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const SpellcheckCustomDictionary::Change& change) OVERRIDE { changes_++; } | 167 const SpellcheckCustomDictionary::Change& change) OVERRIDE { changes_++; } |
| 181 | 168 |
| 182 private: | 169 private: |
| 183 int loads_; | 170 int loads_; |
| 184 int changes_; | 171 int changes_; |
| 185 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); | 172 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); |
| 186 }; | 173 }; |
| 187 | 174 |
| 188 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { | 175 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { |
| 189 base::FilePath path = | 176 base::FilePath path = |
| 190 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 177 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 191 WordList loaded_custom_words = LoadDictionaryFile(path); | 178 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 192 | 179 |
| 193 // The custom word list should be empty now. | 180 // The custom word list should be empty now. |
| 194 WordList expected; | 181 WordList expected; |
| 195 EXPECT_EQ(expected, loaded_custom_words); | 182 EXPECT_EQ(expected, loaded_custom_words); |
| 196 | 183 |
| 197 SpellcheckCustomDictionary::Change change; | 184 SpellcheckCustomDictionary::Change change; |
| 198 change.AddWord("bar"); | 185 change.AddWord("bar"); |
| 199 change.AddWord("foo"); | 186 change.AddWord("foo"); |
| 200 | 187 |
| 201 UpdateDictionaryFile(change, path); | 188 UpdateDictionaryFile(change, path); |
| 202 expected.push_back("bar"); | 189 expected.push_back("bar"); |
| 203 expected.push_back("foo"); | 190 expected.push_back("foo"); |
| 204 | 191 |
| 205 // The custom word list should include written words. | 192 // The custom word list should include written words. |
| 206 loaded_custom_words = LoadDictionaryFile(path); | 193 loaded_custom_words = LoadDictionaryFile(path); |
| 207 EXPECT_EQ(expected, loaded_custom_words); | 194 EXPECT_EQ(expected, loaded_custom_words); |
| 208 | 195 |
| 209 change = SpellcheckCustomDictionary::Change(); | 196 change = SpellcheckCustomDictionary::Change(); |
| 210 change.RemoveWord("bar"); | 197 change.RemoveWord("bar"); |
| 211 change.RemoveWord("foo"); | 198 change.RemoveWord("foo"); |
| 212 UpdateDictionaryFile(change, path); | 199 UpdateDictionaryFile(change, path); |
| 213 loaded_custom_words = LoadDictionaryFile(path); | 200 loaded_custom_words = LoadDictionaryFile(path); |
| 214 expected.clear(); | 201 expected.clear(); |
| 215 EXPECT_EQ(expected, loaded_custom_words); | 202 EXPECT_EQ(expected, loaded_custom_words); |
| 216 } | 203 } |
| 217 | 204 |
| 218 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { | 205 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { |
| 219 SpellcheckService* spellcheck_service = | 206 SpellcheckService* spellcheck_service = |
| 220 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 207 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 221 SpellcheckCustomDictionary* custom_dictionary = | 208 SpellcheckCustomDictionary* custom_dictionary = |
| 222 spellcheck_service->GetCustomDictionary(); | 209 spellcheck_service->GetCustomDictionary(); |
| 223 TestingProfile profile2; | 210 TestingProfile profile2; |
| 224 SpellcheckService* spellcheck_service2 = | 211 SpellcheckService* spellcheck_service2 = |
| 225 static_cast<SpellcheckService*>( | 212 static_cast<SpellcheckService*>( |
| 226 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 213 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 227 &profile2, &BuildSpellcheckService)); | 214 &profile2, &BuildSpellcheckService)); |
| 228 SpellcheckCustomDictionary* custom_dictionary2 = | 215 SpellcheckCustomDictionary* custom_dictionary2 = |
| 229 spellcheck_service2->GetCustomDictionary(); | 216 spellcheck_service2->GetCustomDictionary(); |
| 230 | 217 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 244 WordSet actual1 = custom_dictionary->GetWords(); | 231 WordSet actual1 = custom_dictionary->GetWords(); |
| 245 EXPECT_EQ(actual1, expected1); | 232 EXPECT_EQ(actual1, expected1); |
| 246 | 233 |
| 247 WordSet actual2 = custom_dictionary2->GetWords(); | 234 WordSet actual2 = custom_dictionary2->GetWords(); |
| 248 EXPECT_EQ(actual2, expected2); | 235 EXPECT_EQ(actual2, expected2); |
| 249 } | 236 } |
| 250 | 237 |
| 251 // Legacy empty dictionary should be converted to new format empty dictionary. | 238 // Legacy empty dictionary should be converted to new format empty dictionary. |
| 252 TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) { | 239 TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) { |
| 253 base::FilePath path = | 240 base::FilePath path = |
| 254 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 241 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 255 | 242 |
| 256 std::string content; | 243 std::string content; |
| 257 file_util::WriteFile(path, content.c_str(), content.length()); | 244 file_util::WriteFile(path, content.c_str(), content.length()); |
| 258 WordList loaded_custom_words = LoadDictionaryFile(path); | 245 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 259 EXPECT_TRUE(loaded_custom_words.empty()); | 246 EXPECT_TRUE(loaded_custom_words.empty()); |
| 260 } | 247 } |
| 261 | 248 |
| 262 // Legacy dictionary with two words should be converted to new format dictionary | 249 // Legacy dictionary with two words should be converted to new format dictionary |
| 263 // with two words. | 250 // with two words. |
| 264 TEST_F(SpellcheckCustomDictionaryTest, | 251 TEST_F(SpellcheckCustomDictionaryTest, |
| 265 LegacyDictionaryWithTwoWordsShouldBeConverted) { | 252 LegacyDictionaryWithTwoWordsShouldBeConverted) { |
| 266 base::FilePath path = | 253 base::FilePath path = |
| 267 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 254 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 268 | 255 |
| 269 std::string content = "foo\nbar\nfoo\n"; | 256 std::string content = "foo\nbar\nfoo\n"; |
| 270 file_util::WriteFile(path, content.c_str(), content.length()); | 257 file_util::WriteFile(path, content.c_str(), content.length()); |
| 271 WordList loaded_custom_words = LoadDictionaryFile(path); | 258 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 272 WordList expected; | 259 WordList expected; |
| 273 expected.push_back("bar"); | 260 expected.push_back("bar"); |
| 274 expected.push_back("foo"); | 261 expected.push_back("foo"); |
| 275 EXPECT_EQ(expected, loaded_custom_words); | 262 EXPECT_EQ(expected, loaded_custom_words); |
| 276 } | 263 } |
| 277 | 264 |
| 278 // Illegal words should be removed. Leading and trailing whitespace should be | 265 // Illegal words should be removed. Leading and trailing whitespace should be |
| 279 // trimmed. | 266 // trimmed. |
| 280 TEST_F(SpellcheckCustomDictionaryTest, | 267 TEST_F(SpellcheckCustomDictionaryTest, |
| 281 IllegalWordsShouldBeRemovedFromDictionary) { | 268 IllegalWordsShouldBeRemovedFromDictionary) { |
| 282 base::FilePath path = | 269 base::FilePath path = |
| 283 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 270 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 284 | 271 |
| 285 std::string content = "foo\n foo bar \n\n \nbar\n" | 272 std::string content = "foo\n foo bar \n\n \nbar\n" |
| 286 "01234567890123456789012345678901234567890123456789" | 273 "01234567890123456789012345678901234567890123456789" |
| 287 "01234567890123456789012345678901234567890123456789"; | 274 "01234567890123456789012345678901234567890123456789"; |
| 288 file_util::WriteFile(path, content.c_str(), content.length()); | 275 file_util::WriteFile(path, content.c_str(), content.length()); |
| 289 WordList loaded_custom_words = LoadDictionaryFile(path); | 276 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 290 WordList expected; | 277 WordList expected; |
| 291 expected.push_back("bar"); | 278 expected.push_back("bar"); |
| 292 expected.push_back("foo"); | 279 expected.push_back("foo"); |
| 293 expected.push_back("foo bar"); | 280 expected.push_back("foo bar"); |
| 294 EXPECT_EQ(expected, loaded_custom_words); | 281 EXPECT_EQ(expected, loaded_custom_words); |
| 295 } | 282 } |
| 296 | 283 |
| 297 // Write to dictionary should backup previous version and write the word to the | 284 // Write to dictionary should backup previous version and write the word to the |
| 298 // end of the dictionary. If the dictionary file is corrupted on disk, the | 285 // end of the dictionary. If the dictionary file is corrupted on disk, the |
| 299 // previous version should be reloaded. | 286 // previous version should be reloaded. |
| 300 TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) { | 287 TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) { |
| 301 base::FilePath path = | 288 base::FilePath path = |
| 302 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 289 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 303 | 290 |
| 304 std::string content = "foo\nbar"; | 291 std::string content = "foo\nbar"; |
| 305 file_util::WriteFile(path, content.c_str(), content.length()); | 292 file_util::WriteFile(path, content.c_str(), content.length()); |
| 306 WordList loaded_custom_words = LoadDictionaryFile(path); | 293 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 307 WordList expected; | 294 WordList expected; |
| 308 expected.push_back("bar"); | 295 expected.push_back("bar"); |
| 309 expected.push_back("foo"); | 296 expected.push_back("foo"); |
| 310 EXPECT_EQ(expected, loaded_custom_words); | 297 EXPECT_EQ(expected, loaded_custom_words); |
| 311 | 298 |
| 312 SpellcheckCustomDictionary::Change change; | 299 SpellcheckCustomDictionary::Change change; |
| 313 change.AddWord("baz"); | 300 change.AddWord("baz"); |
| 314 UpdateDictionaryFile(change, path); | 301 UpdateDictionaryFile(change, path); |
| 315 content.clear(); | 302 content.clear(); |
| 316 file_util::ReadFileToString(path, &content); | 303 file_util::ReadFileToString(path, &content); |
| 317 content.append("corruption"); | 304 content.append("corruption"); |
| 318 file_util::WriteFile(path, content.c_str(), content.length()); | 305 file_util::WriteFile(path, content.c_str(), content.length()); |
| 319 loaded_custom_words = LoadDictionaryFile(path); | 306 loaded_custom_words = LoadDictionaryFile(path); |
| 320 EXPECT_EQ(expected, loaded_custom_words); | 307 EXPECT_EQ(expected, loaded_custom_words); |
| 321 } | 308 } |
| 322 | 309 |
| 323 TEST_F(SpellcheckCustomDictionaryTest, | 310 TEST_F(SpellcheckCustomDictionaryTest, |
| 324 GetAllSyncDataAccuratelyReflectsDictionaryState) { | 311 GetAllSyncDataAccuratelyReflectsDictionaryState) { |
| 325 SpellcheckCustomDictionary* dictionary = | 312 SpellcheckCustomDictionary* dictionary = |
| 326 SpellcheckServiceFactory::GetForProfile( | 313 SpellcheckServiceFactory::GetForProfile( |
| 327 profile_.get())->GetCustomDictionary(); | 314 &profile_)->GetCustomDictionary(); |
| 328 | 315 |
| 329 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 316 syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
| 330 EXPECT_TRUE(data.empty()); | 317 EXPECT_TRUE(data.empty()); |
| 331 | 318 |
| 332 EXPECT_TRUE(dictionary->AddWord("bar")); | 319 EXPECT_TRUE(dictionary->AddWord("bar")); |
| 333 EXPECT_TRUE(dictionary->AddWord("foo")); | 320 EXPECT_TRUE(dictionary->AddWord("foo")); |
| 334 | 321 |
| 335 data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 322 data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
| 336 EXPECT_EQ(2UL, data.size()); | 323 EXPECT_EQ(2UL, data.size()); |
| 337 std::vector<std::string> words; | 324 std::vector<std::string> words; |
| 338 words.push_back("bar"); | 325 words.push_back("bar"); |
| 339 words.push_back("foo"); | 326 words.push_back("foo"); |
| 340 for (size_t i = 0; i < data.size(); i++) { | 327 for (size_t i = 0; i < data.size(); i++) { |
| 341 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary()); | 328 EXPECT_TRUE(data[i].GetSpecifics().has_dictionary()); |
| 342 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType()); | 329 EXPECT_EQ(syncer::DICTIONARY, data[i].GetDataType()); |
| 343 EXPECT_EQ(words[i], data[i].GetTag()); | 330 EXPECT_EQ(words[i], data[i].GetTag()); |
| 344 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word()); | 331 EXPECT_EQ(words[i], data[i].GetSpecifics().dictionary().word()); |
| 345 } | 332 } |
| 346 | 333 |
| 347 EXPECT_TRUE(dictionary->RemoveWord("bar")); | 334 EXPECT_TRUE(dictionary->RemoveWord("bar")); |
| 348 EXPECT_TRUE(dictionary->RemoveWord("foo")); | 335 EXPECT_TRUE(dictionary->RemoveWord("foo")); |
| 349 | 336 |
| 350 data = dictionary->GetAllSyncData(syncer::DICTIONARY); | 337 data = dictionary->GetAllSyncData(syncer::DICTIONARY); |
| 351 EXPECT_TRUE(data.empty()); | 338 EXPECT_TRUE(data.empty()); |
| 352 } | 339 } |
| 353 | 340 |
| 354 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { | 341 TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) { |
| 355 SpellcheckCustomDictionary* dictionary = | 342 SpellcheckCustomDictionary* dictionary = |
| 356 SpellcheckServiceFactory::GetForProfile( | 343 SpellcheckServiceFactory::GetForProfile( |
| 357 profile_.get())->GetCustomDictionary(); | 344 &profile_)->GetCustomDictionary(); |
| 358 | 345 |
| 359 SpellcheckCustomDictionary::Change change; | 346 SpellcheckCustomDictionary::Change change; |
| 360 for (size_t i = 0; | 347 for (size_t i = 0; |
| 361 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; | 348 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1; |
| 362 i++) { | 349 i++) { |
| 363 change.AddWord("foo" + base::Uint64ToString(i)); | 350 change.AddWord("foo" + base::Uint64ToString(i)); |
| 364 } | 351 } |
| 365 Apply(*dictionary, change); | 352 Apply(*dictionary, change); |
| 366 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, | 353 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS - 1, |
| 367 dictionary->GetWords().size()); | 354 dictionary->GetWords().size()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 382 | 369 |
| 383 dictionary->AddWord("snafoo"); | 370 dictionary->AddWord("snafoo"); |
| 384 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, | 371 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS + 2, |
| 385 dictionary->GetWords().size()); | 372 dictionary->GetWords().size()); |
| 386 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 373 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 387 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 374 dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 388 } | 375 } |
| 389 | 376 |
| 390 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { | 377 TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) { |
| 391 SpellcheckService* spellcheck_service = | 378 SpellcheckService* spellcheck_service = |
| 392 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 379 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 393 SpellcheckCustomDictionary* dictionary = | 380 SpellcheckCustomDictionary* dictionary = |
| 394 spellcheck_service->GetCustomDictionary(); | 381 spellcheck_service->GetCustomDictionary(); |
| 395 | 382 |
| 396 dictionary->AddWord("foo"); | 383 dictionary->AddWord("foo"); |
| 397 dictionary->AddWord("bar"); | 384 dictionary->AddWord("bar"); |
| 398 | 385 |
| 399 syncer::SyncChangeList changes; | 386 syncer::SyncChangeList changes; |
| 400 { | 387 { |
| 401 // Add existing word. | 388 // Add existing word. |
| 402 std::string word = "foo"; | 389 std::string word = "foo"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 440 |
| 454 const WordSet& words = dictionary->GetWords(); | 441 const WordSet& words = dictionary->GetWords(); |
| 455 EXPECT_EQ(2UL, words.size()); | 442 EXPECT_EQ(2UL, words.size()); |
| 456 EXPECT_EQ(0UL, words.count("bar")); | 443 EXPECT_EQ(0UL, words.count("bar")); |
| 457 EXPECT_EQ(1UL, words.count("foo")); | 444 EXPECT_EQ(1UL, words.count("foo")); |
| 458 EXPECT_EQ(1UL, words.count("baz")); | 445 EXPECT_EQ(1UL, words.count("baz")); |
| 459 } | 446 } |
| 460 | 447 |
| 461 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) { | 448 TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) { |
| 462 SpellcheckService* spellcheck_service = | 449 SpellcheckService* spellcheck_service = |
| 463 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 450 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 464 SpellcheckCustomDictionary* custom_dictionary = | 451 SpellcheckCustomDictionary* custom_dictionary = |
| 465 spellcheck_service->GetCustomDictionary(); | 452 spellcheck_service->GetCustomDictionary(); |
| 466 TestingProfile profile2; | 453 TestingProfile profile2; |
| 467 SpellcheckService* spellcheck_service2 = | 454 SpellcheckService* spellcheck_service2 = |
| 468 static_cast<SpellcheckService*>( | 455 static_cast<SpellcheckService*>( |
| 469 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 456 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 470 &profile2, &BuildSpellcheckService)); | 457 &profile2, &BuildSpellcheckService)); |
| 471 SpellcheckCustomDictionary* custom_dictionary2 = | 458 SpellcheckCustomDictionary* custom_dictionary2 = |
| 472 spellcheck_service2->GetCustomDictionary(); | 459 spellcheck_service2->GetCustomDictionary(); |
| 473 | 460 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 499 EXPECT_TRUE(custom_dictionary->IsSyncing()); | 486 EXPECT_TRUE(custom_dictionary->IsSyncing()); |
| 500 | 487 |
| 501 WordSet words = custom_dictionary->GetWords(); | 488 WordSet words = custom_dictionary->GetWords(); |
| 502 WordSet words2 = custom_dictionary2->GetWords(); | 489 WordSet words2 = custom_dictionary2->GetWords(); |
| 503 EXPECT_EQ(words.size(), words2.size()); | 490 EXPECT_EQ(words.size(), words2.size()); |
| 504 EXPECT_EQ(words, words2); | 491 EXPECT_EQ(words, words2); |
| 505 } | 492 } |
| 506 | 493 |
| 507 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) { | 494 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) { |
| 508 SpellcheckService* spellcheck_service = | 495 SpellcheckService* spellcheck_service = |
| 509 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 496 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 510 SpellcheckCustomDictionary* custom_dictionary = | 497 SpellcheckCustomDictionary* custom_dictionary = |
| 511 spellcheck_service->GetCustomDictionary(); | 498 spellcheck_service->GetCustomDictionary(); |
| 512 TestingProfile profile2; | 499 TestingProfile profile2; |
| 513 SpellcheckService* spellcheck_service2 = | 500 SpellcheckService* spellcheck_service2 = |
| 514 static_cast<SpellcheckService*>( | 501 static_cast<SpellcheckService*>( |
| 515 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 502 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 516 &profile2, &BuildSpellcheckService)); | 503 &profile2, &BuildSpellcheckService)); |
| 517 SpellcheckCustomDictionary* custom_dictionary2 = | 504 SpellcheckCustomDictionary* custom_dictionary2 = |
| 518 spellcheck_service2->GetCustomDictionary(); | 505 spellcheck_service2->GetCustomDictionary(); |
| 519 | 506 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 542 custom_dictionary2->GetWords().size()); | 529 custom_dictionary2->GetWords().size()); |
| 543 | 530 |
| 544 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 531 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 545 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 532 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 546 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 533 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 547 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 534 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 548 } | 535 } |
| 549 | 536 |
| 550 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { | 537 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) { |
| 551 SpellcheckService* spellcheck_service = | 538 SpellcheckService* spellcheck_service = |
| 552 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 539 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 553 SpellcheckCustomDictionary* custom_dictionary = | 540 SpellcheckCustomDictionary* custom_dictionary = |
| 554 spellcheck_service->GetCustomDictionary(); | 541 spellcheck_service->GetCustomDictionary(); |
| 555 TestingProfile profile2; | 542 TestingProfile profile2; |
| 556 SpellcheckService* spellcheck_service2 = | 543 SpellcheckService* spellcheck_service2 = |
| 557 static_cast<SpellcheckService*>( | 544 static_cast<SpellcheckService*>( |
| 558 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 545 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 559 &profile2, &BuildSpellcheckService)); | 546 &profile2, &BuildSpellcheckService)); |
| 560 SpellcheckCustomDictionary* custom_dictionary2 = | 547 SpellcheckCustomDictionary* custom_dictionary2 = |
| 561 spellcheck_service2->GetCustomDictionary(); | 548 spellcheck_service2->GetCustomDictionary(); |
| 562 | 549 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 custom_dictionary2->GetWords().size()); | 581 custom_dictionary2->GetWords().size()); |
| 595 | 582 |
| 596 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 583 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 597 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 584 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 598 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 585 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 599 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 586 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 600 } | 587 } |
| 601 | 588 |
| 602 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { | 589 TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) { |
| 603 SpellcheckService* spellcheck_service = | 590 SpellcheckService* spellcheck_service = |
| 604 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 591 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 605 SpellcheckCustomDictionary* custom_dictionary = | 592 SpellcheckCustomDictionary* custom_dictionary = |
| 606 spellcheck_service->GetCustomDictionary(); | 593 spellcheck_service->GetCustomDictionary(); |
| 607 TestingProfile profile2; | 594 TestingProfile profile2; |
| 608 SpellcheckService* spellcheck_service2 = | 595 SpellcheckService* spellcheck_service2 = |
| 609 static_cast<SpellcheckService*>( | 596 static_cast<SpellcheckService*>( |
| 610 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 597 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 611 &profile2, &BuildSpellcheckService)); | 598 &profile2, &BuildSpellcheckService)); |
| 612 SpellcheckCustomDictionary* custom_dictionary2 = | 599 SpellcheckCustomDictionary* custom_dictionary2 = |
| 613 spellcheck_service2->GetCustomDictionary(); | 600 spellcheck_service2->GetCustomDictionary(); |
| 614 | 601 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 645 custom_dictionary2->GetWords().size()); | 632 custom_dictionary2->GetWords().size()); |
| 646 | 633 |
| 647 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 634 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 648 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 635 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 649 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 636 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 650 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 637 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 651 } | 638 } |
| 652 | 639 |
| 653 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { | 640 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) { |
| 654 SpellcheckService* spellcheck_service = | 641 SpellcheckService* spellcheck_service = |
| 655 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 642 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 656 SpellcheckCustomDictionary* custom_dictionary = | 643 SpellcheckCustomDictionary* custom_dictionary = |
| 657 spellcheck_service->GetCustomDictionary(); | 644 spellcheck_service->GetCustomDictionary(); |
| 658 TestingProfile profile2; | 645 TestingProfile profile2; |
| 659 SpellcheckService* spellcheck_service2 = | 646 SpellcheckService* spellcheck_service2 = |
| 660 static_cast<SpellcheckService*>( | 647 static_cast<SpellcheckService*>( |
| 661 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 648 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 662 &profile2, &BuildSpellcheckService)); | 649 &profile2, &BuildSpellcheckService)); |
| 663 SpellcheckCustomDictionary* custom_dictionary2 = | 650 SpellcheckCustomDictionary* custom_dictionary2 = |
| 664 spellcheck_service2->GetCustomDictionary(); | 651 spellcheck_service2->GetCustomDictionary(); |
| 665 | 652 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 691 custom_dictionary2->GetWords().size()); | 678 custom_dictionary2->GetWords().size()); |
| 692 | 679 |
| 693 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 680 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 694 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 681 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 695 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 682 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 696 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 683 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 697 } | 684 } |
| 698 | 685 |
| 699 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { | 686 TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) { |
| 700 SpellcheckService* spellcheck_service = | 687 SpellcheckService* spellcheck_service = |
| 701 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 688 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 702 SpellcheckCustomDictionary* custom_dictionary = | 689 SpellcheckCustomDictionary* custom_dictionary = |
| 703 spellcheck_service->GetCustomDictionary(); | 690 spellcheck_service->GetCustomDictionary(); |
| 704 TestingProfile profile2; | 691 TestingProfile profile2; |
| 705 SpellcheckService* spellcheck_service2 = | 692 SpellcheckService* spellcheck_service2 = |
| 706 static_cast<SpellcheckService*>( | 693 static_cast<SpellcheckService*>( |
| 707 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 694 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 708 &profile2, &BuildSpellcheckService)); | 695 &profile2, &BuildSpellcheckService)); |
| 709 SpellcheckCustomDictionary* custom_dictionary2 = | 696 SpellcheckCustomDictionary* custom_dictionary2 = |
| 710 spellcheck_service2->GetCustomDictionary(); | 697 spellcheck_service2->GetCustomDictionary(); |
| 711 | 698 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 742 custom_dictionary2->GetWords().size()); | 729 custom_dictionary2->GetWords().size()); |
| 743 | 730 |
| 744 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 731 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 745 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 732 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 746 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 733 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 747 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 734 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 748 } | 735 } |
| 749 | 736 |
| 750 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { | 737 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) { |
| 751 SpellcheckService* spellcheck_service = | 738 SpellcheckService* spellcheck_service = |
| 752 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 739 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 753 SpellcheckCustomDictionary* custom_dictionary = | 740 SpellcheckCustomDictionary* custom_dictionary = |
| 754 spellcheck_service->GetCustomDictionary(); | 741 spellcheck_service->GetCustomDictionary(); |
| 755 TestingProfile profile2; | 742 TestingProfile profile2; |
| 756 SpellcheckService* spellcheck_service2 = | 743 SpellcheckService* spellcheck_service2 = |
| 757 static_cast<SpellcheckService*>( | 744 static_cast<SpellcheckService*>( |
| 758 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 745 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 759 &profile2, &BuildSpellcheckService)); | 746 &profile2, &BuildSpellcheckService)); |
| 760 SpellcheckCustomDictionary* custom_dictionary2 = | 747 SpellcheckCustomDictionary* custom_dictionary2 = |
| 761 spellcheck_service2->GetCustomDictionary(); | 748 spellcheck_service2->GetCustomDictionary(); |
| 762 | 749 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 780 | 767 |
| 781 EXPECT_EQ(2UL, custom_dictionary->GetWords().size()); | 768 EXPECT_EQ(2UL, custom_dictionary->GetWords().size()); |
| 782 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size()); | 769 EXPECT_EQ(2UL, custom_dictionary2->GetWords().size()); |
| 783 | 770 |
| 784 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 771 EXPECT_EQ(2UL, custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 785 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 772 EXPECT_EQ(2UL, custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 786 } | 773 } |
| 787 | 774 |
| 788 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) { | 775 TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) { |
| 789 SpellcheckService* spellcheck_service = | 776 SpellcheckService* spellcheck_service = |
| 790 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 777 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 791 SpellcheckCustomDictionary* custom_dictionary = | 778 SpellcheckCustomDictionary* custom_dictionary = |
| 792 spellcheck_service->GetCustomDictionary(); | 779 spellcheck_service->GetCustomDictionary(); |
| 793 TestingProfile profile2; | 780 TestingProfile profile2; |
| 794 SpellcheckService* spellcheck_service2 = | 781 SpellcheckService* spellcheck_service2 = |
| 795 static_cast<SpellcheckService*>( | 782 static_cast<SpellcheckService*>( |
| 796 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 783 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 797 &profile2, &BuildSpellcheckService)); | 784 &profile2, &BuildSpellcheckService)); |
| 798 SpellcheckCustomDictionary* custom_dictionary2 = | 785 SpellcheckCustomDictionary* custom_dictionary2 = |
| 799 spellcheck_service2->GetCustomDictionary(); | 786 spellcheck_service2->GetCustomDictionary(); |
| 800 | 787 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 827 custom_dictionary2->GetWords().size()); | 814 custom_dictionary2->GetWords().size()); |
| 828 | 815 |
| 829 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 816 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 830 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 817 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 831 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, | 818 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS, |
| 832 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 819 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 833 } | 820 } |
| 834 | 821 |
| 835 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { | 822 TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) { |
| 836 SpellcheckService* spellcheck_service = | 823 SpellcheckService* spellcheck_service = |
| 837 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 824 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 838 SpellcheckCustomDictionary* custom_dictionary = | 825 SpellcheckCustomDictionary* custom_dictionary = |
| 839 spellcheck_service->GetCustomDictionary(); | 826 spellcheck_service->GetCustomDictionary(); |
| 840 TestingProfile profile2; | 827 TestingProfile profile2; |
| 841 SpellcheckService* spellcheck_service2 = | 828 SpellcheckService* spellcheck_service2 = |
| 842 static_cast<SpellcheckService*>( | 829 static_cast<SpellcheckService*>( |
| 843 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 830 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 844 &profile2, &BuildSpellcheckService)); | 831 &profile2, &BuildSpellcheckService)); |
| 845 SpellcheckCustomDictionary* custom_dictionary2 = | 832 SpellcheckCustomDictionary* custom_dictionary2 = |
| 846 spellcheck_service2->GetCustomDictionary(); | 833 spellcheck_service2->GetCustomDictionary(); |
| 847 | 834 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 874 custom_dictionary2->GetWords().size()); | 861 custom_dictionary2->GetWords().size()); |
| 875 | 862 |
| 876 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 863 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 877 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); | 864 custom_dictionary->GetAllSyncData(syncer::DICTIONARY).size()); |
| 878 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, | 865 EXPECT_EQ(chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS / 2, |
| 879 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); | 866 custom_dictionary2->GetAllSyncData(syncer::DICTIONARY).size()); |
| 880 } | 867 } |
| 881 | 868 |
| 882 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { | 869 TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) { |
| 883 SpellcheckService* spellcheck_service = | 870 SpellcheckService* spellcheck_service = |
| 884 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 871 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 885 SpellcheckCustomDictionary* custom_dictionary = | 872 SpellcheckCustomDictionary* custom_dictionary = |
| 886 spellcheck_service->GetCustomDictionary(); | 873 spellcheck_service->GetCustomDictionary(); |
| 887 | 874 |
| 888 DictionaryObserverCounter observer; | 875 DictionaryObserverCounter observer; |
| 889 custom_dictionary->AddObserver(&observer); | 876 custom_dictionary->AddObserver(&observer); |
| 890 | 877 |
| 891 WordList custom_words; | 878 WordList custom_words; |
| 892 custom_words.push_back("foo"); | 879 custom_words.push_back("foo"); |
| 893 custom_words.push_back("bar"); | 880 custom_words.push_back("bar"); |
| 894 OnLoaded(*custom_dictionary, custom_words); | 881 OnLoaded(*custom_dictionary, custom_words); |
| 895 | 882 |
| 896 EXPECT_GE(observer.loads(), 1); | 883 EXPECT_GE(observer.loads(), 1); |
| 897 EXPECT_LE(observer.loads(), 2); | 884 EXPECT_LE(observer.loads(), 2); |
| 898 EXPECT_EQ(0, observer.changes()); | 885 EXPECT_EQ(0, observer.changes()); |
| 899 | 886 |
| 900 custom_dictionary->RemoveObserver(&observer); | 887 custom_dictionary->RemoveObserver(&observer); |
| 901 } | 888 } |
| 902 | 889 |
| 903 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) { | 890 TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) { |
| 904 SpellcheckService* spellcheck_service = | 891 SpellcheckService* spellcheck_service = |
| 905 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 892 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 906 SpellcheckCustomDictionary* custom_dictionary = | 893 SpellcheckCustomDictionary* custom_dictionary = |
| 907 spellcheck_service->GetCustomDictionary(); | 894 spellcheck_service->GetCustomDictionary(); |
| 908 | 895 |
| 909 OnLoaded(*custom_dictionary, WordList()); | 896 OnLoaded(*custom_dictionary, WordList()); |
| 910 | 897 |
| 911 DictionaryObserverCounter observer; | 898 DictionaryObserverCounter observer; |
| 912 custom_dictionary->AddObserver(&observer); | 899 custom_dictionary->AddObserver(&observer); |
| 913 | 900 |
| 914 EXPECT_TRUE(custom_dictionary->AddWord("foo")); | 901 EXPECT_TRUE(custom_dictionary->AddWord("foo")); |
| 915 EXPECT_TRUE(custom_dictionary->AddWord("bar")); | 902 EXPECT_TRUE(custom_dictionary->AddWord("bar")); |
| 916 EXPECT_FALSE(custom_dictionary->AddWord("bar")); | 903 EXPECT_FALSE(custom_dictionary->AddWord("bar")); |
| 917 | 904 |
| 918 EXPECT_EQ(2, observer.changes()); | 905 EXPECT_EQ(2, observer.changes()); |
| 919 | 906 |
| 920 custom_dictionary->RemoveObserver(&observer); | 907 custom_dictionary->RemoveObserver(&observer); |
| 921 } | 908 } |
| 922 | 909 |
| 923 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) { | 910 TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) { |
| 924 SpellcheckService* spellcheck_service = | 911 SpellcheckService* spellcheck_service = |
| 925 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 912 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 926 SpellcheckCustomDictionary* custom_dictionary = | 913 SpellcheckCustomDictionary* custom_dictionary = |
| 927 spellcheck_service->GetCustomDictionary(); | 914 spellcheck_service->GetCustomDictionary(); |
| 928 | 915 |
| 929 OnLoaded(*custom_dictionary, WordList()); | 916 OnLoaded(*custom_dictionary, WordList()); |
| 930 | 917 |
| 931 EXPECT_TRUE(custom_dictionary->AddWord("foo")); | 918 EXPECT_TRUE(custom_dictionary->AddWord("foo")); |
| 932 EXPECT_TRUE(custom_dictionary->AddWord("bar")); | 919 EXPECT_TRUE(custom_dictionary->AddWord("bar")); |
| 933 | 920 |
| 934 DictionaryObserverCounter observer; | 921 DictionaryObserverCounter observer; |
| 935 custom_dictionary->AddObserver(&observer); | 922 custom_dictionary->AddObserver(&observer); |
| 936 | 923 |
| 937 EXPECT_TRUE(custom_dictionary->RemoveWord("foo")); | 924 EXPECT_TRUE(custom_dictionary->RemoveWord("foo")); |
| 938 EXPECT_TRUE(custom_dictionary->RemoveWord("bar")); | 925 EXPECT_TRUE(custom_dictionary->RemoveWord("bar")); |
| 939 EXPECT_FALSE(custom_dictionary->RemoveWord("baz")); | 926 EXPECT_FALSE(custom_dictionary->RemoveWord("baz")); |
| 940 | 927 |
| 941 EXPECT_EQ(2, observer.changes()); | 928 EXPECT_EQ(2, observer.changes()); |
| 942 | 929 |
| 943 custom_dictionary->RemoveObserver(&observer); | 930 custom_dictionary->RemoveObserver(&observer); |
| 944 } | 931 } |
| 945 | 932 |
| 946 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) { | 933 TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) { |
| 947 SpellcheckService* spellcheck_service = | 934 SpellcheckService* spellcheck_service = |
| 948 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 935 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 949 SpellcheckCustomDictionary* custom_dictionary = | 936 SpellcheckCustomDictionary* custom_dictionary = |
| 950 spellcheck_service->GetCustomDictionary(); | 937 spellcheck_service->GetCustomDictionary(); |
| 951 TestingProfile profile2; | 938 TestingProfile profile2; |
| 952 SpellcheckService* spellcheck_service2 = | 939 SpellcheckService* spellcheck_service2 = |
| 953 static_cast<SpellcheckService*>( | 940 static_cast<SpellcheckService*>( |
| 954 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 941 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 955 &profile2, &BuildSpellcheckService)); | 942 &profile2, &BuildSpellcheckService)); |
| 956 SpellcheckCustomDictionary* custom_dictionary2 = | 943 SpellcheckCustomDictionary* custom_dictionary2 = |
| 957 spellcheck_service2->GetCustomDictionary(); | 944 spellcheck_service2->GetCustomDictionary(); |
| 958 | 945 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 986 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 1000 &server_profile, &BuildSpellcheckService)); | 987 &server_profile, &BuildSpellcheckService)); |
| 1001 | 988 |
| 1002 // Here, |server_custom_dictionary| plays the role of the sync server. | 989 // Here, |server_custom_dictionary| plays the role of the sync server. |
| 1003 SpellcheckCustomDictionary* server_custom_dictionary = | 990 SpellcheckCustomDictionary* server_custom_dictionary = |
| 1004 server_spellcheck_service->GetCustomDictionary(); | 991 server_spellcheck_service->GetCustomDictionary(); |
| 1005 | 992 |
| 1006 // Upload the maximum number of words to the sync server. | 993 // Upload the maximum number of words to the sync server. |
| 1007 { | 994 { |
| 1008 SpellcheckService* spellcheck_service = | 995 SpellcheckService* spellcheck_service = |
| 1009 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 996 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 1010 SpellcheckCustomDictionary* custom_dictionary = | 997 SpellcheckCustomDictionary* custom_dictionary = |
| 1011 spellcheck_service->GetCustomDictionary(); | 998 spellcheck_service->GetCustomDictionary(); |
| 1012 | 999 |
| 1013 SpellcheckCustomDictionary::Change change; | 1000 SpellcheckCustomDictionary::Change change; |
| 1014 for (size_t i = 0; | 1001 for (size_t i = 0; |
| 1015 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; | 1002 i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS; |
| 1016 ++i) { | 1003 ++i) { |
| 1017 change.AddWord("foo" + base::Uint64ToString(i)); | 1004 change.AddWord("foo" + base::Uint64ToString(i)); |
| 1018 } | 1005 } |
| 1019 Apply(*custom_dictionary, change); | 1006 Apply(*custom_dictionary, change); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 // Record a baseline. | 1072 // Record a baseline. |
| 1086 SpellCheckHostMetrics::RecordCustomWordCountStats(123); | 1073 SpellCheckHostMetrics::RecordCustomWordCountStats(123); |
| 1087 | 1074 |
| 1088 HistogramBase* histogram = | 1075 HistogramBase* histogram = |
| 1089 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); | 1076 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
| 1090 ASSERT_TRUE(histogram != NULL); | 1077 ASSERT_TRUE(histogram != NULL); |
| 1091 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples(); | 1078 scoped_ptr<HistogramSamples> baseline = histogram->SnapshotSamples(); |
| 1092 | 1079 |
| 1093 // Load the dictionary which should be empty. | 1080 // Load the dictionary which should be empty. |
| 1094 base::FilePath path = | 1081 base::FilePath path = |
| 1095 profile_->GetPath().Append(chrome::kCustomDictionaryFileName); | 1082 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
| 1096 WordList loaded_custom_words = LoadDictionaryFile(path); | 1083 WordList loaded_custom_words = LoadDictionaryFile(path); |
| 1097 EXPECT_EQ(0u, loaded_custom_words.size()); | 1084 EXPECT_EQ(0u, loaded_custom_words.size()); |
| 1098 | 1085 |
| 1099 // We expect there to be an entry with 0. | 1086 // We expect there to be an entry with 0. |
| 1100 histogram = | 1087 histogram = |
| 1101 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); | 1088 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
| 1102 ASSERT_TRUE(histogram != NULL); | 1089 ASSERT_TRUE(histogram != NULL); |
| 1103 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); | 1090 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
| 1104 | 1091 |
| 1105 samples->Subtract(*baseline); | 1092 samples->Subtract(*baseline); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1118 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); | 1105 StatisticsRecorder::FindHistogram("SpellCheck.CustomWords"); |
| 1119 ASSERT_TRUE(histogram != NULL); | 1106 ASSERT_TRUE(histogram != NULL); |
| 1120 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); | 1107 scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); |
| 1121 | 1108 |
| 1122 samples2->Subtract(*baseline); | 1109 samples2->Subtract(*baseline); |
| 1123 EXPECT_EQ(2,samples2->sum()); | 1110 EXPECT_EQ(2,samples2->sum()); |
| 1124 } | 1111 } |
| 1125 | 1112 |
| 1126 TEST_F(SpellcheckCustomDictionaryTest, HasWord) { | 1113 TEST_F(SpellcheckCustomDictionaryTest, HasWord) { |
| 1127 SpellcheckService* spellcheck_service = | 1114 SpellcheckService* spellcheck_service = |
| 1128 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 1115 SpellcheckServiceFactory::GetForProfile(&profile_); |
| 1129 SpellcheckCustomDictionary* custom_dictionary = | 1116 SpellcheckCustomDictionary* custom_dictionary = |
| 1130 spellcheck_service->GetCustomDictionary(); | 1117 spellcheck_service->GetCustomDictionary(); |
| 1131 OnLoaded(*custom_dictionary, WordList()); | 1118 OnLoaded(*custom_dictionary, WordList()); |
| 1132 EXPECT_FALSE(custom_dictionary->HasWord("foo")); | 1119 EXPECT_FALSE(custom_dictionary->HasWord("foo")); |
| 1133 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1120 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
| 1134 custom_dictionary->AddWord("foo"); | 1121 custom_dictionary->AddWord("foo"); |
| 1135 EXPECT_TRUE(custom_dictionary->HasWord("foo")); | 1122 EXPECT_TRUE(custom_dictionary->HasWord("foo")); |
| 1136 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1123 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
| 1137 } | 1124 } |
| OLD | NEW |