| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 new net::ProxyConfigServiceFixed(proxy_config_)); | 79 new net::ProxyConfigServiceFixed(proxy_config_)); |
| 80 done_->Signal(); | 80 done_->Signal(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 base::WaitableEvent* done_; | 84 base::WaitableEvent* done_; |
| 85 URLRequestContextGetter* url_request_context_getter_; | 85 URLRequestContextGetter* url_request_context_getter_; |
| 86 net::ProxyConfig proxy_config_; | 86 net::ProxyConfig proxy_config_; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // This is a our notion of a sync client for automation purposes. It is a helper | |
| 90 // class that specializes ProfileSyncServiceHarness, and is used to wait on | |
| 91 // various sync operations. | |
| 92 class SyncClient : public ProfileSyncServiceHarness { | |
| 93 public: | |
| 94 SyncClient(Profile* profile, | |
| 95 const std::string& username, | |
| 96 const std::string& password, int id) | |
| 97 : ProfileSyncServiceHarness(profile, username, password, id) {} | |
| 98 | |
| 99 virtual ~SyncClient() {} | |
| 100 | |
| 101 // Indicates that the sync operation being waited on is complete. Overrides | |
| 102 // ProfileSyncServiceHarness::SignalStateComplete(). | |
| 103 virtual void SignalStateComplete() { MessageLoopForUI::current()->Quit(); } | |
| 104 | |
| 105 // Waits until the sync client's status changes. Overrides | |
| 106 // ProfileSyncServiceHarness::AwaitStatusChange(). | |
| 107 virtual void AwaitStatusChange() { ui_test_utils::RunMessageLoop(); } | |
| 108 | |
| 109 private: | |
| 110 DISALLOW_COPY_AND_ASSIGN(SyncClient); | |
| 111 }; | |
| 112 | |
| 113 void LiveSyncTest::SetUp() { | 89 void LiveSyncTest::SetUp() { |
| 114 // At this point, the browser hasn't been launched, and no services are | 90 // At this point, the browser hasn't been launched, and no services are |
| 115 // available. But we can verify our command line parameters and fail | 91 // available. But we can verify our command line parameters and fail |
| 116 // early. | 92 // early. |
| 117 CommandLine* cl = CommandLine::ForCurrentProcess(); | 93 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 118 if (cl->HasSwitch(switches::kPasswordFileForTest)) { | 94 if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
| 119 ReadPasswordFile(); | 95 ReadPasswordFile(); |
| 120 } else { | 96 } else { |
| 121 // Read GAIA credentials from the "--sync-XXX-for-test" command line | 97 // Read GAIA credentials from the "--sync-XXX-for-test" command line |
| 122 // parameters. | 98 // parameters. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 LOG(FATAL) << "SetupClients() has already been called."; | 174 LOG(FATAL) << "SetupClients() has already been called."; |
| 199 | 175 |
| 200 // Start up a sync test server if one is needed. | 176 // Start up a sync test server if one is needed. |
| 201 SetUpTestServerIfRequired(); | 177 SetUpTestServerIfRequired(); |
| 202 | 178 |
| 203 // Create the required number of sync profiles and clients. | 179 // Create the required number of sync profiles and clients. |
| 204 for (int i = 0; i < num_clients_; ++i) { | 180 for (int i = 0; i < num_clients_; ++i) { |
| 205 profiles_.push_back(MakeProfile( | 181 profiles_.push_back(MakeProfile( |
| 206 StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); | 182 StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); |
| 207 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; | 183 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; |
| 208 clients_.push_back(new SyncClient(GetProfile(i), username_, password_, i)); | 184 clients_.push_back( |
| 185 new ProfileSyncServiceHarness(GetProfile(i), username_, password_, i)); |
| 209 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; | 186 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; |
| 210 } | 187 } |
| 211 | 188 |
| 212 // Create the verifier profile. | 189 // Create the verifier profile. |
| 213 verifier_.reset(MakeProfile(FILE_PATH_LITERAL("Verifier"))); | 190 verifier_.reset(MakeProfile(FILE_PATH_LITERAL("Verifier"))); |
| 214 return (verifier_.get() != NULL); | 191 return (verifier_.get() != NULL); |
| 215 } | 192 } |
| 216 | 193 |
| 217 bool LiveSyncTest::SetupSync() { | 194 bool LiveSyncTest::SetupSync() { |
| 218 // Create sync profiles and clients if they haven't already been created. | 195 // Create sync profiles and clients if they haven't already been created. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 const net::ProxyConfig& proxy_config) { | 390 const net::ProxyConfig& proxy_config) { |
| 414 base::WaitableEvent done(false, false); | 391 base::WaitableEvent done(false, false); |
| 415 BrowserThread::PostTask( | 392 BrowserThread::PostTask( |
| 416 BrowserThread::IO, | 393 BrowserThread::IO, |
| 417 FROM_HERE, | 394 FROM_HERE, |
| 418 new SetProxyConfigTask(&done, | 395 new SetProxyConfigTask(&done, |
| 419 context_getter, | 396 context_getter, |
| 420 proxy_config)); | 397 proxy_config)); |
| 421 done.Wait(); | 398 done.Wait(); |
| 422 } | 399 } |
| OLD | NEW |