| 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 r.AppendFileToUpload(path); | 324 r.AppendFileToUpload(path); |
| 325 | 325 |
| 326 // This file should just be ignored in the upload stream. | 326 // This file should just be ignored in the upload stream. |
| 327 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); | 327 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); |
| 328 | 328 |
| 329 r.Start(); | 329 r.Start(); |
| 330 EXPECT_TRUE(r.is_pending()); | 330 EXPECT_TRUE(r.is_pending()); |
| 331 | 331 |
| 332 MessageLoop::current()->Run(); | 332 MessageLoop::current()->Run(); |
| 333 | 333 |
| 334 #if defined(OS_WIN) |
| 334 HANDLE file = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, | 335 HANDLE file = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, |
| 335 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 336 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 336 ASSERT_NE(INVALID_HANDLE_VALUE, file); | 337 ASSERT_NE(INVALID_HANDLE_VALUE, file); |
| 337 | 338 |
| 338 DWORD size = GetFileSize(file, NULL); | 339 DWORD size = GetFileSize(file, NULL); |
| 339 scoped_array<char> buf(new char[size]); | 340 scoped_array<char> buf(new char[size]); |
| 340 | 341 |
| 341 DWORD size_read; | 342 DWORD size_read; |
| 342 EXPECT_TRUE(ReadFile(file, buf.get(), size, &size_read, NULL)); | 343 EXPECT_TRUE(ReadFile(file, buf.get(), size, &size_read, NULL)); |
| 343 | 344 |
| 344 CloseHandle(file); | 345 CloseHandle(file); |
| 345 | 346 |
| 346 EXPECT_EQ(size, size_read); | 347 EXPECT_EQ(size, size_read); |
| 347 | 348 |
| 348 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 349 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| 349 (int) r.status().status() << ", os error: " << r.status().os_error(); | 350 (int) r.status().status() << ", os error: " << r.status().os_error(); |
| 350 | 351 |
| 351 EXPECT_FALSE(d.received_data_before_response()); | 352 EXPECT_FALSE(d.received_data_before_response()); |
| 352 | 353 |
| 353 ASSERT_EQ(size, d.bytes_received()); | 354 ASSERT_EQ(size, d.bytes_received()); |
| 354 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 355 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
| 356 #else |
| 357 NOTIMPLEMENTED(); |
| 358 #endif |
| 355 } | 359 } |
| 356 #ifndef NDEBUG | 360 #ifndef NDEBUG |
| 357 DCHECK_EQ(url_request_metrics.object_count,0); | 361 DCHECK_EQ(url_request_metrics.object_count,0); |
| 358 #endif | 362 #endif |
| 359 } | 363 } |
| 360 | 364 |
| 361 TEST(URLRequestTest, AboutBlankTest) { | 365 TEST(URLRequestTest, AboutBlankTest) { |
| 362 TestDelegate d; | 366 TestDelegate d; |
| 363 { | 367 { |
| 364 TestURLRequest r(GURL("about:blank"), &d); | 368 TestURLRequest r(GURL("about:blank"), &d); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 req.set_context(context); | 693 req.set_context(context); |
| 690 req.SetExtraRequestHeaders("foo:1"); | 694 req.SetExtraRequestHeaders("foo:1"); |
| 691 req.Start(); | 695 req.Start(); |
| 692 MessageLoop::current()->Run(); | 696 MessageLoop::current()->Run(); |
| 693 | 697 |
| 694 response_time = req.response_time(); | 698 response_time = req.response_time(); |
| 695 } | 699 } |
| 696 | 700 |
| 697 // Make sure that the response time of a future response will be in the | 701 // Make sure that the response time of a future response will be in the |
| 698 // future! | 702 // future! |
| 699 Sleep(10); | 703 PlatformThread::Sleep(10); |
| 700 | 704 |
| 701 // expect a cache hit | 705 // expect a cache hit |
| 702 { | 706 { |
| 703 TestDelegate d; | 707 TestDelegate d; |
| 704 URLRequest req(server.TestServerPage("echoheader?foo"), &d); | 708 URLRequest req(server.TestServerPage("echoheader?foo"), &d); |
| 705 req.set_context(context); | 709 req.set_context(context); |
| 706 req.SetExtraRequestHeaders("foo:1"); | 710 req.SetExtraRequestHeaders("foo:1"); |
| 707 req.Start(); | 711 req.Start(); |
| 708 MessageLoop::current()->Run(); | 712 MessageLoop::current()->Run(); |
| 709 | 713 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 745 |
| 742 MessageLoop::current()->Run(); | 746 MessageLoop::current()->Run(); |
| 743 | 747 |
| 744 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 748 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 745 | 749 |
| 746 response_time = r.response_time(); | 750 response_time = r.response_time(); |
| 747 } | 751 } |
| 748 | 752 |
| 749 // Let some time pass so we can ensure that a future response will have a | 753 // Let some time pass so we can ensure that a future response will have a |
| 750 // response time value in the future. | 754 // response time value in the future. |
| 751 Sleep(10 /* milliseconds */); | 755 PlatformThread::Sleep(10 /* milliseconds */); |
| 752 | 756 |
| 753 // repeat request with end-to-end validation. since auth-basic results in a | 757 // repeat request with end-to-end validation. since auth-basic results in a |
| 754 // cachable page, we expect this test to result in a 304. in which case, the | 758 // cachable page, we expect this test to result in a 304. in which case, the |
| 755 // response should be fetched from the cache. | 759 // response should be fetched from the cache. |
| 756 { | 760 { |
| 757 TestDelegate d; | 761 TestDelegate d; |
| 758 d.set_username(L"user"); | 762 d.set_username(L"user"); |
| 759 d.set_password(L"secret"); | 763 d.set_password(L"secret"); |
| 760 | 764 |
| 761 URLRequest r(server.TestServerPage("auth-basic"), &d); | 765 URLRequest r(server.TestServerPage("auth-basic"), &d); |
| 762 r.set_context(context); | 766 r.set_context(context); |
| 763 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 767 r.set_load_flags(net::LOAD_VALIDATE_CACHE); |
| 764 r.Start(); | 768 r.Start(); |
| 765 | 769 |
| 766 MessageLoop::current()->Run(); | 770 MessageLoop::current()->Run(); |
| 767 | 771 |
| 768 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 772 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 769 | 773 |
| 770 // Should be the same cached document, which means that the response time | 774 // Should be the same cached document, which means that the response time |
| 771 // should not have changed. | 775 // should not have changed. |
| 772 EXPECT_TRUE(response_time == r.response_time()); | 776 EXPECT_TRUE(response_time == r.response_time()); |
| 773 } | 777 } |
| 774 } | 778 } |
| 775 | 779 |
| OLD | NEW |