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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 182031: Speed up net_unittests by re-using one FTP test server instance. (Closed)
Patch Set: add google.patch Created 11 years, 3 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "net/url_request/url_request_unittest.h" 5 #include "net/url_request/url_request_unittest.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1912
1913 // Check the interceptor got called as expected 1913 // Check the interceptor got called as expected
1914 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 1914 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
1915 EXPECT_FALSE(interceptor.did_intercept_final_); 1915 EXPECT_FALSE(interceptor.did_intercept_final_);
1916 1916
1917 // Check we see a canceled request 1917 // Check we see a canceled request
1918 EXPECT_FALSE(req.status().is_success()); 1918 EXPECT_FALSE(req.status().is_success());
1919 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1919 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
1920 } 1920 }
1921 1921
1922 TEST_F(URLRequestTest, FTPGetTestAnonymous) { 1922 class URLRequestTestFTP : public URLRequestTest {
1923 scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L""); 1923 protected:
1924 ASSERT_TRUE(NULL != server.get()); 1924 static void SetUpTestCase() {
wtc 2009/08/31 20:38:44 Where do we call SetUpTestCase() and TearDownTestC
1925 server_ = FTPTestServer::CreateServer(L"");
1926 }
1927
1928 static void TearDownTestCase() {
1929 server_ = NULL;
1930 }
1931
1932 static scoped_refptr<FTPTestServer> server_;
1933 };
1934
1935 // static
1936 scoped_refptr<FTPTestServer> URLRequestTestFTP::server_;
1937
1938 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
1939 ASSERT_TRUE(NULL != server_.get());
1925 FilePath app_path; 1940 FilePath app_path;
1926 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 1941 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
1927 app_path = app_path.AppendASCII("LICENSE"); 1942 app_path = app_path.AppendASCII("LICENSE");
1928 TestDelegate d; 1943 TestDelegate d;
1929 { 1944 {
1930 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 1945 TestURLRequest r(server_->TestServerPage("/LICENSE"), &d);
1931 r.Start(); 1946 r.Start();
1932 EXPECT_TRUE(r.is_pending()); 1947 EXPECT_TRUE(r.is_pending());
1933 1948
1934 MessageLoop::current()->Run(); 1949 MessageLoop::current()->Run();
1935 1950
1936 int64 file_size = 0; 1951 int64 file_size = 0;
1937 file_util::GetFileSize(app_path, &file_size); 1952 file_util::GetFileSize(app_path, &file_size);
1938 1953
1939 EXPECT_FALSE(r.is_pending()); 1954 EXPECT_FALSE(r.is_pending());
1940 EXPECT_EQ(1, d.response_started_count()); 1955 EXPECT_EQ(1, d.response_started_count());
1941 EXPECT_FALSE(d.received_data_before_response()); 1956 EXPECT_FALSE(d.received_data_before_response());
1942 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 1957 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
1943 } 1958 }
1944 } 1959 }
1945 1960
1946 TEST_F(URLRequestTest, FTPGetTest) { 1961 TEST_F(URLRequestTestFTP, FTPGetTest) {
1947 scoped_refptr<FTPTestServer> server = 1962 ASSERT_TRUE(NULL != server_.get());
1948 FTPTestServer::CreateServer(L"", "chrome", "chrome");
1949 ASSERT_TRUE(NULL != server.get());
1950 FilePath app_path; 1963 FilePath app_path;
1951 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 1964 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
1952 app_path = app_path.AppendASCII("LICENSE"); 1965 app_path = app_path.AppendASCII("LICENSE");
1953 TestDelegate d; 1966 TestDelegate d;
1954 { 1967 {
1955 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 1968 TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"),
1969 &d);
1956 r.Start(); 1970 r.Start();
1957 EXPECT_TRUE(r.is_pending()); 1971 EXPECT_TRUE(r.is_pending());
1958 1972
1959 MessageLoop::current()->Run(); 1973 MessageLoop::current()->Run();
1960 1974
1961 int64 file_size = 0; 1975 int64 file_size = 0;
1962 file_util::GetFileSize(app_path, &file_size); 1976 file_util::GetFileSize(app_path, &file_size);
1963 1977
1964 EXPECT_FALSE(r.is_pending()); 1978 EXPECT_FALSE(r.is_pending());
1965 EXPECT_EQ(1, d.response_started_count()); 1979 EXPECT_EQ(1, d.response_started_count());
1966 EXPECT_FALSE(d.received_data_before_response()); 1980 EXPECT_FALSE(d.received_data_before_response());
1967 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 1981 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
1968 } 1982 }
1969 } 1983 }
1970 1984
1971 TEST_F(URLRequestTest, FTPCheckWrongPassword) { 1985 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
1972 scoped_refptr<FTPTestServer> server = 1986 ASSERT_TRUE(NULL != server_.get());
1973 FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
1974 ASSERT_TRUE(NULL != server.get());
1975 FilePath app_path; 1987 FilePath app_path;
1976 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 1988 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
1977 app_path = app_path.AppendASCII("LICENSE"); 1989 app_path = app_path.AppendASCII("LICENSE");
1978 TestDelegate d; 1990 TestDelegate d;
1979 { 1991 {
1980 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 1992 TestURLRequest r(server_->TestServerPage("/LICENSE",
1993 "chrome", "wrong_password"), &d);
1981 r.Start(); 1994 r.Start();
1982 EXPECT_TRUE(r.is_pending()); 1995 EXPECT_TRUE(r.is_pending());
1983 1996
1984 MessageLoop::current()->Run(); 1997 MessageLoop::current()->Run();
1985 1998
1986 int64 file_size = 0; 1999 int64 file_size = 0;
1987 file_util::GetFileSize(app_path, &file_size); 2000 file_util::GetFileSize(app_path, &file_size);
1988 2001
1989 EXPECT_FALSE(r.is_pending()); 2002 EXPECT_FALSE(r.is_pending());
1990 EXPECT_EQ(1, d.response_started_count()); 2003 EXPECT_EQ(1, d.response_started_count());
1991 EXPECT_FALSE(d.received_data_before_response()); 2004 EXPECT_FALSE(d.received_data_before_response());
1992 EXPECT_EQ(d.bytes_received(), 0); 2005 EXPECT_EQ(d.bytes_received(), 0);
1993 } 2006 }
1994 } 2007 }
1995 2008
1996 TEST_F(URLRequestTest, FTPCheckWrongPasswordRestart) { 2009 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
1997 // Pass wrong login credentials in the request URL. 2010 ASSERT_TRUE(NULL != server_.get());
1998 scoped_refptr<FTPTestServer> server =
1999 FTPTestServer::CreateServer(L"", "chrome", "wrong_password");
2000 ASSERT_TRUE(NULL != server.get());
2001 FilePath app_path; 2011 FilePath app_path;
2002 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2012 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2003 app_path = app_path.AppendASCII("LICENSE"); 2013 app_path = app_path.AppendASCII("LICENSE");
2004 TestDelegate d; 2014 TestDelegate d;
2005 // Set correct login credentials. The delegate will be asked for them when 2015 // Set correct login credentials. The delegate will be asked for them when
2006 // the initial login with wrong credentials will fail. 2016 // the initial login with wrong credentials will fail.
2007 d.set_username(L"chrome"); 2017 d.set_username(L"chrome");
2008 d.set_password(L"chrome"); 2018 d.set_password(L"chrome");
2009 { 2019 {
2010 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 2020 TestURLRequest r(server_->TestServerPage("/LICENSE",
2021 "chrome", "wrong_password"), &d);
2011 r.Start(); 2022 r.Start();
2012 EXPECT_TRUE(r.is_pending()); 2023 EXPECT_TRUE(r.is_pending());
2013 2024
2014 MessageLoop::current()->Run(); 2025 MessageLoop::current()->Run();
2015 2026
2016 int64 file_size = 0; 2027 int64 file_size = 0;
2017 file_util::GetFileSize(app_path, &file_size); 2028 file_util::GetFileSize(app_path, &file_size);
2018 2029
2019 EXPECT_FALSE(r.is_pending()); 2030 EXPECT_FALSE(r.is_pending());
2020 EXPECT_EQ(1, d.response_started_count()); 2031 EXPECT_EQ(1, d.response_started_count());
2021 EXPECT_FALSE(d.received_data_before_response()); 2032 EXPECT_FALSE(d.received_data_before_response());
2022 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2033 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2023 } 2034 }
2024 } 2035 }
2025 2036
2026 TEST_F(URLRequestTest, FTPCheckWrongUser) { 2037 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
2027 scoped_refptr<FTPTestServer> server = 2038 ASSERT_TRUE(NULL != server_.get());
2028 FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
2029 ASSERT_TRUE(NULL != server.get());
2030 FilePath app_path; 2039 FilePath app_path;
2031 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2040 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2032 app_path = app_path.AppendASCII("LICENSE"); 2041 app_path = app_path.AppendASCII("LICENSE");
2033 TestDelegate d; 2042 TestDelegate d;
2034 { 2043 {
2035 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 2044 TestURLRequest r(server_->TestServerPage("/LICENSE",
2045 "wrong_user", "chrome"), &d);
2036 r.Start(); 2046 r.Start();
2037 EXPECT_TRUE(r.is_pending()); 2047 EXPECT_TRUE(r.is_pending());
2038 2048
2039 MessageLoop::current()->Run(); 2049 MessageLoop::current()->Run();
2040 2050
2041 int64 file_size = 0; 2051 int64 file_size = 0;
2042 file_util::GetFileSize(app_path, &file_size); 2052 file_util::GetFileSize(app_path, &file_size);
2043 2053
2044 EXPECT_FALSE(r.is_pending()); 2054 EXPECT_FALSE(r.is_pending());
2045 EXPECT_EQ(1, d.response_started_count()); 2055 EXPECT_EQ(1, d.response_started_count());
2046 EXPECT_FALSE(d.received_data_before_response()); 2056 EXPECT_FALSE(d.received_data_before_response());
2047 EXPECT_EQ(d.bytes_received(), 0); 2057 EXPECT_EQ(d.bytes_received(), 0);
2048 } 2058 }
2049 } 2059 }
2050 2060
2051 TEST_F(URLRequestTest, FTPCheckWrongUserRestart) { 2061 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
2052 // Pass wrong login credentials in the request URL. 2062 ASSERT_TRUE(NULL != server_.get());
2053 scoped_refptr<FTPTestServer> server =
2054 FTPTestServer::CreateServer(L"", "wrong_user", "chrome");
2055 ASSERT_TRUE(NULL != server.get());
2056 FilePath app_path; 2063 FilePath app_path;
2057 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2064 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2058 app_path = app_path.AppendASCII("LICENSE"); 2065 app_path = app_path.AppendASCII("LICENSE");
2059 TestDelegate d; 2066 TestDelegate d;
2060 // Set correct login credentials. The delegate will be asked for them when 2067 // Set correct login credentials. The delegate will be asked for them when
2061 // the initial login with wrong credentials will fail. 2068 // the initial login with wrong credentials will fail.
2062 d.set_username(L"chrome"); 2069 d.set_username(L"chrome");
2063 d.set_password(L"chrome"); 2070 d.set_password(L"chrome");
2064 { 2071 {
2065 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); 2072 TestURLRequest r(server_->TestServerPage("/LICENSE",
2073 "wrong_user", "chrome"), &d);
2066 r.Start(); 2074 r.Start();
2067 EXPECT_TRUE(r.is_pending()); 2075 EXPECT_TRUE(r.is_pending());
2068 2076
2069 MessageLoop::current()->Run(); 2077 MessageLoop::current()->Run();
2070 2078
2071 int64 file_size = 0; 2079 int64 file_size = 0;
2072 file_util::GetFileSize(app_path, &file_size); 2080 file_util::GetFileSize(app_path, &file_size);
2073 2081
2074 EXPECT_FALSE(r.is_pending()); 2082 EXPECT_FALSE(r.is_pending());
2075 EXPECT_EQ(1, d.response_started_count()); 2083 EXPECT_EQ(1, d.response_started_count());
2076 EXPECT_FALSE(d.received_data_before_response()); 2084 EXPECT_FALSE(d.received_data_before_response());
2077 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2085 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2078 } 2086 }
2079 } 2087 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698