OLD | NEW |
---|---|
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 #include "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
10 #include "content/public/common/request_context_type.h" | 10 #include "content/public/common/request_context_type.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 : NavigationThrottle(handle), | 140 : NavigationThrottle(handle), |
141 will_start_result_(will_start_result), | 141 will_start_result_(will_start_result), |
142 will_redirect_result_(will_redirect_result), | 142 will_redirect_result_(will_redirect_result), |
143 will_process_result_(will_process_result), | 143 will_process_result_(will_process_result), |
144 did_call_will_start_(did_call_will_start), | 144 did_call_will_start_(did_call_will_start), |
145 did_call_will_redirect_(did_call_will_redirect), | 145 did_call_will_redirect_(did_call_will_redirect), |
146 did_call_will_process_(did_call_will_process) {} | 146 did_call_will_process_(did_call_will_process) {} |
147 ~TestNavigationThrottle() override {} | 147 ~TestNavigationThrottle() override {} |
148 | 148 |
149 void Resume() { navigation_handle()->Resume(); } | 149 void Resume() { navigation_handle()->Resume(); } |
150 void Cancel(NavigationThrottle::ThrottleCheckResult result) { | |
151 navigation_handle()->CancelDeferredNavigation(result); | |
152 } | |
150 | 153 |
151 RequestContextType request_context_type() { return request_context_type_; } | 154 RequestContextType request_context_type() { return request_context_type_; } |
152 | 155 |
153 private: | 156 private: |
154 // NavigationThrottle implementation. | 157 // NavigationThrottle implementation. |
155 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { | 158 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
156 NavigationHandleImpl* navigation_handle_impl = | 159 NavigationHandleImpl* navigation_handle_impl = |
157 static_cast<NavigationHandleImpl*>(navigation_handle()); | 160 static_cast<NavigationHandleImpl*>(navigation_handle()); |
158 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, | 161 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, |
159 navigation_handle_impl->request_context_type()); | 162 navigation_handle_impl->request_context_type()); |
(...skipping 27 matching lines...) Expand all Loading... | |
187 | 190 |
188 NavigationThrottle::ThrottleCheckResult will_start_result_; | 191 NavigationThrottle::ThrottleCheckResult will_start_result_; |
189 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 192 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
190 NavigationThrottle::ThrottleCheckResult will_process_result_; | 193 NavigationThrottle::ThrottleCheckResult will_process_result_; |
191 base::Closure did_call_will_start_; | 194 base::Closure did_call_will_start_; |
192 base::Closure did_call_will_redirect_; | 195 base::Closure did_call_will_redirect_; |
193 base::Closure did_call_will_process_; | 196 base::Closure did_call_will_process_; |
194 RequestContextType request_context_type_; | 197 RequestContextType request_context_type_; |
195 }; | 198 }; |
196 | 199 |
197 // Install a TestNavigationThrottle on all following requests and allows waiting | 200 // Installs a TestNavigationThrottle either on all following requests or on |
198 // for various NavigationThrottle related events. Waiting works only for the | 201 // requests with an expected starting URL, and allows waiting for various |
199 // immediately next navigation. New instances are needed to wait for further | 202 // NavigationThrottle related events. Waiting works only for the immediately |
200 // navigations. | 203 // next navigation. New instances are needed to wait for further navigations. |
201 class TestNavigationThrottleInstaller : public WebContentsObserver { | 204 class TestNavigationThrottleInstaller : public WebContentsObserver { |
202 public: | 205 public: |
203 TestNavigationThrottleInstaller( | 206 TestNavigationThrottleInstaller( |
204 WebContents* web_contents, | 207 WebContents* web_contents, |
205 NavigationThrottle::ThrottleCheckResult will_start_result, | 208 NavigationThrottle::ThrottleCheckResult will_start_result, |
206 NavigationThrottle::ThrottleCheckResult will_redirect_result, | 209 NavigationThrottle::ThrottleCheckResult will_redirect_result, |
207 NavigationThrottle::ThrottleCheckResult will_process_result) | 210 NavigationThrottle::ThrottleCheckResult will_process_result, |
211 GURL expected_start_url = GURL()) | |
dcheng
2017/02/28 05:36:22
const GURL& -- this should still work even with a
engedy
2017/04/10 14:36:41
Done.
| |
208 : WebContentsObserver(web_contents), | 212 : WebContentsObserver(web_contents), |
209 will_start_result_(will_start_result), | 213 will_start_result_(will_start_result), |
210 will_redirect_result_(will_redirect_result), | 214 will_redirect_result_(will_redirect_result), |
211 will_process_result_(will_process_result), | 215 will_process_result_(will_process_result), |
212 will_start_called_(0), | 216 will_start_called_(0), |
213 will_redirect_called_(0), | 217 will_redirect_called_(0), |
214 will_process_called_(0), | 218 will_process_called_(0), |
215 navigation_throttle_(nullptr), | 219 navigation_throttle_(nullptr), |
220 expected_start_url_(expected_start_url), | |
216 weak_factory_(this) {} | 221 weak_factory_(this) {} |
217 ~TestNavigationThrottleInstaller() override {} | 222 ~TestNavigationThrottleInstaller() override {} |
218 | 223 |
219 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } | 224 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } |
220 | 225 |
221 void WaitForThrottleWillStart() { | 226 void WaitForThrottleWillStart() { |
222 if (will_start_called_) | 227 if (will_start_called_) |
223 return; | 228 return; |
224 will_start_loop_runner_ = new MessageLoopRunner(); | 229 will_start_loop_runner_ = new MessageLoopRunner(); |
225 will_start_loop_runner_->Run(); | 230 will_start_loop_runner_->Run(); |
226 will_start_loop_runner_ = nullptr; | 231 will_start_loop_runner_ = nullptr; |
227 } | 232 } |
228 | 233 |
229 void WaitForThrottleWillRedirect() { | 234 void WaitForThrottleWillRedirect() { |
230 if (will_redirect_called_) | 235 if (will_redirect_called_) |
231 return; | 236 return; |
232 will_redirect_loop_runner_ = new MessageLoopRunner(); | 237 will_redirect_loop_runner_ = new MessageLoopRunner(); |
233 will_redirect_loop_runner_->Run(); | 238 will_redirect_loop_runner_->Run(); |
234 will_redirect_loop_runner_ = nullptr; | 239 will_redirect_loop_runner_ = nullptr; |
235 } | 240 } |
236 | 241 |
237 void WaitForThrottleWillProcess() { | 242 void WaitForThrottleWillProcess() { |
238 if (will_process_called_) | 243 if (will_process_called_) |
239 return; | 244 return; |
240 will_process_loop_runner_ = new MessageLoopRunner(); | 245 will_process_loop_runner_ = new MessageLoopRunner(); |
241 will_process_loop_runner_->Run(); | 246 will_process_loop_runner_->Run(); |
242 will_process_loop_runner_ = nullptr; | 247 will_process_loop_runner_ = nullptr; |
243 } | 248 } |
244 | 249 |
250 void Continue(NavigationThrottle::ThrottleCheckResult result) { | |
251 ASSERT_NE(NavigationThrottle::DEFER, result); | |
252 if (result == NavigationThrottle::PROCEED) | |
253 navigation_throttle()->Resume(); | |
254 else | |
255 navigation_throttle()->Cancel(result); | |
256 } | |
257 | |
245 int will_start_called() { return will_start_called_; } | 258 int will_start_called() { return will_start_called_; } |
246 int will_redirect_called() { return will_redirect_called_; } | 259 int will_redirect_called() { return will_redirect_called_; } |
247 int will_process_called() { return will_process_called_; } | 260 int will_process_called() { return will_process_called_; } |
248 | 261 |
262 protected: | |
263 virtual void DidCallWillStartRequest() { | |
264 will_start_called_++; | |
265 if (will_start_loop_runner_) | |
266 will_start_loop_runner_->Quit(); | |
267 } | |
268 | |
269 virtual void DidCallWillRedirectRequest() { | |
270 will_redirect_called_++; | |
271 if (will_redirect_loop_runner_) | |
272 will_redirect_loop_runner_->Quit(); | |
273 } | |
274 | |
275 virtual void DidCallWillProcessResponse() { | |
276 will_process_called_++; | |
277 if (will_process_loop_runner_) | |
278 will_process_loop_runner_->Quit(); | |
279 } | |
280 | |
249 private: | 281 private: |
250 void DidStartNavigation(NavigationHandle* handle) override { | 282 void DidStartNavigation(NavigationHandle* handle) override { |
283 if (!expected_start_url_.is_empty() && | |
284 handle->GetURL() != expected_start_url_) | |
285 return; | |
286 | |
251 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( | 287 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( |
252 handle, will_start_result_, will_redirect_result_, will_process_result_, | 288 handle, will_start_result_, will_redirect_result_, will_process_result_, |
253 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, | 289 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, |
254 weak_factory_.GetWeakPtr()), | 290 weak_factory_.GetWeakPtr()), |
255 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, | 291 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, |
256 weak_factory_.GetWeakPtr()), | 292 weak_factory_.GetWeakPtr()), |
257 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, | 293 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, |
258 weak_factory_.GetWeakPtr()))); | 294 weak_factory_.GetWeakPtr()))); |
259 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); | 295 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); |
260 handle->RegisterThrottleForTesting(std::move(throttle)); | 296 handle->RegisterThrottleForTesting(std::move(throttle)); |
261 } | 297 } |
262 | 298 |
263 void DidFinishNavigation(NavigationHandle* handle) override { | 299 void DidFinishNavigation(NavigationHandle* handle) override { |
264 if (!navigation_throttle_) | 300 if (!navigation_throttle_) |
265 return; | 301 return; |
266 | 302 |
267 if (handle == navigation_throttle_->navigation_handle()) | 303 if (handle == navigation_throttle_->navigation_handle()) |
268 navigation_throttle_ = nullptr; | 304 navigation_throttle_ = nullptr; |
269 } | 305 } |
270 | 306 |
271 void DidCallWillStartRequest() { | |
272 will_start_called_++; | |
273 if (will_start_loop_runner_) | |
274 will_start_loop_runner_->Quit(); | |
275 } | |
276 | |
277 void DidCallWillRedirectRequest() { | |
278 will_redirect_called_++; | |
279 if (will_redirect_loop_runner_) | |
280 will_redirect_loop_runner_->Quit(); | |
281 } | |
282 | |
283 void DidCallWillProcessResponse() { | |
284 will_process_called_++; | |
285 if (will_process_loop_runner_) | |
286 will_process_loop_runner_->Quit(); | |
287 } | |
288 | |
289 NavigationThrottle::ThrottleCheckResult will_start_result_; | 307 NavigationThrottle::ThrottleCheckResult will_start_result_; |
290 NavigationThrottle::ThrottleCheckResult will_redirect_result_; | 308 NavigationThrottle::ThrottleCheckResult will_redirect_result_; |
291 NavigationThrottle::ThrottleCheckResult will_process_result_; | 309 NavigationThrottle::ThrottleCheckResult will_process_result_; |
292 int will_start_called_; | 310 int will_start_called_; |
293 int will_redirect_called_; | 311 int will_redirect_called_; |
294 int will_process_called_; | 312 int will_process_called_; |
295 TestNavigationThrottle* navigation_throttle_; | 313 TestNavigationThrottle* navigation_throttle_; |
296 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; | 314 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; |
297 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; | 315 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; |
298 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; | 316 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; |
317 GURL expected_start_url_; | |
299 | 318 |
300 // The throttle installer can be deleted before all tasks posted by its | 319 // The throttle installer can be deleted before all tasks posted by its |
301 // throttles are run, so it must be referenced via weak pointers. | 320 // throttles are run, so it must be referenced via weak pointers. |
302 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; | 321 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; |
303 }; | 322 }; |
304 | 323 |
324 // Same as above, but installs NavigationThrottles that do not directly return | |
325 // the pre-programmed check results, but first DEFER the navigation at each | |
326 // stage and then resume/cancel asynchronously. | |
327 class TestDeferringNavigationThrottleInstaller | |
328 : public TestNavigationThrottleInstaller { | |
329 public: | |
330 TestDeferringNavigationThrottleInstaller( | |
331 WebContents* web_contents, | |
332 NavigationThrottle::ThrottleCheckResult will_start_result, | |
333 NavigationThrottle::ThrottleCheckResult will_redirect_result, | |
334 NavigationThrottle::ThrottleCheckResult will_process_result, | |
335 GURL expected_start_url = GURL()) | |
336 : TestNavigationThrottleInstaller(web_contents, | |
337 NavigationThrottle::DEFER, | |
338 NavigationThrottle::DEFER, | |
339 NavigationThrottle::DEFER, | |
340 expected_start_url), | |
341 will_start_deferred_result_(will_start_result), | |
342 will_redirect_deferred_result_(will_redirect_result), | |
343 will_process_deferred_result_(will_process_result) {} | |
344 | |
345 protected: | |
346 void DidCallWillStartRequest() override { | |
347 TestNavigationThrottleInstaller::DidCallWillStartRequest(); | |
348 Continue(will_start_deferred_result_); | |
349 } | |
350 | |
351 void DidCallWillRedirectRequest() override { | |
352 TestNavigationThrottleInstaller::DidCallWillStartRequest(); | |
353 Continue(will_redirect_deferred_result_); | |
354 } | |
355 | |
356 void DidCallWillProcessResponse() override { | |
357 TestNavigationThrottleInstaller::DidCallWillStartRequest(); | |
358 Continue(will_process_deferred_result_); | |
359 } | |
360 | |
361 private: | |
362 NavigationThrottle::ThrottleCheckResult will_start_deferred_result_; | |
363 NavigationThrottle::ThrottleCheckResult will_redirect_deferred_result_; | |
364 NavigationThrottle::ThrottleCheckResult will_process_deferred_result_; | |
365 }; | |
366 | |
305 // Records all navigation start URLs from the WebContents. | 367 // Records all navigation start URLs from the WebContents. |
306 class NavigationStartUrlRecorder : public WebContentsObserver { | 368 class NavigationStartUrlRecorder : public WebContentsObserver { |
307 public: | 369 public: |
308 NavigationStartUrlRecorder(WebContents* web_contents) | 370 NavigationStartUrlRecorder(WebContents* web_contents) |
309 : WebContentsObserver(web_contents) {} | 371 : WebContentsObserver(web_contents) {} |
310 | 372 |
311 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 373 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
312 urls_.push_back(navigation_handle->GetURL()); | 374 urls_.push_back(navigation_handle->GetURL()); |
313 } | 375 } |
314 | 376 |
315 const std::vector<GURL>& urls() const { return urls_; } | 377 const std::vector<GURL>& urls() const { return urls_; } |
316 | 378 |
317 private: | 379 private: |
318 std::vector<GURL> urls_; | 380 std::vector<GURL> urls_; |
319 }; | 381 }; |
320 | 382 |
383 bool IsChildFrameCollapsed(Shell* shell, const char* element_id) { | |
nasko
2017/03/01 20:08:04
nit: std::string?
engedy
2017/04/10 14:36:41
Done.
| |
384 const char kScript[] = | |
385 "window.domAutomationController.send(" | |
386 " document.getElementById(\"%s\").clientWidth" | |
387 ");"; | |
388 int client_width = 0; | |
389 EXPECT_TRUE(ExecuteScriptAndExtractInt( | |
390 shell, base::StringPrintf(kScript, element_id), &client_width)); | |
391 return !client_width; | |
392 } | |
393 | |
321 } // namespace | 394 } // namespace |
322 | 395 |
323 class NavigationHandleImplBrowserTest : public ContentBrowserTest { | 396 class NavigationHandleImplBrowserTest : public ContentBrowserTest { |
324 protected: | 397 protected: |
325 void SetUpOnMainThread() override { | 398 void SetUpOnMainThread() override { |
326 host_resolver()->AddRule("*", "127.0.0.1"); | 399 host_resolver()->AddRule("*", "127.0.0.1"); |
327 SetupCrossSiteRedirector(embedded_test_server()); | 400 SetupCrossSiteRedirector(embedded_test_server()); |
328 ASSERT_TRUE(embedded_test_server()->Start()); | 401 ASSERT_TRUE(embedded_test_server()->Start()); |
329 } | 402 } |
330 }; | 403 }; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 // Wait for the end of the navigation. | 791 // Wait for the end of the navigation. |
719 navigation_observer.Wait(); | 792 navigation_observer.Wait(); |
720 | 793 |
721 EXPECT_TRUE(observer.has_committed()); | 794 EXPECT_TRUE(observer.has_committed()); |
722 EXPECT_TRUE(observer.was_redirected()); | 795 EXPECT_TRUE(observer.was_redirected()); |
723 EXPECT_FALSE(observer.is_error()); | 796 EXPECT_FALSE(observer.is_error()); |
724 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), | 797 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), |
725 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); | 798 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
726 } | 799 } |
727 | 800 |
801 // Ensure that a NavigationThrottle can block the navigation and collapse the | |
802 // frame owner both on request start as well as after a redirect. Plus, ensure | |
803 // that the frame is restored on the subsequent non-error-page navigation. | |
804 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, | |
805 ThrottleBlockAndCollapse) { | |
806 const char kChildFrameId[] = "child0"; | |
807 GURL main_url(embedded_test_server()->GetURL( | |
808 "a.com", "/frame_tree/page_with_one_frame.html")); | |
809 GURL blocked_subframe_url(embedded_test_server()->GetURL( | |
810 "a.com", "/cross-site/baz.com/title1.html")); | |
811 GURL allowed_subframe_url(embedded_test_server()->GetURL( | |
812 "a.com", "/cross-site/baz.com/title2.html")); | |
813 GURL allowed_subframe_final_url( | |
814 embedded_test_server()->GetURL("baz.com", "/title2.html")); | |
815 | |
816 // Exercise both synchronous and deferred throttle check results, and both on | |
817 // WillStartRequest and on WillRedirectRequest. | |
818 for (const bool deferred_block : {false, true}) { | |
819 for (const bool block_on_redirect : {false, true}) { | |
820 SCOPED_TRACE(deferred_block ? "Direct block" : "Deferred block"); | |
821 SCOPED_TRACE(block_on_redirect ? "Block on WillRedirectRequest" | |
822 : "Block on WillStartRequest"); | |
823 | |
824 NavigationThrottle::ThrottleCheckResult will_start_result = | |
825 block_on_redirect ? NavigationThrottle::PROCEED | |
826 : NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE; | |
827 NavigationThrottle::ThrottleCheckResult will_redirect_result = | |
828 block_on_redirect ? NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE | |
829 : NavigationThrottle::PROCEED; | |
nasko
2017/03/01 20:08:04
I wonder if this test can be simplified a bit by c
engedy
2017/04/10 14:36:41
Is this what you had in mind?
nasko
2017/05/03 16:58:30
Yes. Thanks!
| |
830 | |
831 std::unique_ptr<TestNavigationThrottleInstaller> | |
832 subframe_throttle_installer; | |
833 if (deferred_block) { | |
834 subframe_throttle_installer.reset( | |
835 new TestDeferringNavigationThrottleInstaller( | |
836 shell()->web_contents(), will_start_result, | |
837 will_redirect_result, NavigationThrottle::PROCEED, | |
838 blocked_subframe_url)); | |
839 } else { | |
840 subframe_throttle_installer.reset(new TestNavigationThrottleInstaller( | |
841 shell()->web_contents(), will_start_result, will_redirect_result, | |
842 NavigationThrottle::PROCEED, blocked_subframe_url)); | |
843 } | |
844 | |
845 { | |
846 SCOPED_TRACE("Initial navigation blocked on main frame load."); | |
847 NavigationHandleObserver subframe_observer(shell()->web_contents(), | |
848 blocked_subframe_url); | |
849 | |
850 ASSERT_TRUE(NavigateToURL(shell(), main_url)); | |
851 EXPECT_TRUE(subframe_observer.is_error()); | |
852 EXPECT_TRUE(subframe_observer.has_committed()); | |
853 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, | |
854 subframe_observer.net_error_code()); | |
855 EXPECT_TRUE(IsChildFrameCollapsed(shell(), kChildFrameId)); | |
856 } | |
857 | |
858 { | |
859 SCOPED_TRACE("Subsequent subframe navigation is allowed."); | |
860 NavigationHandleObserver subframe_observer(shell()->web_contents(), | |
861 allowed_subframe_url); | |
862 | |
863 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId, | |
864 allowed_subframe_url)); | |
865 EXPECT_TRUE(subframe_observer.has_committed()); | |
866 EXPECT_FALSE(subframe_observer.is_error()); | |
867 EXPECT_EQ(allowed_subframe_final_url, | |
868 subframe_observer.last_committed_url()); | |
869 EXPECT_FALSE(IsChildFrameCollapsed(shell(), kChildFrameId)); | |
870 } | |
871 | |
872 { | |
873 SCOPED_TRACE("Subsequent subframe navigation is blocked."); | |
874 NavigationHandleObserver subframe_observer(shell()->web_contents(), | |
875 blocked_subframe_url); | |
876 | |
877 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId, | |
878 blocked_subframe_url)); | |
879 | |
880 EXPECT_TRUE(subframe_observer.has_committed()); | |
881 EXPECT_TRUE(subframe_observer.is_error()); | |
882 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, | |
883 subframe_observer.net_error_code()); | |
884 EXPECT_TRUE(IsChildFrameCollapsed(shell(), kChildFrameId)); | |
885 } | |
886 } | |
887 } | |
888 } | |
889 | |
728 // Checks that the RequestContextType value is properly set. | 890 // Checks that the RequestContextType value is properly set. |
729 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, | 891 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
730 VerifyRequestContextTypeForFrameTree) { | 892 VerifyRequestContextTypeForFrameTree) { |
731 GURL main_url(embedded_test_server()->GetURL( | 893 GURL main_url(embedded_test_server()->GetURL( |
732 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); | 894 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); |
733 GURL b_url(embedded_test_server()->GetURL( | 895 GURL b_url(embedded_test_server()->GetURL( |
734 "b.com", "/cross_site_iframe_factory.html?b(c())")); | 896 "b.com", "/cross_site_iframe_factory.html?b(c())")); |
735 GURL c_url(embedded_test_server()->GetURL( | 897 GURL c_url(embedded_test_server()->GetURL( |
736 "c.com", "/cross_site_iframe_factory.html?c()")); | 898 "c.com", "/cross_site_iframe_factory.html?c()")); |
737 | 899 |
738 TestNavigationThrottleInstaller installer( | 900 TestNavigationThrottleInstaller installer( |
739 shell()->web_contents(), NavigationThrottle::PROCEED, | 901 shell()->web_contents(), NavigationThrottle::PROCEED, |
740 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 902 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
741 TestNavigationManager main_manager(shell()->web_contents(), main_url); | 903 TestNavigationManager main_manager(shell()->web_contents(), main_url); |
742 TestNavigationManager b_manager(shell()->web_contents(), b_url); | 904 TestNavigationManager b_manager(shell()->web_contents(), b_url); |
743 TestNavigationManager c_manager(shell()->web_contents(), c_url); | 905 TestNavigationManager c_manager(shell()->web_contents(), c_url); |
744 NavigationStartUrlRecorder url_recorder(shell()->web_contents()); | 906 NavigationStartUrlRecorder url_recorder(shell()->web_contents()); |
745 TestNavigationThrottle* previous_throttle = nullptr; | 907 TestNavigationThrottle* previous_throttle = nullptr; |
746 | 908 |
747 // Starts and verifies the main frame navigation. | 909 // Starts and verifies the main frame navigation. |
748 shell()->LoadURL(main_url); | 910 shell()->LoadURL(main_url); |
749 EXPECT_TRUE(main_manager.WaitForRequestStart()); | 911 EXPECT_TRUE(main_manager.WaitForRequestStart()); |
750 // The throttle should not be null. | 912 // The throttle should not be null. |
751 EXPECT_NE(previous_throttle, installer.navigation_throttle()); | 913 EXPECT_NE(previous_throttle, installer.navigation_throttle()); |
752 // Checks the only URL recorded so far is the one expected for the main frame. | 914 // Checks the only URL recorded so far is the one expected for the main |
915 // frame. | |
753 EXPECT_EQ(main_url, url_recorder.urls().back()); | 916 EXPECT_EQ(main_url, url_recorder.urls().back()); |
754 EXPECT_EQ(1ul, url_recorder.urls().size()); | 917 EXPECT_EQ(1ul, url_recorder.urls().size()); |
755 // Checks the main frame RequestContextType. | 918 // Checks the main frame RequestContextType. |
756 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, | 919 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
757 installer.navigation_throttle()->request_context_type()); | 920 installer.navigation_throttle()->request_context_type()); |
758 // For each navigations the throttle should be a different instance. | 921 // For each navigations the throttle should be a different instance. |
759 previous_throttle = installer.navigation_throttle(); | 922 previous_throttle = installer.navigation_throttle(); |
760 | 923 |
761 // Ditto for frame b navigation. | 924 // Ditto for frame b navigation. |
762 main_manager.WaitForNavigationFinished(); | 925 main_manager.WaitForNavigationFinished(); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1043 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 1206 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
1044 NavigationHandleObserver observer(shell()->web_contents(), url); | 1207 NavigationHandleObserver observer(shell()->web_contents(), url); |
1045 EXPECT_TRUE(NavigateToURL(shell(), url)); | 1208 EXPECT_TRUE(NavigateToURL(shell(), url)); |
1046 EXPECT_EQ(1, installer.will_start_called()); | 1209 EXPECT_EQ(1, installer.will_start_called()); |
1047 EXPECT_EQ(1, installer.will_process_called()); | 1210 EXPECT_EQ(1, installer.will_process_called()); |
1048 EXPECT_FALSE(observer.is_same_page()); | 1211 EXPECT_FALSE(observer.is_same_page()); |
1049 } | 1212 } |
1050 } | 1213 } |
1051 | 1214 |
1052 } // namespace content | 1215 } // namespace content |
OLD | NEW |