| 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 "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | 7 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.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/common/spellcheck_common.h" | 10 #include "chrome/common/spellcheck_common.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 MessageLoop::current()->RunUntilIdle(); | 38 MessageLoop::current()->RunUntilIdle(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 MessageLoop message_loop_; | 41 MessageLoop message_loop_; |
| 42 content::TestBrowserThread ui_thread_; | 42 content::TestBrowserThread ui_thread_; |
| 43 content::TestBrowserThread file_thread_; | 43 content::TestBrowserThread file_thread_; |
| 44 | 44 |
| 45 scoped_ptr<TestingProfile> profile_; | 45 scoped_ptr<TestingProfile> profile_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // TODO(rlp/rouslan): Shift some of these to a cutsom dictionary test suite. | |
| 49 TEST_F(SpellcheckCustomDictionaryTest, SpellcheckSetCustomWordList) { | 48 TEST_F(SpellcheckCustomDictionaryTest, SpellcheckSetCustomWordList) { |
| 50 SpellcheckService* spellcheck_service = | 49 SpellcheckService* spellcheck_service = |
| 51 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 50 SpellcheckServiceFactory::GetForProfile(profile_.get()); |
| 52 | 51 |
| 53 WordList loaded_custom_words; | 52 WordList loaded_custom_words; |
| 54 loaded_custom_words.push_back("foo"); | 53 loaded_custom_words.push_back("foo"); |
| 55 loaded_custom_words.push_back("bar"); | 54 loaded_custom_words.push_back("bar"); |
| 56 WordList expected(loaded_custom_words); | 55 WordList expected(loaded_custom_words); |
| 57 SpellcheckCustomDictionary* custom_dictionary = | 56 SpellcheckCustomDictionary* custom_dictionary = |
| 58 spellcheck_service->GetCustomDictionary(); | 57 spellcheck_service->GetCustomDictionary(); |
| 59 custom_dictionary->SetCustomWordList(&loaded_custom_words); | 58 custom_dictionary->SetCustomWordList(&loaded_custom_words); |
| 60 EXPECT_EQ(custom_dictionary->GetWords(), expected); | 59 EXPECT_EQ(custom_dictionary->GetWords(), expected); |
| 61 } | 60 } |
| 62 | 61 |
| 63 TEST_F(SpellcheckCustomDictionaryTest, CustomWordAddedLocally) { | 62 TEST_F(SpellcheckCustomDictionaryTest, CustomWordAddedAndRemovedLocally) { |
| 64 SpellcheckService* spellcheck_service = | 63 SpellcheckService* spellcheck_service = |
| 65 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 64 SpellcheckServiceFactory::GetForProfile(profile_.get()); |
| 66 | 65 |
| 67 WordList loaded_custom_words; | 66 WordList loaded_custom_words; |
| 68 SpellcheckCustomDictionary* custom_dictionary = | 67 SpellcheckCustomDictionary* custom_dictionary = |
| 69 spellcheck_service->GetCustomDictionary(); | 68 spellcheck_service->GetCustomDictionary(); |
| 70 custom_dictionary->Load(); | |
| 71 WordList expected; | 69 WordList expected; |
| 72 EXPECT_EQ(custom_dictionary->GetWords(), expected); | 70 EXPECT_EQ(custom_dictionary->GetWords(), expected); |
| 73 custom_dictionary->CustomWordAddedLocally("foo"); | 71 custom_dictionary->CustomWordAddedLocally("foo"); |
| 74 expected.push_back("foo"); | 72 expected.push_back("foo"); |
| 75 EXPECT_EQ(custom_dictionary->GetWords(), expected); | 73 EXPECT_EQ(custom_dictionary->GetWords(), expected); |
| 76 custom_dictionary->CustomWordAddedLocally("bar"); | 74 custom_dictionary->CustomWordAddedLocally("bar"); |
| 77 expected.push_back("bar"); | 75 expected.push_back("bar"); |
| 78 EXPECT_EQ(custom_dictionary->GetWords(), expected); | 76 EXPECT_EQ(custom_dictionary->GetWords(), expected); |
| 77 |
| 78 custom_dictionary->CustomWordRemovedLocally("foo"); |
| 79 custom_dictionary->CustomWordRemovedLocally("bar"); |
| 80 expected.clear(); |
| 81 EXPECT_EQ(custom_dictionary->GetWords(), expected); |
| 79 } | 82 } |
| 80 | 83 |
| 81 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { | 84 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { |
| 82 SpellcheckService* spellcheck_service = | 85 SpellcheckService* spellcheck_service = |
| 83 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 86 SpellcheckServiceFactory::GetForProfile(profile_.get()); |
| 84 SpellcheckCustomDictionary* custom_dictionary = | 87 SpellcheckCustomDictionary* custom_dictionary = |
| 85 spellcheck_service->GetCustomDictionary(); | 88 spellcheck_service->GetCustomDictionary(); |
| 86 | 89 |
| 87 WordList loaded_custom_words; | 90 WordList loaded_custom_words; |
| 88 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words); | 91 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words); | 104 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words); |
| 102 EXPECT_EQ(loaded_custom_words, expected); | 105 EXPECT_EQ(loaded_custom_words, expected); |
| 103 | 106 |
| 104 // Load in another instance of SpellCheckService. | 107 // Load in another instance of SpellCheckService. |
| 105 // The result should be the same. | 108 // The result should be the same. |
| 106 SpellcheckService spellcheck_service2(profile_.get()); | 109 SpellcheckService spellcheck_service2(profile_.get()); |
| 107 WordList loaded_custom_words2; | 110 WordList loaded_custom_words2; |
| 108 spellcheck_service2.GetCustomDictionary()-> | 111 spellcheck_service2.GetCustomDictionary()-> |
| 109 LoadDictionaryIntoCustomWordList(&loaded_custom_words2); | 112 LoadDictionaryIntoCustomWordList(&loaded_custom_words2); |
| 110 EXPECT_EQ(loaded_custom_words2, expected); | 113 EXPECT_EQ(loaded_custom_words2, expected); |
| 114 |
| 115 custom_dictionary->EraseWordFromCustomDictionary("foo"); |
| 116 custom_dictionary->EraseWordFromCustomDictionary("bar"); |
| 117 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words); |
| 118 expected.clear(); |
| 119 EXPECT_EQ(loaded_custom_words, expected); |
| 120 |
| 111 // Flush the loop now to prevent service init tasks from being run during | 121 // Flush the loop now to prevent service init tasks from being run during |
| 112 // TearDown(); | 122 // TearDown(); |
| 113 MessageLoop::current()->RunUntilIdle(); | 123 MessageLoop::current()->RunUntilIdle(); |
| 114 } | 124 } |
| 115 | 125 |
| 116 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { | 126 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) { |
| 117 SpellcheckService* spellcheck_service = | 127 SpellcheckService* spellcheck_service = |
| 118 SpellcheckServiceFactory::GetForProfile(profile_.get()); | 128 SpellcheckServiceFactory::GetForProfile(profile_.get()); |
| 119 SpellcheckCustomDictionary* custom_dictionary = | 129 SpellcheckCustomDictionary* custom_dictionary = |
| 120 spellcheck_service->GetCustomDictionary(); | 130 spellcheck_service->GetCustomDictionary(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 144 EXPECT_EQ(actual1, expected1); | 154 EXPECT_EQ(actual1, expected1); |
| 145 | 155 |
| 146 WordList actual2; | 156 WordList actual2; |
| 147 custom_dictionary2->LoadDictionaryIntoCustomWordList(&actual2); | 157 custom_dictionary2->LoadDictionaryIntoCustomWordList(&actual2); |
| 148 EXPECT_EQ(actual2, expected2); | 158 EXPECT_EQ(actual2, expected2); |
| 149 | 159 |
| 150 // Flush the loop now to prevent service init tasks from being run during | 160 // Flush the loop now to prevent service init tasks from being run during |
| 151 // TearDown(); | 161 // TearDown(); |
| 152 MessageLoop::current()->RunUntilIdle(); | 162 MessageLoop::current()->RunUntilIdle(); |
| 153 } | 163 } |
| OLD | NEW |