OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 EXPECT_NE(kData, d.data_received()); | 472 EXPECT_NE(kData, d.data_received()); |
473 } | 473 } |
474 } | 474 } |
475 if (HasFailure()) | 475 if (HasFailure()) |
476 LOG(WARNING) << "Request method was: " << request_method; | 476 LOG(WARNING) << "Request method was: " << request_method; |
477 } | 477 } |
478 | 478 |
479 void HTTPUploadDataOperationTest(const std::string& method) { | 479 void HTTPUploadDataOperationTest(const std::string& method) { |
480 const int kMsgSize = 20000; // multiple of 10 | 480 const int kMsgSize = 20000; // multiple of 10 |
481 const int kIterations = 50; | 481 const int kIterations = 50; |
482 char *uploadBytes = new char[kMsgSize+1]; | 482 char* uploadBytes = new char[kMsgSize+1]; |
483 char *ptr = uploadBytes; | 483 char* ptr = uploadBytes; |
484 char marker = 'a'; | 484 char marker = 'a'; |
485 for (int idx = 0; idx < kMsgSize/10; idx++) { | 485 for (int idx = 0; idx < kMsgSize/10; idx++) { |
486 memcpy(ptr, "----------", 10); | 486 memcpy(ptr, "----------", 10); |
487 ptr += 10; | 487 ptr += 10; |
488 if (idx % 100 == 0) { | 488 if (idx % 100 == 0) { |
489 ptr--; | 489 ptr--; |
490 *ptr++ = marker; | 490 *ptr++ = marker; |
491 if (++marker > 'z') | 491 if (++marker > 'z') |
492 marker = 'a'; | 492 marker = 'a'; |
493 } | 493 } |
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 // preloaded HSTS entries in the TransportSecurityState. This means that we | 1767 // preloaded HSTS entries in the TransportSecurityState. This means that we |
1768 // have to use a MockHostResolver in order to direct www.google.com to the | 1768 // have to use a MockHostResolver in order to direct www.google.com to the |
1769 // testserver. | 1769 // testserver. |
1770 | 1770 |
1771 MockHostResolver host_resolver; | 1771 MockHostResolver host_resolver; |
1772 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); | 1772 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); |
1773 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1773 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1774 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1774 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
1775 context->set_network_delegate(&network_delegate); | 1775 context->set_network_delegate(&network_delegate); |
1776 context->set_host_resolver(&host_resolver); | 1776 context->set_host_resolver(&host_resolver); |
1777 TransportSecurityState transport_security_state(""); | 1777 TransportSecurityState transport_security_state; |
1778 context->set_transport_security_state(&transport_security_state); | 1778 context->set_transport_security_state(&transport_security_state); |
1779 context->Init(); | 1779 context->Init(); |
1780 | 1780 |
1781 TestDelegate d; | 1781 TestDelegate d; |
1782 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1782 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
1783 test_server.host_port_pair().port())), | 1783 test_server.host_port_pair().port())), |
1784 &d); | 1784 &d); |
1785 r.set_context(context); | 1785 r.set_context(context); |
1786 | 1786 |
1787 r.Start(); | 1787 r.Start(); |
(...skipping 22 matching lines...) Expand all Loading... |
1810 // preloaded and dynamic HSTS and public key pin entries in the | 1810 // preloaded and dynamic HSTS and public key pin entries in the |
1811 // TransportSecurityState. This means that we have to use a | 1811 // TransportSecurityState. This means that we have to use a |
1812 // MockHostResolver in order to direct www.google.com to the testserver. | 1812 // MockHostResolver in order to direct www.google.com to the testserver. |
1813 | 1813 |
1814 MockHostResolver host_resolver; | 1814 MockHostResolver host_resolver; |
1815 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); | 1815 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); |
1816 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1816 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1817 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1817 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
1818 context->set_network_delegate(&network_delegate); | 1818 context->set_network_delegate(&network_delegate); |
1819 context->set_host_resolver(&host_resolver); | 1819 context->set_host_resolver(&host_resolver); |
1820 TransportSecurityState transport_security_state(""); | 1820 TransportSecurityState transport_security_state; |
1821 TransportSecurityState::DomainState domain_state; | 1821 TransportSecurityState::DomainState domain_state; |
1822 EXPECT_TRUE(transport_security_state.HasMetadata(&domain_state, | 1822 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
1823 "www.google.com", true)); | 1823 &domain_state)); |
1824 context->set_transport_security_state(&transport_security_state); | 1824 context->set_transport_security_state(&transport_security_state); |
1825 context->Init(); | 1825 context->Init(); |
1826 | 1826 |
1827 TestDelegate d; | 1827 TestDelegate d; |
1828 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1828 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
1829 test_server.host_port_pair().port())), | 1829 test_server.host_port_pair().port())), |
1830 &d); | 1830 &d); |
1831 r.set_context(context); | 1831 r.set_context(context); |
1832 | 1832 |
1833 r.Start(); | 1833 r.Start(); |
1834 EXPECT_TRUE(r.is_pending()); | 1834 EXPECT_TRUE(r.is_pending()); |
1835 | 1835 |
1836 MessageLoop::current()->Run(); | 1836 MessageLoop::current()->Run(); |
1837 | 1837 |
1838 EXPECT_EQ(1, d.response_started_count()); | 1838 EXPECT_EQ(1, d.response_started_count()); |
1839 EXPECT_FALSE(d.received_data_before_response()); | 1839 EXPECT_FALSE(d.received_data_before_response()); |
1840 EXPECT_TRUE(d.have_certificate_errors()); | 1840 EXPECT_TRUE(d.have_certificate_errors()); |
1841 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 1841 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
1842 | 1842 |
1843 // Get a fresh copy of the state, and check that it hasn't been updated. | 1843 // Get a fresh copy of the state, and check that it hasn't been updated. |
1844 TransportSecurityState::DomainState new_domain_state; | 1844 TransportSecurityState::DomainState new_domain_state; |
1845 EXPECT_TRUE(transport_security_state.HasMetadata(&new_domain_state, | 1845 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
1846 "www.google.com", true)); | 1846 &new_domain_state)); |
1847 EXPECT_EQ(new_domain_state.mode, domain_state.mode); | 1847 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode); |
1848 EXPECT_EQ(new_domain_state.include_subdomains, | 1848 EXPECT_EQ(new_domain_state.include_subdomains, |
1849 domain_state.include_subdomains); | 1849 domain_state.include_subdomains); |
1850 EXPECT_TRUE(FingerprintsEqual(new_domain_state.preloaded_spki_hashes, | 1850 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, |
1851 domain_state.preloaded_spki_hashes)); | 1851 domain_state.static_spki_hashes)); |
1852 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, | 1852 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, |
1853 domain_state.dynamic_spki_hashes)); | 1853 domain_state.dynamic_spki_hashes)); |
1854 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_preloaded_spki_hashes, | 1854 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, |
1855 domain_state.bad_preloaded_spki_hashes)); | 1855 domain_state.bad_static_spki_hashes)); |
1856 } | 1856 } |
1857 | 1857 |
1858 namespace { | 1858 namespace { |
1859 | 1859 |
1860 class SSLClientAuthTestDelegate : public TestDelegate { | 1860 class SSLClientAuthTestDelegate : public TestDelegate { |
1861 public: | 1861 public: |
1862 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 1862 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
1863 } | 1863 } |
1864 virtual void OnCertificateRequested( | 1864 virtual void OnCertificateRequested( |
1865 URLRequest* request, | 1865 URLRequest* request, |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2564 FilePath app_path; | 2564 FilePath app_path; |
2565 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 2565 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
2566 app_path = app_path.AppendASCII("net"); | 2566 app_path = app_path.AppendASCII("net"); |
2567 app_path = app_path.AppendASCII("data"); | 2567 app_path = app_path.AppendASCII("data"); |
2568 app_path = app_path.AppendASCII("url_request_unittest"); | 2568 app_path = app_path.AppendASCII("url_request_unittest"); |
2569 app_path = app_path.AppendASCII("with-headers.html"); | 2569 app_path = app_path.AppendASCII("with-headers.html"); |
2570 | 2570 |
2571 std::wstring lnk_path = app_path.value() + L".lnk"; | 2571 std::wstring lnk_path = app_path.value() + L".lnk"; |
2572 | 2572 |
2573 HRESULT result; | 2573 HRESULT result; |
2574 IShellLink *shell = NULL; | 2574 IShellLink* shell = NULL; |
2575 IPersistFile *persist = NULL; | 2575 IPersistFile* persist = NULL; |
2576 | 2576 |
2577 CoInitialize(NULL); | 2577 CoInitialize(NULL); |
2578 // Temporarily create a shortcut for test | 2578 // Temporarily create a shortcut for test |
2579 result = CoCreateInstance(CLSID_ShellLink, NULL, | 2579 result = CoCreateInstance(CLSID_ShellLink, NULL, |
2580 CLSCTX_INPROC_SERVER, IID_IShellLink, | 2580 CLSCTX_INPROC_SERVER, IID_IShellLink, |
2581 reinterpret_cast<LPVOID*>(&shell)); | 2581 reinterpret_cast<LPVOID*>(&shell)); |
2582 ASSERT_TRUE(SUCCEEDED(result)); | 2582 ASSERT_TRUE(SUCCEEDED(result)); |
2583 result = shell->QueryInterface(IID_IPersistFile, | 2583 result = shell->QueryInterface(IID_IPersistFile, |
2584 reinterpret_cast<LPVOID*>(&persist)); | 2584 reinterpret_cast<LPVOID*>(&persist)); |
2585 ASSERT_TRUE(SUCCEEDED(result)); | 2585 ASSERT_TRUE(SUCCEEDED(result)); |
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4584 req.SetExtraRequestHeaders(headers); | 4584 req.SetExtraRequestHeaders(headers); |
4585 req.Start(); | 4585 req.Start(); |
4586 MessageLoop::current()->Run(); | 4586 MessageLoop::current()->Run(); |
4587 // If the net tests are being run with ChromeFrame then we need to allow for | 4587 // If the net tests are being run with ChromeFrame then we need to allow for |
4588 // the 'chromeframe' suffix which is added to the user agent before the | 4588 // the 'chromeframe' suffix which is added to the user agent before the |
4589 // closing parentheses. | 4589 // closing parentheses. |
4590 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4590 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
4591 } | 4591 } |
4592 | 4592 |
4593 } // namespace net | 4593 } // namespace net |
OLD | NEW |