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

Side by Side Diff: content/browser/loader/test_url_loader_client.h

Issue 2467833002: Implement redirect handling on MojoAsyncResourceHandler (Closed)
Patch Set: fix Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 5 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "content/common/resource_request_completion_status.h" 12 #include "content/common/resource_request_completion_status.h"
13 #include "content/common/url_loader.mojom.h" 13 #include "content/common/url_loader.mojom.h"
14 #include "content/common/url_loader_factory.mojom.h" 14 #include "content/common/url_loader_factory.mojom.h"
15 #include "content/public/common/resource_response.h" 15 #include "content/public/common/resource_response.h"
16 #include "mojo/public/c/system/data_pipe.h" 16 #include "mojo/public/c/system/data_pipe.h"
17 #include "mojo/public/cpp/bindings/associated_binding.h" 17 #include "mojo/public/cpp/bindings/associated_binding.h"
18 #include "net/url_request/redirect_info.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls 22 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls
22 // the closure set via set_quit_closure if set, in order to make it possible to 23 // the closure set via set_quit_closure if set, in order to make it possible to
23 // create a base::RunLoop, set its quit closure to this client and then run the 24 // create a base::RunLoop, set its quit closure to this client and then run the
24 // RunLoop. 25 // RunLoop.
25 class TestURLLoaderClient final : public mojom::URLLoaderClient { 26 class TestURLLoaderClient final : public mojom::URLLoaderClient {
26 public: 27 public:
27 TestURLLoaderClient(); 28 TestURLLoaderClient();
28 ~TestURLLoaderClient() override; 29 ~TestURLLoaderClient() override;
29 30
30 void OnReceiveResponse(const ResourceResponseHead& response_head) override; 31 void OnReceiveResponse(const ResourceResponseHead& response_head) override;
32 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
33 const ResourceResponseHead& response_head) override;
31 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; 34 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override;
32 void OnStartLoadingResponseBody( 35 void OnStartLoadingResponseBody(
33 mojo::ScopedDataPipeConsumerHandle body) override; 36 mojo::ScopedDataPipeConsumerHandle body) override;
34 void OnComplete(const ResourceRequestCompletionStatus& status) override; 37 void OnComplete(const ResourceRequestCompletionStatus& status) override;
35 38
36 bool has_received_response() const { return has_received_response_; } 39 bool has_received_response() const { return has_received_response_; }
40 bool has_received_redirect() const { return has_received_redirect_; }
mmenke 2016/11/10 21:42:41 Can we count the number of redirects or something,
yhirano 2016/11/11 09:47:04 I added EXPECT_FALSE(has_received_redirect_) in th
37 bool has_data_downloaded() const { return has_data_downloaded_; } 41 bool has_data_downloaded() const { return has_data_downloaded_; }
38 bool has_received_completion() const { return has_received_completion_; } 42 bool has_received_completion() const { return has_received_completion_; }
39 const ResourceResponseHead& response_head() const { return response_head_; } 43 const ResourceResponseHead& response_head() const { return response_head_; }
44 const net::RedirectInfo& redirect_info() const { return redirect_info_; }
40 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } 45 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); }
41 const ResourceRequestCompletionStatus& completion_status() const { 46 const ResourceRequestCompletionStatus& completion_status() const {
42 return completion_status_; 47 return completion_status_;
43 } 48 }
44 int64_t download_data_length() const { return download_data_length_; } 49 int64_t download_data_length() const { return download_data_length_; }
45 int64_t encoded_download_data_length() const { 50 int64_t encoded_download_data_length() const {
46 return encoded_download_data_length_; 51 return encoded_download_data_length_;
47 } 52 }
48 53
49 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The 54 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The
50 // returned PtrInfo is marked as remote, i.e., expected to be passed to the 55 // returned PtrInfo is marked as remote, i.e., expected to be passed to the
51 // remote endpoint. 56 // remote endpoint.
52 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo( 57 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo(
53 mojo::AssociatedGroup* associated_group); 58 mojo::AssociatedGroup* associated_group);
54 59
55 void Unbind(); 60 void Unbind();
56 61
57 void RunUntilResponseReceived(); 62 void RunUntilResponseReceived();
63 void RunUntilRedirectReceived();
58 void RunUntilDataDownloaded(); 64 void RunUntilDataDownloaded();
59 void RunUntilResponseBodyArrived(); 65 void RunUntilResponseBodyArrived();
60 void RunUntilComplete(); 66 void RunUntilComplete();
61 67
62 private: 68 private:
63 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; 69 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_;
64 ResourceResponseHead response_head_; 70 ResourceResponseHead response_head_;
71 net::RedirectInfo redirect_info_;
65 mojo::ScopedDataPipeConsumerHandle response_body_; 72 mojo::ScopedDataPipeConsumerHandle response_body_;
66 ResourceRequestCompletionStatus completion_status_; 73 ResourceRequestCompletionStatus completion_status_;
67 bool has_received_response_ = false; 74 bool has_received_response_ = false;
75 bool has_received_redirect_ = false;
68 bool has_data_downloaded_ = false; 76 bool has_data_downloaded_ = false;
69 bool has_received_completion_ = false; 77 bool has_received_completion_ = false;
70 base::Closure quit_closure_for_on_received_response_; 78 base::Closure quit_closure_for_on_receive_response_;
79 base::Closure quit_closure_for_on_receive_redirect_;
71 base::Closure quit_closure_for_on_data_downloaded_; 80 base::Closure quit_closure_for_on_data_downloaded_;
72 base::Closure quit_closure_for_on_start_loading_response_body_; 81 base::Closure quit_closure_for_on_start_loading_response_body_;
73 base::Closure quit_closure_for_on_complete_; 82 base::Closure quit_closure_for_on_complete_;
74 mojom::URLLoaderFactoryPtr url_loader_factory_; 83 mojom::URLLoaderFactoryPtr url_loader_factory_;
75 int64_t download_data_length_ = 0; 84 int64_t download_data_length_ = 0;
76 int64_t encoded_download_data_length_ = 0; 85 int64_t encoded_download_data_length_ = 0;
77 86
78 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); 87 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient);
79 }; 88 };
80 89
81 } // namespace content 90 } // namespace content
82 91
83 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ 92 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698