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

Side by Side Diff: content/public/test/navigation_simulator.h

Issue 2698393002: Allow asynchronous deferral in NavigationSimulator (Closed)
Patch Set: Remove the wait API Created 3 years, 9 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 #ifndef CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ 5 #ifndef CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_
6 #define CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ 6 #define CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h"
11 #include "base/optional.h"
12 #include "content/public/browser/navigation_throttle.h"
10 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/common/referrer.h" 14 #include "content/public/common/referrer.h"
12 #include "content/public/test/navigation_simulator.h" 15 #include "content/public/test/navigation_simulator.h"
13 #include "ui/base/page_transition_types.h" 16 #include "ui/base/page_transition_types.h"
14 17
15 class GURL; 18 class GURL;
16 19
17 namespace content { 20 namespace content {
18 21
19 class NavigationHandleImpl; 22 class NavigationHandleImpl;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // for (GURL redirect_url : redirects) 81 // for (GURL redirect_url : redirects)
79 // simulator->Redirect(redirect_url); 82 // simulator->Redirect(redirect_url);
80 // simulator->Fail(net::ERR_TIMED_OUT); 83 // simulator->Fail(net::ERR_TIMED_OUT);
81 // simulator->CommitErrorPage(); 84 // simulator->CommitErrorPage();
82 // 85 //
83 // Example of usage for a same-page renderer-initiated navigation: 86 // Example of usage for a same-page renderer-initiated navigation:
84 // unique_ptr<NavigationSimulator> simulator = 87 // unique_ptr<NavigationSimulator> simulator =
85 // NavigationSimulator::CreateRendererInitiated( 88 // NavigationSimulator::CreateRendererInitiated(
86 // original_url, render_frame_host); 89 // original_url, render_frame_host);
87 // simulator->CommitSamePage(); 90 // simulator->CommitSamePage();
91 //
92 // Example of usage for a renderer-initiated navigation which is cancelled by
93 // a throttle upon redirecting. Note that registering the throttle is done
94 // elsewhere:
95 // unique_ptr<NavigationSimulator> simulator =
96 // NavigationSimulator::CreateRendererInitiated(
97 // original_url, render_frame_host);
98 // simulator->SetTransition(ui::PAGE_TRANSITION_LINK);
99 // simulator->Start();
100 // simulator->Redirect(redirect_url);
101 // EXPECT_EQ(NavigationThrottle::CANCEL,
102 // simulator->GetLastThrottleCheckResult());
88 103
89 // Simulates the start of the navigation. 104 // Simulates the start of the navigation.
90 virtual void Start(); 105 virtual void Start();
91 106
92 // Simulates a redirect to |new_url| for the navigation. 107 // Simulates a redirect to |new_url| for the navigation.
93 virtual void Redirect(const GURL& new_url); 108 virtual void Redirect(const GURL& new_url);
94 109
95 // Simulates the commit of the navigation in the RenderFrameHost. 110 // Simulates the commit of the navigation in the RenderFrameHost.
96 virtual void Commit(); 111 virtual void Commit();
97 112
(...skipping 17 matching lines...) Expand all
115 // The following parameters are constant during the navigation and may only be 130 // The following parameters are constant during the navigation and may only be
116 // specified before calling |Start|. 131 // specified before calling |Start|.
117 virtual void SetTransition(ui::PageTransition transition); 132 virtual void SetTransition(ui::PageTransition transition);
118 133
119 // The following parameters can change during redirects. They should be 134 // The following parameters can change during redirects. They should be
120 // specified before calling |Start| if they need to apply to the navigation to 135 // specified before calling |Start| if they need to apply to the navigation to
121 // the original url. Otherwise, they should be specified before calling 136 // the original url. Otherwise, they should be specified before calling
122 // |Redirect|. 137 // |Redirect|.
123 virtual void SetReferrer(const Referrer& referrer); 138 virtual void SetReferrer(const Referrer& referrer);
124 139
140 // Gets the last throttle check result computed by the navigation throttles.
141 // It is an error to call this before Start() is called.
142 virtual NavigationThrottle::ThrottleCheckResult GetLastThrottleCheckResult();
143
125 private: 144 private:
126 // WebContentsObserver: 145 // WebContentsObserver:
127 void DidStartNavigation(NavigationHandle* navigation_handle) override; 146 void DidStartNavigation(NavigationHandle* navigation_handle) override;
128 void DidRedirectNavigation(NavigationHandle* navigation_handle) override; 147 void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
129 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override; 148 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
130 void DidFinishNavigation(NavigationHandle* navigation_handle) override; 149 void DidFinishNavigation(NavigationHandle* navigation_handle) override;
131 150
132 void OnWillStartRequest(); 151 void OnWillStartRequest();
133 void OnWillRedirectRequest(); 152 void OnWillRedirectRequest();
134 void OnWillProcessResponse(); 153 void OnWillProcessResponse();
135 154
155 // This method will block waiting for throttle checks to complete.
156 void WaitForThrottleChecksComplete();
157
158 // Sets |last_throttle_check_result_| and calls
159 // |throttle_checks_wait_closure_|.
160 void OnThrottleChecksComplete(NavigationThrottle::ThrottleCheckResult result);
161
162 // Helper method to set the OnThrottleChecksComplete callback on the
163 // NavigationHandle.
164 void PrepareCompleteCallbackOnHandle();
165
136 enum State { 166 enum State {
137 INITIALIZATION, 167 INITIALIZATION,
138 STARTED, 168 STARTED,
139 FAILED, 169 FAILED,
140 FINISHED, 170 FINISHED,
141 }; 171 };
142 172
143 State state_ = INITIALIZATION; 173 State state_ = INITIALIZATION;
144 174
145 // The renderer associated with this navigation. 175 // The renderer associated with this navigation.
146 TestRenderFrameHost* render_frame_host_; 176 TestRenderFrameHost* render_frame_host_;
147 177
148 // The NavigationHandle associated with this navigation. 178 // The NavigationHandle associated with this navigation.
149 NavigationHandleImpl* handle_; 179 NavigationHandleImpl* handle_;
150 180
151 GURL navigation_url_; 181 GURL navigation_url_;
152 Referrer referrer_; 182 Referrer referrer_;
153 ui::PageTransition transition_ = ui::PAGE_TRANSITION_LINK; 183 ui::PageTransition transition_ = ui::PAGE_TRANSITION_LINK;
154 184
155 // These are used to sanity check the content/public/ API calls emitted as 185 // These are used to sanity check the content/public/ API calls emitted as
156 // part of the navigation. 186 // part of the navigation.
157 int num_did_start_navigation_called_ = 0; 187 int num_did_start_navigation_called_ = 0;
158 int num_will_start_request_called_ = 0; 188 int num_will_start_request_called_ = 0;
159 int num_will_redirect_request_called_ = 0; 189 int num_will_redirect_request_called_ = 0;
160 int num_did_redirect_navigation_called_ = 0; 190 int num_did_redirect_navigation_called_ = 0;
161 int num_will_process_response_called_ = 0; 191 int num_will_process_response_called_ = 0;
162 int num_ready_to_commit_called_ = 0; 192 int num_ready_to_commit_called_ = 0;
163 int num_did_finish_navigation_called_ = 0; 193 int num_did_finish_navigation_called_ = 0;
164 194
195 // Holds the last ThrottleCheckResult calculated by the navigation's
196 // throttles. Will be unset before WillStartRequest is finished. Will be unset
197 // while throttles are being run, but before they finish.
198 base::Optional<NavigationThrottle::ThrottleCheckResult>
199 last_throttle_check_result_;
200
201 // Closure that is set when WaitForThrottleChecksComplete is called.
202 base::Closure throttle_checks_wait_closure_;
203
165 base::WeakPtrFactory<NavigationSimulator> weak_factory_; 204 base::WeakPtrFactory<NavigationSimulator> weak_factory_;
166 }; 205 };
167 206
168 } // namespace content 207 } // namespace content
169 208
170 #endif // CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ 209 #endif // CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698