| 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 "components/spellcheck/browser/spelling_service_client.h" | 5 #include "components/spellcheck/browser/spelling_service_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 " }\n" | 324 " }\n" |
| 325 " }\n" | 325 " }\n" |
| 326 "}", | 326 "}", |
| 327 true, | 327 true, |
| 328 "I'm at the In'N'Out.", | 328 "I'm at the In'N'Out.", |
| 329 "en", | 329 "en", |
| 330 }, | 330 }, |
| 331 }; | 331 }; |
| 332 | 332 |
| 333 PrefService* pref = profile_.GetPrefs(); | 333 PrefService* pref = profile_.GetPrefs(); |
| 334 pref->SetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck, true); | 334 pref->SetBoolean(spellcheck::prefs::kEnableSpellcheck, true); |
| 335 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, true); | 335 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, true); |
| 336 | 336 |
| 337 for (size_t i = 0; i < arraysize(kTests); ++i) { | 337 for (size_t i = 0; i < arraysize(kTests); ++i) { |
| 338 client_.SetHTTPRequest(kTests[i].request_type, | 338 client_.SetHTTPRequest(kTests[i].request_type, |
| 339 kTests[i].sanitized_request_text, | 339 kTests[i].sanitized_request_text, |
| 340 kTests[i].language); | 340 kTests[i].language); |
| 341 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data); | 341 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data); |
| 342 client_.SetExpectedTextCheckResult(kTests[i].success, | 342 client_.SetExpectedTextCheckResult(kTests[i].success, |
| 343 kTests[i].corrected_text); | 343 kTests[i].corrected_text); |
| 344 base::ListValue dictionary; | 344 base::ListValue dictionary; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 359 // can send suggest requests or spellcheck requests. | 359 // can send suggest requests or spellcheck requests. |
| 360 TEST_F(SpellingServiceClientTest, AvailableServices) { | 360 TEST_F(SpellingServiceClientTest, AvailableServices) { |
| 361 const SpellingServiceClient::ServiceType kSuggest = | 361 const SpellingServiceClient::ServiceType kSuggest = |
| 362 SpellingServiceClient::SUGGEST; | 362 SpellingServiceClient::SUGGEST; |
| 363 const SpellingServiceClient::ServiceType kSpellcheck = | 363 const SpellingServiceClient::ServiceType kSpellcheck = |
| 364 SpellingServiceClient::SPELLCHECK; | 364 SpellingServiceClient::SPELLCHECK; |
| 365 | 365 |
| 366 // When a user disables spellchecking or prevent using the Spelling service, | 366 // When a user disables spellchecking or prevent using the Spelling service, |
| 367 // this function should return false both for suggestions and for spellcheck. | 367 // this function should return false both for suggestions and for spellcheck. |
| 368 PrefService* pref = profile_.GetPrefs(); | 368 PrefService* pref = profile_.GetPrefs(); |
| 369 pref->SetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck, false); | 369 pref->SetBoolean(spellcheck::prefs::kEnableSpellcheck, false); |
| 370 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, false); | 370 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, false); |
| 371 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); | 371 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); |
| 372 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); | 372 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 373 | 373 |
| 374 pref->SetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck, true); | 374 pref->SetBoolean(spellcheck::prefs::kEnableSpellcheck, true); |
| 375 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, true); | 375 pref->SetBoolean(spellcheck::prefs::kSpellCheckUseSpellingService, true); |
| 376 | 376 |
| 377 // For locales supported by the SpellCheck service, this function returns | 377 // For locales supported by the SpellCheck service, this function returns |
| 378 // false for suggestions and true for spellcheck. (The comment in | 378 // false for suggestions and true for spellcheck. (The comment in |
| 379 // SpellingServiceClient::IsAvailable() describes why this function returns | 379 // SpellingServiceClient::IsAvailable() describes why this function returns |
| 380 // false for suggestions.) If there is no language set, then we | 380 // false for suggestions.) If there is no language set, then we |
| 381 // do not allow any remote. | 381 // do not allow any remote. |
| 382 pref->Set(spellcheck::prefs::kSpellCheckDictionaries, base::ListValue()); | 382 pref->Set(spellcheck::prefs::kSpellCheckDictionaries, base::ListValue()); |
| 383 | 383 |
| 384 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); | 384 EXPECT_FALSE(client_.IsAvailable(&profile_, kSuggest)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); | 416 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 | 419 |
| 420 // Verify that an error in JSON response from spelling service will result in | 420 // Verify that an error in JSON response from spelling service will result in |
| 421 // ParseResponse returning false. | 421 // ParseResponse returning false. |
| 422 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { | 422 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { |
| 423 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); | 423 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); |
| 424 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); | 424 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); |
| 425 } | 425 } |
| OLD | NEW |