| 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 "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 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
| 28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 29 #include "chrome/browser/signin/profile_identity_provider.h" | 29 #include "chrome/browser/signin/profile_identity_provider.h" |
| 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 31 #include "chrome/browser/signin/signin_manager_factory.h" | 31 #include "chrome/browser/signin/signin_manager_factory.h" |
| 32 #include "chrome/browser/sync/glue/invalidation_helper.h" | 32 #include "chrome/browser/sync/glue/invalidation_helper.h" |
| 33 #include "chrome/browser/sync/profile_sync_service.h" | 33 #include "chrome/browser/sync/profile_sync_service.h" |
| 34 #include "chrome/browser/sync/profile_sync_service_factory.h" | 34 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 35 #include "chrome/browser/sync/test/integration/fake_server_invalidation_service.
h" | 35 #include "chrome/browser/sync/test/integration/fake_server_invalidation_service.
h" |
| 36 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h" | 36 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h" |
| 37 #include "chrome/browser/sync/test/integration/p2p_sync_refresher.h" |
| 37 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 38 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 38 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 39 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| 39 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 40 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 40 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 41 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 41 #include "chrome/browser/ui/browser.h" | 42 #include "chrome/browser/ui/browser.h" |
| 42 #include "chrome/browser/ui/browser_finder.h" | 43 #include "chrome/browser/ui/browser_finder.h" |
| 43 #include "chrome/browser/ui/host_desktop.h" | 44 #include "chrome/browser/ui/host_desktop.h" |
| 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 45 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 46 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 46 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (num_clients_ <= 0) | 381 if (num_clients_ <= 0) |
| 381 LOG(FATAL) << "num_clients_ incorrectly initialized."; | 382 LOG(FATAL) << "num_clients_ incorrectly initialized."; |
| 382 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) | 383 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) |
| 383 LOG(FATAL) << "SetupClients() has already been called."; | 384 LOG(FATAL) << "SetupClients() has already been called."; |
| 384 | 385 |
| 385 // Create the required number of sync profiles, browsers and clients. | 386 // Create the required number of sync profiles, browsers and clients. |
| 386 profiles_.resize(num_clients_); | 387 profiles_.resize(num_clients_); |
| 387 browsers_.resize(num_clients_); | 388 browsers_.resize(num_clients_); |
| 388 clients_.resize(num_clients_); | 389 clients_.resize(num_clients_); |
| 389 invalidation_forwarders_.resize(num_clients_); | 390 invalidation_forwarders_.resize(num_clients_); |
| 391 sync_refreshers_.resize(num_clients_); |
| 390 fake_server_invalidation_services_.resize(num_clients_); | 392 fake_server_invalidation_services_.resize(num_clients_); |
| 391 for (int i = 0; i < num_clients_; ++i) { | 393 for (int i = 0; i < num_clients_; ++i) { |
| 392 InitializeInstance(i); | 394 InitializeInstance(i); |
| 393 } | 395 } |
| 394 | 396 |
| 395 // Create the verifier profile. | 397 // Create the verifier profile. |
| 396 verifier_ = MakeProfile(FILE_PATH_LITERAL("Verifier")); | 398 verifier_ = MakeProfile(FILE_PATH_LITERAL("Verifier")); |
| 397 bookmarks::test::WaitForBookmarkModelToLoad( | 399 bookmarks::test::WaitForBookmarkModelToLoad( |
| 398 BookmarkModelFactory::GetForProfile(verifier())); | 400 BookmarkModelFactory::GetForProfile(verifier())); |
| 399 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( | 401 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 GetInvalidationService()); | 477 GetInvalidationService()); |
| 476 fake_server_->AddObserver(invalidation_service); | 478 fake_server_->AddObserver(invalidation_service); |
| 477 if (TestUsesSelfNotifications()) { | 479 if (TestUsesSelfNotifications()) { |
| 478 invalidation_service->EnableSelfNotifications(); | 480 invalidation_service->EnableSelfNotifications(); |
| 479 } else { | 481 } else { |
| 480 invalidation_service->DisableSelfNotifications(); | 482 invalidation_service->DisableSelfNotifications(); |
| 481 } | 483 } |
| 482 fake_server_invalidation_services_[index] = invalidation_service; | 484 fake_server_invalidation_services_[index] = invalidation_service; |
| 483 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { | 485 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { |
| 484 // DO NOTHING. External live sync servers use GCM to notify profiles of any | 486 // DO NOTHING. External live sync servers use GCM to notify profiles of any |
| 485 // invalidations in sync'ed data. | 487 // invalidations in sync'ed data. In this case, to notify other profiles of |
| 488 // invalidations, we use sync refresh notifications instead. |
| 486 } else { | 489 } else { |
| 487 invalidation::P2PInvalidationService* p2p_invalidation_service = | 490 invalidation::P2PInvalidationService* p2p_invalidation_service = |
| 488 static_cast<invalidation::P2PInvalidationService*>( | 491 static_cast<invalidation::P2PInvalidationService*>( |
| 489 static_cast<invalidation::ProfileInvalidationProvider*>( | 492 static_cast<invalidation::ProfileInvalidationProvider*>( |
| 490 invalidation::ProfileInvalidationProviderFactory:: | 493 invalidation::ProfileInvalidationProviderFactory:: |
| 491 GetInstance()->SetTestingFactoryAndUse( | 494 GetInstance()->SetTestingFactoryAndUse( |
| 492 GetProfile(index), | 495 GetProfile(index), |
| 493 TestUsesSelfNotifications() ? | 496 TestUsesSelfNotifications() ? |
| 494 BuildSelfNotifyingP2PProfileInvalidationProvider : | 497 BuildSelfNotifyingP2PProfileInvalidationProvider : |
| 495 BuildRealisticP2PProfileInvalidationProvider))-> | 498 BuildRealisticP2PProfileInvalidationProvider))-> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 519 // session-releated data is rewritten), we need to ensure all startup-based | 522 // session-releated data is rewritten), we need to ensure all startup-based |
| 520 // changes have propagated between the clients. | 523 // changes have propagated between the clients. |
| 521 // | 524 // |
| 522 // Tests that don't use self-notifications can't await quiescense. They'll | 525 // Tests that don't use self-notifications can't await quiescense. They'll |
| 523 // have to find their own way of waiting for an initial state if they really | 526 // have to find their own way of waiting for an initial state if they really |
| 524 // need such guarantees. | 527 // need such guarantees. |
| 525 if (TestUsesSelfNotifications()) { | 528 if (TestUsesSelfNotifications()) { |
| 526 AwaitQuiescence(); | 529 AwaitQuiescence(); |
| 527 } | 530 } |
| 528 | 531 |
| 532 // SyncRefresher is used instead of invalidations to notify other profiles to |
| 533 // do a sync refresh on committed data sets. This is only needed when running |
| 534 // tests against external live server, otherwise invalidation service is used. |
| 535 // With external live servers, the profiles commit data on first sync cycle |
| 536 // automatically after signing in. To avoid misleading sync commit |
| 537 // notifications at start up, we start the SyncRefresher observers post |
| 538 // client set up. |
| 539 if (server_type_ == EXTERNAL_LIVE_SERVER) { |
| 540 for (int i = 0; i < num_clients_; ++i) { |
| 541 sync_refreshers_[i] = new P2PSyncRefresher(clients_[i]->service()); |
| 542 } |
| 543 } |
| 544 |
| 529 return true; | 545 return true; |
| 530 } | 546 } |
| 531 | 547 |
| 532 void SyncTest::TearDownOnMainThread() { | 548 void SyncTest::TearDownOnMainThread() { |
| 533 for (size_t i = 0; i < clients_.size(); ++i) { | 549 for (size_t i = 0; i < clients_.size(); ++i) { |
| 534 clients_[i]->service()->DisableForUser(); | 550 clients_[i]->service()->DisableForUser(); |
| 535 } | 551 } |
| 536 | 552 |
| 537 // Some of the pending messages might rely on browser windows still being | 553 // Some of the pending messages might rely on browser windows still being |
| 538 // around, so run messages both before and after closing all browsers. | 554 // around, so run messages both before and after closing all browsers. |
| 539 content::RunAllPendingInMessageLoop(); | 555 content::RunAllPendingInMessageLoop(); |
| 540 // Close all browser windows. | 556 // Close all browser windows. |
| 541 chrome::CloseAllBrowsers(); | 557 chrome::CloseAllBrowsers(); |
| 542 content::RunAllPendingInMessageLoop(); | 558 content::RunAllPendingInMessageLoop(); |
| 543 | 559 |
| 544 if (fake_server_.get()) { | 560 if (fake_server_.get()) { |
| 545 std::vector<fake_server::FakeServerInvalidationService*>::const_iterator it; | 561 std::vector<fake_server::FakeServerInvalidationService*>::const_iterator it; |
| 546 for (it = fake_server_invalidation_services_.begin(); | 562 for (it = fake_server_invalidation_services_.begin(); |
| 547 it != fake_server_invalidation_services_.end(); ++it) { | 563 it != fake_server_invalidation_services_.end(); ++it) { |
| 548 fake_server_->RemoveObserver(*it); | 564 fake_server_->RemoveObserver(*it); |
| 549 } | 565 } |
| 550 } | 566 } |
| 551 | 567 |
| 552 // All browsers should be closed at this point, or else we could see memory | 568 // All browsers should be closed at this point, or else we could see memory |
| 553 // corruption in QuitBrowser(). | 569 // corruption in QuitBrowser(). |
| 554 CHECK_EQ(0U, chrome::GetTotalBrowserCount()); | 570 CHECK_EQ(0U, chrome::GetTotalBrowserCount()); |
| 555 invalidation_forwarders_.clear(); | 571 invalidation_forwarders_.clear(); |
| 572 sync_refreshers_.clear(); |
| 556 fake_server_invalidation_services_.clear(); | 573 fake_server_invalidation_services_.clear(); |
| 557 clients_.clear(); | 574 clients_.clear(); |
| 558 } | 575 } |
| 559 | 576 |
| 560 void SyncTest::SetUpInProcessBrowserTestFixture() { | 577 void SyncTest::SetUpInProcessBrowserTestFixture() { |
| 561 // We don't take a reference to |resolver|, but mock_host_resolver_override_ | 578 // We don't take a reference to |resolver|, but mock_host_resolver_override_ |
| 562 // does, so effectively assumes ownership. | 579 // does, so effectively assumes ownership. |
| 563 net::RuleBasedHostResolverProc* resolver = | 580 net::RuleBasedHostResolverProc* resolver = |
| 564 new net::RuleBasedHostResolverProc(host_resolver()); | 581 new net::RuleBasedHostResolverProc(host_resolver()); |
| 565 resolver->AllowDirectLookup("*.google.com"); | 582 resolver->AllowDirectLookup("*.google.com"); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 BrowserThread::PostTask( | 1001 BrowserThread::PostTask( |
| 985 BrowserThread::IO, FROM_HERE, | 1002 BrowserThread::IO, FROM_HERE, |
| 986 base::Bind(&SetupNetworkCallback, &done, | 1003 base::Bind(&SetupNetworkCallback, &done, |
| 987 make_scoped_refptr(context_getter))); | 1004 make_scoped_refptr(context_getter))); |
| 988 done.Wait(); | 1005 done.Wait(); |
| 989 } | 1006 } |
| 990 | 1007 |
| 991 fake_server::FakeServer* SyncTest::GetFakeServer() const { | 1008 fake_server::FakeServer* SyncTest::GetFakeServer() const { |
| 992 return fake_server_.get(); | 1009 return fake_server_.get(); |
| 993 } | 1010 } |
| OLD | NEW |