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

Side by Side Diff: chrome/browser/history/web_history_service_unittest.cc

Issue 1143343005: chrome/browser: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/history/core/browser/web_history_service.h" 5 #include "components/history/core/browser/web_history_service.h"
6 6
7 #include "base/location.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
9 #include "chrome/browser/history/web_history_service_factory.h" 12 #include "chrome/browser/history/web_history_service_factory.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager_factory.h" 14 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 15 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
14 #include "chrome/browser/sync/profile_sync_service_mock.h" 17 #include "chrome/browser/sync/profile_sync_service_mock.h"
15 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
16 #include "components/signin/core/browser/profile_oauth2_token_service.h" 19 #include "components/signin/core/browser/profile_oauth2_token_service.h"
17 #include "components/signin/core/browser/signin_manager.h" 20 #include "components/signin/core/browser/signin_manager.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // history::Request overrides 122 // history::Request overrides
120 bool IsPending() override { return is_pending_; } 123 bool IsPending() override { return is_pending_; }
121 int GetResponseCode() override { return response_code_; } 124 int GetResponseCode() override { return response_code_; }
122 const std::string& GetResponseBody() override { return response_body_; } 125 const std::string& GetResponseBody() override { return response_body_; }
123 void SetPostData(const std::string& post_data) override { 126 void SetPostData(const std::string& post_data) override {
124 post_data_ = post_data; 127 post_data_ = post_data;
125 } 128 }
126 129
127 void Start() override { 130 void Start() override {
128 is_pending_ = true; 131 is_pending_ = true;
129 base::MessageLoop::current()->PostTask( 132 base::ThreadTaskRunnerHandle::Get()->PostTask(
130 FROM_HERE, 133 FROM_HERE,
131 base::Bind(&TestRequest::MimicReturnFromFetch, base::Unretained(this))); 134 base::Bind(&TestRequest::MimicReturnFromFetch, base::Unretained(this)));
132 } 135 }
133 136
134 void MimicReturnFromFetch() { 137 void MimicReturnFromFetch() {
135 // Mimic a successful fetch and return. We don't actually send out a request 138 // Mimic a successful fetch and return. We don't actually send out a request
136 // in unittests. 139 // in unittests.
137 EXPECT_EQ(web_history_service_->GetExpectedPostData(this), post_data_); 140 EXPECT_EQ(web_history_service_->GetExpectedPostData(this), post_data_);
138 callback_.Run(this, true); 141 callback_.Run(this, true);
139 } 142 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_)); 231 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_));
229 EXPECT_CALL(*sync_service, 232 EXPECT_CALL(*sync_service,
230 IsSyncActive()).WillRepeatedly(Return(true)); 233 IsSyncActive()).WillRepeatedly(Return(true));
231 syncer::ModelTypeSet result; 234 syncer::ModelTypeSet result;
232 result.Put(syncer::HISTORY_DELETE_DIRECTIVES); 235 result.Put(syncer::HISTORY_DELETE_DIRECTIVES);
233 EXPECT_CALL(*sync_service, 236 EXPECT_CALL(*sync_service,
234 GetActiveDataTypes()).WillRepeatedly(Return(result)); 237 GetActiveDataTypes()).WillRepeatedly(Return(result));
235 } 238 }
236 void TearDown() override { 239 void TearDown() override {
237 base::RunLoop run_loop; 240 base::RunLoop run_loop;
238 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); 241 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
242 run_loop.QuitClosure());
239 run_loop.Run(); 243 run_loop.Run();
240 } 244 }
241 Profile* profile() { return &profile_; } 245 Profile* profile() { return &profile_; }
242 246
243 ProfileSyncServiceMock* mock_sync_service() { 247 ProfileSyncServiceMock* mock_sync_service() {
244 return static_cast<ProfileSyncServiceMock*>( 248 return static_cast<ProfileSyncServiceMock*>(
245 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_)); 249 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_));
246 } 250 }
247 251
248 private: 252 private:
249 253
250 content::TestBrowserThreadBundle thread_bundle_; 254 content::TestBrowserThreadBundle thread_bundle_;
251 TestingProfile profile_; 255 TestingProfile profile_;
252 256
253 DISALLOW_COPY_AND_ASSIGN(WebHistoryServiceTest); 257 DISALLOW_COPY_AND_ASSIGN(WebHistoryServiceTest);
254 }; 258 };
255 259
256 TEST_F(WebHistoryServiceTest, GetAudioHistoryEnabled) { 260 TEST_F(WebHistoryServiceTest, GetAudioHistoryEnabled) {
257 TestingWebHistoryService* web_history_service = 261 TestingWebHistoryService* web_history_service =
258 static_cast<TestingWebHistoryService*>( 262 static_cast<TestingWebHistoryService*>(
259 WebHistoryServiceFactory::GetForProfile(profile())); 263 WebHistoryServiceFactory::GetForProfile(profile()));
260 EXPECT_TRUE(web_history_service); 264 EXPECT_TRUE(web_history_service);
261 265
262 web_history_service->SetExpectedURL( 266 web_history_service->SetExpectedURL(
263 GURL("https://history.google.com/history/api/lookup?client=audio")); 267 GURL("https://history.google.com/history/api/lookup?client=audio"));
264 web_history_service->SetExpectedAudioHistoryValue(true); 268 web_history_service->SetExpectedAudioHistoryValue(true);
265 web_history_service->GetAudioHistoryEnabled( 269 web_history_service->GetAudioHistoryEnabled(
266 base::Bind(&TestingWebHistoryService::GetAudioHistoryCallback, 270 base::Bind(&TestingWebHistoryService::GetAudioHistoryCallback,
267 base::Unretained(web_history_service))); 271 base::Unretained(web_history_service)));
268 base::MessageLoop::current()->PostTask( 272 base::ThreadTaskRunnerHandle::Get()->PostTask(
269 FROM_HERE, 273 FROM_HERE,
270 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain, 274 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain,
271 base::Unretained(web_history_service))); 275 base::Unretained(web_history_service)));
272 } 276 }
273 277
274 TEST_F(WebHistoryServiceTest, SetAudioHistoryEnabledTrue) { 278 TEST_F(WebHistoryServiceTest, SetAudioHistoryEnabledTrue) {
275 TestingWebHistoryService* web_history_service = 279 TestingWebHistoryService* web_history_service =
276 static_cast<TestingWebHistoryService*>( 280 static_cast<TestingWebHistoryService*>(
277 WebHistoryServiceFactory::GetForProfile(profile())); 281 WebHistoryServiceFactory::GetForProfile(profile()));
278 EXPECT_TRUE(web_history_service); 282 EXPECT_TRUE(web_history_service);
279 283
280 web_history_service->SetExpectedURL( 284 web_history_service->SetExpectedURL(
281 GURL("https://history.google.com/history/api/change")); 285 GURL("https://history.google.com/history/api/change"));
282 web_history_service->SetExpectedAudioHistoryValue(true); 286 web_history_service->SetExpectedAudioHistoryValue(true);
283 web_history_service->SetExpectedPostData( 287 web_history_service->SetExpectedPostData(
284 "{\"client\":\"audio\",\"enable_history_recording\":true}"); 288 "{\"client\":\"audio\",\"enable_history_recording\":true}");
285 web_history_service->SetAudioHistoryEnabled( 289 web_history_service->SetAudioHistoryEnabled(
286 true, 290 true,
287 base::Bind(&TestingWebHistoryService::SetAudioHistoryCallback, 291 base::Bind(&TestingWebHistoryService::SetAudioHistoryCallback,
288 base::Unretained(web_history_service))); 292 base::Unretained(web_history_service)));
289 base::MessageLoop::current()->PostTask( 293 base::ThreadTaskRunnerHandle::Get()->PostTask(
290 FROM_HERE, 294 FROM_HERE,
291 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain, 295 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain,
292 base::Unretained(web_history_service))); 296 base::Unretained(web_history_service)));
293 } 297 }
294 298
295 TEST_F(WebHistoryServiceTest, SetAudioHistoryEnabledFalse) { 299 TEST_F(WebHistoryServiceTest, SetAudioHistoryEnabledFalse) {
296 TestingWebHistoryService* web_history_service = 300 TestingWebHistoryService* web_history_service =
297 static_cast<TestingWebHistoryService*>( 301 static_cast<TestingWebHistoryService*>(
298 WebHistoryServiceFactory::GetForProfile(profile())); 302 WebHistoryServiceFactory::GetForProfile(profile()));
299 EXPECT_TRUE(web_history_service); 303 EXPECT_TRUE(web_history_service);
300 304
301 web_history_service->SetExpectedURL( 305 web_history_service->SetExpectedURL(
302 GURL("https://history.google.com/history/api/change")); 306 GURL("https://history.google.com/history/api/change"));
303 web_history_service->SetExpectedAudioHistoryValue(false); 307 web_history_service->SetExpectedAudioHistoryValue(false);
304 web_history_service->SetExpectedPostData( 308 web_history_service->SetExpectedPostData(
305 "{\"client\":\"audio\",\"enable_history_recording\":false}"); 309 "{\"client\":\"audio\",\"enable_history_recording\":false}");
306 web_history_service->SetAudioHistoryEnabled( 310 web_history_service->SetAudioHistoryEnabled(
307 false, 311 false,
308 base::Bind(&TestingWebHistoryService::SetAudioHistoryCallback, 312 base::Bind(&TestingWebHistoryService::SetAudioHistoryCallback,
309 base::Unretained(web_history_service))); 313 base::Unretained(web_history_service)));
310 base::MessageLoop::current()->PostTask( 314 base::ThreadTaskRunnerHandle::Get()->PostTask(
311 FROM_HERE, 315 FROM_HERE,
312 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain, 316 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain,
313 base::Unretained(web_history_service))); 317 base::Unretained(web_history_service)));
314 } 318 }
315 319
316 TEST_F(WebHistoryServiceTest, MultipleRequests) { 320 TEST_F(WebHistoryServiceTest, MultipleRequests) {
317 TestingWebHistoryService* web_history_service = 321 TestingWebHistoryService* web_history_service =
318 static_cast<TestingWebHistoryService*>( 322 static_cast<TestingWebHistoryService*>(
319 WebHistoryServiceFactory::GetForProfile(profile())); 323 WebHistoryServiceFactory::GetForProfile(profile()));
320 EXPECT_TRUE(web_history_service); 324 EXPECT_TRUE(web_history_service);
321 325
322 web_history_service->SetExpectedURL( 326 web_history_service->SetExpectedURL(
323 GURL("https://history.google.com/history/api/change")); 327 GURL("https://history.google.com/history/api/change"));
324 web_history_service->SetExpectedAudioHistoryValue(false); 328 web_history_service->SetExpectedAudioHistoryValue(false);
325 web_history_service->SetExpectedPostData( 329 web_history_service->SetExpectedPostData(
326 "{\"client\":\"audio\",\"enable_history_recording\":false}"); 330 "{\"client\":\"audio\",\"enable_history_recording\":false}");
327 web_history_service->SetAudioHistoryEnabled( 331 web_history_service->SetAudioHistoryEnabled(
328 false, 332 false,
329 base::Bind(&TestingWebHistoryService::MultipleRequestsCallback, 333 base::Bind(&TestingWebHistoryService::MultipleRequestsCallback,
330 base::Unretained(web_history_service))); 334 base::Unretained(web_history_service)));
331 335
332 web_history_service->SetExpectedURL( 336 web_history_service->SetExpectedURL(
333 GURL("https://history.google.com/history/api/lookup?client=audio")); 337 GURL("https://history.google.com/history/api/lookup?client=audio"));
334 web_history_service->SetExpectedPostData(""); 338 web_history_service->SetExpectedPostData("");
335 web_history_service->GetAudioHistoryEnabled( 339 web_history_service->GetAudioHistoryEnabled(
336 base::Bind(&TestingWebHistoryService::MultipleRequestsCallback, 340 base::Bind(&TestingWebHistoryService::MultipleRequestsCallback,
337 base::Unretained(web_history_service))); 341 base::Unretained(web_history_service)));
338 342
339 // Check that both requests are no longer pending. 343 // Check that both requests are no longer pending.
340 base::MessageLoop::current()->PostTask( 344 base::ThreadTaskRunnerHandle::Get()->PostTask(
341 FROM_HERE, 345 FROM_HERE,
342 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain, 346 base::Bind(&TestingWebHistoryService::EnsureNoPendingRequestsRemain,
343 base::Unretained(web_history_service))); 347 base::Unretained(web_history_service)));
344 } 348 }
345 349
346 TEST_F(WebHistoryServiceTest, VerifyReadResponse) { 350 TEST_F(WebHistoryServiceTest, VerifyReadResponse) {
347 // Test that properly formatted response with good response code returns true 351 // Test that properly formatted response with good response code returns true
348 // as expected. 352 // as expected.
349 WebHistoryService::CompletionCallback completion_callback; 353 WebHistoryService::CompletionCallback completion_callback;
350 scoped_ptr<WebHistoryService::Request> request( 354 scoped_ptr<WebHistoryService::Request> request(
351 new TestRequest( 355 new TestRequest(
352 GURL("http://history.google.com/"), 356 GURL("http://history.google.com/"),
353 completion_callback, 357 completion_callback,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 " \"history_recording\": true\n" 424 " \"history_recording\": true\n"
421 "}")); 425 "}"));
422 scoped_ptr<base::DictionaryValue> response_value5; 426 scoped_ptr<base::DictionaryValue> response_value5;
423 // ReadResponse deletes the request 427 // ReadResponse deletes the request
424 response_value5 = TestingWebHistoryService::ReadResponse(request5.get()); 428 response_value5 = TestingWebHistoryService::ReadResponse(request5.get());
425 enabled_value = true; 429 enabled_value = true;
426 EXPECT_FALSE(response_value5->GetBoolean("history_recording_enabled", 430 EXPECT_FALSE(response_value5->GetBoolean("history_recording_enabled",
427 &enabled_value)); 431 &enabled_value));
428 EXPECT_TRUE(enabled_value); 432 EXPECT_TRUE(enabled_value);
429 } 433 }
OLDNEW
« no previous file with comments | « chrome/browser/history/redirect_browsertest.cc ('k') | chrome/browser/infobars/infobar_responder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698