| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/sync/test/integration/sync_test.h" | 5 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 347 } |
| 348 base::FilePath profile_path = tmp_profile_paths_[index]->GetPath(); | 348 base::FilePath profile_path = tmp_profile_paths_[index]->GetPath(); |
| 349 if (UsingExternalServers()) { | 349 if (UsingExternalServers()) { |
| 350 // If running against an EXTERNAL_LIVE_SERVER, we signin profiles using real | 350 // If running against an EXTERNAL_LIVE_SERVER, we signin profiles using real |
| 351 // GAIA server. This requires creating profiles with no test hooks. | 351 // GAIA server. This requires creating profiles with no test hooks. |
| 352 InitializeProfile(index, MakeProfileForUISignin(profile_path)); | 352 InitializeProfile(index, MakeProfileForUISignin(profile_path)); |
| 353 } else { | 353 } else { |
| 354 // Without need of real GAIA authentication, we create new test profiles. | 354 // Without need of real GAIA authentication, we create new test profiles. |
| 355 // For test profiles, a custom delegate needs to be used to do the | 355 // For test profiles, a custom delegate needs to be used to do the |
| 356 // initialization work before the profile is registered. | 356 // initialization work before the profile is registered. |
| 357 profile_delegates_[index].reset(new SyncProfileDelegate(base::Bind( | 357 profile_delegates_[index] = |
| 358 &SyncTest::InitializeProfile, base::Unretained(this), index))); | 358 base::MakeUnique<SyncProfileDelegate>(base::Bind( |
| 359 &SyncTest::InitializeProfile, base::Unretained(this), index)); |
| 359 MakeTestProfile(profile_path, index); | 360 MakeTestProfile(profile_path, index); |
| 360 } | 361 } |
| 361 | 362 |
| 362 // Once profile initialization has kicked off, wait for it to finish. | 363 // Once profile initialization has kicked off, wait for it to finish. |
| 363 WaitForDataModels(GetProfile(index)); | 364 WaitForDataModels(GetProfile(index)); |
| 364 } | 365 } |
| 365 | 366 |
| 366 // Called when the ProfileManager has created a profile. | 367 // Called when the ProfileManager has created a profile. |
| 367 // static | 368 // static |
| 368 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, | 369 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 501 } |
| 501 | 502 |
| 502 // Verifier account is not useful when running against external servers. | 503 // Verifier account is not useful when running against external servers. |
| 503 if (UsingExternalServers()) | 504 if (UsingExternalServers()) |
| 504 DisableVerifier(); | 505 DisableVerifier(); |
| 505 | 506 |
| 506 // Create the verifier profile. | 507 // Create the verifier profile. |
| 507 if (use_verifier_) { | 508 if (use_verifier_) { |
| 508 base::FilePath user_data_dir; | 509 base::FilePath user_data_dir; |
| 509 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 510 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 510 profile_delegates_[num_clients_].reset( | 511 profile_delegates_[num_clients_] = |
| 511 new SyncProfileDelegate(base::Callback<void(Profile*)>())); | 512 base::MakeUnique<SyncProfileDelegate>(base::Callback<void(Profile*)>()); |
| 512 verifier_ = MakeTestProfile( | 513 verifier_ = MakeTestProfile( |
| 513 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); | 514 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); |
| 514 WaitForDataModels(verifier()); | 515 WaitForDataModels(verifier()); |
| 515 } | 516 } |
| 516 // Error cases are all handled by LOG(FATAL) messages. So there is not really | 517 // Error cases are all handled by LOG(FATAL) messages. So there is not really |
| 517 // a case that returns false. In case we failed to create a verifier profile, | 518 // a case that returns false. In case we failed to create a verifier profile, |
| 518 // any call to the verifier() would fail. | 519 // any call to the verifier() would fail. |
| 519 return true; | 520 return true; |
| 520 } | 521 } |
| 521 | 522 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 695 |
| 695 // Allow connection to googleapis.com for oauth token requests in E2E tests. | 696 // Allow connection to googleapis.com for oauth token requests in E2E tests. |
| 696 resolver->AllowDirectLookup("*.googleapis.com"); | 697 resolver->AllowDirectLookup("*.googleapis.com"); |
| 697 | 698 |
| 698 // On Linux, we use Chromium's NSS implementation which uses the following | 699 // On Linux, we use Chromium's NSS implementation which uses the following |
| 699 // hosts for certificate verification. Without these overrides, running the | 700 // hosts for certificate verification. Without these overrides, running the |
| 700 // integration tests on Linux causes error as we make external DNS lookups. | 701 // integration tests on Linux causes error as we make external DNS lookups. |
| 701 resolver->AllowDirectLookup("*.thawte.com"); | 702 resolver->AllowDirectLookup("*.thawte.com"); |
| 702 resolver->AllowDirectLookup("*.geotrust.com"); | 703 resolver->AllowDirectLookup("*.geotrust.com"); |
| 703 resolver->AllowDirectLookup("*.gstatic.com"); | 704 resolver->AllowDirectLookup("*.gstatic.com"); |
| 704 mock_host_resolver_override_.reset( | 705 mock_host_resolver_override_ = |
| 705 new net::ScopedDefaultHostResolverProc(resolver)); | 706 base::MakeUnique<net::ScopedDefaultHostResolverProc>(resolver); |
| 706 } | 707 } |
| 707 | 708 |
| 708 void SyncTest::TearDownInProcessBrowserTestFixture() { | 709 void SyncTest::TearDownInProcessBrowserTestFixture() { |
| 709 mock_host_resolver_override_.reset(); | 710 mock_host_resolver_override_.reset(); |
| 710 } | 711 } |
| 711 | 712 |
| 712 void SyncTest::WaitForDataModels(Profile* profile) { | 713 void SyncTest::WaitForDataModels(Profile* profile) { |
| 713 bookmarks::test::WaitForBookmarkModelToLoad( | 714 bookmarks::test::WaitForBookmarkModelToLoad( |
| 714 BookmarkModelFactory::GetForBrowserContext(profile)); | 715 BookmarkModelFactory::GetForBrowserContext(profile)); |
| 715 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( | 716 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 731 std::vector<std::string> tokens = base::SplitString( | 732 std::vector<std::string> tokens = base::SplitString( |
| 732 file_contents, "\r\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 733 file_contents, "\r\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 733 ASSERT_EQ(2U, tokens.size()) << "Password file \"" | 734 ASSERT_EQ(2U, tokens.size()) << "Password file \"" |
| 734 << password_file_.value() | 735 << password_file_.value() |
| 735 << "\" must contain exactly two lines of text."; | 736 << "\" must contain exactly two lines of text."; |
| 736 username_ = tokens[0]; | 737 username_ = tokens[0]; |
| 737 password_ = tokens[1]; | 738 password_ = tokens[1]; |
| 738 } | 739 } |
| 739 | 740 |
| 740 void SyncTest::SetupMockGaiaResponses() { | 741 void SyncTest::SetupMockGaiaResponses() { |
| 741 factory_.reset(new net::URLFetcherImplFactory()); | 742 factory_ = base::MakeUnique<net::URLFetcherImplFactory>(); |
| 742 fake_factory_.reset(new net::FakeURLFetcherFactory(factory_.get())); | 743 fake_factory_ = base::MakeUnique<net::FakeURLFetcherFactory>(factory_.get()); |
| 743 fake_factory_->SetFakeResponse( | 744 fake_factory_->SetFakeResponse( |
| 744 GaiaUrls::GetInstance()->get_user_info_url(), | 745 GaiaUrls::GetInstance()->get_user_info_url(), |
| 745 "email=user@gmail.com\ndisplayEmail=user@gmail.com", | 746 "email=user@gmail.com\ndisplayEmail=user@gmail.com", |
| 746 net::HTTP_OK, | 747 net::HTTP_OK, |
| 747 net::URLRequestStatus::SUCCESS); | 748 net::URLRequestStatus::SUCCESS); |
| 748 fake_factory_->SetFakeResponse( | 749 fake_factory_->SetFakeResponse( |
| 749 GaiaUrls::GetInstance()->issue_auth_token_url(), | 750 GaiaUrls::GetInstance()->issue_auth_token_url(), |
| 750 "auth", | 751 "auth", |
| 751 net::HTTP_OK, | 752 net::HTTP_OK, |
| 752 net::URLRequestStatus::SUCCESS); | 753 net::URLRequestStatus::SUCCESS); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 if (!SetUpLocalPythonTestServer()) | 862 if (!SetUpLocalPythonTestServer()) |
| 862 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; | 863 LOG(FATAL) << "Failed to set up local python sync and XMPP servers"; |
| 863 SetupMockGaiaResponses(); | 864 SetupMockGaiaResponses(); |
| 864 } else if (server_type_ == LOCAL_LIVE_SERVER) { | 865 } else if (server_type_ == LOCAL_LIVE_SERVER) { |
| 865 // Using mock gaia credentials requires the use of a mock XMPP server. | 866 // Using mock gaia credentials requires the use of a mock XMPP server. |
| 866 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) | 867 if (username_ == "user@gmail.com" && !SetUpLocalPythonTestServer()) |
| 867 LOG(FATAL) << "Failed to set up local python XMPP server"; | 868 LOG(FATAL) << "Failed to set up local python XMPP server"; |
| 868 if (!SetUpLocalTestServer()) | 869 if (!SetUpLocalTestServer()) |
| 869 LOG(FATAL) << "Failed to set up local test server"; | 870 LOG(FATAL) << "Failed to set up local test server"; |
| 870 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) { | 871 } else if (server_type_ == IN_PROCESS_FAKE_SERVER) { |
| 871 fake_server_.reset(new fake_server::FakeServer()); | 872 fake_server_ = base::MakeUnique<fake_server::FakeServer>(); |
| 872 SetupMockGaiaResponses(); | 873 SetupMockGaiaResponses(); |
| 873 } else { | 874 } else { |
| 874 LOG(FATAL) << "Don't know which server environment to run test in."; | 875 LOG(FATAL) << "Don't know which server environment to run test in."; |
| 875 } | 876 } |
| 876 } | 877 } |
| 877 | 878 |
| 878 bool SyncTest::SetUpLocalPythonTestServer() { | 879 bool SyncTest::SetUpLocalPythonTestServer() { |
| 879 EXPECT_TRUE(sync_server_.Start()) | 880 EXPECT_TRUE(sync_server_.Start()) |
| 880 << "Could not launch local python test server."; | 881 << "Could not launch local python test server."; |
| 881 | 882 |
| 882 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 883 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 883 if (server_type_ == LOCAL_PYTHON_SERVER) { | 884 if (server_type_ == LOCAL_PYTHON_SERVER) { |
| 884 std::string sync_service_url = sync_server_.GetURL("chromiumsync").spec(); | 885 std::string sync_service_url = sync_server_.GetURL("chromiumsync").spec(); |
| 885 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); | 886 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); |
| 886 DVLOG(1) << "Started local python sync server at " << sync_service_url; | 887 DVLOG(1) << "Started local python sync server at " << sync_service_url; |
| 887 } | 888 } |
| 888 | 889 |
| 889 int xmpp_port = 0; | 890 int xmpp_port = 0; |
| 890 if (!sync_server_.server_data().GetInteger("xmpp_port", &xmpp_port)) { | 891 if (!sync_server_.server_data().GetInteger("xmpp_port", &xmpp_port)) { |
| 891 LOG(ERROR) << "Could not find valid xmpp_port value"; | 892 LOG(ERROR) << "Could not find valid xmpp_port value"; |
| 892 return false; | 893 return false; |
| 893 } | 894 } |
| 894 if ((xmpp_port <= 0) || (xmpp_port > std::numeric_limits<uint16_t>::max())) { | 895 if ((xmpp_port <= 0) || (xmpp_port > std::numeric_limits<uint16_t>::max())) { |
| 895 LOG(ERROR) << "Invalid xmpp port: " << xmpp_port; | 896 LOG(ERROR) << "Invalid xmpp port: " << xmpp_port; |
| 896 return false; | 897 return false; |
| 897 } | 898 } |
| 898 | 899 |
| 899 net::HostPortPair xmpp_host_port_pair(sync_server_.host_port_pair()); | 900 net::HostPortPair xmpp_host_port_pair(sync_server_.host_port_pair()); |
| 900 xmpp_host_port_pair.set_port(xmpp_port); | 901 xmpp_host_port_pair.set_port(xmpp_port); |
| 901 xmpp_port_.reset(new net::ScopedPortException(xmpp_port)); | 902 xmpp_port_ = base::MakeUnique<net::ScopedPortException>(xmpp_port); |
| 902 | 903 |
| 903 if (!cl->HasSwitch(invalidation::switches::kSyncNotificationHostPort)) { | 904 if (!cl->HasSwitch(invalidation::switches::kSyncNotificationHostPort)) { |
| 904 cl->AppendSwitchASCII(invalidation::switches::kSyncNotificationHostPort, | 905 cl->AppendSwitchASCII(invalidation::switches::kSyncNotificationHostPort, |
| 905 xmpp_host_port_pair.ToString()); | 906 xmpp_host_port_pair.ToString()); |
| 906 // The local XMPP server only supports insecure connections. | 907 // The local XMPP server only supports insecure connections. |
| 907 cl->AppendSwitch(invalidation::switches::kSyncAllowInsecureXmppConnection); | 908 cl->AppendSwitch(invalidation::switches::kSyncAllowInsecureXmppConnection); |
| 908 } | 909 } |
| 909 DVLOG(1) << "Started local python XMPP server at " | 910 DVLOG(1) << "Started local python XMPP server at " |
| 910 << xmpp_host_port_pair.ToString(); | 911 << xmpp_host_port_pair.ToString(); |
| 911 | 912 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 | 1128 |
| 1128 void SyncTest::TriggerSyncForModelTypes(int index, | 1129 void SyncTest::TriggerSyncForModelTypes(int index, |
| 1129 syncer::ModelTypeSet model_types) { | 1130 syncer::ModelTypeSet model_types) { |
| 1130 GetSyncService(index)->TriggerRefresh(model_types); | 1131 GetSyncService(index)->TriggerRefresh(model_types); |
| 1131 } | 1132 } |
| 1132 | 1133 |
| 1133 void SyncTest::SetPreexistingPreferencesFileContents( | 1134 void SyncTest::SetPreexistingPreferencesFileContents( |
| 1134 const std::string& contents) { | 1135 const std::string& contents) { |
| 1135 preexisting_preferences_file_contents_ = contents; | 1136 preexisting_preferences_file_contents_ = contents; |
| 1136 } | 1137 } |
| OLD | NEW |