| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 void SetUp() override { | 72 void SetUp() override { |
| 73 test_server_.AddDefaultHandlers( | 73 test_server_.AddDefaultHandlers( |
| 74 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 74 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 75 ASSERT_TRUE(test_server_.Start()); | 75 ASSERT_TRUE(test_server_.Start()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void Load(const GURL& url, | 78 void Load(const GURL& url, |
| 79 TestURLLoaderClient* client, | 79 TestURLLoaderClient* client, |
| 80 uint32_t options = 0) { | 80 uint32_t options = 0) { |
| 81 mojom::URLLoaderAssociatedPtr loader; | 81 mojom::URLLoaderPtr loader; |
| 82 | 82 |
| 83 ResourceRequest request = | 83 ResourceRequest request = |
| 84 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, url); | 84 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, url); |
| 85 | 85 |
| 86 URLLoaderImpl loader_impl(context(), mojo::MakeIsolatedRequest(&loader), | 86 URLLoaderImpl loader_impl(context(), mojo::MakeRequest(&loader), options, |
| 87 options, request, client->CreateInterfacePtr(), | 87 request, client->CreateInterfacePtr(), |
| 88 TRAFFIC_ANNOTATION_FOR_TESTS); | 88 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 89 | 89 |
| 90 client->RunUntilComplete(); | 90 client->RunUntilComplete(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void LoadAndCompareFile(const std::string& path) { | 93 void LoadAndCompareFile(const std::string& path) { |
| 94 TestURLLoaderClient client; | 94 TestURLLoaderClient client; |
| 95 GURL url = test_server()->GetURL(std::string("/") + path); | 95 GURL url = test_server()->GetURL(std::string("/") + path); |
| 96 Load(url, &client); | 96 Load(url, &client); |
| 97 | 97 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 Load(url, &client, 0); | 155 Load(url, &client, 0); |
| 156 ASSERT_FALSE(!!client.ssl_info()); | 156 ASSERT_FALSE(!!client.ssl_info()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 TEST_F(URLLoaderImplTest, DestroyContextWithLiveRequest) { | 159 TEST_F(URLLoaderImplTest, DestroyContextWithLiveRequest) { |
| 160 TestURLLoaderClient client; | 160 TestURLLoaderClient client; |
| 161 GURL url = test_server()->GetURL("/hung-after-headers"); | 161 GURL url = test_server()->GetURL("/hung-after-headers"); |
| 162 ResourceRequest request = | 162 ResourceRequest request = |
| 163 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, url); | 163 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, url); |
| 164 | 164 |
| 165 mojom::URLLoaderAssociatedPtr loader; | 165 mojom::URLLoaderPtr loader; |
| 166 // The loader is implicitly owned by the client and the NetworkContext, so | 166 // The loader is implicitly owned by the client and the NetworkContext, so |
| 167 // don't hold on to a pointer to it. | 167 // don't hold on to a pointer to it. |
| 168 base::WeakPtr<URLLoaderImpl> loader_impl = | 168 base::WeakPtr<URLLoaderImpl> loader_impl = |
| 169 (new URLLoaderImpl(context(), mojo::MakeIsolatedRequest(&loader), 0, | 169 (new URLLoaderImpl(context(), mojo::MakeRequest(&loader), 0, request, |
| 170 request, client.CreateInterfacePtr(), | 170 client.CreateInterfacePtr(), |
| 171 TRAFFIC_ANNOTATION_FOR_TESTS)) | 171 TRAFFIC_ANNOTATION_FOR_TESTS)) |
| 172 ->GetWeakPtrForTests(); | 172 ->GetWeakPtrForTests(); |
| 173 | 173 |
| 174 client.RunUntilResponseReceived(); | 174 client.RunUntilResponseReceived(); |
| 175 EXPECT_TRUE(client.has_received_response()); | 175 EXPECT_TRUE(client.has_received_response()); |
| 176 EXPECT_FALSE(client.has_received_completion()); | 176 EXPECT_FALSE(client.has_received_completion()); |
| 177 | 177 |
| 178 // Request hasn't completed, so the loader should not have been destroyed. | 178 // Request hasn't completed, so the loader should not have been destroyed. |
| 179 EXPECT_TRUE(loader_impl); | 179 EXPECT_TRUE(loader_impl); |
| 180 | 180 |
| 181 // Destroying the context should result in destroying the loader and the | 181 // Destroying the context should result in destroying the loader and the |
| 182 // client receiving a connection error. | 182 // client receiving a connection error. |
| 183 DestroyContext(); | 183 DestroyContext(); |
| 184 EXPECT_FALSE(loader_impl); | 184 EXPECT_FALSE(loader_impl); |
| 185 | 185 |
| 186 client.RunUntilConnectionError(); | 186 client.RunUntilConnectionError(); |
| 187 EXPECT_FALSE(client.has_received_completion()); | 187 EXPECT_FALSE(client.has_received_completion()); |
| 188 EXPECT_EQ(0u, client.download_data_length()); | 188 EXPECT_EQ(0u, client.download_data_length()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace content | 191 } // namespace content |
| OLD | NEW |