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

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, 8 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/invalidation/profile_invalidation_auth_provider.h" 29 #include "chrome/browser/invalidation/profile_invalidation_auth_provider.h"
30 #include "chrome/browser/lifetime/application_lifetime.h" 30 #include "chrome/browser/lifetime/application_lifetime.h"
31 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/profiles/profile_manager.h" 32 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/browser/search_engines/template_url_service.h" 33 #include "chrome/browser/search_engines/template_url_service.h"
34 #include "chrome/browser/search_engines/template_url_service_factory.h" 34 #include "chrome/browser/search_engines/template_url_service_factory.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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 profiles_[index] = MakeProfile( 347 profiles_[index] = MakeProfile(
347 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index)); 348 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index));
348 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile " 349 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile "
349 << index << "."; 350 << index << ".";
350 351
351 browsers_[index] = new Browser(Browser::CreateParams( 352 browsers_[index] = new Browser(Browser::CreateParams(
352 GetProfile(index), chrome::GetActiveDesktop())); 353 GetProfile(index), chrome::GetActiveDesktop()));
353 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser " 354 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser "
354 << index << "."; 355 << index << ".";
355 356
356 invalidation::P2PInvalidationService* p2p_invalidation_service =
357 static_cast<invalidation::P2PInvalidationService*>(
358 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
359 GetProfile(index),
360 TestUsesSelfNotifications() ?
361 BuildSelfNotifyingP2PInvalidationService
362 : BuildRealisticP2PInvalidationService));
363 p2p_invalidation_service->UpdateCredentials(username_, password_);
364 357
365 // Make sure the ProfileSyncService has been created before creating the 358 // Make sure the ProfileSyncService has been created before creating the
366 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to 359 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to
367 // already exist. 360 // already exist.
368 ProfileSyncService* profile_sync_service = 361 ProfileSyncService* profile_sync_service =
369 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); 362 ProfileSyncServiceFactory::GetForProfile(GetProfile(index));
370 363
371 if (server_type_ == IN_PROCESS_FAKE_SERVER) { 364 if (server_type_ == IN_PROCESS_FAKE_SERVER) {
372 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. 365 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer.
373 profile_sync_service->OverrideNetworkResourcesForTest( 366 profile_sync_service->OverrideNetworkResourcesForTest(
374 make_scoped_ptr<syncer::NetworkResources>( 367 make_scoped_ptr<syncer::NetworkResources>(
375 new fake_server::FakeServerNetworkResources(fake_server_.get()))); 368 new fake_server::FakeServerNetworkResources(fake_server_.get())));
376 } 369 }
377 370
378 clients_[index] = 371 clients_[index] =
379 ProfileSyncServiceHarness::Create( 372 ProfileSyncServiceHarness::Create(
380 GetProfile(index), 373 GetProfile(index),
381 username_, 374 username_,
382 password_); 375 password_);
383 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " 376 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client "
384 << index << "."; 377 << index << ".";
385 378 InitializeInvalidations(index);
386 // Start listening for and emitting notificaitons of commits.
387 invalidation_forwarders_[index] =
388 new P2PInvalidationForwarder(clients_[index]->service(),
389 p2p_invalidation_service);
390 379
391 test::WaitForBookmarkModelToLoad( 380 test::WaitForBookmarkModelToLoad(
392 BookmarkModelFactory::GetForProfile(GetProfile(index))); 381 BookmarkModelFactory::GetForProfile(GetProfile(index)));
393 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( 382 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile(
394 GetProfile(index), Profile::EXPLICIT_ACCESS)); 383 GetProfile(index), Profile::EXPLICIT_ACCESS));
395 ui_test_utils::WaitForTemplateURLServiceToLoad( 384 ui_test_utils::WaitForTemplateURLServiceToLoad(
396 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); 385 TemplateURLServiceFactory::GetForProfile(GetProfile(index)));
397 } 386 }
398 387
388 void SyncTest::InitializeInvalidations(int index) {
389 if (server_type_ == IN_PROCESS_FAKE_SERVER) {
390 CHECK(fake_server_.get());
391 fake_server::FakeServerInvalidationService* invalidation_service =
392 static_cast<fake_server::FakeServerInvalidationService*>(
393 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
394 GetProfile(index),
395 fake_server::FakeServerInvalidationService::Build));
396 fake_server_->AddObserver(invalidation_service);
397 } else {
398 invalidation::P2PInvalidationService* p2p_invalidation_service =
399 static_cast<invalidation::P2PInvalidationService*>(
400 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse(
401 GetProfile(index),
402 TestUsesSelfNotifications() ?
403 BuildSelfNotifyingP2PInvalidationService
404 : BuildRealisticP2PInvalidationService));
405 p2p_invalidation_service->UpdateCredentials(username_, password_);
406 // Start listening for and emitting notificaitons of commits.
407 invalidation_forwarders_[index] =
408 new P2PInvalidationForwarder(clients_[index]->service(),
409 p2p_invalidation_service);
410 }
411 }
412
399 bool SyncTest::SetupSync() { 413 bool SyncTest::SetupSync() {
400 // Create sync profiles and clients if they haven't already been created. 414 // Create sync profiles and clients if they haven't already been created.
401 if (profiles_.empty()) { 415 if (profiles_.empty()) {
402 if (!SetupClients()) 416 if (!SetupClients())
403 LOG(FATAL) << "SetupClients() failed."; 417 LOG(FATAL) << "SetupClients() failed.";
404 } 418 }
405 419
406 // Sync each of the profiles. 420 // Sync each of the profiles.
407 for (int i = 0; i < num_clients_; ++i) { 421 for (int i = 0; i < num_clients_; ++i) {
408 if (!GetClient(i)->SetupSync()) 422 if (!GetClient(i)->SetupSync())
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; 613 LOG(FATAL) << "Failed to set up local python sync and XMPP servers";
600 SetupMockGaiaResponses(); 614 SetupMockGaiaResponses();
601 } else if (server_type_ == LOCAL_LIVE_SERVER) { 615 } else if (server_type_ == LOCAL_LIVE_SERVER) {
602 // Using mock gaia credentials requires the use of a mock XMPP server. 616 // Using mock gaia credentials requires the use of a mock XMPP server.
603 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) 617 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer())
604 LOG(FATAL) << "Failed to set up local python XMPP server"; 618 LOG(FATAL) << "Failed to set up local python XMPP server";
605 if (!SetUpLocalTestServer()) 619 if (!SetUpLocalTestServer())
606 LOG(FATAL) << "Failed to set up local test server"; 620 LOG(FATAL) << "Failed to set up local test server";
607 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) { 621 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) {
608 fake_server_.reset(new fake_server::FakeServer()); 622 fake_server_.reset(new fake_server::FakeServer());
609 // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP.
610 SetUpLocalPythonTestServer();
611 SetupMockGaiaResponses(); 623 SetupMockGaiaResponses();
612 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { 624 } else if (server_type_ == EXTERNAL_LIVE_SERVER) {
613 // Nothing to do; we'll just talk to the URL we were given. 625 // Nothing to do; we'll just talk to the URL we were given.
614 } else { 626 } else {
615 LOG(FATAL) << "Don't know which server environment to run test in."; 627 LOG(FATAL) << "Don't know which server environment to run test in.";
616 } 628 }
617 } 629 }
618 630
619 bool SyncTest::SetUpLocalPythonTestServer() { 631 bool SyncTest::SetUpLocalPythonTestServer() {
620 EXPECT_TRUE(sync_server_.Start()) 632 EXPECT_TRUE(sync_server_.Start())
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 992
981 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, 993 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter,
982 const net::ProxyConfig& proxy_config) { 994 const net::ProxyConfig& proxy_config) {
983 base::WaitableEvent done(false, false); 995 base::WaitableEvent done(false, false);
984 BrowserThread::PostTask( 996 BrowserThread::PostTask(
985 BrowserThread::IO, FROM_HERE, 997 BrowserThread::IO, FROM_HERE,
986 base::Bind(&SetProxyConfigCallback, &done, 998 base::Bind(&SetProxyConfigCallback, &done,
987 make_scoped_refptr(context_getter), proxy_config)); 999 make_scoped_refptr(context_getter), proxy_config));
988 done.Wait(); 1000 done.Wait();
989 } 1001 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698