| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/notifier/p2p_invalidator.h" | 61 #include "sync/notifier/p2p_invalidator.h" |
| 62 #include "sync/protocol/sync.pb.h" | 62 #include "sync/protocol/sync.pb.h" |
| 63 #include "sync/test/fake_server/fake_server.h" |
| 64 #include "sync/test/fake_server/fake_server_network_resources.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"; |
| 71 const char kSyncPasswordForTest[] = "sync-password-for-test"; | 73 const char kSyncPasswordForTest[] = "sync-password-for-test"; |
| 72 const char kSyncServerCommandLine[] = "sync-server-command-line"; | 74 const char kSyncServerCommandLine[] = "sync-server-command-line"; |
| (...skipping 63 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 // IN_PROCESS_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_ == IN_PROCESS_FAKE_SERVER) { |
| 329 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. |
| 330 profile_sync_service->OverrideNetworkResourcesForTest( |
| 331 make_scoped_ptr<syncer::NetworkResources>( |
| 332 new syncer::FakeServerNetworkResources(fake_server_.get()))); |
| 333 } |
| 320 | 334 |
| 321 clients_[index] = | 335 clients_[index] = |
| 322 ProfileSyncServiceHarness::CreateForIntegrationTest( | 336 ProfileSyncServiceHarness::CreateForIntegrationTest( |
| 323 GetProfile(index), | 337 GetProfile(index), |
| 324 username_, | 338 username_, |
| 325 password_, | 339 password_, |
| 326 p2p_invalidation_service); | 340 p2p_invalidation_service); |
| 327 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " | 341 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " |
| 328 << index << "."; | 342 << index << "."; |
| 329 | 343 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 if (server_type_ == LOCAL_PYTHON_SERVER) { | 509 if (server_type_ == LOCAL_PYTHON_SERVER) { |
| 496 if (!SetUpLocalPythonTestServer()) | 510 if (!SetUpLocalPythonTestServer()) |
| 497 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; | 511 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; |
| 498 SetupMockGaiaResponses(); | 512 SetupMockGaiaResponses(); |
| 499 } else if (server_type_ == LOCAL_LIVE_SERVER) { | 513 } else if (server_type_ == LOCAL_LIVE_SERVER) { |
| 500 // Using mock gaia credentials requires the use of a mock XMPP server. | 514 // Using mock gaia credentials requires the use of a mock XMPP server. |
| 501 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) | 515 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) |
| 502 LOG(FATAL) << "Failed to set up local python XMPP server"; | 516 LOG(FATAL) << "Failed to set up local python XMPP server"; |
| 503 if (!SetUpLocalTestServer()) | 517 if (!SetUpLocalTestServer()) |
| 504 LOG(FATAL) << "Failed to set up local test server"; | 518 LOG(FATAL) << "Failed to set up local test server"; |
| 519 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) { |
| 520 fake_server_.reset(new syncer::FakeServer()); |
| 521 // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP. |
| 522 SetUpLocalPythonTestServer(); |
| 523 SetupMockGaiaResponses(); |
| 505 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { | 524 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { |
| 506 // Nothing to do; we'll just talk to the URL we were given. | 525 // Nothing to do; we'll just talk to the URL we were given. |
| 507 } else { | 526 } else { |
| 508 LOG(FATAL) << "Don't know which server environment to run test in."; | 527 LOG(FATAL) << "Don't know which server environment to run test in."; |
| 509 } | 528 } |
| 510 } | 529 } |
| 511 | 530 |
| 512 bool SyncTest::SetUpLocalPythonTestServer() { | 531 bool SyncTest::SetUpLocalPythonTestServer() { |
| 513 EXPECT_TRUE(sync_server_.Start()) | 532 EXPECT_TRUE(sync_server_.Start()) |
| 514 << "Could not launch local python test server."; | 533 << "Could not launch local python test server."; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 867 |
| 849 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, | 868 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, |
| 850 const net::ProxyConfig& proxy_config) { | 869 const net::ProxyConfig& proxy_config) { |
| 851 base::WaitableEvent done(false, false); | 870 base::WaitableEvent done(false, false); |
| 852 BrowserThread::PostTask( | 871 BrowserThread::PostTask( |
| 853 BrowserThread::IO, FROM_HERE, | 872 BrowserThread::IO, FROM_HERE, |
| 854 base::Bind(&SetProxyConfigCallback, &done, | 873 base::Bind(&SetProxyConfigCallback, &done, |
| 855 make_scoped_refptr(context_getter), proxy_config)); | 874 make_scoped_refptr(context_getter), proxy_config)); |
| 856 done.Wait(); | 875 done.Wait(); |
| 857 } | 876 } |
| 877 |
| 878 void SyncTest::UseFakeServer() { |
| 879 DCHECK_EQ(SERVER_TYPE_UNDECIDED, server_type_); |
| 880 server_type_ = IN_PROCESS_FAKE_SERVER; |
| 881 } |
| OLD | NEW |