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

Side by Side Diff: content/renderer/resource_fetcher_browsertest.cc

Issue 1873783003: Convert //content/renderer from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « content/renderer/renderer_main_platform_delegate_win.cc ('k') | content/renderer/sad_plugin.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/renderer/resource_fetcher.h" 5 #include "content/public/renderer/resource_fetcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 FetcherDelegate::OnURLFetchComplete(response, data); 117 FetcherDelegate::OnURLFetchComplete(response, data);
118 118
119 // Destroy the ResourceFetcher here. We are testing that upon returning 119 // Destroy the ResourceFetcher here. We are testing that upon returning
120 // to the ResourceFetcher that it does not crash. This must be done after 120 // to the ResourceFetcher that it does not crash. This must be done after
121 // calling FetcherDelegate::OnURLFetchComplete, since deleting the fetcher 121 // calling FetcherDelegate::OnURLFetchComplete, since deleting the fetcher
122 // invalidates |response| and |data|. 122 // invalidates |response| and |data|.
123 fetcher_.reset(); 123 fetcher_.reset();
124 } 124 }
125 125
126 private: 126 private:
127 scoped_ptr<ResourceFetcher> fetcher_; 127 std::unique_ptr<ResourceFetcher> fetcher_;
128 }; 128 };
129 129
130 class ResourceFetcherTests : public ContentBrowserTest { 130 class ResourceFetcherTests : public ContentBrowserTest {
131 public: 131 public:
132 ResourceFetcherTests() : render_view_routing_id_(MSG_ROUTING_NONE) {} 132 ResourceFetcherTests() : render_view_routing_id_(MSG_ROUTING_NONE) {}
133 133
134 void SetUpCommandLine(base::CommandLine* command_line) override { 134 void SetUpCommandLine(base::CommandLine* command_line) override {
135 command_line->AppendSwitch(switches::kSingleProcess); 135 command_line->AppendSwitch(switches::kSingleProcess);
136 #if defined(OS_WIN) 136 #if defined(OS_WIN)
137 // Don't want to try to create a GPU process. 137 // Don't want to try to create a GPU process.
138 command_line->AppendSwitch(switches::kDisableGpu); 138 command_line->AppendSwitch(switches::kDisableGpu);
139 #endif 139 #endif
140 } 140 }
141 141
142 void SetUpOnMainThread() override { 142 void SetUpOnMainThread() override {
143 render_view_routing_id_ = 143 render_view_routing_id_ =
144 shell()->web_contents()->GetRenderViewHost()->GetRoutingID(); 144 shell()->web_contents()->GetRenderViewHost()->GetRoutingID();
145 } 145 }
146 146
147 RenderView* GetRenderView() { 147 RenderView* GetRenderView() {
148 return RenderView::FromRoutingID(render_view_routing_id_); 148 return RenderView::FromRoutingID(render_view_routing_id_);
149 } 149 }
150 150
151 void ResourceFetcherDownloadOnRenderer(const GURL& url) { 151 void ResourceFetcherDownloadOnRenderer(const GURL& url) {
152 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 152 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
153 153
154 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 154 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
155 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 155 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
156 fetcher->Start(frame, 156 fetcher->Start(frame,
157 WebURLRequest::RequestContextInternal, 157 WebURLRequest::RequestContextInternal,
158 WebURLRequest::FrameTypeNone, 158 WebURLRequest::FrameTypeNone,
159 ResourceFetcher::PLATFORM_LOADER, 159 ResourceFetcher::PLATFORM_LOADER,
160 delegate->NewCallback()); 160 delegate->NewCallback());
161 161
162 delegate->WaitForResponse(); 162 delegate->WaitForResponse();
163 163
164 ASSERT_TRUE(delegate->completed()); 164 ASSERT_TRUE(delegate->completed());
165 EXPECT_EQ(delegate->response().httpStatusCode(), 200); 165 EXPECT_EQ(delegate->response().httpStatusCode(), 200);
166 std::string text = delegate->data(); 166 std::string text = delegate->data();
167 EXPECT_TRUE(text.find("Basic html test.") != std::string::npos); 167 EXPECT_TRUE(text.find("Basic html test.") != std::string::npos);
168 } 168 }
169 169
170 void ResourceFetcher404OnRenderer(const GURL& url) { 170 void ResourceFetcher404OnRenderer(const GURL& url) {
171 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 171 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
172 172
173 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 173 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
174 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 174 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
175 fetcher->Start(frame, 175 fetcher->Start(frame,
176 WebURLRequest::RequestContextInternal, 176 WebURLRequest::RequestContextInternal,
177 WebURLRequest::FrameTypeNone, 177 WebURLRequest::FrameTypeNone,
178 ResourceFetcher::PLATFORM_LOADER, 178 ResourceFetcher::PLATFORM_LOADER,
179 delegate->NewCallback()); 179 delegate->NewCallback());
180 180
181 delegate->WaitForResponse(); 181 delegate->WaitForResponse();
182 182
183 ASSERT_TRUE(delegate->completed()); 183 ASSERT_TRUE(delegate->completed());
184 EXPECT_EQ(delegate->response().httpStatusCode(), 404); 184 EXPECT_EQ(delegate->response().httpStatusCode(), 404);
185 } 185 }
186 186
187 void ResourceFetcherDidFailOnRenderer() { 187 void ResourceFetcherDidFailOnRenderer() {
188 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 188 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
189 189
190 // Try to fetch a page on a site that doesn't exist. 190 // Try to fetch a page on a site that doesn't exist.
191 GURL url("http://localhost:1339/doesnotexist"); 191 GURL url("http://localhost:1339/doesnotexist");
192 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 192 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
193 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 193 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
194 fetcher->Start(frame, 194 fetcher->Start(frame,
195 WebURLRequest::RequestContextInternal, 195 WebURLRequest::RequestContextInternal,
196 WebURLRequest::FrameTypeNone, 196 WebURLRequest::FrameTypeNone,
197 ResourceFetcher::PLATFORM_LOADER, 197 ResourceFetcher::PLATFORM_LOADER,
198 delegate->NewCallback()); 198 delegate->NewCallback());
199 199
200 delegate->WaitForResponse(); 200 delegate->WaitForResponse();
201 201
202 // When we fail, we still call the Delegate callback but we pass in empty 202 // When we fail, we still call the Delegate callback but we pass in empty
203 // values. 203 // values.
204 EXPECT_TRUE(delegate->completed()); 204 EXPECT_TRUE(delegate->completed());
205 EXPECT_TRUE(delegate->response().isNull()); 205 EXPECT_TRUE(delegate->response().isNull());
206 EXPECT_EQ(delegate->data(), std::string()); 206 EXPECT_EQ(delegate->data(), std::string());
207 EXPECT_FALSE(delegate->timed_out()); 207 EXPECT_FALSE(delegate->timed_out());
208 } 208 }
209 209
210 void ResourceFetcherTimeoutOnRenderer(const GURL& url) { 210 void ResourceFetcherTimeoutOnRenderer(const GURL& url) {
211 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 211 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
212 212
213 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 213 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
214 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 214 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
215 fetcher->Start(frame, 215 fetcher->Start(frame,
216 WebURLRequest::RequestContextInternal, 216 WebURLRequest::RequestContextInternal,
217 WebURLRequest::FrameTypeNone, 217 WebURLRequest::FrameTypeNone,
218 ResourceFetcher::PLATFORM_LOADER, 218 ResourceFetcher::PLATFORM_LOADER,
219 delegate->NewCallback()); 219 delegate->NewCallback());
220 fetcher->SetTimeout(base::TimeDelta()); 220 fetcher->SetTimeout(base::TimeDelta());
221 221
222 delegate->WaitForResponse(); 222 delegate->WaitForResponse();
223 223
224 // When we timeout, we still call the Delegate callback but we pass in empty 224 // When we timeout, we still call the Delegate callback but we pass in empty
225 // values. 225 // values.
226 EXPECT_TRUE(delegate->completed()); 226 EXPECT_TRUE(delegate->completed());
227 EXPECT_TRUE(delegate->response().isNull()); 227 EXPECT_TRUE(delegate->response().isNull());
228 EXPECT_EQ(delegate->data(), std::string()); 228 EXPECT_EQ(delegate->data(), std::string());
229 EXPECT_FALSE(delegate->timed_out()); 229 EXPECT_FALSE(delegate->timed_out());
230 } 230 }
231 231
232 void ResourceFetcherDeletedInCallbackOnRenderer(const GURL& url) { 232 void ResourceFetcherDeletedInCallbackOnRenderer(const GURL& url) {
233 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 233 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
234 234
235 scoped_ptr<EvilFetcherDelegate> delegate(new EvilFetcherDelegate); 235 std::unique_ptr<EvilFetcherDelegate> delegate(new EvilFetcherDelegate);
236 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 236 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
237 fetcher->Start(frame, 237 fetcher->Start(frame,
238 WebURLRequest::RequestContextInternal, 238 WebURLRequest::RequestContextInternal,
239 WebURLRequest::FrameTypeNone, 239 WebURLRequest::FrameTypeNone,
240 ResourceFetcher::PLATFORM_LOADER, 240 ResourceFetcher::PLATFORM_LOADER,
241 delegate->NewCallback()); 241 delegate->NewCallback());
242 fetcher->SetTimeout(base::TimeDelta()); 242 fetcher->SetTimeout(base::TimeDelta());
243 delegate->SetFetcher(fetcher.release()); 243 delegate->SetFetcher(fetcher.release());
244 244
245 delegate->WaitForResponse(); 245 delegate->WaitForResponse();
246 EXPECT_FALSE(delegate->timed_out()); 246 EXPECT_FALSE(delegate->timed_out());
247 } 247 }
248 248
249 void ResourceFetcherPost(const GURL& url) { 249 void ResourceFetcherPost(const GURL& url) {
250 const char* kBody = "Really nifty POST body!"; 250 const char* kBody = "Really nifty POST body!";
251 251
252 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 252 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
253 253
254 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 254 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
255 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 255 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
256 fetcher->SetMethod("POST"); 256 fetcher->SetMethod("POST");
257 fetcher->SetBody(kBody); 257 fetcher->SetBody(kBody);
258 fetcher->Start(frame, 258 fetcher->Start(frame,
259 WebURLRequest::RequestContextInternal, 259 WebURLRequest::RequestContextInternal,
260 WebURLRequest::FrameTypeNone, 260 WebURLRequest::FrameTypeNone,
261 ResourceFetcher::PLATFORM_LOADER, 261 ResourceFetcher::PLATFORM_LOADER,
262 delegate->NewCallback()); 262 delegate->NewCallback());
263 263
264 delegate->WaitForResponse(); 264 delegate->WaitForResponse();
265 ASSERT_TRUE(delegate->completed()); 265 ASSERT_TRUE(delegate->completed());
266 EXPECT_EQ(delegate->response().httpStatusCode(), 200); 266 EXPECT_EQ(delegate->response().httpStatusCode(), 200);
267 EXPECT_EQ(kBody, delegate->data()); 267 EXPECT_EQ(kBody, delegate->data());
268 } 268 }
269 269
270 void ResourceFetcherSetHeader(const GURL& url) { 270 void ResourceFetcherSetHeader(const GURL& url) {
271 const char* kHeader = "Rather boring header."; 271 const char* kHeader = "Rather boring header.";
272 272
273 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame(); 273 WebFrame* frame = GetRenderView()->GetWebView()->mainFrame();
274 274
275 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 275 std::unique_ptr<FetcherDelegate> delegate(new FetcherDelegate);
276 scoped_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url)); 276 std::unique_ptr<ResourceFetcher> fetcher(ResourceFetcher::Create(url));
277 fetcher->SetHeader("header", kHeader); 277 fetcher->SetHeader("header", kHeader);
278 fetcher->Start(frame, 278 fetcher->Start(frame,
279 WebURLRequest::RequestContextInternal, 279 WebURLRequest::RequestContextInternal,
280 WebURLRequest::FrameTypeNone, 280 WebURLRequest::FrameTypeNone,
281 ResourceFetcher::PLATFORM_LOADER, 281 ResourceFetcher::PLATFORM_LOADER,
282 delegate->NewCallback()); 282 delegate->NewCallback());
283 283
284 delegate->WaitForResponse(); 284 delegate->WaitForResponse();
285 ASSERT_TRUE(delegate->completed()); 285 ASSERT_TRUE(delegate->completed());
286 EXPECT_EQ(delegate->response().httpStatusCode(), 200); 286 EXPECT_EQ(delegate->response().httpStatusCode(), 200);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 ASSERT_TRUE(embedded_test_server()->Start()); 382 ASSERT_TRUE(embedded_test_server()->Start());
383 GURL url(embedded_test_server()->GetURL("/echoheader?header")); 383 GURL url(embedded_test_server()->GetURL("/echoheader?header"));
384 384
385 PostTaskToInProcessRendererAndWait( 385 PostTaskToInProcessRendererAndWait(
386 base::Bind( 386 base::Bind(
387 &ResourceFetcherTests::ResourceFetcherSetHeader, 387 &ResourceFetcherTests::ResourceFetcherSetHeader,
388 base::Unretained(this), url)); 388 base::Unretained(this), url));
389 } 389 }
390 390
391 } // namespace content 391 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/renderer_main_platform_delegate_win.cc ('k') | content/renderer/sad_plugin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698