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

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

Issue 1964863002: Persist prompt/block download limiter state on renderer-initiated loads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding subframe limiter test Created 4 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 "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 #include "content/browser/web_contents/web_contents_impl.h" 6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/browser/web_contents.h" 7 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_contents_observer.h" 8 #include "content/public/browser/web_contents_observer.h"
9 #include "content/public/test/browser_test_utils.h" 9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h" 10 #include "content/public/test/content_browser_test.h"
(...skipping 11 matching lines...) Expand all
22 22
23 class NavigationHandleObserver : public WebContentsObserver { 23 class NavigationHandleObserver : public WebContentsObserver {
24 public: 24 public:
25 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) 25 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url)
26 : WebContentsObserver(web_contents), 26 : WebContentsObserver(web_contents),
27 handle_(nullptr), 27 handle_(nullptr),
28 has_committed_(false), 28 has_committed_(false),
29 is_error_(false), 29 is_error_(false),
30 is_main_frame_(false), 30 is_main_frame_(false),
31 is_parent_main_frame_(false), 31 is_parent_main_frame_(false),
32 is_renderer_initiated_(true),
32 is_synchronous_(false), 33 is_synchronous_(false),
33 is_srcdoc_(false), 34 is_srcdoc_(false),
34 was_redirected_(false), 35 was_redirected_(false),
35 frame_tree_node_id_(-1), 36 frame_tree_node_id_(-1),
36 page_transition_(ui::PAGE_TRANSITION_LINK), 37 page_transition_(ui::PAGE_TRANSITION_LINK),
37 expected_url_(expected_url) {} 38 expected_url_(expected_url) {}
38 39
39 void DidStartNavigation(NavigationHandle* navigation_handle) override { 40 void DidStartNavigation(NavigationHandle* navigation_handle) override {
40 if (handle_ || navigation_handle->GetURL() != expected_url_) 41 if (handle_ || navigation_handle->GetURL() != expected_url_)
41 return; 42 return;
42 43
43 handle_ = navigation_handle; 44 handle_ = navigation_handle;
44 has_committed_ = false; 45 has_committed_ = false;
45 is_error_ = false; 46 is_error_ = false;
46 page_transition_ = ui::PAGE_TRANSITION_LINK; 47 page_transition_ = ui::PAGE_TRANSITION_LINK;
47 last_committed_url_ = GURL(); 48 last_committed_url_ = GURL();
48 49
49 is_main_frame_ = navigation_handle->IsInMainFrame(); 50 is_main_frame_ = navigation_handle->IsInMainFrame();
50 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); 51 is_parent_main_frame_ = navigation_handle->IsParentMainFrame();
52 is_renderer_initiated_ = navigation_handle->IsRendererInitiated();
51 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); 53 is_synchronous_ = navigation_handle->IsSynchronousNavigation();
52 is_srcdoc_ = navigation_handle->IsSrcdoc(); 54 is_srcdoc_ = navigation_handle->IsSrcdoc();
53 was_redirected_ = navigation_handle->WasServerRedirect(); 55 was_redirected_ = navigation_handle->WasServerRedirect();
54 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); 56 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId();
55 } 57 }
56 58
57 void DidFinishNavigation(NavigationHandle* navigation_handle) override { 59 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
58 if (navigation_handle != handle_) 60 if (navigation_handle != handle_)
59 return; 61 return;
60 62
61 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); 63 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame());
62 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); 64 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame());
63 DCHECK_EQ(is_synchronous_, navigation_handle->IsSynchronousNavigation()); 65 DCHECK_EQ(is_synchronous_, navigation_handle->IsSynchronousNavigation());
66 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated());
64 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc()); 67 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc());
65 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); 68 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId());
66 69
67 was_redirected_ = navigation_handle->WasServerRedirect(); 70 was_redirected_ = navigation_handle->WasServerRedirect();
68 71
69 if (navigation_handle->HasCommitted()) { 72 if (navigation_handle->HasCommitted()) {
70 has_committed_ = true; 73 has_committed_ = true;
71 if (!navigation_handle->IsErrorPage()) { 74 if (!navigation_handle->IsErrorPage()) {
72 page_transition_ = navigation_handle->GetPageTransition(); 75 page_transition_ = navigation_handle->GetPageTransition();
73 last_committed_url_ = navigation_handle->GetURL(); 76 last_committed_url_ = navigation_handle->GetURL();
74 } else { 77 } else {
75 is_error_ = true; 78 is_error_ = true;
76 } 79 }
77 } else { 80 } else {
78 has_committed_ = false; 81 has_committed_ = false;
79 is_error_ = true; 82 is_error_ = true;
80 } 83 }
81 84
82 handle_ = nullptr; 85 handle_ = nullptr;
83 } 86 }
84 87
85 bool has_committed() { return has_committed_; } 88 bool has_committed() { return has_committed_; }
86 bool is_error() { return is_error_; } 89 bool is_error() { return is_error_; }
87 bool is_main_frame() { return is_main_frame_; } 90 bool is_main_frame() { return is_main_frame_; }
88 bool is_parent_main_frame() { return is_parent_main_frame_; } 91 bool is_parent_main_frame() { return is_parent_main_frame_; }
92 bool is_renderer_initiated() { return is_renderer_initiated_; }
89 bool is_synchronous() { return is_synchronous_; } 93 bool is_synchronous() { return is_synchronous_; }
90 bool is_srcdoc() { return is_srcdoc_; } 94 bool is_srcdoc() { return is_srcdoc_; }
91 bool was_redirected() { return was_redirected_; } 95 bool was_redirected() { return was_redirected_; }
92 int frame_tree_node_id() { return frame_tree_node_id_; } 96 int frame_tree_node_id() { return frame_tree_node_id_; }
93 97
94 const GURL& last_committed_url() { return last_committed_url_; } 98 const GURL& last_committed_url() { return last_committed_url_; }
95 99
96 ui::PageTransition page_transition() { return page_transition_; } 100 ui::PageTransition page_transition() { return page_transition_; }
97 101
98 private: 102 private:
99 // A reference to the NavigationHandle so this class will track only 103 // A reference to the NavigationHandle so this class will track only
100 // one navigation at a time. It is set at DidStartNavigation and cleared 104 // one navigation at a time. It is set at DidStartNavigation and cleared
101 // at DidFinishNavigation before the NavigationHandle is destroyed. 105 // at DidFinishNavigation before the NavigationHandle is destroyed.
102 NavigationHandle* handle_; 106 NavigationHandle* handle_;
103 bool has_committed_; 107 bool has_committed_;
104 bool is_error_; 108 bool is_error_;
105 bool is_main_frame_; 109 bool is_main_frame_;
106 bool is_parent_main_frame_; 110 bool is_parent_main_frame_;
111 bool is_renderer_initiated_;
107 bool is_synchronous_; 112 bool is_synchronous_;
108 bool is_srcdoc_; 113 bool is_srcdoc_;
109 bool was_redirected_; 114 bool was_redirected_;
110 int frame_tree_node_id_; 115 int frame_tree_node_id_;
111 ui::PageTransition page_transition_; 116 ui::PageTransition page_transition_;
112 GURL expected_url_; 117 GURL expected_url_;
113 GURL last_committed_url_; 118 GURL last_committed_url_;
114 }; 119 };
115 120
116 // A test NavigationThrottle that will return pre-determined checks and run 121 // A test NavigationThrottle that will return pre-determined checks and run
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 NavigationHandleObserver observer(shell()->web_contents(), url); 385 NavigationHandleObserver observer(shell()->web_contents(), url);
381 386
382 NavigateToURL(shell(), url); 387 NavigateToURL(shell(), url);
383 388
384 EXPECT_TRUE(observer.has_committed()); 389 EXPECT_TRUE(observer.has_committed());
385 EXPECT_FALSE(observer.is_error()); 390 EXPECT_FALSE(observer.is_error());
386 EXPECT_TRUE(observer.was_redirected()); 391 EXPECT_TRUE(observer.was_redirected());
387 } 392 }
388 } 393 }
389 394
395 // Ensure that the IsRendererInitiated() method on NavigationHandle behaves
396 // correctly.
397 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
398 VerifyRendererInitiated) {
399 {
400 // Test browser initiated navigation.
401 GURL url(embedded_test_server()->GetURL("/title1.html"));
402 NavigationHandleObserver observer(shell()->web_contents(), url);
403
404 EXPECT_TRUE(NavigateToURL(shell(), url));
405
406 EXPECT_TRUE(observer.has_committed());
407 EXPECT_FALSE(observer.is_error());
408 EXPECT_FALSE(observer.is_renderer_initiated());
409 }
410
411 {
412 // Test a main frame + subframes navigation.
413 GURL main_url(embedded_test_server()->GetURL(
414 "a.com", "/cross_site_iframe_factory.html?a(b(c))"));
415 GURL b_url(embedded_test_server()->GetURL(
416 "b.com", "/cross_site_iframe_factory.html?b(c())"));
417 GURL c_url(embedded_test_server()->GetURL(
418 "c.com", "/cross_site_iframe_factory.html?c()"));
419
420 NavigationHandleObserver main_observer(shell()->web_contents(), main_url);
421 NavigationHandleObserver b_observer(shell()->web_contents(), b_url);
422 NavigationHandleObserver c_observer(shell()->web_contents(), c_url);
423
424 EXPECT_TRUE(NavigateToURL(shell(), main_url));
425
426 // Verify that the main frame navigation is not renderer initiated.
427 EXPECT_TRUE(main_observer.has_committed());
428 EXPECT_FALSE(main_observer.is_error());
429 EXPECT_FALSE(main_observer.is_renderer_initiated());
430
431 // Verify that the subframe navigations are renderer initiated.
432 EXPECT_TRUE(b_observer.has_committed());
433 EXPECT_FALSE(b_observer.is_error());
434 EXPECT_TRUE(b_observer.is_renderer_initiated());
435 EXPECT_TRUE(c_observer.has_committed());
436 EXPECT_FALSE(c_observer.is_error());
437 EXPECT_TRUE(c_observer.is_renderer_initiated());
438 }
439
440 {
441 // Test a pushState navigation.
442 GURL url(embedded_test_server()->GetURL(
443 "a.com", "/cross_site_iframe_factory.html?a(a())"));
444 EXPECT_TRUE(NavigateToURL(shell(), url));
445
446 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
447 ->GetFrameTree()
448 ->root();
449
450 NavigationHandleObserver observer(
451 shell()->web_contents(),
452 embedded_test_server()->GetURL("a.com", "/bar"));
453 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(),
454 "window.history.pushState({}, '', 'bar');"));
455
456 EXPECT_TRUE(observer.has_committed());
457 EXPECT_FALSE(observer.is_error());
458 EXPECT_TRUE(observer.is_renderer_initiated());
459 }
460 }
461
390 // Ensure that the IsSrcdoc() method on NavigationHandle behaves correctly. 462 // Ensure that the IsSrcdoc() method on NavigationHandle behaves correctly.
391 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) { 463 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) {
392 GURL url(embedded_test_server()->GetURL( 464 GURL url(embedded_test_server()->GetURL(
393 "/frame_tree/page_with_srcdoc_frame.html")); 465 "/frame_tree/page_with_srcdoc_frame.html"));
394 NavigationHandleObserver observer(shell()->web_contents(), 466 NavigationHandleObserver observer(shell()->web_contents(),
395 GURL(url::kAboutBlankURL)); 467 GURL(url::kAboutBlankURL));
396 468
397 EXPECT_TRUE(NavigateToURL(shell(), url)); 469 EXPECT_TRUE(NavigateToURL(shell(), url));
398 470
399 EXPECT_TRUE(observer.has_committed()); 471 EXPECT_TRUE(observer.has_committed());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 navigation_observer.Wait(); 623 navigation_observer.Wait();
552 624
553 EXPECT_TRUE(observer.has_committed()); 625 EXPECT_TRUE(observer.has_committed());
554 EXPECT_TRUE(observer.was_redirected()); 626 EXPECT_TRUE(observer.was_redirected());
555 EXPECT_FALSE(observer.is_error()); 627 EXPECT_FALSE(observer.is_error());
556 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), 628 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(),
557 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); 629 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html")));
558 } 630 }
559 631
560 } // namespace content 632 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698