Chromium Code Reviews| Index: chrome/browser/sync/test/integration/sync_test.cc |
| diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc |
| index e936fd10c43b8b0e6b37613ef155ec978b9410fd..101f30eafb13eb7b0b5adff54fe22a23dafd63e9 100644 |
| --- a/chrome/browser/sync/test/integration/sync_test.cc |
| +++ b/chrome/browser/sync/test/integration/sync_test.cc |
| @@ -58,6 +58,8 @@ |
| #include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "sync/engine/sync_scheduler_impl.h" |
| +#include "sync/internal_api/public/test/fake_server.h" |
| +#include "sync/internal_api/public/test/fake_server_network_resources.h" |
| #include "sync/notifier/p2p_invalidator.h" |
| #include "sync/protocol/sync.pb.h" |
| #include "url/gurl.h" |
| @@ -143,30 +145,34 @@ void SyncTest::SetUp() { |
| password_ = "password"; |
| } |
| - if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| - !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| - // If neither a sync server URL nor a sync server command line is |
| - // provided, start up a local python sync test server and point Chrome |
| - // to its URL. This is the most common configuration, and the only |
| - // one that makes sense for most developers. |
| - server_type_ = LOCAL_PYTHON_SERVER; |
| - } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| - cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| - // If a sync server URL and a sync server command line are provided, |
| - // start up a local sync server by running the command line. Chrome |
| - // will connect to the server at the URL that was provided. |
| - server_type_ = LOCAL_LIVE_SERVER; |
| - } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| - !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| - // If a sync server URL is provided, but not a server command line, |
| - // it is assumed that the server is already running. Chrome will |
| - // automatically connect to it at the URL provided. There is nothing |
| - // to do here. |
| - server_type_ = EXTERNAL_LIVE_SERVER; |
| - } else { |
| - // If a sync server command line is provided, but not a server URL, |
| - // we flag an error. |
| - LOG(FATAL) << "Can't figure out how to run a server."; |
| + // Only set |server_type_| if it hasn't already been set. This allows for |
| + // FAKE_SERVER tests to set this value in each test class. |
| + if (server_type_ == SERVER_TYPE_UNDECIDED) { |
| + if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| + !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| + // If neither a sync server URL nor a sync server command line is |
| + // provided, start up a local python sync test server and point Chrome |
| + // to its URL. This is the most common configuration, and the only |
| + // one that makes sense for most developers. |
| + server_type_ = LOCAL_PYTHON_SERVER; |
| + } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| + cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| + // If a sync server URL and a sync server command line are provided, |
| + // start up a local sync server by running the command line. Chrome |
| + // will connect to the server at the URL that was provided. |
| + server_type_ = LOCAL_LIVE_SERVER; |
| + } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| + !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| + // If a sync server URL is provided, but not a server command line, |
| + // it is assumed that the server is already running. Chrome will |
| + // automatically connect to it at the URL provided. There is nothing |
| + // to do here. |
| + server_type_ = EXTERNAL_LIVE_SERVER; |
| + } else { |
| + // If a sync server command line is provided, but not a server URL, |
| + // we flag an error. |
| + LOG(FATAL) << "Can't figure out how to run a server."; |
| + } |
| } |
| if (username_.empty() || password_.empty()) |
| @@ -316,7 +322,14 @@ void SyncTest::InitializeInstance(int index) { |
| // Make sure the ProfileSyncService has been created before creating the |
| // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to |
| // already exist. |
| - ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| + ProfileSyncService* profile_sync_service = |
| + ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| + |
| + if (server_type_ == FAKE_SERVER) { |
| + profile_sync_service->OverrideNetworkResourcesForTest( |
| + make_scoped_ptr<syncer::NetworkResources>( |
| + new syncer::FakeServerNetworkResources(fake_server_.get()))); |
| + } |
| clients_[index] = |
| ProfileSyncServiceHarness::CreateForIntegrationTest( |
| @@ -502,6 +515,13 @@ void SyncTest::SetUpTestServerIfRequired() { |
| LOG(FATAL) << "Failed to set up local python XMPP server"; |
| if (!SetUpLocalTestServer()) |
| LOG(FATAL) << "Failed to set up local test server"; |
| + } else if (server_type_ == FAKE_SERVER) { |
| + fake_server_.reset(new syncer::FakeServer()); |
| + if (!fake_server_->Init()) |
| + LOG(FATAL) << "Failed to initialize fake server."; |
| + // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP. |
| + SetUpLocalPythonTestServer(); |
| + SetupMockGaiaResponses(); |
| } else if (server_type_ == EXTERNAL_LIVE_SERVER) { |
| // Nothing to do; we'll just talk to the URL we were given. |
| } else { |
| @@ -855,3 +875,7 @@ void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, |
| make_scoped_refptr(context_getter), proxy_config)); |
| done.Wait(); |
| } |
| + |
| +void SyncTest::UseFakeServer() { |
| + server_type_ = FAKE_SERVER; |
|
rlarocque
2013/12/18 20:22:01
Can you somehow DCHECK that SetUp() hasn't been ca
pval...(no longer on Chromium)
2013/12/19 01:16:56
Great idea. Thanks.
|
| +} |