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

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

Issue 115243007: Basic implementation of the Sync C++ fake server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix constant for clang Created 6 years, 11 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
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (server_type_ == LOCAL_PYTHON_SERVER) { 516 if (server_type_ == LOCAL_PYTHON_SERVER) {
503 if (!SetUpLocalPythonTestServer()) 517 if (!SetUpLocalPythonTestServer())
504 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; 518 LOG(FATAL) << "Failed to set up local python sync and XMPP servers";
505 SetupMockGaiaResponses(); 519 SetupMockGaiaResponses();
506 } else if (server_type_ == LOCAL_LIVE_SERVER) { 520 } else if (server_type_ == LOCAL_LIVE_SERVER) {
507 // Using mock gaia credentials requires the use of a mock XMPP server. 521 // Using mock gaia credentials requires the use of a mock XMPP server.
508 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) 522 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer())
509 LOG(FATAL) << "Failed to set up local python XMPP server"; 523 LOG(FATAL) << "Failed to set up local python XMPP server";
510 if (!SetUpLocalTestServer()) 524 if (!SetUpLocalTestServer())
511 LOG(FATAL) << "Failed to set up local test server"; 525 LOG(FATAL) << "Failed to set up local test server";
526 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) {
527 fake_server_.reset(new syncer::FakeServer());
528 // Similar to LOCAL_LIVE_SERVER, we must start this for XMPP.
529 SetUpLocalPythonTestServer();
530 SetupMockGaiaResponses();
512 } else if (server_type_ == EXTERNAL_LIVE_SERVER) { 531 } else if (server_type_ == EXTERNAL_LIVE_SERVER) {
513 // Nothing to do; we'll just talk to the URL we were given. 532 // Nothing to do; we'll just talk to the URL we were given.
514 } else { 533 } else {
515 LOG(FATAL) << "Don't know which server environment to run test in."; 534 LOG(FATAL) << "Don't know which server environment to run test in.";
516 } 535 }
517 } 536 }
518 537
519 bool SyncTest::SetUpLocalPythonTestServer() { 538 bool SyncTest::SetUpLocalPythonTestServer() {
520 EXPECT_TRUE(sync_server_.Start()) 539 EXPECT_TRUE(sync_server_.Start())
521 << "Could not launch local python test server."; 540 << "Could not launch local python test server.";
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 874
856 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, 875 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter,
857 const net::ProxyConfig& proxy_config) { 876 const net::ProxyConfig& proxy_config) {
858 base::WaitableEvent done(false, false); 877 base::WaitableEvent done(false, false);
859 BrowserThread::PostTask( 878 BrowserThread::PostTask(
860 BrowserThread::IO, FROM_HERE, 879 BrowserThread::IO, FROM_HERE,
861 base::Bind(&SetProxyConfigCallback, &done, 880 base::Bind(&SetProxyConfigCallback, &done,
862 make_scoped_refptr(context_getter), proxy_config)); 881 make_scoped_refptr(context_getter), proxy_config));
863 done.Wait(); 882 done.Wait();
864 } 883 }
884
885 void SyncTest::UseFakeServer() {
886 DCHECK_EQ(SERVER_TYPE_UNDECIDED, server_type_);
887 server_type_ = IN_PROCESS_FAKE_SERVER;
888 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698