Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "net/proxy/proxy_config.h" | 51 #include "net/proxy/proxy_config.h" |
| 52 #include "net/proxy/proxy_config_service_fixed.h" | 52 #include "net/proxy/proxy_config_service_fixed.h" |
| 53 #include "net/proxy/proxy_service.h" | 53 #include "net/proxy/proxy_service.h" |
| 54 #include "net/test/spawned_test_server/spawned_test_server.h" | 54 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 55 #include "net/url_request/test_url_fetcher_factory.h" | 55 #include "net/url_request/test_url_fetcher_factory.h" |
| 56 #include "net/url_request/url_fetcher.h" | 56 #include "net/url_request/url_fetcher.h" |
| 57 #include "net/url_request/url_fetcher_delegate.h" | 57 #include "net/url_request/url_fetcher_delegate.h" |
| 58 #include "net/url_request/url_request_context.h" | 58 #include "net/url_request/url_request_context.h" |
| 59 #include "net/url_request/url_request_context_getter.h" | 59 #include "net/url_request/url_request_context_getter.h" |
| 60 #include "sync/engine/sync_scheduler_impl.h" | 60 #include "sync/engine/sync_scheduler_impl.h" |
| 61 #include "sync/internal_api/public/test/fake_server.h" | |
| 62 #include "sync/internal_api/public/test/fake_server_network_resources.h" | |
| 61 #include "sync/notifier/p2p_invalidator.h" | 63 #include "sync/notifier/p2p_invalidator.h" |
| 62 #include "sync/protocol/sync.pb.h" | 64 #include "sync/protocol/sync.pb.h" |
| 63 #include "url/gurl.h" | 65 #include "url/gurl.h" |
| 64 | 66 |
| 65 using content::BrowserThread; | 67 using content::BrowserThread; |
| 66 using invalidation::InvalidationServiceFactory; | 68 using invalidation::InvalidationServiceFactory; |
| 67 | 69 |
| 68 namespace switches { | 70 namespace switches { |
| 69 const char kPasswordFileForTest[] = "password-file-for-test"; | 71 const char kPasswordFileForTest[] = "password-file-for-test"; |
| 70 const char kSyncUserForTest[] = "sync-user-for-test"; | 72 const char kSyncUserForTest[] = "sync-user-for-test"; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 ReadPasswordFile(); | 138 ReadPasswordFile(); |
| 137 } else if (cl->HasSwitch(switches::kSyncUserForTest) && | 139 } else if (cl->HasSwitch(switches::kSyncUserForTest) && |
| 138 cl->HasSwitch(switches::kSyncPasswordForTest)) { | 140 cl->HasSwitch(switches::kSyncPasswordForTest)) { |
| 139 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); | 141 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
| 140 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | 142 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
| 141 } else { | 143 } else { |
| 142 username_ = "user@gmail.com"; | 144 username_ = "user@gmail.com"; |
| 143 password_ = "password"; | 145 password_ = "password"; |
| 144 } | 146 } |
| 145 | 147 |
| 146 if (!cl->HasSwitch(switches::kSyncServiceURL) && | 148 // Only set |server_type_| if it hasn't already been set. This allows for |
| 147 !cl->HasSwitch(switches::kSyncServerCommandLine)) { | 149 // FAKE_SERVER tests to set this value in each test class. |
| 148 // If neither a sync server URL nor a sync server command line is | 150 if (server_type_ == SERVER_TYPE_UNDECIDED) { |
| 149 // provided, start up a local python sync test server and point Chrome | 151 if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| 150 // to its URL. This is the most common configuration, and the only | 152 !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 151 // one that makes sense for most developers. | 153 // If neither a sync server URL nor a sync server command line is |
| 152 server_type_ = LOCAL_PYTHON_SERVER; | 154 // provided, start up a local python sync test server and point Chrome |
| 153 } else if (cl->HasSwitch(switches::kSyncServiceURL) && | 155 // to its URL. This is the most common configuration, and the only |
| 154 cl->HasSwitch(switches::kSyncServerCommandLine)) { | 156 // one that makes sense for most developers. |
| 155 // If a sync server URL and a sync server command line are provided, | 157 server_type_ = LOCAL_PYTHON_SERVER; |
| 156 // start up a local sync server by running the command line. Chrome | 158 } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| 157 // will connect to the server at the URL that was provided. | 159 cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 158 server_type_ = LOCAL_LIVE_SERVER; | 160 // If a sync server URL and a sync server command line are provided, |
| 159 } else if (cl->HasSwitch(switches::kSyncServiceURL) && | 161 // start up a local sync server by running the command line. Chrome |
| 160 !cl->HasSwitch(switches::kSyncServerCommandLine)) { | 162 // will connect to the server at the URL that was provided. |
| 161 // If a sync server URL is provided, but not a server command line, | 163 server_type_ = LOCAL_LIVE_SERVER; |
| 162 // it is assumed that the server is already running. Chrome will | 164 } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| 163 // automatically connect to it at the URL provided. There is nothing | 165 !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 164 // to do here. | 166 // If a sync server URL is provided, but not a server command line, |
| 165 server_type_ = EXTERNAL_LIVE_SERVER; | 167 // it is assumed that the server is already running. Chrome will |
| 166 } else { | 168 // automatically connect to it at the URL provided. There is nothing |
| 167 // If a sync server command line is provided, but not a server URL, | 169 // to do here. |
| 168 // we flag an error. | 170 server_type_ = EXTERNAL_LIVE_SERVER; |
| 169 LOG(FATAL) << "Can't figure out how to run a server."; | 171 } else { |
| 172 // If a sync server command line is provided, but not a server URL, | |
| 173 // we flag an error. | |
| 174 LOG(FATAL) << "Can't figure out how to run a server."; | |
| 175 } | |
| 170 } | 176 } |
| 171 | 177 |
| 172 if (username_.empty() || password_.empty()) | 178 if (username_.empty() || password_.empty()) |
| 173 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; | 179 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; |
| 174 | 180 |
| 175 // Mock the Mac Keychain service. The real Keychain can block on user input. | 181 // Mock the Mac Keychain service. The real Keychain can block on user input. |
| 176 #if defined(OS_MACOSX) | 182 #if defined(OS_MACOSX) |
| 177 Encryptor::UseMockKeychain(true); | 183 Encryptor::UseMockKeychain(true); |
| 178 #endif | 184 #endif |
| 179 | 185 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 << index << "."; | 315 << index << "."; |
| 310 | 316 |
| 311 invalidation::P2PInvalidationService* p2p_invalidation_service = | 317 invalidation::P2PInvalidationService* p2p_invalidation_service = |
| 312 InvalidationServiceFactory::GetInstance()-> | 318 InvalidationServiceFactory::GetInstance()-> |
| 313 BuildAndUseP2PInvalidationServiceForTest(GetProfile(index)); | 319 BuildAndUseP2PInvalidationServiceForTest(GetProfile(index)); |
| 314 p2p_invalidation_service->UpdateCredentials(username_, password_); | 320 p2p_invalidation_service->UpdateCredentials(username_, password_); |
| 315 | 321 |
| 316 // Make sure the ProfileSyncService has been created before creating the | 322 // Make sure the ProfileSyncService has been created before creating the |
| 317 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to | 323 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to |
| 318 // already exist. | 324 // already exist. |
| 319 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | 325 ProfileSyncService* profile_sync_service = |
| 326 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | |
| 327 | |
| 328 if (server_type_ == FAKE_SERVER) { | |
| 329 profile_sync_service->OverrideNetworkResourcesForTest( | |
| 330 make_scoped_ptr<syncer::NetworkResources>( | |
| 331 new syncer::FakeServerNetworkResources(fake_server_.get()))); | |
| 332 } | |
| 320 | 333 |
| 321 clients_[index] = | 334 clients_[index] = |
| 322 ProfileSyncServiceHarness::CreateForIntegrationTest( | 335 ProfileSyncServiceHarness::CreateForIntegrationTest( |
| 323 GetProfile(index), | 336 GetProfile(index), |
| 324 username_, | 337 username_, |
| 325 password_, | 338 password_, |
| 326 p2p_invalidation_service); | 339 p2p_invalidation_service); |
| 327 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " | 340 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " |
| 328 << index << "."; | 341 << index << "."; |
| 329 | 342 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 if (server_type_ == LOCAL_PYTHON_SERVER) { | 508 if (server_type_ == LOCAL_PYTHON_SERVER) { |
| 496 if (!SetUpLocalPythonTestServer()) | 509 if (!SetUpLocalPythonTestServer()) |
| 497 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; | 510 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; |
| 498 SetupMockGaiaResponses(); | 511 SetupMockGaiaResponses(); |
| 499 } else if (server_type_ == LOCAL_LIVE_SERVER) { | 512 } else if (server_type_ == LOCAL_LIVE_SERVER) { |
| 500 // Using mock gaia credentials requires the use of a mock XMPP server. | 513 // Using mock gaia credentials requires the use of a mock XMPP server. |
| 501 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) | 514 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) |
| 502 LOG(FATAL) << "Failed to set up local python XMPP server"; | 515 LOG(FATAL) << "Failed to set up local python XMPP server"; |
| 503 if (!SetUpLocalTestServer()) | 516 if (!SetUpLocalTestServer()) |
| 504 LOG(FATAL) << "Failed to set up local test server"; | 517 LOG(FATAL) << "Failed to set up local test server"; |
| 518 } else if (server_type_ == FAKE_SERVER) { | |
| 519 fake_server_.reset(new syncer::FakeServer()); | |
| 520 if (!fake_server_->Init()) | |
| 521 LOG(FATAL) << "Failed to initialize fake server."; | |
| 522 // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP. | |
| 523 SetUpLocalPythonTestServer(); | |
| 524 SetupMockGaiaResponses(); | |
| 505 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { | 525 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { |
| 506 // Nothing to do; we'll just talk to the URL we were given. | 526 // Nothing to do; we'll just talk to the URL we were given. |
| 507 } else { | 527 } else { |
| 508 LOG(FATAL) << "Don't know which server environment to run test in."; | 528 LOG(FATAL) << "Don't know which server environment to run test in."; |
| 509 } | 529 } |
| 510 } | 530 } |
| 511 | 531 |
| 512 bool SyncTest::SetUpLocalPythonTestServer() { | 532 bool SyncTest::SetUpLocalPythonTestServer() { |
| 513 EXPECT_TRUE(sync_server_.Start()) | 533 EXPECT_TRUE(sync_server_.Start()) |
| 514 << "Could not launch local python test server."; | 534 << "Could not launch local python test server."; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 | 868 |
| 849 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, | 869 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, |
| 850 const net::ProxyConfig& proxy_config) { | 870 const net::ProxyConfig& proxy_config) { |
| 851 base::WaitableEvent done(false, false); | 871 base::WaitableEvent done(false, false); |
| 852 BrowserThread::PostTask( | 872 BrowserThread::PostTask( |
| 853 BrowserThread::IO, FROM_HERE, | 873 BrowserThread::IO, FROM_HERE, |
| 854 base::Bind(&SetProxyConfigCallback, &done, | 874 base::Bind(&SetProxyConfigCallback, &done, |
| 855 make_scoped_refptr(context_getter), proxy_config)); | 875 make_scoped_refptr(context_getter), proxy_config)); |
| 856 done.Wait(); | 876 done.Wait(); |
| 857 } | 877 } |
| 878 | |
| 879 void SyncTest::UseFakeServer() { | |
| 880 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.
| |
| 881 } | |
| OLD | NEW |