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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl_browsertest.cc

Issue 2632633006: Implement NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE. (Closed)
Patch Set: Rebase. Created 3 years, 7 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 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/browser_side_navigation_policy.h" 10 #include "content/public/common/browser_side_navigation_policy.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 will_redirect_result_(will_redirect_result), 135 will_redirect_result_(will_redirect_result),
136 will_process_result_(will_process_result), 136 will_process_result_(will_process_result),
137 did_call_will_start_(did_call_will_start), 137 did_call_will_start_(did_call_will_start),
138 did_call_will_redirect_(did_call_will_redirect), 138 did_call_will_redirect_(did_call_will_redirect),
139 did_call_will_process_(did_call_will_process) {} 139 did_call_will_process_(did_call_will_process) {}
140 ~TestNavigationThrottle() override {} 140 ~TestNavigationThrottle() override {}
141 141
142 const char* GetNameForLogging() override { return "TestNavigationThrottle"; } 142 const char* GetNameForLogging() override { return "TestNavigationThrottle"; }
143 143
144 void Resume() { navigation_handle()->Resume(); } 144 void Resume() { navigation_handle()->Resume(); }
145 void Cancel(NavigationThrottle::ThrottleCheckResult result) {
146 navigation_handle()->CancelDeferredNavigation(result);
147 }
145 148
146 RequestContextType request_context_type() { return request_context_type_; } 149 RequestContextType request_context_type() { return request_context_type_; }
147 150
148 private: 151 private:
149 // NavigationThrottle implementation. 152 // NavigationThrottle implementation.
150 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { 153 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
151 NavigationHandleImpl* navigation_handle_impl = 154 NavigationHandleImpl* navigation_handle_impl =
152 static_cast<NavigationHandleImpl*>(navigation_handle()); 155 static_cast<NavigationHandleImpl*>(navigation_handle());
153 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, 156 CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED,
154 navigation_handle_impl->request_context_type()); 157 navigation_handle_impl->request_context_type());
(...skipping 27 matching lines...) Expand all
182 185
183 NavigationThrottle::ThrottleCheckResult will_start_result_; 186 NavigationThrottle::ThrottleCheckResult will_start_result_;
184 NavigationThrottle::ThrottleCheckResult will_redirect_result_; 187 NavigationThrottle::ThrottleCheckResult will_redirect_result_;
185 NavigationThrottle::ThrottleCheckResult will_process_result_; 188 NavigationThrottle::ThrottleCheckResult will_process_result_;
186 base::Closure did_call_will_start_; 189 base::Closure did_call_will_start_;
187 base::Closure did_call_will_redirect_; 190 base::Closure did_call_will_redirect_;
188 base::Closure did_call_will_process_; 191 base::Closure did_call_will_process_;
189 RequestContextType request_context_type_ = REQUEST_CONTEXT_TYPE_UNSPECIFIED; 192 RequestContextType request_context_type_ = REQUEST_CONTEXT_TYPE_UNSPECIFIED;
190 }; 193 };
191 194
192 // Install a TestNavigationThrottle on all following requests and allows waiting 195 // Installs a TestNavigationThrottle either on all following requests or on
193 // for various NavigationThrottle related events. Waiting works only for the 196 // requests with an expected starting URL, and allows waiting for various
194 // immediately next navigation. New instances are needed to wait for further 197 // NavigationThrottle related events. Waiting works only for the immediately
195 // navigations. 198 // next navigation. New instances are needed to wait for further navigations.
196 class TestNavigationThrottleInstaller : public WebContentsObserver { 199 class TestNavigationThrottleInstaller : public WebContentsObserver {
197 public: 200 public:
198 TestNavigationThrottleInstaller( 201 TestNavigationThrottleInstaller(
199 WebContents* web_contents, 202 WebContents* web_contents,
200 NavigationThrottle::ThrottleCheckResult will_start_result, 203 NavigationThrottle::ThrottleCheckResult will_start_result,
201 NavigationThrottle::ThrottleCheckResult will_redirect_result, 204 NavigationThrottle::ThrottleCheckResult will_redirect_result,
202 NavigationThrottle::ThrottleCheckResult will_process_result) 205 NavigationThrottle::ThrottleCheckResult will_process_result,
206 const GURL& expected_start_url = GURL())
203 : WebContentsObserver(web_contents), 207 : WebContentsObserver(web_contents),
204 will_start_result_(will_start_result), 208 will_start_result_(will_start_result),
205 will_redirect_result_(will_redirect_result), 209 will_redirect_result_(will_redirect_result),
206 will_process_result_(will_process_result), 210 will_process_result_(will_process_result),
211 expected_start_url_(expected_start_url),
207 weak_factory_(this) {} 212 weak_factory_(this) {}
208 ~TestNavigationThrottleInstaller() override {} 213 ~TestNavigationThrottleInstaller() override {}
209 214
210 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } 215 TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; }
211 216
212 void WaitForThrottleWillStart() { 217 void WaitForThrottleWillStart() {
213 if (will_start_called_) 218 if (will_start_called_)
214 return; 219 return;
215 will_start_loop_runner_ = new MessageLoopRunner(); 220 will_start_loop_runner_ = new MessageLoopRunner();
216 will_start_loop_runner_->Run(); 221 will_start_loop_runner_->Run();
217 will_start_loop_runner_ = nullptr; 222 will_start_loop_runner_ = nullptr;
218 } 223 }
219 224
220 void WaitForThrottleWillRedirect() { 225 void WaitForThrottleWillRedirect() {
221 if (will_redirect_called_) 226 if (will_redirect_called_)
222 return; 227 return;
223 will_redirect_loop_runner_ = new MessageLoopRunner(); 228 will_redirect_loop_runner_ = new MessageLoopRunner();
224 will_redirect_loop_runner_->Run(); 229 will_redirect_loop_runner_->Run();
225 will_redirect_loop_runner_ = nullptr; 230 will_redirect_loop_runner_ = nullptr;
226 } 231 }
227 232
228 void WaitForThrottleWillProcess() { 233 void WaitForThrottleWillProcess() {
229 if (will_process_called_) 234 if (will_process_called_)
230 return; 235 return;
231 will_process_loop_runner_ = new MessageLoopRunner(); 236 will_process_loop_runner_ = new MessageLoopRunner();
232 will_process_loop_runner_->Run(); 237 will_process_loop_runner_->Run();
233 will_process_loop_runner_ = nullptr; 238 will_process_loop_runner_ = nullptr;
234 } 239 }
235 240
241 void Continue(NavigationThrottle::ThrottleCheckResult result) {
242 ASSERT_NE(NavigationThrottle::DEFER, result);
243 if (result == NavigationThrottle::PROCEED)
244 navigation_throttle()->Resume();
245 else
246 navigation_throttle()->Cancel(result);
247 }
248
236 int will_start_called() { return will_start_called_; } 249 int will_start_called() { return will_start_called_; }
237 int will_redirect_called() { return will_redirect_called_; } 250 int will_redirect_called() { return will_redirect_called_; }
238 int will_process_called() { return will_process_called_; } 251 int will_process_called() { return will_process_called_; }
239 252
240 int install_count() { return install_count_; } 253 int install_count() { return install_count_; }
241 254
255 protected:
256 virtual void DidCallWillStartRequest() {
257 will_start_called_++;
258 if (will_start_loop_runner_)
259 will_start_loop_runner_->Quit();
260 }
261
262 virtual void DidCallWillRedirectRequest() {
263 will_redirect_called_++;
264 if (will_redirect_loop_runner_)
265 will_redirect_loop_runner_->Quit();
266 }
267
268 virtual void DidCallWillProcessResponse() {
269 will_process_called_++;
270 if (will_process_loop_runner_)
271 will_process_loop_runner_->Quit();
272 }
273
242 private: 274 private:
243 void DidStartNavigation(NavigationHandle* handle) override { 275 void DidStartNavigation(NavigationHandle* handle) override {
276 if (!expected_start_url_.is_empty() &&
277 handle->GetURL() != expected_start_url_)
278 return;
279
244 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( 280 std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle(
245 handle, will_start_result_, will_redirect_result_, will_process_result_, 281 handle, will_start_result_, will_redirect_result_, will_process_result_,
246 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest, 282 base::Bind(&TestNavigationThrottleInstaller::DidCallWillStartRequest,
247 weak_factory_.GetWeakPtr()), 283 weak_factory_.GetWeakPtr()),
248 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest, 284 base::Bind(&TestNavigationThrottleInstaller::DidCallWillRedirectRequest,
249 weak_factory_.GetWeakPtr()), 285 weak_factory_.GetWeakPtr()),
250 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse, 286 base::Bind(&TestNavigationThrottleInstaller::DidCallWillProcessResponse,
251 weak_factory_.GetWeakPtr()))); 287 weak_factory_.GetWeakPtr())));
252 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get()); 288 navigation_throttle_ = static_cast<TestNavigationThrottle*>(throttle.get());
253 handle->RegisterThrottleForTesting(std::move(throttle)); 289 handle->RegisterThrottleForTesting(std::move(throttle));
254 ++install_count_; 290 ++install_count_;
255 } 291 }
256 292
257 void DidFinishNavigation(NavigationHandle* handle) override { 293 void DidFinishNavigation(NavigationHandle* handle) override {
258 if (!navigation_throttle_) 294 if (!navigation_throttle_)
259 return; 295 return;
260 296
261 if (handle == navigation_throttle_->navigation_handle()) 297 if (handle == navigation_throttle_->navigation_handle())
262 navigation_throttle_ = nullptr; 298 navigation_throttle_ = nullptr;
263 } 299 }
264 300
265 void DidCallWillStartRequest() {
266 will_start_called_++;
267 if (will_start_loop_runner_)
268 will_start_loop_runner_->Quit();
269 }
270
271 void DidCallWillRedirectRequest() {
272 will_redirect_called_++;
273 if (will_redirect_loop_runner_)
274 will_redirect_loop_runner_->Quit();
275 }
276
277 void DidCallWillProcessResponse() {
278 will_process_called_++;
279 if (will_process_loop_runner_)
280 will_process_loop_runner_->Quit();
281 }
282
283 NavigationThrottle::ThrottleCheckResult will_start_result_; 301 NavigationThrottle::ThrottleCheckResult will_start_result_;
284 NavigationThrottle::ThrottleCheckResult will_redirect_result_; 302 NavigationThrottle::ThrottleCheckResult will_redirect_result_;
285 NavigationThrottle::ThrottleCheckResult will_process_result_; 303 NavigationThrottle::ThrottleCheckResult will_process_result_;
286 int will_start_called_ = 0; 304 int will_start_called_ = 0;
287 int will_redirect_called_ = 0; 305 int will_redirect_called_ = 0;
288 int will_process_called_ = 0; 306 int will_process_called_ = 0;
289 TestNavigationThrottle* navigation_throttle_ = nullptr; 307 TestNavigationThrottle* navigation_throttle_ = nullptr;
290 int install_count_ = 0; 308 int install_count_ = 0;
291 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; 309 scoped_refptr<MessageLoopRunner> will_start_loop_runner_;
292 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_; 310 scoped_refptr<MessageLoopRunner> will_redirect_loop_runner_;
293 scoped_refptr<MessageLoopRunner> will_process_loop_runner_; 311 scoped_refptr<MessageLoopRunner> will_process_loop_runner_;
312 GURL expected_start_url_;
294 313
295 // The throttle installer can be deleted before all tasks posted by its 314 // The throttle installer can be deleted before all tasks posted by its
296 // throttles are run, so it must be referenced via weak pointers. 315 // throttles are run, so it must be referenced via weak pointers.
297 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_; 316 base::WeakPtrFactory<TestNavigationThrottleInstaller> weak_factory_;
298 }; 317 };
299 318
319 // Same as above, but installs NavigationThrottles that do not directly return
320 // the pre-programmed check results, but first DEFER the navigation at each
321 // stage and then resume/cancel asynchronously.
322 class TestDeferringNavigationThrottleInstaller
323 : public TestNavigationThrottleInstaller {
324 public:
325 TestDeferringNavigationThrottleInstaller(
326 WebContents* web_contents,
327 NavigationThrottle::ThrottleCheckResult will_start_result,
328 NavigationThrottle::ThrottleCheckResult will_redirect_result,
329 NavigationThrottle::ThrottleCheckResult will_process_result,
330 GURL expected_start_url = GURL())
331 : TestNavigationThrottleInstaller(web_contents,
332 NavigationThrottle::DEFER,
333 NavigationThrottle::DEFER,
334 NavigationThrottle::DEFER,
335 expected_start_url),
336 will_start_deferred_result_(will_start_result),
337 will_redirect_deferred_result_(will_redirect_result),
338 will_process_deferred_result_(will_process_result) {}
339
340 protected:
341 void DidCallWillStartRequest() override {
342 TestNavigationThrottleInstaller::DidCallWillStartRequest();
343 Continue(will_start_deferred_result_);
344 }
345
346 void DidCallWillRedirectRequest() override {
347 TestNavigationThrottleInstaller::DidCallWillStartRequest();
348 Continue(will_redirect_deferred_result_);
349 }
350
351 void DidCallWillProcessResponse() override {
352 TestNavigationThrottleInstaller::DidCallWillStartRequest();
353 Continue(will_process_deferred_result_);
354 }
355
356 private:
357 NavigationThrottle::ThrottleCheckResult will_start_deferred_result_;
358 NavigationThrottle::ThrottleCheckResult will_redirect_deferred_result_;
359 NavigationThrottle::ThrottleCheckResult will_process_deferred_result_;
360 };
361
300 // Records all navigation start URLs from the WebContents. 362 // Records all navigation start URLs from the WebContents.
301 class NavigationStartUrlRecorder : public WebContentsObserver { 363 class NavigationStartUrlRecorder : public WebContentsObserver {
302 public: 364 public:
303 NavigationStartUrlRecorder(WebContents* web_contents) 365 NavigationStartUrlRecorder(WebContents* web_contents)
304 : WebContentsObserver(web_contents) {} 366 : WebContentsObserver(web_contents) {}
305 367
306 void DidStartNavigation(NavigationHandle* navigation_handle) override { 368 void DidStartNavigation(NavigationHandle* navigation_handle) override {
307 urls_.push_back(navigation_handle->GetURL()); 369 urls_.push_back(navigation_handle->GetURL());
308 } 370 }
309 371
310 const std::vector<GURL>& urls() const { return urls_; } 372 const std::vector<GURL>& urls() const { return urls_; }
311 373
312 private: 374 private:
313 std::vector<GURL> urls_; 375 std::vector<GURL> urls_;
314 }; 376 };
315 377
378 void ExpectChildFrameSetAsCollapsedInFTN(Shell* shell, bool expect_collapsed) {
379 // Check if the frame should be collapsed in theory as per FTN.
380 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell->web_contents())
381 ->GetFrameTree()
382 ->root();
383 ASSERT_EQ(1u, root->child_count());
384 FrameTreeNode* child = root->child_at(0u);
385 EXPECT_EQ(expect_collapsed, child->is_collapsed());
386 }
387
388 void ExpectChildFrameCollapsedInLayout(Shell* shell,
389 const std::string& frame_id,
390 bool expect_collapsed) {
391 // Check if the frame is collapsed in practice.
392 const char kScript[] =
393 "window.domAutomationController.send("
394 " document.getElementById(\"%s\").clientWidth"
395 ");";
396 int client_width = 0;
397 EXPECT_TRUE(ExecuteScriptAndExtractInt(
398 shell, base::StringPrintf(kScript, frame_id.c_str()), &client_width));
399 EXPECT_EQ(expect_collapsed, !client_width) << client_width;
400 }
401
402 void ExpectChildFrameCollapsed(Shell* shell,
403 const std::string& frame_id,
404 bool expect_collapsed) {
405 ExpectChildFrameSetAsCollapsedInFTN(shell, expect_collapsed);
406 ExpectChildFrameCollapsedInLayout(shell, frame_id, expect_collapsed);
407 }
408
316 } // namespace 409 } // namespace
317 410
318 class NavigationHandleImplBrowserTest : public ContentBrowserTest { 411 class NavigationHandleImplBrowserTest : public ContentBrowserTest {
319 protected: 412 protected:
320 void SetUpOnMainThread() override { 413 void SetUpOnMainThread() override {
321 host_resolver()->AddRule("*", "127.0.0.1"); 414 host_resolver()->AddRule("*", "127.0.0.1");
322 SetupCrossSiteRedirector(embedded_test_server()); 415 SetupCrossSiteRedirector(embedded_test_server());
323 ASSERT_TRUE(embedded_test_server()->Start()); 416 ASSERT_TRUE(embedded_test_server()->Start());
324 } 417 }
325 }; 418 };
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 // Wait for the end of the navigation. 807 // Wait for the end of the navigation.
715 navigation_observer.Wait(); 808 navigation_observer.Wait();
716 809
717 EXPECT_TRUE(observer.has_committed()); 810 EXPECT_TRUE(observer.has_committed());
718 EXPECT_TRUE(observer.was_redirected()); 811 EXPECT_TRUE(observer.was_redirected());
719 EXPECT_FALSE(observer.is_error()); 812 EXPECT_FALSE(observer.is_error());
720 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), 813 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(),
721 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); 814 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html")));
722 } 815 }
723 816
817 // Ensure that a NavigationThrottle can block the navigation and collapse the
818 // frame owner both on request start as well as after a redirect. Plus, ensure
819 // that the frame is restored on the subsequent non-error-page navigation.
820 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
821 ThrottleBlockAndCollapse) {
822 const char kChildFrameId[] = "child0";
823 GURL main_url(embedded_test_server()->GetURL(
824 "a.com", "/frame_tree/page_with_one_frame.html"));
825 GURL blocked_subframe_url(embedded_test_server()->GetURL(
826 "a.com", "/cross-site/baz.com/title1.html"));
827 GURL allowed_subframe_url(embedded_test_server()->GetURL(
828 "a.com", "/cross-site/baz.com/title2.html"));
829 GURL allowed_subframe_final_url(
830 embedded_test_server()->GetURL("baz.com", "/title2.html"));
831
832 // Exercise both synchronous and deferred throttle check results, and both on
833 // WillStartRequest and on WillRedirectRequest.
834 const struct {
835 NavigationThrottle::ThrottleCheckResult will_start_result;
836 NavigationThrottle::ThrottleCheckResult will_redirect_result;
837 bool deferred_block;
838 } kTestCases[] = {
839 {NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE,
840 NavigationThrottle::PROCEED, false},
841 {NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE,
842 NavigationThrottle::PROCEED, true},
843 {NavigationThrottle::PROCEED,
844 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, false},
845 {NavigationThrottle::PROCEED,
846 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE, true},
847 };
848
849 for (const auto& test_case : kTestCases) {
850 SCOPED_TRACE(::testing::Message() << test_case.will_start_result << ", "
851 << test_case.will_redirect_result << ", "
852 << test_case.deferred_block);
853
854 if (!IsBrowserSideNavigationEnabled() &&
855 test_case.will_redirect_result ==
856 NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE) {
857 continue;
858 }
859
860 std::unique_ptr<TestNavigationThrottleInstaller>
861 subframe_throttle_installer;
862 if (test_case.deferred_block) {
863 subframe_throttle_installer.reset(
864 new TestDeferringNavigationThrottleInstaller(
865 shell()->web_contents(), test_case.will_start_result,
866 test_case.will_redirect_result, NavigationThrottle::PROCEED,
867 blocked_subframe_url));
868 } else {
869 subframe_throttle_installer.reset(new TestNavigationThrottleInstaller(
870 shell()->web_contents(), test_case.will_start_result,
871 test_case.will_redirect_result, NavigationThrottle::PROCEED,
872 blocked_subframe_url));
873 }
874
875 {
876 SCOPED_TRACE("Initial navigation blocked on main frame load.");
877 NavigationHandleObserver subframe_observer(shell()->web_contents(),
878 blocked_subframe_url);
879
880 ASSERT_TRUE(NavigateToURL(shell(), main_url));
881 EXPECT_TRUE(subframe_observer.is_error());
882 EXPECT_TRUE(subframe_observer.has_committed());
883 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code());
884 ExpectChildFrameCollapsed(shell(), kChildFrameId,
885 true /* expect_collapsed */);
886 }
887
888 {
889 SCOPED_TRACE("Subsequent subframe navigation is allowed.");
890 NavigationHandleObserver subframe_observer(shell()->web_contents(),
891 allowed_subframe_url);
892
893 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId,
894 allowed_subframe_url));
895 EXPECT_TRUE(subframe_observer.has_committed());
896 EXPECT_FALSE(subframe_observer.is_error());
897 EXPECT_EQ(allowed_subframe_final_url,
898 subframe_observer.last_committed_url());
899 ExpectChildFrameCollapsed(shell(), kChildFrameId,
900 false /* expect_collapsed */);
901 }
902
903 {
904 SCOPED_TRACE("Subsequent subframe navigation is blocked.");
905 NavigationHandleObserver subframe_observer(shell()->web_contents(),
906 blocked_subframe_url);
907
908 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId,
909 blocked_subframe_url));
910
911 EXPECT_TRUE(subframe_observer.has_committed());
912 EXPECT_TRUE(subframe_observer.is_error());
913 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code());
914 ExpectChildFrameCollapsed(shell(), kChildFrameId,
915 true /* expect_collapsed */);
916 }
917 }
918 }
919
920 // BLOCK_REQUEST_AND_COLLAPSE should block the navigation in legacy <frame>'s,
921 // but should not collapse the <frame> element itself for legacy reasons.
922 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
923 ThrottleBlockAndCollapse_LegacyFrameNotCollapsed) {
924 const char kChildFrameId[] = "child0";
925 GURL main_url(embedded_test_server()->GetURL(
926 "a.com", "/frame_tree/legacy_frameset.html"));
927 GURL blocked_subframe_url(
928 embedded_test_server()->GetURL("a.com", "/title1.html"));
929 GURL allowed_subframe_url(
930 embedded_test_server()->GetURL("a.com", "/title2.html"));
931
932 TestNavigationThrottleInstaller subframe_throttle_installer(
933 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE,
934 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED,
935 blocked_subframe_url);
936
937 {
938 SCOPED_TRACE("Initial navigation blocked on main frame load.");
939 NavigationHandleObserver subframe_observer(shell()->web_contents(),
940 blocked_subframe_url);
941
942 ASSERT_TRUE(NavigateToURL(shell(), main_url));
943 EXPECT_TRUE(subframe_observer.is_error());
944 EXPECT_TRUE(subframe_observer.has_committed());
945 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, subframe_observer.net_error_code());
946 ExpectChildFrameSetAsCollapsedInFTN(shell(), true /* expect_collapsed */);
947 ExpectChildFrameCollapsedInLayout(shell(), kChildFrameId,
948 false /* expect_collapsed */);
949 }
950
951 {
952 SCOPED_TRACE("Subsequent subframe navigation is allowed.");
953 NavigationHandleObserver subframe_observer(shell()->web_contents(),
954 allowed_subframe_url);
955
956 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), kChildFrameId,
957 allowed_subframe_url));
958 EXPECT_TRUE(subframe_observer.has_committed());
959 EXPECT_FALSE(subframe_observer.is_error());
960 EXPECT_EQ(allowed_subframe_url, subframe_observer.last_committed_url());
961 ExpectChildFrameCollapsed(shell(), kChildFrameId,
962 false /* expect_collapsed */);
963 }
964 }
965
724 // Checks that the RequestContextType value is properly set. 966 // Checks that the RequestContextType value is properly set.
725 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, 967 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
726 VerifyRequestContextTypeForFrameTree) { 968 VerifyRequestContextTypeForFrameTree) {
727 GURL main_url(embedded_test_server()->GetURL( 969 GURL main_url(embedded_test_server()->GetURL(
728 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); 970 "a.com", "/cross_site_iframe_factory.html?a(b(c))"));
729 GURL b_url(embedded_test_server()->GetURL( 971 GURL b_url(embedded_test_server()->GetURL(
730 "b.com", "/cross_site_iframe_factory.html?b(c())")); 972 "b.com", "/cross_site_iframe_factory.html?b(c())"));
731 GURL c_url(embedded_test_server()->GetURL( 973 GURL c_url(embedded_test_server()->GetURL(
732 "c.com", "/cross_site_iframe_factory.html?c()")); 974 "c.com", "/cross_site_iframe_factory.html?c()"));
733 975
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 NavigationHandleObserver observer(shell()->web_contents(), error_url); 1458 NavigationHandleObserver observer(shell()->web_contents(), error_url);
1217 EXPECT_FALSE(NavigateToURL(shell(), error_url)); 1459 EXPECT_FALSE(NavigateToURL(shell(), error_url));
1218 EXPECT_TRUE(observer.has_committed()); 1460 EXPECT_TRUE(observer.has_committed());
1219 EXPECT_TRUE(observer.is_error()); 1461 EXPECT_TRUE(observer.is_error());
1220 EXPECT_NE(site_instance, 1462 EXPECT_NE(site_instance,
1221 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); 1463 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
1222 } 1464 }
1223 } 1465 }
1224 1466
1225 } // namespace content 1467 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698