| 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" | |
| 7 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 8 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/test/scoped_task_environment.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" |
| 11 #include "content/network/network_context.h" | 11 #include "content/network/network_context.h" |
| 12 #include "content/network/url_loader_impl.h" | 12 #include "content/network/url_loader_impl.h" |
| 13 #include "content/public/common/content_paths.h" | 13 #include "content/public/common/content_paths.h" |
| 14 #include "mojo/public/c/system/data_pipe.h" | 14 #include "mojo/public/c/system/data_pipe.h" |
| 15 #include "mojo/public/cpp/system/wait.h" | 15 #include "mojo/public/cpp/system/wait.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 16 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 17 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 MOJO_RESULT_OK); | 59 MOJO_RESULT_OK); |
| 60 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); | 60 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); |
| 61 | 61 |
| 62 return std::string(buffer.data(), buffer.size()); | 62 return std::string(buffer.data(), buffer.size()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 class URLLoaderImplTest : public testing::Test { | 67 class URLLoaderImplTest : public testing::Test { |
| 68 public: | 68 public: |
| 69 URLLoaderImplTest() : context_(NetworkContext::CreateForTesting()) {} | 69 URLLoaderImplTest() |
| 70 : scoped_task_environment_( |
| 71 base::test::ScopedTaskEnvironment::MainThreadType::IO), |
| 72 context_(NetworkContext::CreateForTesting()) {} |
| 70 ~URLLoaderImplTest() override {} | 73 ~URLLoaderImplTest() override {} |
| 71 | 74 |
| 72 void SetUp() override { | 75 void SetUp() override { |
| 73 test_server_.ServeFilesFromSourceDirectory( | 76 test_server_.ServeFilesFromSourceDirectory( |
| 74 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 77 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 75 ASSERT_TRUE(test_server_.Start()); | 78 ASSERT_TRUE(test_server_.Start()); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void Load(const GURL& url, | 81 void Load(const GURL& url, |
| 79 TestURLLoaderClient* client, | 82 TestURLLoaderClient* client, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 107 | 110 |
| 108 std::string data = | 111 std::string data = |
| 109 ReadData(client.response_body().value(), file_contents.size()); | 112 ReadData(client.response_body().value(), file_contents.size()); |
| 110 CHECK_EQ(data, file_contents); | 113 CHECK_EQ(data, file_contents); |
| 111 } | 114 } |
| 112 | 115 |
| 113 net::EmbeddedTestServer* test_server() { return &test_server_; } | 116 net::EmbeddedTestServer* test_server() { return &test_server_; } |
| 114 NetworkContext* context() { return context_.get(); } | 117 NetworkContext* context() { return context_.get(); } |
| 115 | 118 |
| 116 private: | 119 private: |
| 117 base::MessageLoopForIO message_loop_; | 120 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 118 net::EmbeddedTestServer test_server_; | 121 net::EmbeddedTestServer test_server_; |
| 119 std::unique_ptr<NetworkContext> context_; | 122 std::unique_ptr<NetworkContext> context_; |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 TEST_F(URLLoaderImplTest, Basic) { | 125 TEST_F(URLLoaderImplTest, Basic) { |
| 123 LoadAndCompareFile("simple_page.html"); | 126 LoadAndCompareFile("simple_page.html"); |
| 124 } | 127 } |
| 125 | 128 |
| 126 TEST_F(URLLoaderImplTest, Empty) { | 129 TEST_F(URLLoaderImplTest, Empty) { |
| 127 LoadAndCompareFile("empty.html"); | 130 LoadAndCompareFile("empty.html"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 152 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 150 ASSERT_TRUE(https_server.Start()); | 153 ASSERT_TRUE(https_server.Start()); |
| 151 | 154 |
| 152 TestURLLoaderClient client; | 155 TestURLLoaderClient client; |
| 153 GURL url = https_server.GetURL("/simple_page.html"); | 156 GURL url = https_server.GetURL("/simple_page.html"); |
| 154 Load(url, &client, 0); | 157 Load(url, &client, 0); |
| 155 ASSERT_FALSE(!!client.ssl_info()); | 158 ASSERT_FALSE(!!client.ssl_info()); |
| 156 } | 159 } |
| 157 | 160 |
| 158 } // namespace content | 161 } // namespace content |
| OLD | NEW |