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

Side by Side Diff: content/network/url_loader_unittest.cc

Issue 2951813002: Make URLRequestContextBuilder use base/task_scheduler/ (Closed)
Patch Set: Merge Created 3 years, 5 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
OLDNEW
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
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_.AddDefaultHandlers( 76 test_server_.AddDefaultHandlers(
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 28 matching lines...) Expand all
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 void DestroyContext() { context_.reset(); } 118 void DestroyContext() { context_.reset(); }
116 119
117 private: 120 private:
118 base::MessageLoopForIO message_loop_; 121 base::test::ScopedTaskEnvironment scoped_task_environment_;
119 net::EmbeddedTestServer test_server_; 122 net::EmbeddedTestServer test_server_;
120 std::unique_ptr<NetworkContext> context_; 123 std::unique_ptr<NetworkContext> context_;
121 }; 124 };
122 125
123 TEST_F(URLLoaderImplTest, Basic) { 126 TEST_F(URLLoaderImplTest, Basic) {
124 LoadAndCompareFile("simple_page.html"); 127 LoadAndCompareFile("simple_page.html");
125 } 128 }
126 129
127 TEST_F(URLLoaderImplTest, Empty) { 130 TEST_F(URLLoaderImplTest, Empty) {
128 LoadAndCompareFile("empty.html"); 131 LoadAndCompareFile("empty.html");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // client receiving a connection error. 185 // client receiving a connection error.
183 DestroyContext(); 186 DestroyContext();
184 EXPECT_FALSE(loader_impl); 187 EXPECT_FALSE(loader_impl);
185 188
186 client.RunUntilConnectionError(); 189 client.RunUntilConnectionError();
187 EXPECT_FALSE(client.has_received_completion()); 190 EXPECT_FALSE(client.has_received_completion());
188 EXPECT_EQ(0u, client.download_data_length()); 191 EXPECT_EQ(0u, client.download_data_length());
189 } 192 }
190 193
191 } // namespace content 194 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | net/url_request/url_request_context_builder.h » ('j') | net/url_request/url_request_context_builder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698