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/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" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/spellchecker/spelling_service_client.h" | 15 #include "chrome/browser/spellchecker/spelling_service_client.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/spellcheck_result.h" | 17 #include "chrome/common/spellcheck_result.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // A mock URL fetcher used in the TestingSpellingServiceClient class. This class | 26 // A mock URL fetcher used in the TestingSpellingServiceClient class. This class |
26 // verifies JSON-RPC requests when the SpellingServiceClient class sends them to | 27 // verifies JSON-RPC requests when the SpellingServiceClient class sends them to |
27 // the Spelling service. This class also verifies the SpellingServiceClient | 28 // the Spelling service. This class also verifies the SpellingServiceClient |
28 // class does not either send cookies to the Spelling service or accept cookies | 29 // class does not either send cookies to the Spelling service or accept cookies |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 bool success_; | 185 bool success_; |
185 string16 corrected_text_; | 186 string16 corrected_text_; |
186 TestSpellingURLFetcher* fetcher_; // weak | 187 TestSpellingURLFetcher* fetcher_; // weak |
187 }; | 188 }; |
188 | 189 |
189 // A test class used for testing the SpellingServiceClient class. This class | 190 // A test class used for testing the SpellingServiceClient class. This class |
190 // implements a callback function used by the SpellingServiceClient class to | 191 // implements a callback function used by the SpellingServiceClient class to |
191 // monitor the class calls the callback with expected results. | 192 // monitor the class calls the callback with expected results. |
192 class SpellingServiceClientTest : public testing::Test { | 193 class SpellingServiceClientTest : public testing::Test { |
193 public: | 194 public: |
194 SpellingServiceClientTest() {} | |
195 virtual ~SpellingServiceClientTest() {} | |
196 | |
197 virtual void SetUp() OVERRIDE { | |
198 } | |
199 | |
200 void OnTextCheckComplete(int tag, | 195 void OnTextCheckComplete(int tag, |
201 bool success, | 196 bool success, |
202 const string16& text, | 197 const string16& text, |
203 const std::vector<SpellCheckResult>& results) { | 198 const std::vector<SpellCheckResult>& results) { |
204 client_.VerifyResponse(success, text, results); | 199 client_.VerifyResponse(success, text, results); |
205 } | 200 } |
206 | 201 |
207 protected: | 202 protected: |
| 203 content::TestBrowserThreadBundle thread_bundle_; |
208 TestingSpellingServiceClient client_; | 204 TestingSpellingServiceClient client_; |
209 TestingProfile profile_; | 205 TestingProfile profile_; |
210 }; | 206 }; |
211 | 207 |
212 } // namespace | 208 } // namespace |
213 | 209 |
214 // Verifies that SpellingServiceClient::RequestTextCheck() creates a JSON | 210 // Verifies that SpellingServiceClient::RequestTextCheck() creates a JSON |
215 // request sent to the Spelling service as we expect. This test also verifies | 211 // request sent to the Spelling service as we expect. This test also verifies |
216 // that it parses a JSON response from the service and calls the callback | 212 // that it parses a JSON response from the service and calls the callback |
217 // function. To avoid sending JSON-RPC requests to the service, this test uses a | 213 // function. To avoid sending JSON-RPC requests to the service, this test uses a |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); | 379 EXPECT_FALSE(client_.IsAvailable(&profile_, kSpellcheck)); |
384 } | 380 } |
385 } | 381 } |
386 | 382 |
387 // 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 |
388 // ParseResponse returning false. | 384 // ParseResponse returning false. |
389 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { | 385 TEST_F(SpellingServiceClientTest, ResponseErrorTest) { |
390 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); | 386 EXPECT_TRUE(client_.ParseResponseSuccess("{\"result\": {}}")); |
391 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); | 387 EXPECT_FALSE(client_.ParseResponseSuccess("{\"error\": {}}")); |
392 } | 388 } |
OLD | NEW |