| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 // static | 220 // static |
| 221 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { | 221 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { |
| 222 FilePath path; | 222 FilePath path; |
| 223 PathService::Get(chrome::DIR_USER_DATA, &path); | 223 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 224 path = path.Append(name); | 224 path = path.Append(name); |
| 225 | 225 |
| 226 if (!file_util::PathExists(path)) | 226 if (!file_util::PathExists(path)) |
| 227 CHECK(file_util::CreateDirectory(path)); | 227 CHECK(file_util::CreateDirectory(path)); |
| 228 | 228 |
| 229 return Profile::CreateProfile(path); | 229 Profile* profile = Profile::CreateProfile(path); |
| 230 g_browser_process->profile_manager()->RegisterTestingProfile(profile, true); |
| 231 return profile; |
| 230 } | 232 } |
| 231 | 233 |
| 232 Profile* LiveSyncTest::GetProfile(int index) { | 234 Profile* LiveSyncTest::GetProfile(int index) { |
| 233 if (profiles_.empty()) | 235 if (profiles_.empty()) |
| 234 LOG(FATAL) << "SetupSync() has not yet been called."; | 236 LOG(FATAL) << "SetupSync() has not yet been called."; |
| 235 if (index < 0 || index >= static_cast<int>(profiles_.size())) | 237 if (index < 0 || index >= static_cast<int>(profiles_.size())) |
| 236 LOG(FATAL) << "GetProfile(): Index is out of bounds."; | 238 LOG(FATAL) << "GetProfile(): Index is out of bounds."; |
| 237 return profiles_[index]; | 239 return profiles_[index]; |
| 238 } | 240 } |
| 239 | 241 |
| 240 ProfileSyncServiceHarness* LiveSyncTest::GetClient(int index) { | 242 ProfileSyncServiceHarness* LiveSyncTest::GetClient(int index) { |
| 241 if (clients_.empty()) | 243 if (clients_.empty()) |
| 242 LOG(FATAL) << "SetupClients() has not yet been called."; | 244 LOG(FATAL) << "SetupClients() has not yet been called."; |
| 243 if (index < 0 || index >= static_cast<int>(clients_.size())) | 245 if (index < 0 || index >= static_cast<int>(clients_.size())) |
| 244 LOG(FATAL) << "GetClient(): Index is out of bounds."; | 246 LOG(FATAL) << "GetClient(): Index is out of bounds."; |
| 245 return clients_[index]; | 247 return clients_[index]; |
| 246 } | 248 } |
| 247 | 249 |
| 248 Profile* LiveSyncTest::verifier() { | 250 Profile* LiveSyncTest::verifier() { |
| 249 if (verifier_.get() == NULL) | 251 if (verifier_ == NULL) |
| 250 LOG(FATAL) << "SetupClients() has not yet been called."; | 252 LOG(FATAL) << "SetupClients() has not yet been called."; |
| 251 return verifier_.get(); | 253 return verifier_; |
| 252 } | 254 } |
| 253 | 255 |
| 254 void LiveSyncTest::DisableVerifier() { | 256 void LiveSyncTest::DisableVerifier() { |
| 255 use_verifier_ = false; | 257 use_verifier_ = false; |
| 256 } | 258 } |
| 257 | 259 |
| 258 bool LiveSyncTest::SetupClients() { | 260 bool LiveSyncTest::SetupClients() { |
| 259 if (num_clients_ <= 0) | 261 if (num_clients_ <= 0) |
| 260 LOG(FATAL) << "num_clients_ incorrectly initialized."; | 262 LOG(FATAL) << "num_clients_ incorrectly initialized."; |
| 261 if (!profiles_.empty() || !clients_.empty()) | 263 if (!profiles_.empty() || !clients_.empty()) |
| 262 LOG(FATAL) << "SetupClients() has already been called."; | 264 LOG(FATAL) << "SetupClients() has already been called."; |
| 263 | 265 |
| 264 // Start up a sync test server if one is needed. | 266 // Start up a sync test server if one is needed. |
| 265 SetUpTestServerIfRequired(); | 267 SetUpTestServerIfRequired(); |
| 266 | 268 |
| 267 // Create the required number of sync profiles and clients. | 269 // Create the required number of sync profiles and clients. |
| 268 for (int i = 0; i < num_clients_; ++i) { | 270 for (int i = 0; i < num_clients_; ++i) { |
| 269 profiles_.push_back(MakeProfile( | 271 profiles_.push_back(MakeProfile( |
| 270 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); | 272 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); |
| 271 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; | 273 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; |
| 272 clients_.push_back( | 274 clients_.push_back( |
| 273 new ProfileSyncServiceHarness(GetProfile(i), username_, password_)); | 275 new ProfileSyncServiceHarness(GetProfile(i), username_, password_)); |
| 274 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; | 276 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; |
| 275 ui_test_utils::WaitForBookmarkModelToLoad( | 277 ui_test_utils::WaitForBookmarkModelToLoad( |
| 276 GetProfile(i)->GetBookmarkModel()); | 278 GetProfile(i)->GetBookmarkModel()); |
| 277 } | 279 } |
| 278 | 280 |
| 279 // Create the verifier profile. | 281 // Create the verifier profile. |
| 280 verifier_.reset(MakeProfile(FILE_PATH_LITERAL("Verifier"))); | 282 verifier_ = MakeProfile(FILE_PATH_LITERAL("Verifier")); |
| 281 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); | 283 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); |
| 282 return (verifier_.get() != NULL); | 284 return (verifier_ != NULL); |
| 283 } | 285 } |
| 284 | 286 |
| 285 bool LiveSyncTest::SetupSync() { | 287 bool LiveSyncTest::SetupSync() { |
| 286 // Create sync profiles and clients if they haven't already been created. | 288 // Create sync profiles and clients if they haven't already been created. |
| 287 if (profiles_.empty()) { | 289 if (profiles_.empty()) { |
| 288 if (!SetupClients()) | 290 if (!SetupClients()) |
| 289 LOG(FATAL) << "SetupClients() failed."; | 291 LOG(FATAL) << "SetupClients() failed."; |
| 290 } | 292 } |
| 291 | 293 |
| 292 // Sync each of the profiles. | 294 // Sync each of the profiles. |
| 293 for (int i = 0; i < num_clients_; ++i) { | 295 for (int i = 0; i < num_clients_; ++i) { |
| 294 if (!GetClient(i)->SetupSync()) | 296 if (!GetClient(i)->SetupSync()) |
| 295 LOG(FATAL) << "SetupSync() failed."; | 297 LOG(FATAL) << "SetupSync() failed."; |
| 296 } | 298 } |
| 297 | 299 |
| 298 return true; | 300 return true; |
| 299 } | 301 } |
| 300 | 302 |
| 301 void LiveSyncTest::CleanUpOnMainThread() { | 303 void LiveSyncTest::CleanUpOnMainThread() { |
| 302 profiles_.reset(); | |
| 303 clients_.reset(); | 304 clients_.reset(); |
| 304 verifier_.reset(NULL); | |
| 305 } | 305 } |
| 306 | 306 |
| 307 void LiveSyncTest::SetUpInProcessBrowserTestFixture() { | 307 void LiveSyncTest::SetUpInProcessBrowserTestFixture() { |
| 308 // We don't take a reference to |resolver|, but mock_host_resolver_override_ | 308 // We don't take a reference to |resolver|, but mock_host_resolver_override_ |
| 309 // does, so effectively assumes ownership. | 309 // does, so effectively assumes ownership. |
| 310 net::RuleBasedHostResolverProc* resolver = | 310 net::RuleBasedHostResolverProc* resolver = |
| 311 new net::RuleBasedHostResolverProc(host_resolver()); | 311 new net::RuleBasedHostResolverProc(host_resolver()); |
| 312 resolver->AllowDirectLookup("*.google.com"); | 312 resolver->AllowDirectLookup("*.google.com"); |
| 313 // On Linux, we use Chromium's NSS implementation which uses the following | 313 // On Linux, we use Chromium's NSS implementation which uses the following |
| 314 // hosts for certificate verification. Without these overrides, running the | 314 // hosts for certificate verification. Without these overrides, running the |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 const net::ProxyConfig& proxy_config) { | 536 const net::ProxyConfig& proxy_config) { |
| 537 base::WaitableEvent done(false, false); | 537 base::WaitableEvent done(false, false); |
| 538 BrowserThread::PostTask( | 538 BrowserThread::PostTask( |
| 539 BrowserThread::IO, | 539 BrowserThread::IO, |
| 540 FROM_HERE, | 540 FROM_HERE, |
| 541 new SetProxyConfigTask(&done, | 541 new SetProxyConfigTask(&done, |
| 542 context_getter, | 542 context_getter, |
| 543 proxy_config)); | 543 proxy_config)); |
| 544 done.Wait(); | 544 done.Wait(); |
| 545 } | 545 } |
| OLD | NEW |