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

Side by Side Diff: chrome/browser/sync/test/integration/sync_test.cc

Issue 234113002: Use FakeServer-based invalidations for Sync tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 (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 "chrome/browser/sync/test/integration/sync_test.h" 5 #include "chrome/browser/sync/test/integration/sync_test.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/lifetime/application_lifetime.h" 29 #include "chrome/browser/lifetime/application_lifetime.h"
30 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/search_engines/template_url_service.h" 32 #include "chrome/browser/search_engines/template_url_service.h"
33 #include "chrome/browser/search_engines/template_url_service_factory.h" 33 #include "chrome/browser/search_engines/template_url_service_factory.h"
34 #include "chrome/browser/signin/profile_identity_provider.h" 34 #include "chrome/browser/signin/profile_identity_provider.h"
35 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 35 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
36 #include "chrome/browser/signin/signin_manager_factory.h" 36 #include "chrome/browser/signin/signin_manager_factory.h"
37 #include "chrome/browser/sync/profile_sync_service.h" 37 #include "chrome/browser/sync/profile_sync_service.h"
38 #include "chrome/browser/sync/profile_sync_service_factory.h" 38 #include "chrome/browser/sync/profile_sync_service_factory.h"
39 #include "chrome/browser/sync/test/integration/fake_server_invalidation_service. h"
39 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h" 40 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h"
40 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 41 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
41 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" 42 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
42 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 43 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
43 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 44 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
44 #include "chrome/browser/ui/browser.h" 45 #include "chrome/browser/ui/browser.h"
45 #include "chrome/browser/ui/browser_finder.h" 46 #include "chrome/browser/ui/browser_finder.h"
46 #include "chrome/browser/ui/host_desktop.h" 47 #include "chrome/browser/ui/host_desktop.h"
47 #include "chrome/browser/ui/tabs/tab_strip_model.h" 48 #include "chrome/browser/ui/tabs/tab_strip_model.h"
48 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 49 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 ClearMockGaiaResponses(); 228 ClearMockGaiaResponses();
228 229
229 // Allow the InProcessBrowserTest framework to perform its tear down. 230 // Allow the InProcessBrowserTest framework to perform its tear down.
230 InProcessBrowserTest::TearDown(); 231 InProcessBrowserTest::TearDown();
231 232
232 // Stop the local python test server. This is a no-op if one wasn't started. 233 // Stop the local python test server. This is a no-op if one wasn't started.
233 TearDownLocalPythonTestServer(); 234 TearDownLocalPythonTestServer();
234 235
235 // Stop the local sync test server. This is a no-op if one wasn't started. 236 // Stop the local sync test server. This is a no-op if one wasn't started.
236 TearDownLocalTestServer(); 237 TearDownLocalTestServer();
238
239 fake_server_.reset();
237 } 240 }
238 241
239 void SyncTest::SetUpCommandLine(base::CommandLine* cl) { 242 void SyncTest::SetUpCommandLine(base::CommandLine* cl) {
240 AddTestSwitches(cl); 243 AddTestSwitches(cl);
241 AddOptionalTypesToCommandLine(cl); 244 AddOptionalTypesToCommandLine(cl);
242 } 245 }
243 246
244 void SyncTest::AddTestSwitches(base::CommandLine* cl) { 247 void SyncTest::AddTestSwitches(base::CommandLine* cl) {
245 // Disable non-essential access of external network resources. 248 // Disable non-essential access of external network resources.
246 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) 249 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking))
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (num_clients_ <= 0) 322 if (num_clients_ <= 0)
320 LOG(FATAL) << "num_clients_ incorrectly initialized."; 323 LOG(FATAL) << "num_clients_ incorrectly initialized.";
321 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) 324 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty())
322 LOG(FATAL) << "SetupClients() has already been called."; 325 LOG(FATAL) << "SetupClients() has already been called.";
323 326
324 // Create the required number of sync profiles, browsers and clients. 327 // Create the required number of sync profiles, browsers and clients.
325 profiles_.resize(num_clients_); 328 profiles_.resize(num_clients_);
326 browsers_.resize(num_clients_); 329 browsers_.resize(num_clients_);
327 clients_.resize(num_clients_); 330 clients_.resize(num_clients_);
328 invalidation_forwarders_.resize(num_clients_); 331 invalidation_forwarders_.resize(num_clients_);
332 fake_server_invalidation_services_.resize(num_clients_);
329 for (int i = 0; i < num_clients_; ++i) { 333 for (int i = 0; i < num_clients_; ++i) {
330 InitializeInstance(i); 334 InitializeInstance(i);
331 } 335 }
332 336
333 // Create the verifier profile. 337 // Create the verifier profile.
334 verifier_ = MakeProfile(FILE_PATH_LITERAL("Verifier")); 338 verifier_ = MakeProfile(FILE_PATH_LITERAL("Verifier"));
335 test::WaitForBookmarkModelToLoad( 339 test::WaitForBookmarkModelToLoad(
336 BookmarkModelFactory::GetForProfile(verifier())); 340 BookmarkModelFactory::GetForProfile(verifier()));
337 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( 341 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile(
338 verifier(), Profile::EXPLICIT_ACCESS)); 342 verifier(), Profile::EXPLICIT_ACCESS));
339 ui_test_utils::WaitForTemplateURLServiceToLoad( 343 ui_test_utils::WaitForTemplateURLServiceToLoad(
340 TemplateURLServiceFactory::GetForProfile(verifier())); 344 TemplateURLServiceFactory::GetForProfile(verifier()));
341 return (verifier_ != NULL); 345 return (verifier_ != NULL);
342 } 346 }
343 347
344 void SyncTest::InitializeInstance(int index) { 348 void SyncTest::InitializeInstance(int index) {
345 profiles_[index] = MakeProfile( 349 profiles_[index] = MakeProfile(
346 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index)); 350 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index));
347 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile " 351 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile "
348 << index << "."; 352 << index << ".";
349 353
350 browsers_[index] = new Browser(Browser::CreateParams( 354 browsers_[index] = new Browser(Browser::CreateParams(
351 GetProfile(index), chrome::GetActiveDesktop())); 355 GetProfile(index), chrome::GetActiveDesktop()));
352 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser " 356 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser "
353 << index << "."; 357 << index << ".";
354 358
355 invalidation::P2PInvalidationService* p2p_invalidation_service =
356 static_cast<invalidation::P2PInvalidationService*>(
357 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
358 GetProfile(index),
359 TestUsesSelfNotifications() ?
360 BuildSelfNotifyingP2PInvalidationService
361 : BuildRealisticP2PInvalidationService));
362 p2p_invalidation_service->UpdateCredentials(username_, password_);
363 359
364 // Make sure the ProfileSyncService has been created before creating the 360 // Make sure the ProfileSyncService has been created before creating the
365 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to 361 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to
366 // already exist. 362 // already exist.
367 ProfileSyncService* profile_sync_service = 363 ProfileSyncService* profile_sync_service =
368 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); 364 ProfileSyncServiceFactory::GetForProfile(GetProfile(index));
369 365
370 if (server_type_ == IN_PROCESS_FAKE_SERVER) { 366 if (server_type_ == IN_PROCESS_FAKE_SERVER) {
371 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. 367 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer.
372 profile_sync_service->OverrideNetworkResourcesForTest( 368 profile_sync_service->OverrideNetworkResourcesForTest(
373 make_scoped_ptr<syncer::NetworkResources>( 369 make_scoped_ptr<syncer::NetworkResources>(
374 new fake_server::FakeServerNetworkResources(fake_server_.get()))); 370 new fake_server::FakeServerNetworkResources(fake_server_.get())));
375 } 371 }
376 372
377 clients_[index] = 373 clients_[index] =
378 ProfileSyncServiceHarness::Create( 374 ProfileSyncServiceHarness::Create(
379 GetProfile(index), 375 GetProfile(index),
380 username_, 376 username_,
381 password_); 377 password_);
382 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " 378 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client "
383 << index << "."; 379 << index << ".";
384 380 InitializeInvalidations(index);
385 // Start listening for and emitting notificaitons of commits.
386 invalidation_forwarders_[index] =
387 new P2PInvalidationForwarder(clients_[index]->service(),
388 p2p_invalidation_service);
389 381
390 test::WaitForBookmarkModelToLoad( 382 test::WaitForBookmarkModelToLoad(
391 BookmarkModelFactory::GetForProfile(GetProfile(index))); 383 BookmarkModelFactory::GetForProfile(GetProfile(index)));
392 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( 384 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile(
393 GetProfile(index), Profile::EXPLICIT_ACCESS)); 385 GetProfile(index), Profile::EXPLICIT_ACCESS));
394 ui_test_utils::WaitForTemplateURLServiceToLoad( 386 ui_test_utils::WaitForTemplateURLServiceToLoad(
395 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); 387 TemplateURLServiceFactory::GetForProfile(GetProfile(index)));
396 } 388 }
397 389
390 void SyncTest::InitializeInvalidations(int index) {
391 if (server_type_ == IN_PROCESS_FAKE_SERVER) {
392 CHECK(fake_server_.get());
393 fake_server::FakeServerInvalidationService* invalidation_service =
394 static_cast<fake_server::FakeServerInvalidationService*>(
395 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
396 GetProfile(index),
397 fake_server::FakeServerInvalidationService::Build));
398 fake_server_->AddObserver(invalidation_service);
399 fake_server_invalidation_services_[index] = invalidation_service;
400 } else {
401 invalidation::P2PInvalidationService* p2p_invalidation_service =
402 static_cast<invalidation::P2PInvalidationService*>(
403 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
404 GetProfile(index),
405 TestUsesSelfNotifications() ?
406 BuildSelfNotifyingP2PInvalidationService
407 : BuildRealisticP2PInvalidationService));
408 p2p_invalidation_service->UpdateCredentials(username_, password_);
409 // Start listening for and emitting notifications of commits.
410 invalidation_forwarders_[index] =
411 new P2PInvalidationForwarder(clients_[index]->service(),
412 p2p_invalidation_service);
413 }
414 }
415
398 bool SyncTest::SetupSync() { 416 bool SyncTest::SetupSync() {
399 // Create sync profiles and clients if they haven't already been created. 417 // Create sync profiles and clients if they haven't already been created.
400 if (profiles_.empty()) { 418 if (profiles_.empty()) {
401 if (!SetupClients()) 419 if (!SetupClients())
402 LOG(FATAL) << "SetupClients() failed."; 420 LOG(FATAL) << "SetupClients() failed.";
403 } 421 }
404 422
405 // Sync each of the profiles. 423 // Sync each of the profiles.
406 for (int i = 0; i < num_clients_; ++i) { 424 for (int i = 0; i < num_clients_; ++i) {
407 if (!GetClient(i)->SetupSync()) 425 if (!GetClient(i)->SetupSync())
(...skipping 19 matching lines...) Expand all
427 clients_[i]->service()->DisableForUser(); 445 clients_[i]->service()->DisableForUser();
428 } 446 }
429 447
430 // Some of the pending messages might rely on browser windows still being 448 // Some of the pending messages might rely on browser windows still being
431 // around, so run messages both before and after closing all browsers. 449 // around, so run messages both before and after closing all browsers.
432 content::RunAllPendingInMessageLoop(); 450 content::RunAllPendingInMessageLoop();
433 // Close all browser windows. 451 // Close all browser windows.
434 chrome::CloseAllBrowsers(); 452 chrome::CloseAllBrowsers();
435 content::RunAllPendingInMessageLoop(); 453 content::RunAllPendingInMessageLoop();
436 454
455 if (fake_server_.get()) {
456 std::vector<fake_server::FakeServerInvalidationService*>::const_iterator it;
457 for (it = fake_server_invalidation_services_.begin();
458 it != fake_server_invalidation_services_.end(); ++it) {
459 fake_server_->RemoveObserver(*it);
460 }
461 }
462
437 // All browsers should be closed at this point, or else we could see memory 463 // All browsers should be closed at this point, or else we could see memory
438 // corruption in QuitBrowser(). 464 // corruption in QuitBrowser().
439 CHECK_EQ(0U, chrome::GetTotalBrowserCount()); 465 CHECK_EQ(0U, chrome::GetTotalBrowserCount());
440 invalidation_forwarders_.clear(); 466 invalidation_forwarders_.clear();
467 fake_server_invalidation_services_.clear();
441 clients_.clear(); 468 clients_.clear();
442 } 469 }
443 470
444 void SyncTest::SetUpInProcessBrowserTestFixture() { 471 void SyncTest::SetUpInProcessBrowserTestFixture() {
445 // We don't take a reference to |resolver|, but mock_host_resolver_override_ 472 // We don't take a reference to |resolver|, but mock_host_resolver_override_
446 // does, so effectively assumes ownership. 473 // does, so effectively assumes ownership.
447 net::RuleBasedHostResolverProc* resolver = 474 net::RuleBasedHostResolverProc* resolver =
448 new net::RuleBasedHostResolverProc(host_resolver()); 475 new net::RuleBasedHostResolverProc(host_resolver());
449 resolver->AllowDirectLookup("*.google.com"); 476 resolver->AllowDirectLookup("*.google.com");
450 // On Linux, we use Chromium's NSS implementation which uses the following 477 // On Linux, we use Chromium's NSS implementation which uses the following
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; 625 LOG(FATAL) << "Failed to set up local python sync and XMPP servers";
599 SetupMockGaiaResponses(); 626 SetupMockGaiaResponses();
600 } else if (server_type_ == LOCAL_LIVE_SERVER) { 627 } else if (server_type_ == LOCAL_LIVE_SERVER) {
601 // Using mock gaia credentials requires the use of a mock XMPP server. 628 // Using mock gaia credentials requires the use of a mock XMPP server.
602 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) 629 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer())
603 LOG(FATAL) << "Failed to set up local python XMPP server"; 630 LOG(FATAL) << "Failed to set up local python XMPP server";
604 if (!SetUpLocalTestServer()) 631 if (!SetUpLocalTestServer())
605 LOG(FATAL) << "Failed to set up local test server"; 632 LOG(FATAL) << "Failed to set up local test server";
606 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) { 633 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) {
607 fake_server_.reset(new fake_server::FakeServer()); 634 fake_server_.reset(new fake_server::FakeServer());
608 // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP.
609 SetUpLocalPythonTestServer();
610 SetupMockGaiaResponses(); 635 SetupMockGaiaResponses();
611 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { 636 } else if (server_type_ == EXTERNAL_LIVE_SERVER) {
612 // Nothing to do; we'll just talk to the URL we were given. 637 // Nothing to do; we'll just talk to the URL we were given.
613 } else { 638 } else {
614 LOG(FATAL) << "Don't know which server environment to run test in."; 639 LOG(FATAL) << "Don't know which server environment to run test in.";
615 } 640 }
616 } 641 }
617 642
618 bool SyncTest::SetUpLocalPythonTestServer() { 643 bool SyncTest::SetUpLocalPythonTestServer() {
619 EXPECT_TRUE(sync_server_.Start()) 644 EXPECT_TRUE(sync_server_.Start())
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | 743 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE |
719 net::LOAD_DO_NOT_SEND_COOKIES | 744 net::LOAD_DO_NOT_SEND_COOKIES |
720 net::LOAD_DO_NOT_SAVE_COOKIES); 745 net::LOAD_DO_NOT_SAVE_COOKIES);
721 fetcher->SetRequestContext(g_browser_process->system_request_context()); 746 fetcher->SetRequestContext(g_browser_process->system_request_context());
722 fetcher->Start(); 747 fetcher->Start();
723 content::RunMessageLoop(); 748 content::RunMessageLoop();
724 return delegate.running(); 749 return delegate.running();
725 } 750 }
726 751
727 void SyncTest::EnableNetwork(Profile* profile) { 752 void SyncTest::EnableNetwork(Profile* profile) {
753 // TODO(pvalenzuela): Remove this restriction when FakeServer's observers
754 // (namely FakeServerInvaldationService) are aware of a network disconnect.
755 ASSERT_NE(IN_PROCESS_FAKE_SERVER, server_type_)
756 << "FakeServer does not support EnableNetwork.";
728 SetProxyConfig(profile->GetRequestContext(), 757 SetProxyConfig(profile->GetRequestContext(),
729 net::ProxyConfig::CreateDirect()); 758 net::ProxyConfig::CreateDirect());
730 if (notifications_enabled_) { 759 if (notifications_enabled_) {
731 EnableNotificationsImpl(); 760 EnableNotificationsImpl();
732 } 761 }
733 // TODO(rsimha): Remove this line once http://crbug.com/53857 is fixed. 762 // TODO(rsimha): Remove this line once http://crbug.com/53857 is fixed.
734 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 763 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
735 } 764 }
736 765
737 void SyncTest::DisableNetwork(Profile* profile) { 766 void SyncTest::DisableNetwork(Profile* profile) {
767 // TODO(pvalenzuela): Remove this restriction when FakeServer's observers
768 // (namely FakeServerInvaldationService) are aware of a network disconnect.
769 ASSERT_NE(IN_PROCESS_FAKE_SERVER, server_type_)
770 << "FakeServer does not support DisableNetwork.";
738 DisableNotificationsImpl(); 771 DisableNotificationsImpl();
739 // Set the current proxy configuration to a nonexistent proxy to effectively 772 // Set the current proxy configuration to a nonexistent proxy to effectively
740 // disable networking. 773 // disable networking.
741 net::ProxyConfig config; 774 net::ProxyConfig config;
742 config.proxy_rules().ParseFromString("http=127.0.0.1:0"); 775 config.proxy_rules().ParseFromString("http=127.0.0.1:0");
743 SetProxyConfig(profile->GetRequestContext(), config); 776 SetProxyConfig(profile->GetRequestContext(), config);
744 // TODO(rsimha): Remove this line once http://crbug.com/53857 is fixed. 777 // TODO(rsimha): Remove this line once http://crbug.com/53857 is fixed.
745 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 778 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
746 } 779 }
747 780
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 BrowserThread::PostTask( 1027 BrowserThread::PostTask(
995 BrowserThread::IO, FROM_HERE, 1028 BrowserThread::IO, FROM_HERE,
996 base::Bind(&SetProxyConfigCallback, &done, 1029 base::Bind(&SetProxyConfigCallback, &done,
997 make_scoped_refptr(context_getter), proxy_config)); 1030 make_scoped_refptr(context_getter), proxy_config));
998 done.Wait(); 1031 done.Wait();
999 } 1032 }
1000 1033
1001 fake_server::FakeServer* SyncTest::GetFakeServer() const { 1034 fake_server::FakeServer* SyncTest::GetFakeServer() const {
1002 return fake_server_.get(); 1035 return fake_server_.get();
1003 } 1036 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698