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

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

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: review comment and clang fixes Created 3 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
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" 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 MOJO_RESULT_OK); 53 MOJO_RESULT_OK);
54 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); 54 CHECK_EQ(num_bytes, static_cast<uint32_t>(size));
55 55
56 return std::string(buffer.data(), buffer.size()); 56 return std::string(buffer.data(), buffer.size());
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 class URLLoaderImplTest : public testing::Test { 61 class URLLoaderImplTest : public testing::Test {
62 public: 62 public:
63 URLLoaderImplTest() {} 63 URLLoaderImplTest() : context_(NetworkContext::CreateForTesting()) {}
64 ~URLLoaderImplTest() override {} 64 ~URLLoaderImplTest() override {}
65 65
66 void SetUp() override { 66 void SetUp() override {
67 test_server_.ServeFilesFromSourceDirectory( 67 test_server_.ServeFilesFromSourceDirectory(
68 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 68 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
69 ASSERT_TRUE(test_server_.Start()); 69 ASSERT_TRUE(test_server_.Start());
70 } 70 }
71 71
72 void Load(const GURL& url, 72 void Load(const GURL& url,
73 TestURLLoaderClient* client, 73 TestURLLoaderClient* client,
(...skipping 23 matching lines...) Expand all
97 ADD_FAILURE() << "File not found: " << file.value(); 97 ADD_FAILURE() << "File not found: " << file.value();
98 return; 98 return;
99 } 99 }
100 100
101 std::string data = 101 std::string data =
102 ReadData(client.response_body().value(), file_contents.size()); 102 ReadData(client.response_body().value(), file_contents.size());
103 CHECK_EQ(data, file_contents); 103 CHECK_EQ(data, file_contents);
104 } 104 }
105 105
106 net::EmbeddedTestServer* test_server() { return &test_server_; } 106 net::EmbeddedTestServer* test_server() { return &test_server_; }
107 NetworkContext* context() { return &context_; } 107 NetworkContext* context() { return context_.get(); }
108 108
109 private: 109 private:
110 base::MessageLoopForIO message_loop_; 110 base::MessageLoopForIO message_loop_;
111 net::EmbeddedTestServer test_server_; 111 net::EmbeddedTestServer test_server_;
112 NetworkContext context_; 112 std::unique_ptr<NetworkContext> context_;
113 }; 113 };
114 114
115 TEST_F(URLLoaderImplTest, Basic) { 115 TEST_F(URLLoaderImplTest, Basic) {
116 LoadAndCompareFile("simple_page.html"); 116 LoadAndCompareFile("simple_page.html");
117 } 117 }
118 118
119 TEST_F(URLLoaderImplTest, BasicSSL) { 119 TEST_F(URLLoaderImplTest, BasicSSL) {
120 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); 120 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
121 https_server.ServeFilesFromSourceDirectory( 121 https_server.ServeFilesFromSourceDirectory(
122 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 122 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
(...skipping 15 matching lines...) Expand all
138 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 138 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
139 ASSERT_TRUE(https_server.Start()); 139 ASSERT_TRUE(https_server.Start());
140 140
141 TestURLLoaderClient client; 141 TestURLLoaderClient client;
142 GURL url = https_server.GetURL("/simple_page.html"); 142 GURL url = https_server.GetURL("/simple_page.html");
143 Load(url, &client, 0); 143 Load(url, &client, 0);
144 ASSERT_FALSE(!!client.ssl_info()); 144 ASSERT_FALSE(!!client.ssl_info());
145 } 145 }
146 146
147 } // namespace content 147 } // namespace content
OLDNEW
« no previous file with comments | « content/network/network_service_url_loader_factory_impl.cc ('k') | content/public/app/mojo/content_renderer_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698