| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if (cl->HasSwitch(switches::kPasswordFileForTest)) { | 144 if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
| 145 ReadPasswordFile(); | 145 ReadPasswordFile(); |
| 146 } else if (cl->HasSwitch(switches::kSyncUserForTest) && | 146 } else if (cl->HasSwitch(switches::kSyncUserForTest) && |
| 147 cl->HasSwitch(switches::kSyncPasswordForTest)) { | 147 cl->HasSwitch(switches::kSyncPasswordForTest)) { |
| 148 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); | 148 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
| 149 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | 149 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
| 150 } else { | 150 } else { |
| 151 SetupMockGaiaResponses(); | 151 SetupMockGaiaResponses(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 if (!cl->HasSwitch(switches::kSyncServiceURL) && | 154 if (!cl->HasSwitch(switches::kSyncServiceURL) && |
| 155 !cl->HasSwitch(switches::kSyncServerCommandLine)) { | 155 !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 156 // If neither a sync server URL nor a sync server command line is | 156 // If neither a sync server URL nor a sync server command line is |
| 157 // provided, start up a local python sync test server and point Chrome | 157 // provided, start up a local python sync test server and point Chrome |
| 158 // to its URL. This is the most common configuration, and the only | 158 // to its URL. This is the most common configuration, and the only |
| 159 // one that makes sense for most developers. | 159 // one that makes sense for most developers. |
| 160 server_type_ = LOCAL_PYTHON_SERVER; | 160 server_type_ = LOCAL_PYTHON_SERVER; |
| 161 } else if (cl->HasSwitch(switches::kSyncServiceURL) && | 161 } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| 162 cl->HasSwitch(switches::kSyncServerCommandLine)) { | 162 cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 163 // If a sync server URL and a sync server command line are provided, | 163 // If a sync server URL and a sync server command line are provided, |
| 164 // start up a local sync server by running the command line. Chrome | 164 // start up a local sync server by running the command line. Chrome |
| 165 // will connect to the server at the URL that was provided. | 165 // will connect to the server at the URL that was provided. |
| 166 server_type_ = LOCAL_LIVE_SERVER; | 166 server_type_ = LOCAL_LIVE_SERVER; |
| 167 } else if (cl->HasSwitch(switches::kSyncServiceURL) && | 167 } else if (cl->HasSwitch(switches::kSyncServiceURL) && |
| 168 !cl->HasSwitch(switches::kSyncServerCommandLine)) { | 168 !cl->HasSwitch(switches::kSyncServerCommandLine)) { |
| 169 // If a sync server URL is provided, but not a server command line, | 169 // If a sync server URL is provided, but not a server command line, |
| 170 // it is assumed that the server is already running. Chrome will | 170 // it is assumed that the server is already running. Chrome will |
| 171 // automatically connect to it at the URL provided. There is nothing | 171 // automatically connect to it at the URL provided. There is nothing |
| (...skipping 22 matching lines...) Expand all Loading... |
| 194 InProcessBrowserTest::TearDown(); | 194 InProcessBrowserTest::TearDown(); |
| 195 | 195 |
| 196 // Stop the local python test server. This is a no-op if one wasn't started. | 196 // Stop the local python test server. This is a no-op if one wasn't started. |
| 197 TearDownLocalPythonTestServer(); | 197 TearDownLocalPythonTestServer(); |
| 198 | 198 |
| 199 // Stop the local sync test server. This is a no-op if one wasn't started. | 199 // Stop the local sync test server. This is a no-op if one wasn't started. |
| 200 TearDownLocalTestServer(); | 200 TearDownLocalTestServer(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void LiveSyncTest::SetUpCommandLine(CommandLine* cl) { | 203 void LiveSyncTest::SetUpCommandLine(CommandLine* cl) { |
| 204 AddTestSwitches(cl); |
| 205 AddOptionalTypesToCommandLine(cl); |
| 206 } |
| 207 |
| 208 void LiveSyncTest::AddTestSwitches(CommandLine* cl) { |
| 204 // TODO(rsimha): Until we implement a fake Tango server against which tests | 209 // TODO(rsimha): Until we implement a fake Tango server against which tests |
| 205 // can run, we need to set the --sync-notification-method to "p2p". | 210 // can run, we need to set the --sync-notification-method to "p2p". |
| 206 if (!cl->HasSwitch(switches::kSyncNotificationMethod)) | 211 if (!cl->HasSwitch(switches::kSyncNotificationMethod)) |
| 207 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); | 212 cl->AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); |
| 208 | 213 |
| 209 // TODO(sync): Remove this once sessions sync is enabled by default. | |
| 210 if (!cl->HasSwitch(switches::kEnableSyncSessions)) | |
| 211 cl->AppendSwitch(switches::kEnableSyncSessions); | |
| 212 | |
| 213 // Disable non-essential access of external network resources. | 214 // Disable non-essential access of external network resources. |
| 214 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) | 215 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) |
| 215 cl->AppendSwitch(switches::kDisableBackgroundNetworking); | 216 cl->AppendSwitch(switches::kDisableBackgroundNetworking); |
| 216 } | 217 } |
| 217 | 218 |
| 219 void LiveSyncTest::AddOptionalTypesToCommandLine(CommandLine* cl) { |
| 220 // TODO(sync): Remove this once sessions sync is enabled by default. |
| 221 if (!cl->HasSwitch(switches::kEnableSyncSessions)) |
| 222 cl->AppendSwitch(switches::kEnableSyncSessions); |
| 223 } |
| 224 |
| 218 // static | 225 // static |
| 219 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { | 226 Profile* LiveSyncTest::MakeProfile(const FilePath::StringType name) { |
| 220 FilePath path; | 227 FilePath path; |
| 221 PathService::Get(chrome::DIR_USER_DATA, &path); | 228 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 222 path = path.Append(name); | 229 path = path.Append(name); |
| 223 | 230 |
| 224 if (!file_util::PathExists(path)) | 231 if (!file_util::PathExists(path)) |
| 225 CHECK(file_util::CreateDirectory(path)); | 232 CHECK(file_util::CreateDirectory(path)); |
| 226 | 233 |
| 227 return Profile::CreateProfile(path); | 234 return Profile::CreateProfile(path); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (password_file_.empty()) | 357 if (password_file_.empty()) |
| 351 LOG(FATAL) << "Can't run live server test without specifying --" | 358 LOG(FATAL) << "Can't run live server test without specifying --" |
| 352 << switches::kPasswordFileForTest << "=<filename>"; | 359 << switches::kPasswordFileForTest << "=<filename>"; |
| 353 std::string file_contents; | 360 std::string file_contents; |
| 354 file_util::ReadFileToString(password_file_, &file_contents); | 361 file_util::ReadFileToString(password_file_, &file_contents); |
| 355 ASSERT_NE(file_contents, "") << "Password file \"" | 362 ASSERT_NE(file_contents, "") << "Password file \"" |
| 356 << password_file_.value() << "\" does not exist."; | 363 << password_file_.value() << "\" does not exist."; |
| 357 std::vector<std::string> tokens; | 364 std::vector<std::string> tokens; |
| 358 std::string delimiters = "\r\n"; | 365 std::string delimiters = "\r\n"; |
| 359 Tokenize(file_contents, delimiters, &tokens); | 366 Tokenize(file_contents, delimiters, &tokens); |
| 360 ASSERT_TRUE(tokens.size() == 2) << "Password file \"" | 367 ASSERT_EQ(2U, tokens.size()) << "Password file \"" |
| 361 << password_file_.value() | 368 << password_file_.value() |
| 362 << "\" must contain exactly two lines of text."; | 369 << "\" must contain exactly two lines of text."; |
| 363 username_ = tokens[0]; | 370 username_ = tokens[0]; |
| 364 password_ = tokens[1]; | 371 password_ = tokens[1]; |
| 365 } | 372 } |
| 366 | 373 |
| 367 void LiveSyncTest::SetupMockGaiaResponses() { | 374 void LiveSyncTest::SetupMockGaiaResponses() { |
| 368 username_ = "user@gmail.com"; | 375 username_ = "user@gmail.com"; |
| 369 password_ = "password"; | 376 password_ = "password"; |
| 370 integration_factory_.reset(new URLFetcherFactory()); | 377 integration_factory_.reset(new URLFetcherFactory()); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 571 } |
| 565 | 572 |
| 566 void LiveSyncTest::TriggerTransientError() { | 573 void LiveSyncTest::TriggerTransientError() { |
| 567 ASSERT_TRUE(ServerSupportsErrorTriggering()); | 574 ASSERT_TRUE(ServerSupportsErrorTriggering()); |
| 568 std::string path = "chromiumsync/transienterror"; | 575 std::string path = "chromiumsync/transienterror"; |
| 569 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); | 576 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); |
| 570 ASSERT_EQ("Transient error", | 577 ASSERT_EQ("Transient error", |
| 571 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); | 578 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); |
| 572 } | 579 } |
| 573 | 580 |
| 581 void LiveSyncTest::TriggerSetSyncTabs() { |
| 582 ASSERT_TRUE(ServerSupportsErrorTriggering()); |
| 583 std::string path = "chromiumsync/synctabs"; |
| 584 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); |
| 585 ASSERT_EQ("Sync Tabs", |
| 586 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); |
| 587 } |
| 588 |
| 574 void LiveSyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, | 589 void LiveSyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, |
| 575 const net::ProxyConfig& proxy_config) { | 590 const net::ProxyConfig& proxy_config) { |
| 576 base::WaitableEvent done(false, false); | 591 base::WaitableEvent done(false, false); |
| 577 BrowserThread::PostTask( | 592 BrowserThread::PostTask( |
| 578 BrowserThread::IO, | 593 BrowserThread::IO, |
| 579 FROM_HERE, | 594 FROM_HERE, |
| 580 new SetProxyConfigTask(&done, | 595 new SetProxyConfigTask(&done, |
| 581 context_getter, | 596 context_getter, |
| 582 proxy_config)); | 597 proxy_config)); |
| 583 done.Wait(); | 598 done.Wait(); |
| 584 } | 599 } |
| OLD | NEW |