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

Side by Side Diff: chrome/test/live_sync/live_sync_test.cc

Issue 7669073: [Sync] Add support for enabling session sync remotely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (cl->HasSwitch(switches::kPasswordFileForTest)) { 143 if (cl->HasSwitch(switches::kPasswordFileForTest)) {
144 ReadPasswordFile(); 144 ReadPasswordFile();
145 } else if (cl->HasSwitch(switches::kSyncUserForTest) && 145 } else if (cl->HasSwitch(switches::kSyncUserForTest) &&
146 cl->HasSwitch(switches::kSyncPasswordForTest)) { 146 cl->HasSwitch(switches::kSyncPasswordForTest)) {
147 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); 147 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest);
148 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); 148 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest);
149 } else { 149 } else {
150 SetupMockGaiaResponses(); 150 SetupMockGaiaResponses();
151 } 151 }
152 152
153 if (!cl->HasSwitch(switches::kSyncServiceURL) && 153 if (!cl->HasSwitch(switches::kSyncServiceURL) &&
154 !cl->HasSwitch(switches::kSyncServerCommandLine)) { 154 !cl->HasSwitch(switches::kSyncServerCommandLine)) {
155 // If neither a sync server URL nor a sync server command line is 155 // If neither a sync server URL nor a sync server command line is
156 // provided, start up a local python sync test server and point Chrome 156 // provided, start up a local python sync test server and point Chrome
157 // to its URL. This is the most common configuration, and the only 157 // to its URL. This is the most common configuration, and the only
158 // one that makes sense for most developers. 158 // one that makes sense for most developers.
159 server_type_ = LOCAL_PYTHON_SERVER; 159 server_type_ = LOCAL_PYTHON_SERVER;
160 } else if (cl->HasSwitch(switches::kSyncServiceURL) && 160 } else if (cl->HasSwitch(switches::kSyncServiceURL) &&
161 cl->HasSwitch(switches::kSyncServerCommandLine)) { 161 cl->HasSwitch(switches::kSyncServerCommandLine)) {
162 // If a sync server URL and a sync server command line are provided, 162 // If a sync server URL and a sync server command line are provided,
163 // start up a local sync server by running the command line. Chrome 163 // start up a local sync server by running the command line. Chrome
164 // will connect to the server at the URL that was provided. 164 // will connect to the server at the URL that was provided.
165 server_type_ = LOCAL_LIVE_SERVER; 165 server_type_ = LOCAL_LIVE_SERVER;
166 } else if (cl->HasSwitch(switches::kSyncServiceURL) && 166 } else if (cl->HasSwitch(switches::kSyncServiceURL) &&
167 !cl->HasSwitch(switches::kSyncServerCommandLine)) { 167 !cl->HasSwitch(switches::kSyncServerCommandLine)) {
168 // If a sync server URL is provided, but not a server command line, 168 // If a sync server URL is provided, but not a server command line,
169 // it is assumed that the server is already running. Chrome will 169 // it is assumed that the server is already running. Chrome will
170 // automatically connect to it at the URL provided. There is nothing 170 // automatically connect to it at the URL provided. There is nothing
(...skipping 22 matching lines...) Expand all
193 InProcessBrowserTest::TearDown(); 193 InProcessBrowserTest::TearDown();
194 194
195 // Stop the local python test server. This is a no-op if one wasn't started. 195 // Stop the local python test server. This is a no-op if one wasn't started.
196 TearDownLocalPythonTestServer(); 196 TearDownLocalPythonTestServer();
197 197
198 // Stop the local sync test server. This is a no-op if one wasn't started. 198 // Stop the local sync test server. This is a no-op if one wasn't started.
199 TearDownLocalTestServer(); 199 TearDownLocalTestServer();
200 } 200 }
201 201
202 void LiveSyncTest::SetUpCommandLine(CommandLine* cl) { 202 void LiveSyncTest::SetUpCommandLine(CommandLine* cl) {
203 AddTestSwitches(cl);
204 AddOptionalTypesToCommandLine(cl);
205 }
206
207 void LiveSyncTest::AddTestSwitches(CommandLine* cl) {
203 // TODO(rsimha): Until we implement a fake Tango server against which tests 208 // TODO(rsimha): Until we implement a fake Tango server against which tests
204 // can run, we need to set the --sync-notification-method to "p2p". 209 // can run, we need to set the --sync-notification-method to "p2p".
205 if (!cl->HasSwitch(switches::kSyncNotificationMethod)) 210 if (!cl->HasSwitch(switches::kSyncNotificationMethod))
206 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); 211 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p");
207 212
213 // Disable non-essential access of external network resources.
214 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking))
215 cl->AppendSwitch(switches::kDisableBackgroundNetworking);
216 }
217
218 void LiveSyncTest::AddOptionalTypesToCommandLine(CommandLine* cl) {
208 // TODO(sync): Remove this once sessions sync is enabled by default. 219 // TODO(sync): Remove this once sessions sync is enabled by default.
209 if (!cl->HasSwitch(switches::kEnableSyncSessions)) 220 if (!cl->HasSwitch(switches::kEnableSyncSessions))
210 cl->AppendSwitch(switches::kEnableSyncSessions); 221 cl->AppendSwitch(switches::kEnableSyncSessions);
211 222
212 // TODO(sync): Remove this once typed url sync is enabled by default. 223 // TODO(sync): Remove this once typed url sync is enabled by default.
213 if (!cl->HasSwitch(switches::kEnableSyncTypedUrls)) 224 if (!cl->HasSwitch(switches::kEnableSyncTypedUrls))
214 cl->AppendSwitch(switches::kEnableSyncTypedUrls); 225 cl->AppendSwitch(switches::kEnableSyncTypedUrls);
215
216 // Disable non-essential access of external network resources.
217 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking))
218 cl->AppendSwitch(switches::kDisableBackgroundNetworking);
219 } 226 }
220 227
221 // static 228 // static
222 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { 229 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) {
223 FilePath path; 230 FilePath path;
224 PathService::Get(chrome::DIR_USER_DATA, &path); 231 PathService::Get(chrome::DIR_USER_DATA, &path);
225 path = path.Append(name); 232 path = path.Append(name);
226 233
227 if (!file_util::PathExists(path)) 234 if (!file_util::PathExists(path))
228 CHECK(file_util::CreateDirectory(path)); 235 CHECK(file_util::CreateDirectory(path));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (password_file_.empty()) 339 if (password_file_.empty())
333 LOG(FATAL) << "Can't run live server test without specifying --" 340 LOG(FATAL) << "Can't run live server test without specifying --"
334 << switches::kPasswordFileForTest << "=<filename>"; 341 << switches::kPasswordFileForTest << "=<filename>";
335 std::string file_contents; 342 std::string file_contents;
336 file_util::ReadFileToString(password_file_, &file_contents); 343 file_util::ReadFileToString(password_file_, &file_contents);
337 ASSERT_NE(file_contents, "") << "Password file \"" 344 ASSERT_NE(file_contents, "") << "Password file \""
338 << password_file_.value() << "\" does not exist."; 345 << password_file_.value() << "\" does not exist.";
339 std::vector<std::string> tokens; 346 std::vector<std::string> tokens;
340 std::string delimiters = "\r\n"; 347 std::string delimiters = "\r\n";
341 Tokenize(file_contents, delimiters, &tokens); 348 Tokenize(file_contents, delimiters, &tokens);
342 ASSERT_TRUE(tokens.size() == 2) << "Password file \"" 349 ASSERT_EQ(2U, tokens.size()) << "Password file \""
343 << password_file_.value() 350 << password_file_.value()
344 << "\" must contain exactly two lines of text."; 351 << "\" must contain exactly two lines of text.";
345 username_ = tokens[0]; 352 username_ = tokens[0];
346 password_ = tokens[1]; 353 password_ = tokens[1];
347 } 354 }
348 355
349 void LiveSyncTest::SetupMockGaiaResponses() { 356 void LiveSyncTest::SetupMockGaiaResponses() {
350 username_ = "user@gmail.com"; 357 username_ = "user@gmail.com";
351 password_ = "password"; 358 password_ = "password";
352 integration_factory_.reset(new URLFetcherFactory()); 359 integration_factory_.reset(new URLFetcherFactory());
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 545 }
539 546
540 void LiveSyncTest::TriggerTransientError() { 547 void LiveSyncTest::TriggerTransientError() {
541 ASSERT_TRUE(ServerSupportsErrorTriggering()); 548 ASSERT_TRUE(ServerSupportsErrorTriggering());
542 std::string path = "chromiumsync/transienterror"; 549 std::string path = "chromiumsync/transienterror";
543 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); 550 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path));
544 ASSERT_EQ("Transient error", 551 ASSERT_EQ("Transient error",
545 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); 552 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle()));
546 } 553 }
547 554
555 void LiveSyncTest::TriggerSetSyncTabs() {
556 ASSERT_TRUE(ServerSupportsErrorTriggering());
557 std::string path = "chromiumsync/synctabs";
558 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path));
559 ASSERT_EQ("Sync Tabs",
560 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle()));
561 }
562
548 void LiveSyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, 563 void LiveSyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter,
549 const net::ProxyConfig& proxy_config) { 564 const net::ProxyConfig& proxy_config) {
550 base::WaitableEvent done(false, false); 565 base::WaitableEvent done(false, false);
551 BrowserThread::PostTask( 566 BrowserThread::PostTask(
552 BrowserThread::IO, 567 BrowserThread::IO,
553 FROM_HERE, 568 FROM_HERE,
554 new SetProxyConfigTask(&done, 569 new SetProxyConfigTask(&done,
555 context_getter, 570 context_getter,
556 proxy_config)); 571 proxy_config));
557 done.Wait(); 572 done.Wait();
558 } 573 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698