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

Side by Side Diff: content/browser/loader/mime_sniffing_resource_handler_unittest.cc

Issue 2366753002: Have MimeSniffingResourceHandler call WillStartRequest on new Handlers. (Closed)
Patch Set: Fix Created 4 years, 2 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/browser/loader/mime_sniffing_resource_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/loader/mime_sniffing_resource_handler.h" 5 #include "content/browser/loader/mime_sniffing_resource_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 namespace content { 31 namespace content {
32 32
33 namespace { 33 namespace {
34 34
35 class TestResourceHandler : public ResourceHandler { 35 class TestResourceHandler : public ResourceHandler {
36 public: 36 public:
37 TestResourceHandler(bool response_started_succeeds, 37 // TODO(mmenke): This constructor is a bit crazy. Switch to taking a bitfield
38 // instead, or maybe use setters?
39 TestResourceHandler(bool will_start_succeeds,
40 bool defer_on_will_start,
41 bool response_started_succeeds,
38 bool defer_on_response_started, 42 bool defer_on_response_started,
39 bool will_read_succeeds, 43 bool will_read_succeeds,
40 bool read_completed_succeeds, 44 bool read_completed_succeeds,
41 bool defer_on_read_completed) 45 bool defer_on_read_completed)
42 : ResourceHandler(nullptr), 46 : ResourceHandler(nullptr),
43 buffer_(new net::IOBuffer(2048)), 47 buffer_(new net::IOBuffer(2048)),
48 will_start_succeeds_(will_start_succeeds),
49 defer_on_will_start_(defer_on_will_start),
44 response_started_succeeds_(response_started_succeeds), 50 response_started_succeeds_(response_started_succeeds),
45 defer_on_response_started_(defer_on_response_started), 51 defer_on_response_started_(defer_on_response_started),
46 will_read_succeeds_(will_read_succeeds), 52 will_read_succeeds_(will_read_succeeds),
47 read_completed_succeeds_(read_completed_succeeds), 53 read_completed_succeeds_(read_completed_succeeds),
48 defer_on_read_completed_(defer_on_read_completed), 54 defer_on_read_completed_(defer_on_read_completed),
49 on_will_start_called_(0), 55 on_will_start_called_(0),
50 on_request_redirected_called_(0), 56 on_request_redirected_called_(0),
51 on_response_started_called_(0), 57 on_response_started_called_(0),
52 on_will_read_called_(0), 58 on_will_read_called_(0),
53 on_read_completed_called_(0) {} 59 on_read_completed_called_(0) {}
54 60
55 void SetController(ResourceController* controller) override {}
56
57 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 61 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
58 ResourceResponse* response, 62 ResourceResponse* response,
59 bool* defer) override { 63 bool* defer) override {
60 on_request_redirected_called_++; 64 on_request_redirected_called_++;
61 NOTREACHED(); 65 NOTREACHED();
62 return false; 66 return false;
63 } 67 }
64 68
65 bool OnResponseStarted(ResourceResponse* response, bool* defer) override { 69 bool OnResponseStarted(ResourceResponse* response, bool* defer) override {
70 EXPECT_TRUE(on_will_start_called_);
71
66 on_response_started_called_++; 72 on_response_started_called_++;
67 if (defer_on_response_started_) 73 if (defer_on_response_started_)
68 *defer = true; 74 *defer = true;
69 return response_started_succeeds_; 75 return response_started_succeeds_;
70 } 76 }
71 77
72 bool OnWillStart(const GURL& url, bool* defer) override { 78 bool OnWillStart(const GURL& url, bool* defer) override {
73 on_will_start_called_++; 79 on_will_start_called_++;
74 return false; 80
81 *defer = defer_on_will_start_;
82 return will_start_succeeds_;
75 } 83 }
76 84
77 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 85 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
78 int* buf_size, 86 int* buf_size,
79 int min_size) override { 87 int min_size) override {
80 on_will_read_called_++; 88 on_will_read_called_++;
81 *buf = buffer_; 89 *buf = buffer_;
82 *buf_size = 2048; 90 *buf_size = 2048;
83 return will_read_succeeds_; 91 return will_read_succeeds_;
84 } 92 }
85 93
86 bool OnReadCompleted(int bytes_read, bool* defer) override { 94 bool OnReadCompleted(int bytes_read, bool* defer) override {
95 EXPECT_TRUE(on_will_start_called_);
96 EXPECT_TRUE(on_response_started_called_);
97
87 DCHECK_LT(bytes_read, 2048); 98 DCHECK_LT(bytes_read, 2048);
88 on_read_completed_called_++; 99 on_read_completed_called_++;
89 if (defer_on_read_completed_) 100 if (defer_on_read_completed_)
90 *defer = true; 101 *defer = true;
91 return read_completed_succeeds_; 102 return read_completed_succeeds_;
92 } 103 }
93 104
94 void OnResponseCompleted(const net::URLRequestStatus& status, 105 void OnResponseCompleted(const net::URLRequestStatus& status,
95 bool* defer) override {} 106 bool* defer) override {
107 // If the request succeeded, OnWillRead and OnResponseStarted must have been
108 // called.
109 if (status.is_success()) {
110 EXPECT_TRUE(on_will_start_called_);
111 EXPECT_TRUE(on_response_started_called_);
112 }
113 }
96 114
97 void OnDataDownloaded(int bytes_downloaded) override { NOTREACHED(); } 115 void OnDataDownloaded(int bytes_downloaded) override { NOTREACHED(); }
98 116
117 // Give text fixture access to ResourceController, for resuming.
118 using ResourceHandler::controller;
119
99 scoped_refptr<net::IOBuffer> buffer() { return buffer_; } 120 scoped_refptr<net::IOBuffer> buffer() { return buffer_; }
100 121
101 int on_will_start_called() const { return on_will_start_called_; } 122 int on_will_start_called() const { return on_will_start_called_; }
102 int on_request_redirected_called() const { 123 int on_request_redirected_called() const {
103 return on_request_redirected_called_; 124 return on_request_redirected_called_;
104 } 125 }
105 int on_response_started_called() const { return on_response_started_called_; } 126 int on_response_started_called() const { return on_response_started_called_; }
106 int on_will_read_called() const { return on_will_read_called_; } 127 int on_will_read_called() const { return on_will_read_called_; }
107 int on_read_completed_called() const { return on_read_completed_called_; } 128 int on_read_completed_called() const { return on_read_completed_called_; }
108 129
109 private: 130 private:
110 scoped_refptr<net::IOBuffer> buffer_; 131 scoped_refptr<net::IOBuffer> buffer_;
132
133 bool will_start_succeeds_;
134 bool defer_on_will_start_;
111 bool response_started_succeeds_; 135 bool response_started_succeeds_;
112 bool defer_on_response_started_; 136 bool defer_on_response_started_;
113 bool will_read_succeeds_; 137 bool will_read_succeeds_;
114 bool read_completed_succeeds_; 138 bool read_completed_succeeds_;
115 bool defer_on_read_completed_; 139 bool defer_on_read_completed_;
116 140
117 int on_will_start_called_; 141 int on_will_start_called_;
118 int on_request_redirected_called_; 142 int on_request_redirected_called_;
119 int on_response_started_called_; 143 int on_response_started_called_;
120 int on_will_read_called_; 144 int on_will_read_called_;
(...skipping 14 matching lines...) Expand all
135 } 159 }
136 160
137 private: 161 private:
138 const bool must_download_; 162 const bool must_download_;
139 }; 163 };
140 164
141 class TestResourceDispatcherHost : public ResourceDispatcherHostImpl { 165 class TestResourceDispatcherHost : public ResourceDispatcherHostImpl {
142 public: 166 public:
143 explicit TestResourceDispatcherHost(bool stream_has_handler) 167 explicit TestResourceDispatcherHost(bool stream_has_handler)
144 : stream_has_handler_(stream_has_handler), 168 : stream_has_handler_(stream_has_handler),
169 new_handler_will_start_succeeds_(true),
170 new_handler_defer_on_will_start_(false),
145 intercepted_as_stream_(false), 171 intercepted_as_stream_(false),
146 intercepted_as_stream_count_(0), 172 intercepted_as_stream_count_(0),
147 new_resource_handler_(nullptr) {} 173 new_resource_handler_(nullptr) {}
148 174
149 bool intercepted_as_stream() const { return intercepted_as_stream_; } 175 bool intercepted_as_stream() const { return intercepted_as_stream_; }
150 176
151 std::unique_ptr<ResourceHandler> CreateResourceHandlerForDownload( 177 std::unique_ptr<ResourceHandler> CreateResourceHandlerForDownload(
152 net::URLRequest* request, 178 net::URLRequest* request,
153 bool is_content_initiated, 179 bool is_content_initiated,
154 bool must_download) override { 180 bool must_download) override {
155 return CreateNewResourceHandler(); 181 return CreateNewResourceHandler();
156 } 182 }
157 183
158 std::unique_ptr<ResourceHandler> MaybeInterceptAsStream( 184 std::unique_ptr<ResourceHandler> MaybeInterceptAsStream(
159 const base::FilePath& plugin_path, 185 const base::FilePath& plugin_path,
160 net::URLRequest* request, 186 net::URLRequest* request,
161 ResourceResponse* response, 187 ResourceResponse* response,
162 std::string* payload) override { 188 std::string* payload) override {
163 intercepted_as_stream_count_++; 189 intercepted_as_stream_count_++;
164 if (stream_has_handler_) 190 if (stream_has_handler_)
165 intercepted_as_stream_ = true; 191 intercepted_as_stream_ = true;
166 return CreateNewResourceHandler(); 192 return CreateNewResourceHandler();
167 } 193 }
168 194
195 void set_new_handler_will_start_succeeds(
196 bool new_handler_will_start_succeeds) {
197 new_handler_will_start_succeeds_ = new_handler_will_start_succeeds;
198 }
199
200 void set_new_handler_defer_on_will_start(
201 bool new_handler_defer_on_will_start) {
202 new_handler_defer_on_will_start_ = new_handler_defer_on_will_start;
203 }
204
169 int intercepted_as_stream_count() const { 205 int intercepted_as_stream_count() const {
170 return intercepted_as_stream_count_; 206 return intercepted_as_stream_count_;
171 } 207 }
172 208
173 TestResourceHandler* new_resource_handler() const { 209 TestResourceHandler* new_resource_handler() const {
174 return new_resource_handler_; 210 return new_resource_handler_;
175 } 211 }
176 212
177 private: 213 private:
178 std::unique_ptr<ResourceHandler> CreateNewResourceHandler() { 214 std::unique_ptr<ResourceHandler> CreateNewResourceHandler() {
179 std::unique_ptr<TestResourceHandler> new_resource_handler( 215 std::unique_ptr<TestResourceHandler> new_resource_handler(
180 new TestResourceHandler(false, false, true, true, false)); 216 new TestResourceHandler(
217 new_handler_will_start_succeeds_, new_handler_defer_on_will_start_,
218 false /* response_started_succeeds */,
219 false /* defer_on_response_started */,
220 true /* will_read_succeeds */, true /* read_completed_succeeds */,
221 false /* defer_on_read_completed */));
181 new_resource_handler_ = new_resource_handler.get(); 222 new_resource_handler_ = new_resource_handler.get();
182 return std::move(new_resource_handler); 223 return std::move(new_resource_handler);
183 } 224 }
184 225
185 // Whether the URL request should be intercepted as a stream. 226 // Whether the URL request should be intercepted as a stream.
186 bool stream_has_handler_; 227 bool stream_has_handler_;
187 228
229 // Behavior of the OnWillStart method of any created ResourceHandlers.
230 bool new_handler_will_start_succeeds_;
231 bool new_handler_defer_on_will_start_;
232
188 // Whether the URL request has been intercepted as a stream. 233 // Whether the URL request has been intercepted as a stream.
189 bool intercepted_as_stream_; 234 bool intercepted_as_stream_;
190 235
191 // Count of number of times MaybeInterceptAsStream function get called in a 236 // Count of number of times MaybeInterceptAsStream function get called in a
192 // test. 237 // test.
193 int intercepted_as_stream_count_; 238 int intercepted_as_stream_count_;
194 239
195 // The last alternative TestResourceHandler created by this 240 // The last alternative TestResourceHandler created by this
196 // TestResourceDispatcherHost. 241 // TestResourceDispatcherHost.
197 TestResourceHandler* new_resource_handler_; 242 TestResourceHandler* new_resource_handler_;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 324 }
280 325
281 void set_plugin_available(bool plugin_available) { 326 void set_plugin_available(bool plugin_available) {
282 plugin_available_ = plugin_available; 327 plugin_available_ = plugin_available;
283 } 328 }
284 329
285 void set_plugin_stale(bool plugin_stale) { plugin_stale_ = plugin_stale; } 330 void set_plugin_stale(bool plugin_stale) { plugin_stale_ = plugin_stale; }
286 331
287 bool TestStreamIsIntercepted(bool allow_download, 332 bool TestStreamIsIntercepted(bool allow_download,
288 bool must_download, 333 bool must_download,
289 ResourceType request_resource_type); 334 ResourceType request_resource_type,
335 bool new_handler_will_start_succeeds,
336 bool new_handler_defer_on_will_start);
290 337
291 // Tests the operation of the MimeSniffingHandler when it needs to buffer 338 // Tests the operation of the MimeSniffingHandler when it needs to buffer
292 // data (example case: the response is text/plain). 339 // data (example case: the response is text/plain).
293 void TestHandlerSniffing(bool response_started, 340 void TestHandlerSniffing(bool response_started,
294 bool defer_response_started, 341 bool defer_response_started,
295 bool will_read, 342 bool will_read,
296 bool read_completed, 343 bool read_completed,
297 bool defer_read_completed); 344 bool defer_read_completed);
298 345
299 // Tests the operation of the MimeSniffingHandler when it doesn't buffer 346 // Tests the operation of the MimeSniffingHandler when it doesn't buffer
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 0, // render_view_id 380 0, // render_view_id
334 0, // render_frame_id 381 0, // render_frame_id
335 is_main_frame, // is_main_frame 382 is_main_frame, // is_main_frame
336 false, // parent_is_main_frame 383 false, // parent_is_main_frame
337 false, // allow_download 384 false, // allow_download
338 true, // is_async 385 true, // is_async
339 false); // is_using_lofi 386 false); // is_using_lofi
340 387
341 std::unique_ptr<ResourceHandler> mime_sniffing_handler( 388 std::unique_ptr<ResourceHandler> mime_sniffing_handler(
342 new MimeSniffingResourceHandler( 389 new MimeSniffingResourceHandler(
343 std::unique_ptr<ResourceHandler>( 390 std::unique_ptr<ResourceHandler>(new TestResourceHandler(
344 new TestResourceHandler(false, false, false, false, false)), 391 true, false, false, false, false, false, false)),
345 nullptr, nullptr, nullptr, request, 392 nullptr, nullptr, nullptr, request,
346 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); 393 REQUEST_CONTEXT_TYPE_UNSPECIFIED));
347 394
348 bool defer = false; 395 bool defer = false;
349 mime_sniffing_handler->OnWillStart(request->url(), &defer); 396 mime_sniffing_handler->OnWillStart(request->url(), &defer);
350 content::RunAllPendingInMessageLoop(); 397 content::RunAllPendingInMessageLoop();
351 398
352 std::string accept_header; 399 std::string accept_header;
353 request->extra_request_headers().GetHeader("Accept", &accept_header); 400 request->extra_request_headers().GetHeader("Accept", &accept_header);
354 return accept_header; 401 return accept_header;
355 } 402 }
356 403
357 bool MimeSniffingResourceHandlerTest::TestStreamIsIntercepted( 404 bool MimeSniffingResourceHandlerTest::TestStreamIsIntercepted(
358 bool allow_download, 405 bool allow_download,
359 bool must_download, 406 bool must_download,
360 ResourceType request_resource_type) { 407 ResourceType request_resource_type,
408 bool new_handler_will_start_succeeds,
409 bool new_handler_defer_on_will_start) {
361 net::URLRequestContext context; 410 net::URLRequestContext context;
362 std::unique_ptr<net::URLRequest> request(context.CreateRequest( 411 std::unique_ptr<net::URLRequest> request(context.CreateRequest(
363 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, nullptr)); 412 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, nullptr));
364 bool is_main_frame = request_resource_type == RESOURCE_TYPE_MAIN_FRAME; 413 bool is_main_frame = request_resource_type == RESOURCE_TYPE_MAIN_FRAME;
365 ResourceRequestInfo::AllocateForTesting(request.get(), request_resource_type, 414 ResourceRequestInfo::AllocateForTesting(request.get(), request_resource_type,
366 nullptr, // context 415 nullptr, // context
367 0, // render_process_id 416 0, // render_process_id
368 0, // render_view_id 417 0, // render_view_id
369 0, // render_frame_id 418 0, // render_frame_id
370 is_main_frame, // is_main_frame 419 is_main_frame, // is_main_frame
371 false, // parent_is_main_frame 420 false, // parent_is_main_frame
372 allow_download, // allow_download 421 allow_download, // allow_download
373 true, // is_async 422 true, // is_async
374 false); // is_using_lofi 423 false); // is_using_lofi
375 424
376 TestResourceDispatcherHost host(stream_has_handler_); 425 TestResourceDispatcherHost host(stream_has_handler_);
426 host.set_new_handler_will_start_succeeds(new_handler_will_start_succeeds);
427 host.set_new_handler_defer_on_will_start(new_handler_defer_on_will_start);
428
377 TestResourceDispatcherHostDelegate host_delegate(must_download); 429 TestResourceDispatcherHostDelegate host_delegate(must_download);
378 host.SetDelegate(&host_delegate); 430 host.SetDelegate(&host_delegate);
379 431
380 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); 432 TestFakePluginService plugin_service(plugin_available_, plugin_stale_);
381 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 433 InterceptingResourceHandler* intercepting_handler =
382 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), 434 new InterceptingResourceHandler(
383 nullptr)); 435 base::MakeUnique<TestResourceHandler>(true, false, false, false, true,
384 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( 436 false, false),
385 std::unique_ptr<ResourceHandler>( 437 nullptr);
386 new TestResourceHandler(false, false, false, false, false)), 438 std::unique_ptr<MimeSniffingResourceHandler> mime_handler(
387 &host, &plugin_service, intercepting_handler.get(), request.get(), 439 new MimeSniffingResourceHandler(base::WrapUnique(intercepting_handler),
388 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); 440 &host, &plugin_service,
441 intercepting_handler, request.get(),
442 REQUEST_CONTEXT_TYPE_UNSPECIFIED));
389 443
390 TestResourceController resource_controller; 444 TestResourceController resource_controller;
391 mime_handler->SetController(&resource_controller); 445 mime_handler->SetController(&resource_controller);
392 446
393 scoped_refptr<ResourceResponse> response(new ResourceResponse); 447 scoped_refptr<ResourceResponse> response(new ResourceResponse);
394 // The MIME type isn't important but it shouldn't be empty. 448 // The MIME type isn't important but it shouldn't be empty.
395 response->head.mime_type = "application/pdf"; 449 response->head.mime_type = "application/pdf";
396 450
397 bool defer = false; 451 bool defer = false;
398 mime_handler->OnResponseStarted(response.get(), &defer); 452 EXPECT_TRUE(mime_handler->OnWillStart(request->url(), &defer));
453 EXPECT_FALSE(defer);
454 bool result = mime_handler->OnResponseStarted(response.get(), &defer);
455
456 // Exit early if the new ResourceHandler should have failed in OnWillStart.
457 if (!new_handler_will_start_succeeds) {
458 EXPECT_FALSE(result);
459 EXPECT_TRUE(host.new_resource_handler()->on_will_start_called());
460 EXPECT_FALSE(host.new_resource_handler()->on_response_started_called());
461 return host.intercepted_as_stream();
462 }
463
464 // If the new ResourceHandler's OnWillStart method should have deferred the
465 // request, check state and resume it.
466 if (new_handler_defer_on_will_start) {
467 EXPECT_TRUE(defer);
468 EXPECT_TRUE(result);
469 EXPECT_TRUE(host.new_resource_handler()->on_will_start_called());
470 EXPECT_FALSE(host.new_resource_handler()->on_response_started_called());
471 host.new_resource_handler()->controller()->Resume();
472 }
399 473
400 content::RunAllPendingInMessageLoop(); 474 content::RunAllPendingInMessageLoop();
401 EXPECT_LT(host.intercepted_as_stream_count(), 2); 475 EXPECT_LT(host.intercepted_as_stream_count(), 2);
476
402 if (allow_download) 477 if (allow_download)
403 EXPECT_TRUE(intercepting_handler->new_handler_for_testing()); 478 EXPECT_TRUE(host.new_resource_handler());
479
480 // If a new resource handler was created, make sure it was successfully
481 // swapped in, and its OnWillStart and OnResponseStarted methods were called.
482 if (host.new_resource_handler()) {
483 EXPECT_EQ(host.new_resource_handler(),
484 intercepting_handler->next_handler_for_testing());
485 EXPECT_TRUE(host.new_resource_handler()->on_will_start_called());
486 EXPECT_TRUE(host.new_resource_handler()->on_response_started_called());
487 }
488
404 return host.intercepted_as_stream(); 489 return host.intercepted_as_stream();
405 } 490 }
406 491
407 void MimeSniffingResourceHandlerTest::TestHandlerSniffing( 492 void MimeSniffingResourceHandlerTest::TestHandlerSniffing(
408 bool response_started, 493 bool response_started,
409 bool defer_response_started, 494 bool defer_response_started,
410 bool will_read, 495 bool will_read,
411 bool read_completed, 496 bool read_completed,
412 bool defer_read_completed) { 497 bool defer_read_completed) {
413 net::URLRequestContext context; 498 net::URLRequestContext context;
(...skipping 14 matching lines...) Expand all
428 TestResourceDispatcherHost host(false); 513 TestResourceDispatcherHost host(false);
429 TestResourceDispatcherHostDelegate host_delegate(false); 514 TestResourceDispatcherHostDelegate host_delegate(false);
430 host.SetDelegate(&host_delegate); 515 host.SetDelegate(&host_delegate);
431 516
432 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); 517 TestFakePluginService plugin_service(plugin_available_, plugin_stale_);
433 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 518 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
434 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), 519 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(),
435 nullptr)); 520 nullptr));
436 std::unique_ptr<TestResourceHandler> scoped_test_handler = 521 std::unique_ptr<TestResourceHandler> scoped_test_handler =
437 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( 522 std::unique_ptr<TestResourceHandler>(new TestResourceHandler(
438 response_started, defer_response_started, will_read, read_completed, 523 true, false, response_started, defer_response_started, will_read,
439 defer_read_completed)); 524 read_completed, defer_read_completed));
440 TestResourceHandler* test_handler = scoped_test_handler.get(); 525 TestResourceHandler* test_handler = scoped_test_handler.get();
441 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( 526 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler(
442 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, 527 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host,
443 &plugin_service, 528 &plugin_service,
444 intercepting_handler.get(), request.get(), 529 intercepting_handler.get(), request.get(),
445 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); 530 REQUEST_CONTEXT_TYPE_UNSPECIFIED));
446 531
447 TestResourceController resource_controller; 532 TestResourceController resource_controller;
448 mime_sniffing_handler->SetController(&resource_controller); 533 mime_sniffing_handler->SetController(&resource_controller);
449 534
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 content::RunAllPendingInMessageLoop(); 592 content::RunAllPendingInMessageLoop();
508 return; 593 return;
509 } 594 }
510 595
511 // The replay can be deferred both at response started and read replay 596 // The replay can be deferred both at response started and read replay
512 // stages. 597 // stages.
513 EXPECT_EQ(defer, defer_response_started || defer_read_completed); 598 EXPECT_EQ(defer, defer_response_started || defer_read_completed);
514 if (defer_response_started) { 599 if (defer_response_started) {
515 EXPECT_TRUE(defer); 600 EXPECT_TRUE(defer);
516 EXPECT_TRUE(return_value); 601 EXPECT_TRUE(return_value);
517 EXPECT_EQ(MimeSniffingResourceHandler::STATE_REPLAYING_RESPONSE_RECEIVED, 602 EXPECT_EQ(MimeSniffingResourceHandler::STATE_REPLAYING_RECEIVED_RESPONSE,
518 mime_sniffing_handler->state_); 603 mime_sniffing_handler->state_);
519 mime_sniffing_handler->Resume(); 604 mime_sniffing_handler->Resume();
520 } 605 }
521 606
522 // The body that was sniffed should be transmitted to the next handler. This 607 // The body that was sniffed should be transmitted to the next handler. This
523 // may cancel the request. 608 // may cancel the request.
524 if (!read_completed) { 609 if (!read_completed) {
525 if (defer_response_started) { 610 if (defer_response_started) {
526 EXPECT_EQ(1, resource_controller.cancel_call_count()); 611 EXPECT_EQ(1, resource_controller.cancel_call_count());
527 } else { 612 } else {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 TestResourceDispatcherHostDelegate host_delegate(false); 675 TestResourceDispatcherHostDelegate host_delegate(false);
591 host.SetDelegate(&host_delegate); 676 host.SetDelegate(&host_delegate);
592 677
593 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); 678 TestFakePluginService plugin_service(plugin_available_, plugin_stale_);
594 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 679 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
595 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), 680 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(),
596 nullptr)); 681 nullptr));
597 682
598 std::unique_ptr<TestResourceHandler> scoped_test_handler = 683 std::unique_ptr<TestResourceHandler> scoped_test_handler =
599 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( 684 std::unique_ptr<TestResourceHandler>(new TestResourceHandler(
600 response_started, defer_response_started, will_read, read_completed, 685 true, false, response_started, defer_response_started, will_read,
601 defer_read_completed)); 686 read_completed, defer_read_completed));
602 TestResourceHandler* test_handler = scoped_test_handler.get(); 687 TestResourceHandler* test_handler = scoped_test_handler.get();
603 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( 688 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler(
604 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, 689 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host,
605 &plugin_service, 690 &plugin_service,
606 intercepting_handler.get(), request.get(), 691 intercepting_handler.get(), request.get(),
607 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); 692 REQUEST_CONTEXT_TYPE_UNSPECIFIED));
608 693
609 TestResourceController resource_controller; 694 TestResourceController resource_controller;
610 mime_sniffing_handler->SetController(&resource_controller); 695 mime_sniffing_handler->SetController(&resource_controller);
611 696
(...skipping 21 matching lines...) Expand all
633 EXPECT_EQ(0, test_handler->on_will_read_called()); 718 EXPECT_EQ(0, test_handler->on_will_read_called());
634 EXPECT_EQ(0, test_handler->on_read_completed_called()); 719 EXPECT_EQ(0, test_handler->on_read_completed_called());
635 720
636 // Process all messages to ensure proper test teardown. 721 // Process all messages to ensure proper test teardown.
637 content::RunAllPendingInMessageLoop(); 722 content::RunAllPendingInMessageLoop();
638 return; 723 return;
639 } 724 }
640 725
641 EXPECT_EQ(defer_response_started, defer); 726 EXPECT_EQ(defer_response_started, defer);
642 if (defer) { 727 if (defer) {
643 EXPECT_EQ(MimeSniffingResourceHandler::STATE_REPLAYING_RESPONSE_RECEIVED, 728 EXPECT_EQ(MimeSniffingResourceHandler::STATE_REPLAYING_RECEIVED_RESPONSE,
644 mime_sniffing_handler->state_); 729 mime_sniffing_handler->state_);
645 expected_resume_calls++; 730 expected_resume_calls++;
646 mime_sniffing_handler->Resume(); 731 mime_sniffing_handler->Resume();
647 } 732 }
648 733
649 EXPECT_EQ(expected_resume_calls, resource_controller.resume_call_count()); 734 EXPECT_EQ(expected_resume_calls, resource_controller.resume_call_count());
650 735
651 // The MimeSniffingResourceHandler should be acting as a pass-through 736 // The MimeSniffingResourceHandler should be acting as a pass-through
652 // ResourceHandler. 737 // ResourceHandler.
653 scoped_refptr<net::IOBuffer> read_buffer; 738 scoped_refptr<net::IOBuffer> read_buffer;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 request.get())); 822 request.get()));
738 } 823 }
739 824
740 // Test that stream requests are correctly intercepted under the right 825 // Test that stream requests are correctly intercepted under the right
741 // circumstances. Test is not relevent when plugins are disabled. 826 // circumstances. Test is not relevent when plugins are disabled.
742 #if defined(ENABLE_PLUGINS) 827 #if defined(ENABLE_PLUGINS)
743 TEST_F(MimeSniffingResourceHandlerTest, StreamHandling) { 828 TEST_F(MimeSniffingResourceHandlerTest, StreamHandling) {
744 bool allow_download; 829 bool allow_download;
745 bool must_download; 830 bool must_download;
746 ResourceType resource_type; 831 ResourceType resource_type;
832 bool new_handler_will_start_succeeds;
833 bool new_handler_defer_on_will_start;
747 834
748 // Ensure the stream is handled by MaybeInterceptAsStream in the 835 // Ensure the stream is handled by MaybeInterceptAsStream in the
749 // ResourceDispatcherHost. 836 // ResourceDispatcherHost.
750 set_stream_has_handler(true); 837 set_stream_has_handler(true);
751 set_plugin_available(true); 838 set_plugin_available(true);
752 839
753 // Main frame request with no download allowed. Stream shouldn't be 840 // Main frame request with no download allowed. Stream shouldn't be
754 // intercepted. 841 // intercepted.
755 allow_download = false; 842 allow_download = false;
756 must_download = false; 843 must_download = false;
757 resource_type = RESOURCE_TYPE_MAIN_FRAME; 844 resource_type = RESOURCE_TYPE_MAIN_FRAME;
758 EXPECT_FALSE( 845 new_handler_will_start_succeeds = true;
759 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 846 new_handler_defer_on_will_start = false;
847 EXPECT_FALSE(TestStreamIsIntercepted(
848 false /* allow_download */, false /* must_download */,
849 RESOURCE_TYPE_MAIN_FRAME, true /* new_handler_will_start_succeeds */,
850 false /* new_handler_defer_on_will_start */));
760 851
761 // Main frame request with download allowed. Stream should be intercepted. 852 // Main frame request with download allowed. Stream should be intercepted.
762 allow_download = true; 853 allow_download = true;
763 must_download = false; 854 must_download = false;
764 resource_type = RESOURCE_TYPE_MAIN_FRAME; 855 resource_type = RESOURCE_TYPE_MAIN_FRAME;
765 EXPECT_TRUE( 856 new_handler_will_start_succeeds = true;
766 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 857 new_handler_defer_on_will_start = false;
858 EXPECT_TRUE(TestStreamIsIntercepted(
859 allow_download, must_download, resource_type,
860 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
861
862 // Main frame request with download allowed, but OnWillStart for the new
863 // handler succeeds asynchronously. Stream should be intercepted.
864 allow_download = true;
865 must_download = false;
866 resource_type = RESOURCE_TYPE_MAIN_FRAME;
867 new_handler_will_start_succeeds = true;
868 new_handler_defer_on_will_start = true;
869 EXPECT_TRUE(TestStreamIsIntercepted(
870 allow_download, must_download, resource_type,
871 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
872
873 // Main frame request with download allowed, but OnWillStart of new handler
874 // fails.
875 allow_download = true;
876 must_download = false;
877 resource_type = RESOURCE_TYPE_MAIN_FRAME;
878 new_handler_will_start_succeeds = false;
879 new_handler_defer_on_will_start = false;
880 EXPECT_TRUE(TestStreamIsIntercepted(
881 allow_download, must_download, resource_type,
882 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
767 883
768 // Main frame request with download forced. Stream shouldn't be intercepted. 884 // Main frame request with download forced. Stream shouldn't be intercepted.
769 allow_download = true; 885 allow_download = true;
770 must_download = true; 886 must_download = true;
771 resource_type = RESOURCE_TYPE_MAIN_FRAME; 887 resource_type = RESOURCE_TYPE_MAIN_FRAME;
772 EXPECT_FALSE( 888 new_handler_will_start_succeeds = true;
773 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 889 new_handler_defer_on_will_start = false;
890 EXPECT_FALSE(TestStreamIsIntercepted(
891 allow_download, must_download, resource_type,
892 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
774 893
775 // Sub-resource request with download not allowed. Stream shouldn't be 894 // Sub-resource request with download not allowed. Stream shouldn't be
776 // intercepted. 895 // intercepted.
777 allow_download = false; 896 allow_download = false;
778 must_download = false; 897 must_download = false;
779 resource_type = RESOURCE_TYPE_SUB_RESOURCE; 898 resource_type = RESOURCE_TYPE_SUB_RESOURCE;
780 EXPECT_FALSE( 899 new_handler_will_start_succeeds = true;
781 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 900 new_handler_defer_on_will_start = false;
901 EXPECT_FALSE(TestStreamIsIntercepted(
902 allow_download, must_download, resource_type,
903 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
782 904
783 // Plugin resource request with download not allowed. Stream shouldn't be 905 // Plugin resource request with download not allowed. Stream shouldn't be
784 // intercepted. 906 // intercepted.
785 allow_download = false; 907 allow_download = false;
786 must_download = false; 908 must_download = false;
787 resource_type = RESOURCE_TYPE_PLUGIN_RESOURCE; 909 resource_type = RESOURCE_TYPE_PLUGIN_RESOURCE;
788 EXPECT_FALSE( 910 new_handler_will_start_succeeds = true;
789 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 911 new_handler_defer_on_will_start = false;
912 EXPECT_FALSE(TestStreamIsIntercepted(
913 allow_download, must_download, resource_type,
914 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
790 915
791 // Object request with download not allowed. Stream should be intercepted. 916 // Object request with download not allowed. Stream should be intercepted.
792 allow_download = false; 917 allow_download = false;
793 must_download = false; 918 must_download = false;
794 resource_type = RESOURCE_TYPE_OBJECT; 919 resource_type = RESOURCE_TYPE_OBJECT;
795 EXPECT_TRUE( 920 new_handler_will_start_succeeds = true;
796 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 921 new_handler_defer_on_will_start = false;
922 EXPECT_TRUE(TestStreamIsIntercepted(
923 allow_download, must_download, resource_type,
924 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
797 925
798 // Test the cases where the stream isn't handled by MaybeInterceptAsStream 926 // Test the cases where the stream isn't handled by MaybeInterceptAsStream
799 // in the ResourceDispatcherHost. 927 // in the ResourceDispatcherHost.
800 set_stream_has_handler(false); 928 set_stream_has_handler(false);
801 allow_download = false; 929 allow_download = false;
802 must_download = false; 930 must_download = false;
803 resource_type = RESOURCE_TYPE_OBJECT; 931 resource_type = RESOURCE_TYPE_OBJECT;
804 EXPECT_FALSE( 932 new_handler_will_start_succeeds = true;
805 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 933 new_handler_defer_on_will_start = false;
934 EXPECT_FALSE(TestStreamIsIntercepted(
935 allow_download, must_download, resource_type,
936 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
806 937
807 // Test the cases where the stream handled by MaybeInterceptAsStream 938 // Test the cases where the stream handled by MaybeInterceptAsStream
808 // with plugin not available. This is the case when intercepting streams for 939 // with plugin not available. This is the case when intercepting streams for
809 // the streamsPrivate extensions API. 940 // the streamsPrivate extensions API.
810 set_stream_has_handler(true); 941 set_stream_has_handler(true);
811 set_plugin_available(false); 942 set_plugin_available(false);
812 allow_download = false; 943 allow_download = false;
813 must_download = false; 944 must_download = false;
814 resource_type = RESOURCE_TYPE_OBJECT; 945 resource_type = RESOURCE_TYPE_OBJECT;
815 EXPECT_TRUE( 946 new_handler_will_start_succeeds = true;
816 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 947 new_handler_defer_on_will_start = false;
948 EXPECT_TRUE(TestStreamIsIntercepted(
949 allow_download, must_download, resource_type,
950 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
817 951
818 // Test the cases where the stream handled by MaybeInterceptAsStream 952 // Test the cases where the stream handled by MaybeInterceptAsStream
819 // with plugin not available. This is the case when intercepting streams for 953 // with plugin not available. This is the case when intercepting streams for
820 // the streamsPrivate extensions API with stale plugin. 954 // the streamsPrivate extensions API with stale plugin.
821 set_plugin_stale(true); 955 set_plugin_stale(true);
822 allow_download = false; 956 allow_download = false;
823 must_download = false; 957 must_download = false;
824 resource_type = RESOURCE_TYPE_OBJECT; 958 resource_type = RESOURCE_TYPE_OBJECT;
825 EXPECT_TRUE( 959 new_handler_will_start_succeeds = true;
826 TestStreamIsIntercepted(allow_download, must_download, resource_type)); 960 new_handler_defer_on_will_start = false;
961 EXPECT_TRUE(TestStreamIsIntercepted(
962 allow_download, must_download, resource_type,
963 new_handler_will_start_succeeds, new_handler_defer_on_will_start));
827 } 964 }
828 #endif 965 #endif
829 966
830 // Test that the MimeSniffingHandler operates properly when it doesn't sniff 967 // Test that the MimeSniffingHandler operates properly when it doesn't sniff
831 // resources. 968 // resources.
832 TEST_F(MimeSniffingResourceHandlerTest, NoSniffing) { 969 TEST_F(MimeSniffingResourceHandlerTest, NoSniffing) {
833 // Test simple case. 970 // Test simple case.
834 TestHandlerNoSniffing( 971 TestHandlerNoSniffing(
835 true /* response_started_succeeds */, 972 true /* response_started_succeeds */,
836 false /* defer_response_started */, 973 false /* defer_response_started */,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 TestResourceDispatcherHost host(false); 1120 TestResourceDispatcherHost host(false);
984 TestResourceDispatcherHostDelegate host_delegate(false); 1121 TestResourceDispatcherHostDelegate host_delegate(false);
985 host.SetDelegate(&host_delegate); 1122 host.SetDelegate(&host_delegate);
986 1123
987 TestFakePluginService plugin_service(false, false); 1124 TestFakePluginService plugin_service(false, false);
988 std::unique_ptr<ResourceHandler> intercepting_handler( 1125 std::unique_ptr<ResourceHandler> intercepting_handler(
989 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), 1126 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(),
990 nullptr)); 1127 nullptr));
991 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( 1128 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler(
992 std::unique_ptr<ResourceHandler>( 1129 std::unique_ptr<ResourceHandler>(
993 new TestResourceHandler(true, false, true, true, false)), 1130 new TestResourceHandler(true, false, true, false, true, true, false)),
994 &host, &plugin_service, 1131 &host, &plugin_service,
995 static_cast<InterceptingResourceHandler*>(intercepting_handler.get()), 1132 static_cast<InterceptingResourceHandler*>(intercepting_handler.get()),
996 request.get(), REQUEST_CONTEXT_TYPE_UNSPECIFIED)); 1133 request.get(), REQUEST_CONTEXT_TYPE_UNSPECIFIED));
997 1134
998 TestResourceController resource_controller; 1135 TestResourceController resource_controller;
999 mime_handler->SetController(&resource_controller); 1136 mime_handler->SetController(&resource_controller);
1000 1137
1001 // Simulate a 304 response. 1138 // Simulate a 304 response.
1002 scoped_refptr<ResourceResponse> response(new ResourceResponse); 1139 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1003 // The MIME type isn't important but it shouldn't be empty. 1140 // The MIME type isn't important but it shouldn't be empty.
1004 response->head.mime_type = "application/pdf"; 1141 response->head.mime_type = "application/pdf";
1005 response->head.headers = new net::HttpResponseHeaders("HTTP/1.x 304 OK"); 1142 response->head.headers = new net::HttpResponseHeaders("HTTP/1.x 304 OK");
1006 1143
1007 // The response is received. No new ResourceHandler should be created to 1144 // The response is received. No new ResourceHandler should be created to
1008 // handle the download. 1145 // handle the download.
1009 bool defer = false; 1146 bool defer = false;
1010 mime_handler->OnResponseStarted(response.get(), &defer); 1147 ASSERT_TRUE(mime_handler->OnWillStart(request->url(), &defer));
1148 ASSERT_FALSE(defer);
1149
1150 ASSERT_TRUE(mime_handler->OnResponseStarted(response.get(), &defer));
1011 EXPECT_FALSE(defer); 1151 EXPECT_FALSE(defer);
1012 EXPECT_FALSE(host.new_resource_handler()); 1152 EXPECT_FALSE(host.new_resource_handler());
1013 1153
1014 content::RunAllPendingInMessageLoop(); 1154 content::RunAllPendingInMessageLoop();
1015 } 1155 }
1016 1156
1017 TEST_F(MimeSniffingResourceHandlerTest, FetchShouldDisableMimeSniffing) { 1157 TEST_F(MimeSniffingResourceHandlerTest, FetchShouldDisableMimeSniffing) {
1018 net::URLRequestContext context; 1158 net::URLRequestContext context;
1019 std::unique_ptr<net::URLRequest> request(context.CreateRequest( 1159 std::unique_ptr<net::URLRequest> request(context.CreateRequest(
1020 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, nullptr)); 1160 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, nullptr));
1021 ResourceRequestInfo::AllocateForTesting(request.get(), 1161 ResourceRequestInfo::AllocateForTesting(request.get(),
1022 RESOURCE_TYPE_MAIN_FRAME, 1162 RESOURCE_TYPE_MAIN_FRAME,
1023 nullptr, // context 1163 nullptr, // context
1024 0, // render_process_id 1164 0, // render_process_id
1025 0, // render_view_id 1165 0, // render_view_id
1026 0, // render_frame_id 1166 0, // render_frame_id
1027 true, // is_main_frame 1167 true, // is_main_frame
1028 false, // parent_is_main_frame 1168 false, // parent_is_main_frame
1029 false, // allow_download 1169 false, // allow_download
1030 true, // is_async 1170 true, // is_async
1031 false); // is_using_lofi 1171 false); // is_using_lofi
1032 1172
1033 TestResourceDispatcherHost host(false); 1173 TestResourceDispatcherHost host(false);
1034 1174
1035 TestFakePluginService plugin_service(false, false); 1175 TestFakePluginService plugin_service(false, false);
1036 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( 1176 std::unique_ptr<InterceptingResourceHandler> intercepting_handler(
1037 new InterceptingResourceHandler(nullptr, nullptr)); 1177 new InterceptingResourceHandler(nullptr, nullptr));
1038 1178
1039 std::unique_ptr<TestResourceHandler> scoped_test_handler( 1179 std::unique_ptr<TestResourceHandler> scoped_test_handler(
1040 new TestResourceHandler(false, // response_started 1180 new TestResourceHandler(true, // will_start_succeeds
1041 false, // defer_response_started 1181 false, // defer_on_will_start
1042 true, // will_read, 1182 false, // response_started_succeeds
1043 true, // read_completed, 1183 false, // defer_on_response_started
1184 true, // will_read_succeeds
1185 true, // read_completed_succeeds
1044 false)); // defer_read_completed 1186 false)); // defer_read_completed
1045 std::unique_ptr<ResourceHandler> mime_sniffing_handler( 1187 std::unique_ptr<ResourceHandler> mime_sniffing_handler(
1046 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, 1188 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host,
1047 &plugin_service, 1189 &plugin_service,
1048 intercepting_handler.get(), request.get(), 1190 intercepting_handler.get(), request.get(),
1049 REQUEST_CONTEXT_TYPE_FETCH)); 1191 REQUEST_CONTEXT_TYPE_FETCH));
1050 1192
1051 TestResourceController resource_controller; 1193 TestResourceController resource_controller;
1052 mime_sniffing_handler->SetController(&resource_controller); 1194 mime_sniffing_handler->SetController(&resource_controller);
1053 1195
1054 bool defer = false; 1196 bool defer = false;
1055 mime_sniffing_handler->OnWillStart(GURL(), &defer); 1197 mime_sniffing_handler->OnWillStart(GURL(), &defer);
1056 ASSERT_FALSE(defer); 1198 ASSERT_FALSE(defer);
1057 1199
1058 scoped_refptr<ResourceResponse> response(new ResourceResponse); 1200 scoped_refptr<ResourceResponse> response(new ResourceResponse);
1059 response->head.mime_type = "text/plain"; 1201 response->head.mime_type = "text/plain";
1060 1202
1061 // |mime_sniffing_handler->OnResponseStarted| should return false because 1203 // |mime_sniffing_handler->OnResponseStarted| should return false because
1062 // mime sniffing is disabled and the wrapped resource handler returns false 1204 // mime sniffing is disabled and the wrapped resource handler returns false
1063 // on OnResponseStarted. 1205 // on OnResponseStarted.
1064 EXPECT_FALSE( 1206 EXPECT_FALSE(
1065 mime_sniffing_handler->OnResponseStarted(response.get(), &defer)); 1207 mime_sniffing_handler->OnResponseStarted(response.get(), &defer));
1066 1208
1067 // Process all messages to ensure proper test teardown. 1209 // Process all messages to ensure proper test teardown.
1068 content::RunAllPendingInMessageLoop(); 1210 content::RunAllPendingInMessageLoop();
1069 } 1211 }
1070 1212
1071 } // namespace content 1213 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/mime_sniffing_resource_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698