Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: chrome/browser/spellchecker/spelling_service_client_unittest.cc

Issue 120983002: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 8 #include "base/bind.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 request_language_ = language; 133 request_language_ = language;
134 } 134 }
135 135
136 void SetHTTPResponse(int status, const char* data) { 136 void SetHTTPResponse(int status, const char* data) {
137 response_status_ = status; 137 response_status_ = status;
138 response_data_.assign(data); 138 response_data_.assign(data);
139 } 139 }
140 140
141 void SetExpectedTextCheckResult(bool success, const char* text) { 141 void SetExpectedTextCheckResult(bool success, const char* text) {
142 success_ = success; 142 success_ = success;
143 corrected_text_.assign(UTF8ToUTF16(text)); 143 corrected_text_.assign(base::UTF8ToUTF16(text));
144 } 144 }
145 145
146 void CallOnURLFetchComplete() { 146 void CallOnURLFetchComplete() {
147 ASSERT_TRUE(!!fetcher_); 147 ASSERT_TRUE(!!fetcher_);
148 fetcher_->delegate()->OnURLFetchComplete(fetcher_); 148 fetcher_->delegate()->OnURLFetchComplete(fetcher_);
149 fetcher_ = NULL; 149 fetcher_ = NULL;
150 } 150 }
151 151
152 void VerifyResponse(bool success, 152 void VerifyResponse(bool success,
153 const base::string16& request_text, 153 const base::string16& request_text,
154 const std::vector<SpellCheckResult>& results) { 154 const std::vector<SpellCheckResult>& results) {
155 EXPECT_EQ(success_, success); 155 EXPECT_EQ(success_, success);
156 base::string16 text(UTF8ToUTF16(request_text_)); 156 base::string16 text(base::UTF8ToUTF16(request_text_));
157 EXPECT_EQ(text, request_text); 157 EXPECT_EQ(text, request_text);
158 for (std::vector<SpellCheckResult>::const_iterator it = results.begin(); 158 for (std::vector<SpellCheckResult>::const_iterator it = results.begin();
159 it != results.end(); ++it) { 159 it != results.end(); ++it) {
160 text.replace(it->location, it->length, it->replacement); 160 text.replace(it->location, it->length, it->replacement);
161 } 161 }
162 EXPECT_EQ(corrected_text_, text); 162 EXPECT_EQ(corrected_text_, text);
163 } 163 }
164 164
165 bool ParseResponseSuccess(const std::string& data) { 165 bool ParseResponseSuccess(const std::string& data) {
166 std::vector<SpellCheckResult> results; 166 std::vector<SpellCheckResult> results;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 307 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
308 client_.SetHTTPRequest(kTests[i].request_type, kTests[i].request_text, 308 client_.SetHTTPRequest(kTests[i].request_type, kTests[i].request_text,
309 kTests[i].language); 309 kTests[i].language);
310 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data); 310 client_.SetHTTPResponse(kTests[i].response_status, kTests[i].response_data);
311 client_.SetExpectedTextCheckResult(kTests[i].success, 311 client_.SetExpectedTextCheckResult(kTests[i].success,
312 kTests[i].corrected_text); 312 kTests[i].corrected_text);
313 pref->SetString(prefs::kSpellCheckDictionary, kTests[i].language); 313 pref->SetString(prefs::kSpellCheckDictionary, kTests[i].language);
314 client_.RequestTextCheck( 314 client_.RequestTextCheck(
315 &profile_, 315 &profile_,
316 kTests[i].request_type, 316 kTests[i].request_type,
317 ASCIIToUTF16(kTests[i].request_text), 317 base::ASCIIToUTF16(kTests[i].request_text),
318 base::Bind(&SpellingServiceClientTest::OnTextCheckComplete, 318 base::Bind(&SpellingServiceClientTest::OnTextCheckComplete,
319 base::Unretained(this), 0)); 319 base::Unretained(this), 0));
320 client_.CallOnURLFetchComplete(); 320 client_.CallOnURLFetchComplete();
321 } 321 }
322 } 322 }
323 323
324 // Verify that SpellingServiceClient::IsAvailable() returns true only when it 324 // Verify that SpellingServiceClient::IsAvailable() returns true only when it
325 // can send suggest requests or spellcheck requests. 325 // can send suggest requests or spellcheck requests.
326 TEST_F(SpellingServiceClientTest, AvailableServices) { 326 TEST_F(SpellingServiceClientTest, AvailableServices) {
327 const SpellingServiceClient::ServiceType kSuggest = 327 const SpellingServiceClient::ServiceType kSuggest =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); 379 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck));
380 } 380 }
381 } 381 }
382 382
383 // Verify that an error in JSON response from spelling service will result in 383 // Verify that an error in JSON response from spelling service will result in
384 // ParseResponse returning false. 384 // ParseResponse returning false.
385 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { 385 TEST_F(SpellingServiceClientTest, ResponseErrorTest) {
386 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); 386 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}"));
387 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); 387 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}"));
388 } 388 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_platform_mac_unittest.cc ('k') | chrome/browser/spellchecker/word_trimmer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698