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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 break; | 124 break; |
125 } | 125 } |
126 case MANY_CLIENT: { | 126 case MANY_CLIENT: { |
127 num_clients_ = 10; | 127 num_clients_ = 10; |
128 break; | 128 break; |
129 } | 129 } |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 void LiveSyncTest::SetUp() { | 133 void LiveSyncTest::SetUp() { |
134 // At this point, the browser hasn't been launched, and no services are | |
135 // available. But we can verify our command line parameters and fail | |
136 // early. | |
137 CommandLine* cl = CommandLine::ForCurrentProcess(); | 134 CommandLine* cl = CommandLine::ForCurrentProcess(); |
138 if (cl->HasSwitch(switches::kPasswordFileForTest)) { | 135 if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
139 ReadPasswordFile(); | 136 ReadPasswordFile(); |
140 } else if (cl->HasSwitch(switches::kSyncUserForTest) && | 137 } else if (cl->HasSwitch(switches::kSyncUserForTest) && |
141 cl->HasSwitch(switches::kSyncPasswordForTest)) { | 138 cl->HasSwitch(switches::kSyncPasswordForTest)) { |
142 // Read GAIA credentials from the "--sync-XXX-for-test" command line | |
143 // parameters. | |
144 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); | 139 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
145 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | 140 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
146 } else { | 141 } else { |
147 SetupMockGaiaResponses(); | 142 SetupMockGaiaResponses(); |
148 } | 143 } |
149 if (username_.empty() || password_.empty()) | 144 if (username_.empty() || password_.empty()) |
150 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; | 145 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; |
151 | 146 |
152 // TODO(rsimha): Until we implement a fake Tango server against which tests | |
153 // can run, we need to set the --sync-notification-method to "p2p". | |
154 if (!cl->HasSwitch(switches::kSyncNotificationMethod)) | |
155 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); | |
156 | |
157 // TODO(sync): Remove this once sessions sync is enabled by default. | |
158 if (!cl->HasSwitch(switches::kEnableSyncSessions)) { | |
159 cl->AppendSwitch(switches::kEnableSyncSessions); | |
160 } | |
161 | |
162 // TODO(sync): Remove this once passwords sync is enabled by default. | |
163 if (!cl->HasSwitch(switches::kEnableSyncPasswords)) { | |
164 cl->AppendSwitch(switches::kEnableSyncPasswords); | |
165 } | |
166 | |
167 // Mock the Mac Keychain service. The real Keychain can block on user input. | 147 // Mock the Mac Keychain service. The real Keychain can block on user input. |
168 #if defined(OS_MACOSX) | 148 #if defined(OS_MACOSX) |
169 Encryptor::UseMockKeychain(true); | 149 Encryptor::UseMockKeychain(true); |
170 #endif | 150 #endif |
171 | 151 |
172 // Yield control back to the InProcessBrowserTest framework. | 152 // Yield control back to the InProcessBrowserTest framework. |
173 InProcessBrowserTest::SetUp(); | 153 InProcessBrowserTest::SetUp(); |
174 } | 154 } |
175 | 155 |
176 void LiveSyncTest::TearDown() { | 156 void LiveSyncTest::TearDown() { |
177 // Allow the InProcessBrowserTest framework to perform its tear down. | 157 // Allow the InProcessBrowserTest framework to perform its tear down. |
178 InProcessBrowserTest::TearDown(); | 158 InProcessBrowserTest::TearDown(); |
179 | 159 |
180 // Stop the local python test server. This is a no-op if one wasn't started. | 160 // Stop the local python test server. This is a no-op if one wasn't started. |
181 TearDownLocalPythonTestServer(); | 161 TearDownLocalPythonTestServer(); |
182 | 162 |
183 // Stop the local sync test server. This is a no-op if one wasn't started. | 163 // Stop the local sync test server. This is a no-op if one wasn't started. |
184 TearDownLocalTestServer(); | 164 TearDownLocalTestServer(); |
185 | 165 |
186 // Switch back to using the default URLFetcher factory. This is a no-op if | 166 // Switch back to using the default URLFetcher factory. This is a no-op if |
187 // a fake factory wasn't used. | 167 // a fake factory wasn't used. |
188 URLFetcher::set_factory(NULL); | 168 URLFetcher::set_factory(NULL); |
189 } | 169 } |
190 | 170 |
| 171 void LiveSyncTest::SetUpCommandLine(CommandLine* cl) { |
| 172 // TODO(rsimha): Until we implement a fake Tango server against which tests |
| 173 // can run, we need to set the --sync-notification-method to "p2p". |
| 174 if (!cl->HasSwitch(switches::kSyncNotificationMethod)) |
| 175 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); |
| 176 |
| 177 // TODO(sync): Remove this once sessions sync is enabled by default. |
| 178 if (!cl->HasSwitch(switches::kEnableSyncSessions)) |
| 179 cl->AppendSwitch(switches::kEnableSyncSessions); |
| 180 |
| 181 // TODO(sync): Remove this once passwords sync is enabled by default. |
| 182 if (!cl->HasSwitch(switches::kEnableSyncPasswords)) |
| 183 cl->AppendSwitch(switches::kEnableSyncPasswords); |
| 184 |
| 185 // Disable non-essential access of external network resources. |
| 186 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) |
| 187 cl->AppendSwitch(switches::kDisableBackgroundNetworking); |
| 188 } |
| 189 |
191 // static | 190 // static |
192 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { | 191 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { |
193 FilePath path; | 192 FilePath path; |
194 PathService::Get(chrome::DIR_USER_DATA, &path); | 193 PathService::Get(chrome::DIR_USER_DATA, &path); |
195 return ProfileManager::CreateProfile(path.Append(name)); | 194 return ProfileManager::CreateProfile(path.Append(name)); |
196 } | 195 } |
197 | 196 |
198 Profile* LiveSyncTest::GetProfile(int index) { | 197 Profile* LiveSyncTest::GetProfile(int index) { |
199 if (profiles_.empty()) | 198 if (profiles_.empty()) |
200 LOG(FATAL) << "SetupSync() has not yet been called."; | 199 LOG(FATAL) << "SetupSync() has not yet been called."; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 const net::ProxyConfig& proxy_config) { | 467 const net::ProxyConfig& proxy_config) { |
469 base::WaitableEvent done(false, false); | 468 base::WaitableEvent done(false, false); |
470 BrowserThread::PostTask( | 469 BrowserThread::PostTask( |
471 BrowserThread::IO, | 470 BrowserThread::IO, |
472 FROM_HERE, | 471 FROM_HERE, |
473 new SetProxyConfigTask(&done, | 472 new SetProxyConfigTask(&done, |
474 context_getter, | 473 context_getter, |
475 proxy_config)); | 474 proxy_config)); |
476 done.Wait(); | 475 done.Wait(); |
477 } | 476 } |
OLD | NEW |