| Index: net/url_request/url_request_unittest.cc
|
| diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
|
| index d82e0850246a347f5f8622a8ef07a3c069aa78c0..0f49671b0bbb6d50885b26e77793ad9402a04c64 100644
|
| --- a/net/url_request/url_request_unittest.cc
|
| +++ b/net/url_request/url_request_unittest.cc
|
| @@ -1942,8 +1942,21 @@ TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
|
|
|
| class URLRequestTestFTP : public URLRequestTest {
|
| protected:
|
| + static FilePath GetDataDir() {
|
| + FilePath data_dir;
|
| + PathService::Get(base::DIR_SOURCE_ROOT, &data_dir);
|
| + data_dir = data_dir.AppendASCII("net");
|
| + data_dir = data_dir.AppendASCII("data");
|
| + data_dir = data_dir.AppendASCII("ftp");
|
| + return data_dir;
|
| + }
|
| +
|
| static void SetUpTestCase() {
|
| - server_ = FTPTestServer::CreateServer(L"");
|
| + FilePath data_dir;
|
| + data_dir = data_dir.AppendASCII("net");
|
| + data_dir = data_dir.AppendASCII("data");
|
| + data_dir = data_dir.AppendASCII("ftp");
|
| + server_ = FTPTestServer::CreateServer(data_dir.ToWStringHack(), false);
|
| }
|
|
|
| static void TearDownTestCase() {
|
| @@ -1960,7 +1973,7 @@ TEST_F(URLRequestTestFTP, FTPDirectoryListing) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| TestDelegate d;
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/"), &d);
|
| + TestURLRequest r(server_->TestServerPage("/", "chrome", "chrome"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
|
|
| @@ -1973,21 +1986,25 @@ TEST_F(URLRequestTestFTP, FTPDirectoryListing) {
|
| }
|
| }
|
|
|
| -TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
|
| - ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| +TEST_F(URLRequestTest, FTPGetTestAnonymous) {
|
| + FilePath data_dir;
|
| + data_dir = data_dir.AppendASCII("net");
|
| + data_dir = data_dir.AppendASCII("data");
|
| + data_dir = data_dir.AppendASCII("ftp");
|
| + scoped_refptr<FTPTestServer> server(
|
| + FTPTestServer::CreateServer(data_dir.ToWStringHack(), true));
|
| + ASSERT_TRUE(NULL != server.get());
|
| + FilePath testfile_path(data_dir.AppendASCII("testfile"));
|
| TestDelegate d;
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE"), &d);
|
| + TestURLRequest r(server->TestServerPage("/testfile"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
|
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -1998,12 +2015,10 @@ TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) {
|
|
|
| TEST_F(URLRequestTestFTP, FTPGetTest) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| TestDelegate d;
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "chrome"),
|
| + TestURLRequest r(server_->TestServerPage("/testfile", "chrome", "chrome"),
|
| &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
| @@ -2011,7 +2026,7 @@ TEST_F(URLRequestTestFTP, FTPGetTest) {
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -2022,12 +2037,10 @@ TEST_F(URLRequestTestFTP, FTPGetTest) {
|
|
|
| TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| TestDelegate d;
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE",
|
| + TestURLRequest r(server_->TestServerPage("/testfile",
|
| "chrome", "wrong_password"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
| @@ -2035,7 +2048,7 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -2046,16 +2059,14 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) {
|
|
|
| TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| TestDelegate d;
|
| - // Set correct login credentials. The delegate will be asked for them when
|
| - // the initial login with wrong credentials will fail.
|
| + // Set correct login identity. The delegate will be asked for it when
|
| + // the initial login with wrong password will fail.
|
| d.set_username(L"chrome");
|
| d.set_password(L"chrome");
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE",
|
| + TestURLRequest r(server_->TestServerPage("/testfile",
|
| "chrome", "wrong_password"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
| @@ -2063,7 +2074,7 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -2074,12 +2085,10 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) {
|
|
|
| TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| TestDelegate d;
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE",
|
| + TestURLRequest r(server_->TestServerPage("/testfile",
|
| "wrong_user", "chrome"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
| @@ -2087,7 +2096,7 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -2098,16 +2107,14 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongUser) {
|
|
|
| TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
|
| ASSERT_TRUE(NULL != server_.get());
|
| - FilePath app_path;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
|
| - app_path = app_path.AppendASCII("LICENSE");
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| TestDelegate d;
|
| - // Set correct login credentials. The delegate will be asked for them when
|
| - // the initial login with wrong credentials will fail.
|
| + // Set correct login identity. The delegate will be asked for it when
|
| + // the initial login with wrong user will fail.
|
| d.set_username(L"chrome");
|
| d.set_password(L"chrome");
|
| {
|
| - TestURLRequest r(server_->TestServerPage("/LICENSE",
|
| + TestURLRequest r(server_->TestServerPage("/testfile",
|
| "wrong_user", "chrome"), &d);
|
| r.Start();
|
| EXPECT_TRUE(r.is_pending());
|
| @@ -2115,7 +2122,7 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
|
| MessageLoop::current()->Run();
|
|
|
| int64 file_size = 0;
|
| - file_util::GetFileSize(app_path, &file_size);
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
|
|
| EXPECT_FALSE(r.is_pending());
|
| EXPECT_EQ(1, d.response_started_count());
|
| @@ -2123,3 +2130,103 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) {
|
| EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
|
| }
|
| }
|
| +
|
| +TEST_F(URLRequestTestFTP, FTPCacheURLIdentity) {
|
| + ASSERT_TRUE(NULL != server_.get());
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| +
|
| + scoped_refptr<URLRequestTestContext> context(new URLRequestTestContext);
|
| +
|
| + scoped_ptr<TestDelegate> d(new TestDelegate);
|
| + {
|
| + // Pass correct identity in the URL. It should be cached.
|
| + TestURLRequest r(server_->TestServerPage("/testfile", "chrome", "chrome"),
|
| + d.get());
|
| + r.set_context(context.get());
|
| + r.Start();
|
| + EXPECT_TRUE(r.is_pending());
|
| +
|
| + MessageLoop::current()->Run();
|
| +
|
| + int64 file_size = 0;
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
| +
|
| + EXPECT_FALSE(r.is_pending());
|
| + EXPECT_EQ(1, d->response_started_count());
|
| + EXPECT_FALSE(d->received_data_before_response());
|
| + EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
|
| + }
|
| +
|
| + // Use a new delegate without explicit identity. The cached one should be
|
| + // used.
|
| + d.reset(new TestDelegate);
|
| + {
|
| + // Don't pass identity in the URL, it would override valid cached one.
|
| + TestURLRequest r(server_->TestServerPage("/testfile"), d.get());
|
| + r.set_context(context.get());
|
| + r.Start();
|
| + EXPECT_TRUE(r.is_pending());
|
| +
|
| + MessageLoop::current()->Run();
|
| +
|
| + int64 file_size = 0;
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
| +
|
| + EXPECT_FALSE(r.is_pending());
|
| + EXPECT_EQ(1, d->response_started_count());
|
| + EXPECT_FALSE(d->received_data_before_response());
|
| + EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
|
| + }
|
| +}
|
| +
|
| +TEST_F(URLRequestTestFTP, FTPCacheLoginBoxIdentity) {
|
| + ASSERT_TRUE(NULL != server_.get());
|
| + FilePath testfile_path(GetDataDir().AppendASCII("testfile"));
|
| +
|
| + scoped_refptr<URLRequestTestContext> context(new URLRequestTestContext);
|
| +
|
| + scoped_ptr<TestDelegate> d(new TestDelegate);
|
| + // Set correct login identity. The delegate will be asked for it when
|
| + // the initial login with wrong password will fail.
|
| + d->set_username(L"chrome");
|
| + d->set_password(L"chrome");
|
| + {
|
| + TestURLRequest r(server_->TestServerPage("/testfile",
|
| + "chrome", "wrong_password"),
|
| + d.get());
|
| + r.set_context(context.get());
|
| + r.Start();
|
| + EXPECT_TRUE(r.is_pending());
|
| +
|
| + MessageLoop::current()->Run();
|
| +
|
| + int64 file_size = 0;
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
| +
|
| + EXPECT_FALSE(r.is_pending());
|
| + EXPECT_EQ(1, d->response_started_count());
|
| + EXPECT_FALSE(d->received_data_before_response());
|
| + EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
|
| + }
|
| +
|
| + // Use a new delegate without explicit identity. The cached one should be
|
| + // used.
|
| + d.reset(new TestDelegate);
|
| + {
|
| + // Don't pass identity in the URL, it would override valid cached one.
|
| + TestURLRequest r(server_->TestServerPage("/testfile"), d.get());
|
| + r.set_context(context.get());
|
| + r.Start();
|
| + EXPECT_TRUE(r.is_pending());
|
| +
|
| + MessageLoop::current()->Run();
|
| +
|
| + int64 file_size = 0;
|
| + file_util::GetFileSize(testfile_path, &file_size);
|
| +
|
| + EXPECT_FALSE(r.is_pending());
|
| + EXPECT_EQ(1, d->response_started_count());
|
| + EXPECT_FALSE(d->received_data_before_response());
|
| + EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
|
| + }
|
| +}
|
|
|