| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "content/browser/loader/test_url_loader_client.h" | 10 #include "content/browser/loader/test_url_loader_client.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 request.download_to_file = false; | 37 request.download_to_file = false; |
| 38 request.should_reset_appcache = false; | 38 request.should_reset_appcache = false; |
| 39 request.is_main_frame = true; | 39 request.is_main_frame = true; |
| 40 request.parent_is_main_frame = false; | 40 request.parent_is_main_frame = false; |
| 41 request.transition_type = ui::PAGE_TRANSITION_LINK; | 41 request.transition_type = ui::PAGE_TRANSITION_LINK; |
| 42 request.allow_download = true; | 42 request.allow_download = true; |
| 43 return request; | 43 return request; |
| 44 } | 44 } |
| 45 | 45 |
| 46 std::string ReadData(MojoHandle consumer, size_t size) { | 46 std::string ReadData(MojoHandle consumer, size_t size) { |
| 47 CHECK_EQ(mojo::Wait(mojo::Handle(consumer), MOJO_HANDLE_SIGNAL_READABLE), | 47 MojoResult rv = |
| 48 MOJO_RESULT_OK); | 48 mojo::Wait(mojo::Handle(consumer), MOJO_HANDLE_SIGNAL_READABLE); |
| 49 if (!size) { |
| 50 CHECK_EQ(rv, MOJO_RESULT_FAILED_PRECONDITION); |
| 51 return std::string(); |
| 52 } |
| 53 CHECK_EQ(rv, MOJO_RESULT_OK); |
| 49 std::vector<char> buffer(size); | 54 std::vector<char> buffer(size); |
| 50 uint32_t num_bytes = static_cast<uint32_t>(size); | 55 uint32_t num_bytes = static_cast<uint32_t>(size); |
| 51 CHECK_EQ(MojoReadData(consumer, buffer.data(), &num_bytes, | 56 CHECK_EQ(MojoReadData(consumer, buffer.data(), &num_bytes, |
| 52 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), | 57 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), |
| 53 MOJO_RESULT_OK); | 58 MOJO_RESULT_OK); |
| 54 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); | 59 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); |
| 55 | 60 |
| 56 return std::string(buffer.data(), buffer.size()); | 61 return std::string(buffer.data(), buffer.size()); |
| 57 } | 62 } |
| 58 | 63 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 private: | 114 private: |
| 110 base::MessageLoopForIO message_loop_; | 115 base::MessageLoopForIO message_loop_; |
| 111 net::EmbeddedTestServer test_server_; | 116 net::EmbeddedTestServer test_server_; |
| 112 std::unique_ptr<NetworkContext> context_; | 117 std::unique_ptr<NetworkContext> context_; |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 TEST_F(URLLoaderImplTest, Basic) { | 120 TEST_F(URLLoaderImplTest, Basic) { |
| 116 LoadAndCompareFile("simple_page.html"); | 121 LoadAndCompareFile("simple_page.html"); |
| 117 } | 122 } |
| 118 | 123 |
| 124 TEST_F(URLLoaderImplTest, Empty) { |
| 125 LoadAndCompareFile("empty.html"); |
| 126 } |
| 127 |
| 119 TEST_F(URLLoaderImplTest, BasicSSL) { | 128 TEST_F(URLLoaderImplTest, BasicSSL) { |
| 120 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 129 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 121 https_server.ServeFilesFromSourceDirectory( | 130 https_server.ServeFilesFromSourceDirectory( |
| 122 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 131 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 123 ASSERT_TRUE(https_server.Start()); | 132 ASSERT_TRUE(https_server.Start()); |
| 124 | 133 |
| 125 TestURLLoaderClient client; | 134 TestURLLoaderClient client; |
| 126 GURL url = https_server.GetURL("/simple_page.html"); | 135 GURL url = https_server.GetURL("/simple_page.html"); |
| 127 Load(url, &client, mojom::kURLLoadOptionSendSSLInfo); | 136 Load(url, &client, mojom::kURLLoadOptionSendSSLInfo); |
| 128 ASSERT_TRUE(!!client.ssl_info()); | 137 ASSERT_TRUE(!!client.ssl_info()); |
| 129 ASSERT_TRUE(!!client.ssl_info()->cert); | 138 ASSERT_TRUE(!!client.ssl_info()->cert); |
| 130 | 139 |
| 131 ASSERT_TRUE( | 140 ASSERT_TRUE( |
| 132 https_server.GetCertificate()->Equals(client.ssl_info()->cert.get())); | 141 https_server.GetCertificate()->Equals(client.ssl_info()->cert.get())); |
| 133 } | 142 } |
| 134 | 143 |
| 135 TEST_F(URLLoaderImplTest, SSLSentOnlyWhenRequested) { | 144 TEST_F(URLLoaderImplTest, SSLSentOnlyWhenRequested) { |
| 136 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 145 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 137 https_server.ServeFilesFromSourceDirectory( | 146 https_server.ServeFilesFromSourceDirectory( |
| 138 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 147 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 139 ASSERT_TRUE(https_server.Start()); | 148 ASSERT_TRUE(https_server.Start()); |
| 140 | 149 |
| 141 TestURLLoaderClient client; | 150 TestURLLoaderClient client; |
| 142 GURL url = https_server.GetURL("/simple_page.html"); | 151 GURL url = https_server.GetURL("/simple_page.html"); |
| 143 Load(url, &client, 0); | 152 Load(url, &client, 0); |
| 144 ASSERT_FALSE(!!client.ssl_info()); | 153 ASSERT_FALSE(!!client.ssl_info()); |
| 145 } | 154 } |
| 146 | 155 |
| 147 } // namespace content | 156 } // namespace content |
| OLD | NEW |