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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/spellchecker/spelling_service_client.h" | 14 #include "chrome/browser/spellchecker/spelling_service_client.h" |
| 15 #include "chrome/common/pref_names.h" |
14 #include "chrome/common/spellcheck_result.h" | 16 #include "chrome/common/spellcheck_result.h" |
15 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
16 #include "content/public/test/test_url_fetcher_factory.h" | 18 #include "content/public/test/test_url_fetcher_factory.h" |
17 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // A mock URL fetcher used in the TestingSpellingServiceClient class. This class | 24 // A mock URL fetcher used in the TestingSpellingServiceClient class. This class |
23 // verifies JSON-RPC requests when the SpellingServiceClient class sends them to | 25 // verifies JSON-RPC requests when the SpellingServiceClient class sends them to |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 " \"canAutoCorrect\": false\n" | 253 " \"canAutoCorrect\": false\n" |
252 " }]\n" | 254 " }]\n" |
253 " }\n" | 255 " }\n" |
254 " }\n" | 256 " }\n" |
255 "}", | 257 "}", |
256 true, | 258 true, |
257 "I have been to USA.", | 259 "I have been to USA.", |
258 }, | 260 }, |
259 }; | 261 }; |
260 | 262 |
| 263 PrefService* pref = profile_.GetPrefs(); |
| 264 pref->SetBoolean(prefs::kEnableSpellCheck, true); |
| 265 pref->SetBoolean(prefs::kSpellCheckUseSpellingService, true); |
| 266 |
261 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 267 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
262 client_.SetHTTPRequest(kTests[i].request_type, kTests[i].request_text); | 268 client_.SetHTTPRequest(kTests[i].request_type, kTests[i].request_text); |
263 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data); | 269 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data); |
264 client_.SetExpectedTextCheckResult(kTests[i].success, | 270 client_.SetExpectedTextCheckResult(kTests[i].success, |
265 kTests[i].corrected_text); | 271 kTests[i].corrected_text); |
266 client_.RequestTextCheck( | 272 client_.RequestTextCheck( |
267 &profile_, | 273 &profile_, |
268 0, | 274 0, |
269 kTests[i].request_type, | 275 kTests[i].request_type, |
270 ASCIIToUTF16(kTests[i].request_text), | 276 ASCIIToUTF16(kTests[i].request_text), |
271 base::Bind(&SpellingServiceClientTest::OnTextCheckComplete, | 277 base::Bind(&SpellingServiceClientTest::OnTextCheckComplete, |
272 base::Unretained(this))); | 278 base::Unretained(this))); |
273 client_.CallOnURLFetchComplete(); | 279 client_.CallOnURLFetchComplete(); |
274 } | 280 } |
275 } | 281 } |
| 282 |
| 283 // Verify that SpellingServiceClient::IsAvailable() returns true only when it |
| 284 // can send suggest requests or spellcheck requests. |
| 285 TEST_F(SpellingServiceClientTest, AvailableServices) { |
| 286 const SpellingServiceClient::ServiceType kSuggest = |
| 287 SpellingServiceClient::SUGGEST; |
| 288 const SpellingServiceClient::ServiceType kSpellcheck = |
| 289 SpellingServiceClient::SPELLCHECK; |
| 290 |
| 291 // When a user disables spellchecking or prevent using the Spelling service, |
| 292 // this function should return false both for suggestions and for spellcheck. |
| 293 PrefService* pref = profile_.GetPrefs(); |
| 294 pref->SetBoolean(prefs::kEnableSpellCheck, false); |
| 295 pref->SetBoolean(prefs::kSpellCheckUseSpellingService, false); |
| 296 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); |
| 297 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 298 |
| 299 pref->SetBoolean(prefs::kEnableSpellCheck, true); |
| 300 pref->SetBoolean(prefs::kSpellCheckUseSpellingService, true); |
| 301 |
| 302 // For locales supported by the SpellCheck service, this function returns |
| 303 // false for suggestions and true for spellcheck. (The comment in |
| 304 // SpellingServiceClient::IsAvailable() describes why this function returns |
| 305 // false for suggestions.) |
| 306 static const char* kSupported[] = { |
| 307 "", "en-AU", "en-CA", "en-GB", "en-US", |
| 308 }; |
| 309 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupported); ++i) { |
| 310 pref->SetString(prefs::kSpellCheckDictionary, kSupported[i]); |
| 311 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); |
| 312 EXPECT_TRUE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 313 } |
| 314 |
| 315 // On the other hand, this function returns true for suggestions and false for |
| 316 // spellcheck for unsupported locales. |
| 317 static const char* kUnsupported[] = { |
| 318 "af-ZA", "bg-BG", "ca-ES", "cs-CZ", "da-DK", "de-DE", "el-GR", "es-ES", |
| 319 "et-EE", "fo-FO", "fr-FR", "he-IL", "hi-IN", "hr-HR", "hu-HU", "id-ID", |
| 320 "it-IT", "lt-LT", "lv-LV", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", |
| 321 "ro-RO", "ru-RU", "sk-SK", "sl-SI", "sh", "sr", "sv-SE", "tr-TR", |
| 322 "uk-UA", "vi-VN", |
| 323 }; |
| 324 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kUnsupported); ++i) { |
| 325 pref->SetString(prefs::kSpellCheckDictionary, kUnsupported[i]); |
| 326 EXPECT_TRUE(client_.IsAvailable(&profile_, kSuggest)); |
| 327 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 328 } |
| 329 } |
OLD | NEW |