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

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

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

Powered by Google App Engine
This is Rietveld 408576698