| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 fetcher_ = NULL; | 153 fetcher_ = NULL; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void VerifyResponse(bool success, | 156 void VerifyResponse(bool success, |
| 157 const base::string16& request_text, | 157 const base::string16& request_text, |
| 158 const std::vector<SpellCheckResult>& results) { | 158 const std::vector<SpellCheckResult>& results) { |
| 159 EXPECT_EQ(success_, success); | 159 EXPECT_EQ(success_, success); |
| 160 base::string16 text(base::UTF8ToUTF16(sanitized_request_text_)); | 160 base::string16 text(base::UTF8ToUTF16(sanitized_request_text_)); |
| 161 for (std::vector<SpellCheckResult>::const_iterator it = results.begin(); | 161 for (std::vector<SpellCheckResult>::const_iterator it = results.begin(); |
| 162 it != results.end(); ++it) { | 162 it != results.end(); ++it) { |
| 163 text.replace(it->location, it->length, it->replacement); | 163 text.replace(it->location, it->length, it->replacements[0]); |
| 164 } | 164 } |
| 165 EXPECT_EQ(corrected_text_, text); | 165 EXPECT_EQ(corrected_text_, text); |
| 166 } | 166 } |
| 167 | 167 |
| 168 bool ParseResponseSuccess(const std::string& data) { | 168 bool ParseResponseSuccess(const std::string& data) { |
| 169 std::vector<SpellCheckResult> results; | 169 std::vector<SpellCheckResult> results; |
| 170 return ParseResponse(data, &results); | 170 return ParseResponse(data, &results); |
| 171 } | 171 } |
| 172 | 172 |
| 173 private: | 173 private: |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); | 418 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 | 421 |
| 422 // Verify that an error in JSON response from spelling service will result in | 422 // Verify that an error in JSON response from spelling service will result in |
| 423 // ParseResponse returning false. | 423 // ParseResponse returning false. |
| 424 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { | 424 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { |
| 425 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); | 425 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); |
| 426 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); | 426 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); |
| 427 } | 427 } |
| OLD | NEW |