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

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

Issue 9415040: Refactor TransportSecurityState. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
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
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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 // preloaded HSTS entries in the TransportSecurityState. This means that we 1763 // preloaded HSTS entries in the TransportSecurityState. This means that we
1764 // have to use a MockHostResolver in order to direct www.google.com to the 1764 // have to use a MockHostResolver in order to direct www.google.com to the
1765 // testserver. 1765 // testserver.
1766 1766
1767 MockHostResolver host_resolver; 1767 MockHostResolver host_resolver;
1768 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); 1768 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1");
1769 TestNetworkDelegate network_delegate; // must outlive URLRequest 1769 TestNetworkDelegate network_delegate; // must outlive URLRequest
1770 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1770 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true));
1771 context->set_network_delegate(&network_delegate); 1771 context->set_network_delegate(&network_delegate);
1772 context->set_host_resolver(&host_resolver); 1772 context->set_host_resolver(&host_resolver);
1773 TransportSecurityState transport_security_state(""); 1773 TransportSecurityState transport_security_state;
1774 context->set_transport_security_state(&transport_security_state); 1774 context->set_transport_security_state(&transport_security_state);
1775 context->Init(); 1775 context->Init();
1776 1776
1777 TestDelegate d; 1777 TestDelegate d;
1778 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", 1778 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d",
1779 test_server.host_port_pair().port())), 1779 test_server.host_port_pair().port())),
1780 &d); 1780 &d);
1781 r.set_context(context); 1781 r.set_context(context);
1782 1782
1783 r.Start(); 1783 r.Start();
(...skipping 22 matching lines...) Expand all
1806 // preloaded and dynamic HSTS and public key pin entries in the 1806 // preloaded and dynamic HSTS and public key pin entries in the
1807 // TransportSecurityState. This means that we have to use a 1807 // TransportSecurityState. This means that we have to use a
1808 // MockHostResolver in order to direct www.google.com to the testserver. 1808 // MockHostResolver in order to direct www.google.com to the testserver.
1809 1809
1810 MockHostResolver host_resolver; 1810 MockHostResolver host_resolver;
1811 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); 1811 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1");
1812 TestNetworkDelegate network_delegate; // must outlive URLRequest 1812 TestNetworkDelegate network_delegate; // must outlive URLRequest
1813 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1813 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true));
1814 context->set_network_delegate(&network_delegate); 1814 context->set_network_delegate(&network_delegate);
1815 context->set_host_resolver(&host_resolver); 1815 context->set_host_resolver(&host_resolver);
1816 TransportSecurityState transport_security_state(""); 1816 TransportSecurityState transport_security_state;
1817 TransportSecurityState::DomainState domain_state; 1817 TransportSecurityState::DomainState domain_state;
1818 EXPECT_TRUE(transport_security_state.HasMetadata(&domain_state, 1818 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
1819 "www.google.com", true)); 1819 &domain_state));
1820 context->set_transport_security_state(&transport_security_state); 1820 context->set_transport_security_state(&transport_security_state);
1821 context->Init(); 1821 context->Init();
1822 1822
1823 TestDelegate d; 1823 TestDelegate d;
1824 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", 1824 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d",
1825 test_server.host_port_pair().port())), 1825 test_server.host_port_pair().port())),
1826 &d); 1826 &d);
1827 r.set_context(context); 1827 r.set_context(context);
1828 1828
1829 r.Start(); 1829 r.Start();
1830 EXPECT_TRUE(r.is_pending()); 1830 EXPECT_TRUE(r.is_pending());
1831 1831
1832 MessageLoop::current()->Run(); 1832 MessageLoop::current()->Run();
1833 1833
1834 EXPECT_EQ(1, d.response_started_count()); 1834 EXPECT_EQ(1, d.response_started_count());
1835 EXPECT_FALSE(d.received_data_before_response()); 1835 EXPECT_FALSE(d.received_data_before_response());
1836 EXPECT_TRUE(d.have_certificate_errors()); 1836 EXPECT_TRUE(d.have_certificate_errors());
1837 EXPECT_TRUE(d.certificate_errors_are_fatal()); 1837 EXPECT_TRUE(d.certificate_errors_are_fatal());
1838 1838
1839 // Get a fresh copy of the state, and check that it hasn't been updated. 1839 // Get a fresh copy of the state, and check that it hasn't been updated.
1840 TransportSecurityState::DomainState new_domain_state; 1840 TransportSecurityState::DomainState new_domain_state;
1841 EXPECT_TRUE(transport_security_state.HasMetadata(&new_domain_state, 1841 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
1842 "www.google.com", true)); 1842 &new_domain_state));
1843 EXPECT_EQ(new_domain_state.mode, domain_state.mode); 1843 EXPECT_EQ(new_domain_state.upgrade_mode, domain_state.upgrade_mode);
1844 EXPECT_EQ(new_domain_state.include_subdomains, 1844 EXPECT_EQ(new_domain_state.include_subdomains,
1845 domain_state.include_subdomains); 1845 domain_state.include_subdomains);
1846 EXPECT_TRUE(FingerprintsEqual(new_domain_state.preloaded_spki_hashes, 1846 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes,
1847 domain_state.preloaded_spki_hashes)); 1847 domain_state.static_spki_hashes));
1848 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, 1848 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes,
1849 domain_state.dynamic_spki_hashes)); 1849 domain_state.dynamic_spki_hashes));
1850 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_preloaded_spki_hashes, 1850 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes,
1851 domain_state.bad_preloaded_spki_hashes)); 1851 domain_state.bad_static_spki_hashes));
1852 } 1852 }
1853 1853
1854 namespace { 1854 namespace {
1855 1855
1856 class SSLClientAuthTestDelegate : public TestDelegate { 1856 class SSLClientAuthTestDelegate : public TestDelegate {
1857 public: 1857 public:
1858 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { 1858 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {
1859 } 1859 }
1860 virtual void OnCertificateRequested( 1860 virtual void OnCertificateRequested(
1861 URLRequest* request, 1861 URLRequest* request,
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 FilePath app_path; 2560 FilePath app_path;
2561 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2561 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2562 app_path = app_path.AppendASCII("net"); 2562 app_path = app_path.AppendASCII("net");
2563 app_path = app_path.AppendASCII("data"); 2563 app_path = app_path.AppendASCII("data");
2564 app_path = app_path.AppendASCII("url_request_unittest"); 2564 app_path = app_path.AppendASCII("url_request_unittest");
2565 app_path = app_path.AppendASCII("with-headers.html"); 2565 app_path = app_path.AppendASCII("with-headers.html");
2566 2566
2567 std::wstring lnk_path = app_path.value() + L".lnk"; 2567 std::wstring lnk_path = app_path.value() + L".lnk";
2568 2568
2569 HRESULT result; 2569 HRESULT result;
2570 IShellLink *shell = NULL; 2570 IShellLink* shell = NULL;
2571 IPersistFile *persist = NULL; 2571 IPersistFile* persist = NULL;
2572 2572
2573 CoInitialize(NULL); 2573 CoInitialize(NULL);
2574 // Temporarily create a shortcut for test 2574 // Temporarily create a shortcut for test
2575 result = CoCreateInstance(CLSID_ShellLink, NULL, 2575 result = CoCreateInstance(CLSID_ShellLink, NULL,
2576 CLSCTX_INPROC_SERVER, IID_IShellLink, 2576 CLSCTX_INPROC_SERVER, IID_IShellLink,
2577 reinterpret_cast<LPVOID*>(&shell)); 2577 reinterpret_cast<LPVOID*>(&shell));
2578 ASSERT_TRUE(SUCCEEDED(result)); 2578 ASSERT_TRUE(SUCCEEDED(result));
2579 result = shell->QueryInterface(IID_IPersistFile, 2579 result = shell->QueryInterface(IID_IPersistFile,
2580 reinterpret_cast<LPVOID*>(&persist)); 2580 reinterpret_cast<LPVOID*>(&persist));
2581 ASSERT_TRUE(SUCCEEDED(result)); 2581 ASSERT_TRUE(SUCCEEDED(result));
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after
4580 req.SetExtraRequestHeaders(headers); 4580 req.SetExtraRequestHeaders(headers);
4581 req.Start(); 4581 req.Start();
4582 MessageLoop::current()->Run(); 4582 MessageLoop::current()->Run();
4583 // If the net tests are being run with ChromeFrame then we need to allow for 4583 // If the net tests are being run with ChromeFrame then we need to allow for
4584 // the 'chromeframe' suffix which is added to the user agent before the 4584 // the 'chromeframe' suffix which is added to the user agent before the
4585 // closing parentheses. 4585 // closing parentheses.
4586 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4586 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4587 } 4587 }
4588 4588
4589 } // namespace net 4589 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698