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

Side by Side Diff: content/child/web_url_loader_impl_unittest.cc

Issue 1910343006: Enable setting deferral state on ResourceDispatcher at request start (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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/child/web_url_loader_impl.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/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // but rather correct cleanup when deleted while parsing. Important details of 52 // but rather correct cleanup when deleted while parsing. Important details of
53 // this list are that it contains more than one entry that are not "." or "..". 53 // this list are that it contains more than one entry that are not "." or "..".
54 const char kFtpDirListing[] = 54 const char kFtpDirListing[] =
55 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 goat\n" 55 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 goat\n"
56 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 hat"; 56 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 hat";
57 57
58 class TestResourceDispatcher : public ResourceDispatcher { 58 class TestResourceDispatcher : public ResourceDispatcher {
59 public: 59 public:
60 TestResourceDispatcher() : 60 TestResourceDispatcher() :
61 ResourceDispatcher(nullptr, nullptr), 61 ResourceDispatcher(nullptr, nullptr),
62 canceled_(false) { 62 canceled_(false),
63 defers_loading_(false) {
63 } 64 }
64 65
65 ~TestResourceDispatcher() override {} 66 ~TestResourceDispatcher() override {}
66 67
67 // TestDispatcher implementation: 68 // TestDispatcher implementation:
68 69
69 int StartAsync(const RequestInfo& request_info, 70 int StartAsync(const RequestInfo& request_info,
70 ResourceRequestBody* request_body, 71 ResourceRequestBody* request_body,
71 std::unique_ptr<RequestPeer> peer) override { 72 std::unique_ptr<RequestPeer> peer) override {
72 EXPECT_FALSE(peer_); 73 EXPECT_FALSE(peer_);
73 peer_ = std::move(peer); 74 peer_ = std::move(peer);
74 url_ = request_info.url; 75 url_ = request_info.url;
75 stream_url_ = request_info.resource_body_stream_url; 76 stream_url_ = request_info.resource_body_stream_url;
76 return 1; 77 return 1;
77 } 78 }
78 79
79 void Cancel(int request_id) override { 80 void Cancel(int request_id) override {
80 EXPECT_FALSE(canceled_); 81 EXPECT_FALSE(canceled_);
81 canceled_ = true; 82 canceled_ = true;
82 } 83 }
83 84
84 RequestPeer* peer() { return peer_.get(); } 85 RequestPeer* peer() { return peer_.get(); }
85 86
86 bool canceled() { return canceled_; } 87 bool canceled() { return canceled_; }
87 88
88 const GURL& url() { return url_; } 89 const GURL& url() { return url_; }
89 const GURL& stream_url() { return stream_url_; } 90 const GURL& stream_url() { return stream_url_; }
90 91
92 void SetDefersLoading(int request_id, bool value) override {
93 defers_loading_ = value;
94 }
95 bool defers_loading() const { return defers_loading_; }
96
91 private: 97 private:
92 std::unique_ptr<RequestPeer> peer_; 98 std::unique_ptr<RequestPeer> peer_;
93 bool canceled_; 99 bool canceled_;
100 bool defers_loading_;
94 GURL url_; 101 GURL url_;
95 GURL stream_url_; 102 GURL stream_url_;
96 103
97 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); 104 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher);
98 }; 105 };
99 106
100 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { 107 class TestWebURLLoaderClient : public blink::WebURLLoaderClient {
101 public: 108 public:
102 TestWebURLLoaderClient(ResourceDispatcher* dispatcher, 109 TestWebURLLoaderClient(ResourceDispatcher* dispatcher,
103 scoped_refptr<scheduler::TaskQueue> task_runner) 110 scoped_refptr<scheduler::TaskQueue> task_runner)
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 client()->loader()->setDefersLoading(false); 500 client()->loader()->setDefersLoading(false);
494 client()->loader()->setDefersLoading(false); 501 client()->loader()->setDefersLoading(false);
495 message_loop()->RunUntilIdle(); 502 message_loop()->RunUntilIdle();
496 EXPECT_TRUE(client()->did_finish()); 503 EXPECT_TRUE(client()->did_finish());
497 504
498 EXPECT_EQ("blah!", client()->received_data()); 505 EXPECT_EQ("blah!", client()->received_data());
499 EXPECT_EQ(net::OK, client()->error().reason); 506 EXPECT_EQ(net::OK, client()->error().reason);
500 EXPECT_EQ("", client()->error().domain.utf8()); 507 EXPECT_EQ("", client()->error().domain.utf8());
501 } 508 }
502 509
510 TEST_F(WebURLLoaderImplTest, DefersLoadingBeforeStart) {
511 client()->loader()->setDefersLoading(true);
512 EXPECT_FALSE(dispatcher()->defers_loading());
513 DoStartAsyncRequest();
514 EXPECT_TRUE(dispatcher()->defers_loading());
515 }
516
503 // FTP integration tests. These are focused more on safe deletion than correct 517 // FTP integration tests. These are focused more on safe deletion than correct
504 // parsing of FTP responses. 518 // parsing of FTP responses.
505 519
506 TEST_F(WebURLLoaderImplTest, Ftp) { 520 TEST_F(WebURLLoaderImplTest, Ftp) {
507 DoStartAsyncRequest(); 521 DoStartAsyncRequest();
508 DoReceiveResponseFtp(); 522 DoReceiveResponseFtp();
509 DoReceiveDataFtp(); 523 DoReceiveDataFtp();
510 DoCompleteRequest(); 524 DoCompleteRequest();
511 EXPECT_FALSE(dispatcher()->canceled()); 525 EXPECT_FALSE(dispatcher()->canceled());
512 } 526 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 info.socket_address = net::HostPortPair(test.ip, 443); 636 info.socket_address = net::HostPortPair(test.ip, 443);
623 blink::WebURLResponse response; 637 blink::WebURLResponse response;
624 response.initialize(); 638 response.initialize();
625 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); 639 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true);
626 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); 640 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8());
627 }; 641 };
628 } 642 }
629 643
630 } // namespace 644 } // namespace
631 } // namespace content 645 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_url_loader_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698