| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/test/live_sync/live_sync_test.h" | 5 #include "chrome/test/live_sync/live_sync_test.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (cl->HasSwitch(switches::kSyncServiceURL) && | 263 if (cl->HasSwitch(switches::kSyncServiceURL) && |
| 264 cl->HasSwitch(switches::kSyncServerCommandLine)) { | 264 cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 265 if (!SetUpLocalTestServer()) | 265 if (!SetUpLocalTestServer()) |
| 266 LOG(FATAL) << "Failed to set up local test server"; | 266 LOG(FATAL) << "Failed to set up local test server"; |
| 267 } else if (!cl->HasSwitch(switches::kSyncServiceURL) && | 267 } else if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| 268 !cl->HasSwitch(switches::kSyncServerCommandLine)) { | 268 !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 269 if (!SetUpLocalPythonTestServer()) | 269 if (!SetUpLocalPythonTestServer()) |
| 270 LOG(FATAL) << "Failed to set up local python test server"; | 270 LOG(FATAL) << "Failed to set up local python test server"; |
| 271 } else if (!cl->HasSwitch(switches::kSyncServiceURL) && | 271 } else if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| 272 cl->HasSwitch(switches::kSyncServerCommandLine)) { | 272 cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 273 LOG(FATAL) | 273 LOG(FATAL) << "Sync server command line must be accompanied by sync " |
| 274 << "Sync server command line must be accompanied by sync service URL."; | 274 "service URL."; |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 bool LiveSyncTest::SetUpLocalPythonTestServer() { | 278 bool LiveSyncTest::SetUpLocalPythonTestServer() { |
| 279 EXPECT_TRUE(test_server()->Start()) | 279 EXPECT_TRUE(test_server()->Start()) |
| 280 << "Could not launch local python test server."; | 280 << "Could not launch local python test server."; |
| 281 | 281 |
| 282 CommandLine* cl = CommandLine::ForCurrentProcess(); | 282 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 283 std::string sync_service_url = StringPrintf("http://%s:%d/chromiumsync", | 283 std::string sync_service_url = StringPrintf("http://%s:%d/chromiumsync", |
| 284 test_server()->host_port_pair().host().c_str(), | 284 test_server()->host_port_pair().host().c_str(), |
| 285 test_server()->host_port_pair().port()); | 285 test_server()->host_port_pair().port()); |
| 286 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); | 286 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); |
| 287 LOG(INFO) << "Started local python test server at " << sync_service_url; | 287 VLOG(1) << "Started local python test server at " << sync_service_url; |
| 288 | 288 |
| 289 // TODO(akalin): Set the kSyncNotificationHost switch here once a local python | 289 // TODO(akalin): Set the kSyncNotificationHost switch here once a local python |
| 290 // notification server is implemented. | 290 // notification server is implemented. |
| 291 | 291 |
| 292 return true; | 292 return true; |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool LiveSyncTest::SetUpLocalTestServer() { | 295 bool LiveSyncTest::SetUpLocalTestServer() { |
| 296 CommandLine* cl = CommandLine::ForCurrentProcess(); | 296 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 297 CommandLine::StringType server_cmdline_string = cl->GetSwitchValueNative( | 297 CommandLine::StringType server_cmdline_string = cl->GetSwitchValueNative( |
| 298 switches::kSyncServerCommandLine); | 298 switches::kSyncServerCommandLine); |
| 299 #if defined(OS_WIN) | 299 #if defined(OS_WIN) |
| 300 CommandLine server_cmdline = CommandLine::FromString(server_cmdline_string); | 300 CommandLine server_cmdline = CommandLine::FromString(server_cmdline_string); |
| 301 #else | 301 #else |
| 302 std::vector<std::string> server_cmdline_vector; | 302 std::vector<std::string> server_cmdline_vector; |
| 303 std::string delimiters(" "); | 303 std::string delimiters(" "); |
| 304 Tokenize(server_cmdline_string, delimiters, &server_cmdline_vector); | 304 Tokenize(server_cmdline_string, delimiters, &server_cmdline_vector); |
| 305 CommandLine server_cmdline(server_cmdline_vector); | 305 CommandLine server_cmdline(server_cmdline_vector); |
| 306 #endif | 306 #endif |
| 307 if (!base::LaunchApp(server_cmdline, false, true, &test_server_handle_)) | 307 if (!base::LaunchApp(server_cmdline, false, true, &test_server_handle_)) |
| 308 LOG(ERROR) << "Could not launch local test server."; | 308 LOG(ERROR) << "Could not launch local test server."; |
| 309 | 309 |
| 310 const int kMaxWaitTime = TestTimeouts::live_operation_timeout_ms(); | 310 const int kMaxWaitTime = TestTimeouts::live_operation_timeout_ms(); |
| 311 const int kNumIntervals = 15; | 311 const int kNumIntervals = 15; |
| 312 if (WaitForTestServerToStart(kMaxWaitTime, kNumIntervals)) { | 312 if (WaitForTestServerToStart(kMaxWaitTime, kNumIntervals)) { |
| 313 LOG(INFO) << "Started local test server at " | 313 VLOG(1) << "Started local test server at " |
| 314 << cl->GetSwitchValueASCII(switches::kSyncServiceURL) << "."; | 314 << cl->GetSwitchValueASCII(switches::kSyncServiceURL) << "."; |
| 315 return true; | 315 return true; |
| 316 } else { | 316 } else { |
| 317 LOG(ERROR) << "Could not start local test server at " | 317 LOG(ERROR) << "Could not start local test server at " |
| 318 << cl->GetSwitchValueASCII(switches::kSyncServiceURL) << "."; | 318 << cl->GetSwitchValueASCII(switches::kSyncServiceURL) << "."; |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 bool LiveSyncTest::TearDownLocalPythonTestServer() { | 323 bool LiveSyncTest::TearDownLocalPythonTestServer() { |
| 324 if (!test_server()->Stop()) { | 324 if (!test_server()->Stop()) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 const net::ProxyConfig& proxy_config) { | 380 const net::ProxyConfig& proxy_config) { |
| 381 base::WaitableEvent done(false, false); | 381 base::WaitableEvent done(false, false); |
| 382 BrowserThread::PostTask( | 382 BrowserThread::PostTask( |
| 383 BrowserThread::IO, | 383 BrowserThread::IO, |
| 384 FROM_HERE, | 384 FROM_HERE, |
| 385 new SetProxyConfigTask(&done, | 385 new SetProxyConfigTask(&done, |
| 386 context_getter, | 386 context_getter, |
| 387 proxy_config)); | 387 proxy_config)); |
| 388 done.Wait(); | 388 done.Wait(); |
| 389 } | 389 } |
| OLD | NEW |