OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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> |
11 #include <shlobj.h> | 11 #include <shlobj.h> |
12 #elif defined(OS_LINUX) | 12 #elif defined(OS_LINUX) |
13 #include "base/nss_init.h" | 13 #include "base/nss_init.h" |
14 #endif | 14 #endif |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <string> | 17 #include <string> |
18 | 18 |
| 19 #include "base/file_path.h" |
19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/process_util.h" | 22 #include "base/process_util.h" |
22 #include "base/string_piece.h" | 23 #include "base/string_piece.h" |
23 #include "base/string_util.h" | 24 #include "base/string_util.h" |
24 #include "net/base/cookie_monster.h" | 25 #include "net/base/cookie_monster.h" |
25 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
27 #include "net/base/net_module.h" | 28 #include "net/base/net_module.h" |
28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 ASSERT_TRUE(NULL != server.get()); | 520 ASSERT_TRUE(NULL != server.get()); |
520 TestDelegate d; | 521 TestDelegate d; |
521 { | 522 { |
522 TestURLRequest r(server->TestServerPage("echo"), &d); | 523 TestURLRequest r(server->TestServerPage("echo"), &d); |
523 r.set_method("POST"); | 524 r.set_method("POST"); |
524 | 525 |
525 std::wstring dir; | 526 std::wstring dir; |
526 PathService::Get(base::DIR_EXE, &dir); | 527 PathService::Get(base::DIR_EXE, &dir); |
527 file_util::SetCurrentDirectory(dir); | 528 file_util::SetCurrentDirectory(dir); |
528 | 529 |
529 std::wstring path; | 530 FilePath path; |
530 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 531 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
531 file_util::AppendToPath(&path, L"net"); | 532 path = path.Append(FILE_PATH_LITERAL("net")); |
532 file_util::AppendToPath(&path, L"data"); | 533 path = path.Append(FILE_PATH_LITERAL("data")); |
533 file_util::AppendToPath(&path, L"url_request_unittest"); | 534 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
534 file_util::AppendToPath(&path, L"with-headers.html"); | 535 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
535 r.AppendFileToUpload(path); | 536 r.AppendFileToUpload(path); |
536 | 537 |
537 // This file should just be ignored in the upload stream. | 538 // This file should just be ignored in the upload stream. |
538 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); | 539 r.AppendFileToUpload(FilePath(FILE_PATH_LITERAL( |
| 540 "c:\\path\\to\\non\\existant\\file.randomness.12345"))); |
539 | 541 |
540 r.Start(); | 542 r.Start(); |
541 EXPECT_TRUE(r.is_pending()); | 543 EXPECT_TRUE(r.is_pending()); |
542 | 544 |
543 MessageLoop::current()->Run(); | 545 MessageLoop::current()->Run(); |
544 | 546 |
545 int64 longsize; | 547 int64 longsize; |
546 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); | 548 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); |
547 int size = static_cast<int>(longsize); | 549 int size = static_cast<int>(longsize); |
548 scoped_array<char> buf(new char[size]); | 550 scoped_array<char> buf(new char[size]); |
(...skipping 30 matching lines...) Expand all Loading... |
579 EXPECT_EQ(d.bytes_received(), 0); | 581 EXPECT_EQ(d.bytes_received(), 0); |
580 } | 582 } |
581 #ifndef NDEBUG | 583 #ifndef NDEBUG |
582 DCHECK_EQ(url_request_metrics.object_count, 0); | 584 DCHECK_EQ(url_request_metrics.object_count, 0); |
583 #endif | 585 #endif |
584 } | 586 } |
585 | 587 |
586 TEST_F(URLRequestTest, FileTest) { | 588 TEST_F(URLRequestTest, FileTest) { |
587 FilePath app_path; | 589 FilePath app_path; |
588 PathService::Get(base::FILE_EXE, &app_path); | 590 PathService::Get(base::FILE_EXE, &app_path); |
589 GURL app_url = net::FilePathToFileURL(app_path.ToWStringHack()); | 591 GURL app_url = net::FilePathToFileURL(app_path); |
590 | 592 |
591 TestDelegate d; | 593 TestDelegate d; |
592 { | 594 { |
593 TestURLRequest r(app_url, &d); | 595 TestURLRequest r(app_url, &d); |
594 | 596 |
595 r.Start(); | 597 r.Start(); |
596 EXPECT_TRUE(r.is_pending()); | 598 EXPECT_TRUE(r.is_pending()); |
597 | 599 |
598 MessageLoop::current()->Run(); | 600 MessageLoop::current()->Run(); |
599 | 601 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 EXPECT_TRUE(SUCCEEDED(result)); | 755 EXPECT_TRUE(SUCCEEDED(result)); |
754 result = persist->Save(lnk_path.c_str(), TRUE); | 756 result = persist->Save(lnk_path.c_str(), TRUE); |
755 EXPECT_TRUE(SUCCEEDED(result)); | 757 EXPECT_TRUE(SUCCEEDED(result)); |
756 if (persist) | 758 if (persist) |
757 persist->Release(); | 759 persist->Release(); |
758 if (shell) | 760 if (shell) |
759 shell->Release(); | 761 shell->Release(); |
760 | 762 |
761 TestDelegate d; | 763 TestDelegate d; |
762 { | 764 { |
763 TestURLRequest r(net::FilePathToFileURL(lnk_path), &d); | 765 TestURLRequest r(net::FilePathToFileURL(FilePath(lnk_path)), &d); |
764 | 766 |
765 r.Start(); | 767 r.Start(); |
766 EXPECT_TRUE(r.is_pending()); | 768 EXPECT_TRUE(r.is_pending()); |
767 | 769 |
768 MessageLoop::current()->Run(); | 770 MessageLoop::current()->Run(); |
769 | 771 |
770 WIN32_FILE_ATTRIBUTE_DATA data; | 772 WIN32_FILE_ATTRIBUTE_DATA data; |
771 GetFileAttributesEx(app_path.c_str(), GetFileExInfoStandard, &data); | 773 GetFileAttributesEx(app_path.c_str(), GetFileExInfoStandard, &data); |
772 HANDLE file = CreateFile(app_path.c_str(), GENERIC_READ, | 774 HANDLE file = CreateFile(app_path.c_str(), GENERIC_READ, |
773 FILE_SHARE_READ, NULL, OPEN_EXISTING, | 775 FILE_SHARE_READ, NULL, OPEN_EXISTING, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 EXPECT_EQ("utf-8", charset); | 818 EXPECT_EQ("utf-8", charset); |
817 req.Cancel(); | 819 req.Cancel(); |
818 } | 820 } |
819 | 821 |
820 TEST_F(URLRequestTest, FileDirCancelTest) { | 822 TEST_F(URLRequestTest, FileDirCancelTest) { |
821 // Put in mock resource provider. | 823 // Put in mock resource provider. |
822 net::NetModule::SetResourceProvider(TestNetResourceProvider); | 824 net::NetModule::SetResourceProvider(TestNetResourceProvider); |
823 | 825 |
824 TestDelegate d; | 826 TestDelegate d; |
825 { | 827 { |
826 std::wstring file_path; | 828 FilePath file_path; |
827 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 829 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
828 file_util::AppendToPath(&file_path, L"net"); | 830 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
829 file_util::AppendToPath(&file_path, L"data"); | 831 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
830 file_util::AppendToPath(&file_path, L""); | |
831 | 832 |
832 TestURLRequest req(net::FilePathToFileURL(file_path), &d); | 833 TestURLRequest req(net::FilePathToFileURL(file_path), &d); |
833 req.Start(); | 834 req.Start(); |
834 EXPECT_TRUE(req.is_pending()); | 835 EXPECT_TRUE(req.is_pending()); |
835 | 836 |
836 d.set_cancel_in_received_data_pending(true); | 837 d.set_cancel_in_received_data_pending(true); |
837 | 838 |
838 MessageLoop::current()->Run(); | 839 MessageLoop::current()->Run(); |
839 } | 840 } |
840 #ifndef NDEBUG | 841 #ifndef NDEBUG |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 | 1215 |
1215 int64 file_size = 0; | 1216 int64 file_size = 0; |
1216 file_util::GetFileSize(app_path, &file_size); | 1217 file_util::GetFileSize(app_path, &file_size); |
1217 | 1218 |
1218 EXPECT_TRUE(!r.is_pending()); | 1219 EXPECT_TRUE(!r.is_pending()); |
1219 EXPECT_EQ(1, d.response_started_count()); | 1220 EXPECT_EQ(1, d.response_started_count()); |
1220 EXPECT_FALSE(d.received_data_before_response()); | 1221 EXPECT_FALSE(d.received_data_before_response()); |
1221 EXPECT_EQ(d.bytes_received(), 0); | 1222 EXPECT_EQ(d.bytes_received(), 0); |
1222 } | 1223 } |
1223 } | 1224 } |
OLD | NEW |