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

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

Issue 201083: Cache login identity for NewFTP transactions. (Closed)
Patch Set: better 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 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 1935 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
1936 EXPECT_FALSE(interceptor.did_intercept_final_); 1936 EXPECT_FALSE(interceptor.did_intercept_final_);
1937 1937
1938 // Check we see a canceled request 1938 // Check we see a canceled request
1939 EXPECT_FALSE(req.status().is_success()); 1939 EXPECT_FALSE(req.status().is_success());
1940 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1940 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
1941 } 1941 }
1942 1942
1943 class URLRequestTestFTP : public URLRequestTest { 1943 class URLRequestTestFTP : public URLRequestTest {
1944 protected: 1944 protected:
1945 static FilePath GetDataDir() {
1946 FilePath data_dir;
1947 PathService::Get(base::DIR_SOURCE_ROOT, &data_dir);
1948 data_dir = data_dir.AppendASCII("net");
1949 data_dir = data_dir.AppendASCII("data");
1950 data_dir = data_dir.AppendASCII("ftp");
1951 return data_dir;
1952 }
1953
1945 static void SetUpTestCase() { 1954 static void SetUpTestCase() {
1946 server_ = FTPTestServer::CreateServer(L""); 1955 FilePath data_dir;
1956 data_dir = data_dir.AppendASCII("net");
1957 data_dir = data_dir.AppendASCII("data");
1958 data_dir = data_dir.AppendASCII("ftp");
1959 server_ = FTPTestServer::CreateServer(data_dir.ToWStringHack(), false);
1947 } 1960 }
1948 1961
1949 static void TearDownTestCase() { 1962 static void TearDownTestCase() {
1950 server_ = NULL; 1963 server_ = NULL;
1951 } 1964 }
1952 1965
1953 static scoped_refptr<FTPTestServer> server_; 1966 static scoped_refptr<FTPTestServer> server_;
1954 }; 1967 };
1955 1968
1956 // static 1969 // static
1957 scoped_refptr<FTPTestServer> URLRequestTestFTP::server_; 1970 scoped_refptr<FTPTestServer> URLRequestTestFTP::server_;
1958 1971
1959 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { 1972 TEST_F(URLRequestTestFTP, FTPDirectoryListing) {
1960 ASSERT_TRUE(NULL != server_.get()); 1973 ASSERT_TRUE(NULL != server_.get());
1961 TestDelegate d; 1974 TestDelegate d;
1962 { 1975 {
1963 TestURLRequest r(server_->TestServerPage("/"), &d); 1976 TestURLRequest r(server_->TestServerPage("/", "chrome", "chrome"), &d);
1964 r.Start(); 1977 r.Start();
1965 EXPECT_TRUE(r.is_pending()); 1978 EXPECT_TRUE(r.is_pending());
1966 1979
1967 MessageLoop::current()->Run(); 1980 MessageLoop::current()->Run();
1968 1981
1969 EXPECT_FALSE(r.is_pending()); 1982 EXPECT_FALSE(r.is_pending());
1970 EXPECT_EQ(1, d.response_started_count()); 1983 EXPECT_EQ(1, d.response_started_count());
1971 EXPECT_FALSE(d.received_data_before_response()); 1984 EXPECT_FALSE(d.received_data_before_response());
1972 EXPECT_LT(0, d.bytes_received()); 1985 EXPECT_LT(0, d.bytes_received());
1973 } 1986 }
1974 } 1987 }
1975 1988
1976 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { 1989 TEST_F(URLRequestTest, FTPGetTestAnonymous) {
1977 ASSERT_TRUE(NULL != server_.get()); 1990 FilePath data_dir;
1978 FilePath app_path; 1991 data_dir = data_dir.AppendASCII("net");
1979 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 1992 data_dir = data_dir.AppendASCII("data");
1980 app_path = app_path.AppendASCII("LICENSE"); 1993 data_dir = data_dir.AppendASCII("ftp");
1994 scoped_refptr<FTPTestServer> server(
1995 FTPTestServer::CreateServer(data_dir.ToWStringHack(), true));
1996 ASSERT_TRUE(NULL != server.get());
1997 FilePath testfile_path(data_dir.AppendASCII("testfile"));
1981 TestDelegate d; 1998 TestDelegate d;
1982 { 1999 {
1983 TestURLRequest r(server_->TestServerPage("/LICENSE"), &d); 2000 TestURLRequest r(server->TestServerPage("/testfile"), &d);
1984 r.Start(); 2001 r.Start();
1985 EXPECT_TRUE(r.is_pending()); 2002 EXPECT_TRUE(r.is_pending());
1986 2003
1987 MessageLoop::current()->Run(); 2004 MessageLoop::current()->Run();
1988 2005
1989 int64 file_size = 0; 2006 int64 file_size = 0;
1990 file_util::GetFileSize(app_path, &file_size); 2007 file_util::GetFileSize(testfile_path, &file_size);
1991 2008
1992 EXPECT_FALSE(r.is_pending()); 2009 EXPECT_FALSE(r.is_pending());
1993 EXPECT_EQ(1, d.response_started_count()); 2010 EXPECT_EQ(1, d.response_started_count());
1994 EXPECT_FALSE(d.received_data_before_response()); 2011 EXPECT_FALSE(d.received_data_before_response());
1995 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2012 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
1996 } 2013 }
1997 } 2014 }
1998 2015
1999 TEST_F(URLRequestTestFTP, FTPGetTest) { 2016 TEST_F(URLRequestTestFTP, FTPGetTest) {
2000 ASSERT_TRUE(NULL != server_.get()); 2017 ASSERT_TRUE(NULL != server_.get());
2001 FilePath app_path; 2018 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2002 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2003 app_path = app_path.AppendASCII("LICENSE");
2004 TestDelegate d; 2019 TestDelegate d;
2005 { 2020 {
2006 TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"), 2021 TestURLRequest r(server_->TestServerPage("/testfile", "chrome", "chrome"),
2007 &d); 2022 &d);
2008 r.Start(); 2023 r.Start();
2009 EXPECT_TRUE(r.is_pending()); 2024 EXPECT_TRUE(r.is_pending());
2010 2025
2011 MessageLoop::current()->Run(); 2026 MessageLoop::current()->Run();
2012 2027
2013 int64 file_size = 0; 2028 int64 file_size = 0;
2014 file_util::GetFileSize(app_path, &file_size); 2029 file_util::GetFileSize(testfile_path, &file_size);
2015 2030
2016 EXPECT_FALSE(r.is_pending()); 2031 EXPECT_FALSE(r.is_pending());
2017 EXPECT_EQ(1, d.response_started_count()); 2032 EXPECT_EQ(1, d.response_started_count());
2018 EXPECT_FALSE(d.received_data_before_response()); 2033 EXPECT_FALSE(d.received_data_before_response());
2019 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2034 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2020 } 2035 }
2021 } 2036 }
2022 2037
2023 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { 2038 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
2024 ASSERT_TRUE(NULL != server_.get()); 2039 ASSERT_TRUE(NULL != server_.get());
2025 FilePath app_path; 2040 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2026 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2027 app_path = app_path.AppendASCII("LICENSE");
2028 TestDelegate d; 2041 TestDelegate d;
2029 { 2042 {
2030 TestURLRequest r(server_->TestServerPage("/LICENSE", 2043 TestURLRequest r(server_->TestServerPage("/testfile",
2031 "chrome", "wrong_password"), &d); 2044 "chrome", "wrong_password"), &d);
2032 r.Start(); 2045 r.Start();
2033 EXPECT_TRUE(r.is_pending()); 2046 EXPECT_TRUE(r.is_pending());
2034 2047
2035 MessageLoop::current()->Run(); 2048 MessageLoop::current()->Run();
2036 2049
2037 int64 file_size = 0; 2050 int64 file_size = 0;
2038 file_util::GetFileSize(app_path, &file_size); 2051 file_util::GetFileSize(testfile_path, &file_size);
2039 2052
2040 EXPECT_FALSE(r.is_pending()); 2053 EXPECT_FALSE(r.is_pending());
2041 EXPECT_EQ(1, d.response_started_count()); 2054 EXPECT_EQ(1, d.response_started_count());
2042 EXPECT_FALSE(d.received_data_before_response()); 2055 EXPECT_FALSE(d.received_data_before_response());
2043 EXPECT_EQ(d.bytes_received(), 0); 2056 EXPECT_EQ(d.bytes_received(), 0);
2044 } 2057 }
2045 } 2058 }
2046 2059
2047 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { 2060 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
2048 ASSERT_TRUE(NULL != server_.get()); 2061 ASSERT_TRUE(NULL != server_.get());
2049 FilePath app_path; 2062 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2050 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2051 app_path = app_path.AppendASCII("LICENSE");
2052 TestDelegate d; 2063 TestDelegate d;
2053 // Set correct login credentials. The delegate will be asked for them when 2064 // Set correct login identity. The delegate will be asked for it when
2054 // the initial login with wrong credentials will fail. 2065 // the initial login with wrong password will fail.
2055 d.set_username(L"chrome"); 2066 d.set_username(L"chrome");
2056 d.set_password(L"chrome"); 2067 d.set_password(L"chrome");
2057 { 2068 {
2058 TestURLRequest r(server_->TestServerPage("/LICENSE", 2069 TestURLRequest r(server_->TestServerPage("/testfile",
2059 "chrome", "wrong_password"), &d); 2070 "chrome", "wrong_password"), &d);
2060 r.Start(); 2071 r.Start();
2061 EXPECT_TRUE(r.is_pending()); 2072 EXPECT_TRUE(r.is_pending());
2062 2073
2063 MessageLoop::current()->Run(); 2074 MessageLoop::current()->Run();
2064 2075
2065 int64 file_size = 0; 2076 int64 file_size = 0;
2066 file_util::GetFileSize(app_path, &file_size); 2077 file_util::GetFileSize(testfile_path, &file_size);
2067 2078
2068 EXPECT_FALSE(r.is_pending()); 2079 EXPECT_FALSE(r.is_pending());
2069 EXPECT_EQ(1, d.response_started_count()); 2080 EXPECT_EQ(1, d.response_started_count());
2070 EXPECT_FALSE(d.received_data_before_response()); 2081 EXPECT_FALSE(d.received_data_before_response());
2071 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2082 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2072 } 2083 }
2073 } 2084 }
2074 2085
2075 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { 2086 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
2076 ASSERT_TRUE(NULL != server_.get()); 2087 ASSERT_TRUE(NULL != server_.get());
2077 FilePath app_path; 2088 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2078 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2079 app_path = app_path.AppendASCII("LICENSE");
2080 TestDelegate d; 2089 TestDelegate d;
2081 { 2090 {
2082 TestURLRequest r(server_->TestServerPage("/LICENSE", 2091 TestURLRequest r(server_->TestServerPage("/testfile",
2083 "wrong_user", "chrome"), &d); 2092 "wrong_user", "chrome"), &d);
2084 r.Start(); 2093 r.Start();
2085 EXPECT_TRUE(r.is_pending()); 2094 EXPECT_TRUE(r.is_pending());
2086 2095
2087 MessageLoop::current()->Run(); 2096 MessageLoop::current()->Run();
2088 2097
2089 int64 file_size = 0; 2098 int64 file_size = 0;
2090 file_util::GetFileSize(app_path, &file_size); 2099 file_util::GetFileSize(testfile_path, &file_size);
2091 2100
2092 EXPECT_FALSE(r.is_pending()); 2101 EXPECT_FALSE(r.is_pending());
2093 EXPECT_EQ(1, d.response_started_count()); 2102 EXPECT_EQ(1, d.response_started_count());
2094 EXPECT_FALSE(d.received_data_before_response()); 2103 EXPECT_FALSE(d.received_data_before_response());
2095 EXPECT_EQ(d.bytes_received(), 0); 2104 EXPECT_EQ(d.bytes_received(), 0);
2096 } 2105 }
2097 } 2106 }
2098 2107
2099 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { 2108 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
2100 ASSERT_TRUE(NULL != server_.get()); 2109 ASSERT_TRUE(NULL != server_.get());
2101 FilePath app_path; 2110 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2102 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2103 app_path = app_path.AppendASCII("LICENSE");
2104 TestDelegate d; 2111 TestDelegate d;
2105 // Set correct login credentials. The delegate will be asked for them when 2112 // Set correct login identity. The delegate will be asked for it when
2106 // the initial login with wrong credentials will fail. 2113 // the initial login with wrong user will fail.
2107 d.set_username(L"chrome"); 2114 d.set_username(L"chrome");
2108 d.set_password(L"chrome"); 2115 d.set_password(L"chrome");
2109 { 2116 {
2110 TestURLRequest r(server_->TestServerPage("/LICENSE", 2117 TestURLRequest r(server_->TestServerPage("/testfile",
2111 "wrong_user", "chrome"), &d); 2118 "wrong_user", "chrome"), &d);
2112 r.Start(); 2119 r.Start();
2113 EXPECT_TRUE(r.is_pending()); 2120 EXPECT_TRUE(r.is_pending());
2114 2121
2115 MessageLoop::current()->Run(); 2122 MessageLoop::current()->Run();
2116 2123
2117 int64 file_size = 0; 2124 int64 file_size = 0;
2118 file_util::GetFileSize(app_path, &file_size); 2125 file_util::GetFileSize(testfile_path, &file_size);
2119 2126
2120 EXPECT_FALSE(r.is_pending()); 2127 EXPECT_FALSE(r.is_pending());
2121 EXPECT_EQ(1, d.response_started_count()); 2128 EXPECT_EQ(1, d.response_started_count());
2122 EXPECT_FALSE(d.received_data_before_response()); 2129 EXPECT_FALSE(d.received_data_before_response());
2123 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2130 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2124 } 2131 }
2125 } 2132 }
2133
2134 TEST_F(URLRequestTestFTP, FTPCacheURLIdentity) {
2135 ASSERT_TRUE(NULL != server_.get());
2136 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2137
2138 scoped_refptr<URLRequestTestContext> context(new URLRequestTestContext);
2139
2140 scoped_ptr<TestDelegate> d(new TestDelegate);
2141 {
2142 // Pass correct identity in the URL. It should be cached.
2143 TestURLRequest r(server_->TestServerPage("/testfile", "chrome", "chrome"),
2144 d.get());
2145 r.set_context(context.get());
2146 r.Start();
2147 EXPECT_TRUE(r.is_pending());
2148
2149 MessageLoop::current()->Run();
2150
2151 int64 file_size = 0;
2152 file_util::GetFileSize(testfile_path, &file_size);
2153
2154 EXPECT_FALSE(r.is_pending());
2155 EXPECT_EQ(1, d->response_started_count());
2156 EXPECT_FALSE(d->received_data_before_response());
2157 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
2158 }
2159
2160 // Use a new delegate without explicit identity. The cached one should be
2161 // used.
2162 d.reset(new TestDelegate);
2163 {
2164 // Don't pass identity in the URL, it would override valid cached one.
2165 TestURLRequest r(server_->TestServerPage("/testfile"), d.get());
2166 r.set_context(context.get());
2167 r.Start();
2168 EXPECT_TRUE(r.is_pending());
2169
2170 MessageLoop::current()->Run();
2171
2172 int64 file_size = 0;
2173 file_util::GetFileSize(testfile_path, &file_size);
2174
2175 EXPECT_FALSE(r.is_pending());
2176 EXPECT_EQ(1, d->response_started_count());
2177 EXPECT_FALSE(d->received_data_before_response());
2178 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
2179 }
2180 }
2181
2182 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxIdentity) {
2183 ASSERT_TRUE(NULL != server_.get());
2184 FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
2185
2186 scoped_refptr<URLRequestTestContext> context(new URLRequestTestContext);
2187
2188 scoped_ptr<TestDelegate> d(new TestDelegate);
2189 // Set correct login identity. The delegate will be asked for it when
2190 // the initial login with wrong password will fail.
2191 d->set_username(L"chrome");
2192 d->set_password(L"chrome");
2193 {
2194 TestURLRequest r(server_->TestServerPage("/testfile",
2195 "chrome", "wrong_password"),
2196 d.get());
2197 r.set_context(context.get());
2198 r.Start();
2199 EXPECT_TRUE(r.is_pending());
2200
2201 MessageLoop::current()->Run();
2202
2203 int64 file_size = 0;
2204 file_util::GetFileSize(testfile_path, &file_size);
2205
2206 EXPECT_FALSE(r.is_pending());
2207 EXPECT_EQ(1, d->response_started_count());
2208 EXPECT_FALSE(d->received_data_before_response());
2209 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
2210 }
2211
2212 // Use a new delegate without explicit identity. The cached one should be
2213 // used.
2214 d.reset(new TestDelegate);
2215 {
2216 // Don't pass identity in the URL, it would override valid cached one.
2217 TestURLRequest r(server_->TestServerPage("/testfile"), d.get());
2218 r.set_context(context.get());
2219 r.Start();
2220 EXPECT_TRUE(r.is_pending());
2221
2222 MessageLoop::current()->Run();
2223
2224 int64 file_size = 0;
2225 file_util::GetFileSize(testfile_path, &file_size);
2226
2227 EXPECT_FALSE(r.is_pending());
2228 EXPECT_EQ(1, d->response_started_count());
2229 EXPECT_FALSE(d->received_data_before_response());
2230 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
2231 }
2232 }
OLDNEW
« net/url_request/url_request_new_ftp_job.cc ('K') | « net/url_request/url_request_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698