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/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.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/spellchecker/spellcheck_custom_dictionary.h" | 10 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 MessageLoop::current()->RunUntilIdle(); | 39 MessageLoop::current()->RunUntilIdle(); |
40 } | 40 } |
41 | 41 |
42 MessageLoop message_loop_; | 42 MessageLoop message_loop_; |
43 content::TestBrowserThread ui_thread_; | 43 content::TestBrowserThread ui_thread_; |
44 content::TestBrowserThread file_thread_; | 44 content::TestBrowserThread file_thread_; |
45 | 45 |
46 scoped_ptr<TestingProfile> profile_; | 46 scoped_ptr<TestingProfile> profile_; |
47 }; | 47 }; |
48 | 48 |
49 // TODO(rlp/rouslan): Shift some of these to a cutsom dictionary test suite. | |
50 TEST_F(SpellcheckServiceTest, SpellcheckSetCustomWordList) { | |
51 SpellcheckService* spellcheck_service = | |
52 SpellcheckServiceFactory::GetForProfile(profile_.get()); | |
53 | |
54 WordList loaded_custom_words; | |
55 loaded_custom_words.push_back("foo"); | |
56 loaded_custom_words.push_back("bar"); | |
57 WordList expected(loaded_custom_words); | |
58 spellcheck_service->GetCustomDictionary()->SetCustomWordList( | |
59 &loaded_custom_words); | |
60 EXPECT_EQ(spellcheck_service->GetCustomWords(), expected); | |
61 } | |
62 | |
63 TEST_F(SpellcheckServiceTest, CustomWordAddedLocally) { | |
64 SpellcheckService* spellcheck_service = | |
65 SpellcheckServiceFactory::GetForProfile(profile_.get()); | |
66 | |
67 WordList loaded_custom_words; | |
68 spellcheck_service->GetCustomDictionary()->Load(); | |
69 WordList expected; | |
70 EXPECT_EQ(spellcheck_service->GetCustomWords(), expected); | |
71 spellcheck_service->CustomWordAddedLocally("foo"); | |
72 expected.push_back("foo"); | |
73 EXPECT_EQ(spellcheck_service->GetCustomWords(), expected); | |
74 spellcheck_service->CustomWordAddedLocally("bar"); | |
75 expected.push_back("bar"); | |
76 EXPECT_EQ(spellcheck_service->GetCustomWords(), expected); | |
77 } | |
78 | |
79 TEST_F(SpellcheckServiceTest, SaveAndLoad) { | |
80 SpellcheckService* spellcheck_service = | |
81 SpellcheckServiceFactory::GetForProfile(profile_.get()); | |
82 | |
83 WordList loaded_custom_words; | |
84 spellcheck_service->LoadDictionaryIntoCustomWordList(&loaded_custom_words); | |
85 | |
86 // The custom word list should be empty now. | |
87 WordList expected; | |
88 EXPECT_EQ(loaded_custom_words, expected); | |
89 | |
90 spellcheck_service->WriteWordToCustomDictionary("foo"); | |
91 expected.push_back("foo"); | |
92 | |
93 spellcheck_service->WriteWordToCustomDictionary("bar"); | |
94 expected.push_back("bar"); | |
95 | |
96 // The custom word list should include written words. | |
97 spellcheck_service->LoadDictionaryIntoCustomWordList(&loaded_custom_words); | |
98 EXPECT_EQ(loaded_custom_words, expected); | |
99 | |
100 // Load in another instance of SpellCheckService. | |
101 // The result should be the same. | |
102 SpellcheckService spellcheck_service2(profile_.get()); | |
103 WordList loaded_custom_words2; | |
104 spellcheck_service2.LoadDictionaryIntoCustomWordList(&loaded_custom_words2); | |
105 EXPECT_EQ(loaded_custom_words2, expected); | |
106 // Flush the loop now to prevent service init tasks from being run during | |
107 // TearDown(); | |
108 MessageLoop::current()->RunUntilIdle(); | |
109 } | |
110 | |
111 TEST_F(SpellcheckServiceTest, MultiProfile) { | |
112 SpellcheckService* spellcheck_service = | |
113 SpellcheckServiceFactory::GetForProfile(profile_.get()); | |
114 TestingProfile profile2; | |
115 SpellcheckService* spellcheck_service2 = | |
116 static_cast<SpellcheckService*>( | |
117 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
118 &profile2, &BuildSpellcheckService)); | |
119 | |
120 WordList expected1; | |
121 WordList expected2; | |
122 | |
123 spellcheck_service->WriteWordToCustomDictionary("foo"); | |
124 spellcheck_service->WriteWordToCustomDictionary("bar"); | |
125 expected1.push_back("foo"); | |
126 expected1.push_back("bar"); | |
127 | |
128 spellcheck_service2->WriteWordToCustomDictionary("hoge"); | |
129 spellcheck_service2->WriteWordToCustomDictionary("fuga"); | |
130 expected2.push_back("hoge"); | |
131 expected2.push_back("fuga"); | |
132 | |
133 WordList actual1; | |
134 spellcheck_service->LoadDictionaryIntoCustomWordList(&actual1); | |
135 EXPECT_EQ(actual1, expected1); | |
136 | |
137 WordList actual2; | |
138 spellcheck_service2->LoadDictionaryIntoCustomWordList(&actual2); | |
139 EXPECT_EQ(actual2, expected2); | |
140 | |
141 // Flush the loop now to prevent service init tasks from being run during | |
142 // TearDown(); | |
143 MessageLoop::current()->RunUntilIdle(); | |
144 } | |
145 | |
146 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages1) { | 49 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages1) { |
147 std::vector<std::string> accept_languages; | 50 std::vector<std::string> accept_languages; |
148 accept_languages.push_back("en"); | 51 accept_languages.push_back("en"); |
149 accept_languages.push_back("en-US"); | 52 accept_languages.push_back("en-US"); |
150 std::vector<std::string> languages; | 53 std::vector<std::string> languages; |
151 | 54 |
152 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( | 55 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( |
153 accept_languages, "en-US", &languages); | 56 accept_languages, "en-US", &languages); |
154 | 57 |
155 EXPECT_EQ(1U, languages.size()); | 58 EXPECT_EQ(1U, languages.size()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 accept_languages.push_back("fr"); | 113 accept_languages.push_back("fr"); |
211 accept_languages.push_back("aa"); // Will not exist. | 114 accept_languages.push_back("aa"); // Will not exist. |
212 std::vector<std::string> languages; | 115 std::vector<std::string> languages; |
213 | 116 |
214 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( | 117 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( |
215 accept_languages, "fr", &languages); | 118 accept_languages, "fr", &languages); |
216 | 119 |
217 EXPECT_EQ(1U, languages.size()); | 120 EXPECT_EQ(1U, languages.size()); |
218 EXPECT_EQ("fr", languages[0]); | 121 EXPECT_EQ("fr", languages[0]); |
219 } | 122 } |
OLD | NEW |