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

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

Issue 2345053006: Remove IsSynchronous API from NavigationHandle. (Closed)
Patch Set: Addressed review comments. 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 #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/common/request_context_type.h" 9 #include "content/public/common/request_context_type.h"
10 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
(...skipping 17 matching lines...) Expand all
28 public: 28 public:
29 NavigationHandleObserver(WebContents* web_contents, 29 NavigationHandleObserver(WebContents* web_contents,
30 const GURL& expected_start_url) 30 const GURL& expected_start_url)
31 : WebContentsObserver(web_contents), 31 : WebContentsObserver(web_contents),
32 handle_(nullptr), 32 handle_(nullptr),
33 has_committed_(false), 33 has_committed_(false),
34 is_error_(false), 34 is_error_(false),
35 is_main_frame_(false), 35 is_main_frame_(false),
36 is_parent_main_frame_(false), 36 is_parent_main_frame_(false),
37 is_renderer_initiated_(true), 37 is_renderer_initiated_(true),
38 is_synchronous_(false), 38 is_same_page_(false),
39 is_srcdoc_(false), 39 is_srcdoc_(false),
40 was_redirected_(false), 40 was_redirected_(false),
41 frame_tree_node_id_(-1), 41 frame_tree_node_id_(-1),
42 page_transition_(ui::PAGE_TRANSITION_LINK), 42 page_transition_(ui::PAGE_TRANSITION_LINK),
43 expected_start_url_(expected_start_url) {} 43 expected_start_url_(expected_start_url) {}
44 44
45 void DidStartNavigation(NavigationHandle* navigation_handle) override { 45 void DidStartNavigation(NavigationHandle* navigation_handle) override {
46 if (handle_ || navigation_handle->GetURL() != expected_start_url_) 46 if (handle_ || navigation_handle->GetURL() != expected_start_url_)
47 return; 47 return;
48 48
49 handle_ = navigation_handle; 49 handle_ = navigation_handle;
50 has_committed_ = false; 50 has_committed_ = false;
51 is_error_ = false; 51 is_error_ = false;
52 page_transition_ = ui::PAGE_TRANSITION_LINK; 52 page_transition_ = ui::PAGE_TRANSITION_LINK;
53 last_committed_url_ = GURL(); 53 last_committed_url_ = GURL();
54 54
55 is_main_frame_ = navigation_handle->IsInMainFrame(); 55 is_main_frame_ = navigation_handle->IsInMainFrame();
56 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); 56 is_parent_main_frame_ = navigation_handle->IsParentMainFrame();
57 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); 57 is_renderer_initiated_ = navigation_handle->IsRendererInitiated();
58 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); 58 is_same_page_ = navigation_handle->IsSamePage();
59 is_srcdoc_ = navigation_handle->IsSrcdoc(); 59 is_srcdoc_ = navigation_handle->IsSrcdoc();
60 was_redirected_ = navigation_handle->WasServerRedirect(); 60 was_redirected_ = navigation_handle->WasServerRedirect();
61 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); 61 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId();
62 } 62 }
63 63
64 void DidFinishNavigation(NavigationHandle* navigation_handle) override { 64 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
65 if (navigation_handle != handle_) 65 if (navigation_handle != handle_)
66 return; 66 return;
67 67
68 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); 68 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame());
69 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); 69 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame());
70 DCHECK_EQ(is_synchronous_, navigation_handle->IsSynchronousNavigation()); 70 DCHECK_EQ(is_same_page_, navigation_handle->IsSamePage());
71 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); 71 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated());
72 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc()); 72 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc());
73 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); 73 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId());
74 74
75 was_redirected_ = navigation_handle->WasServerRedirect(); 75 was_redirected_ = navigation_handle->WasServerRedirect();
76 76
77 if (navigation_handle->HasCommitted()) { 77 if (navigation_handle->HasCommitted()) {
78 has_committed_ = true; 78 has_committed_ = true;
79 if (!navigation_handle->IsErrorPage()) { 79 if (!navigation_handle->IsErrorPage()) {
80 page_transition_ = navigation_handle->GetPageTransition(); 80 page_transition_ = navigation_handle->GetPageTransition();
81 last_committed_url_ = navigation_handle->GetURL(); 81 last_committed_url_ = navigation_handle->GetURL();
82 } else { 82 } else {
83 is_error_ = true; 83 is_error_ = true;
84 } 84 }
85 } else { 85 } else {
86 has_committed_ = false; 86 has_committed_ = false;
87 is_error_ = true; 87 is_error_ = true;
88 } 88 }
89 89
90 handle_ = nullptr; 90 handle_ = nullptr;
91 } 91 }
92 92
93 bool has_committed() { return has_committed_; } 93 bool has_committed() { return has_committed_; }
94 bool is_error() { return is_error_; } 94 bool is_error() { return is_error_; }
95 bool is_main_frame() { return is_main_frame_; } 95 bool is_main_frame() { return is_main_frame_; }
96 bool is_parent_main_frame() { return is_parent_main_frame_; } 96 bool is_parent_main_frame() { return is_parent_main_frame_; }
97 bool is_renderer_initiated() { return is_renderer_initiated_; } 97 bool is_renderer_initiated() { return is_renderer_initiated_; }
98 bool is_synchronous() { return is_synchronous_; } 98 bool is_same_page() { return is_same_page_; }
99 bool is_srcdoc() { return is_srcdoc_; } 99 bool is_srcdoc() { return is_srcdoc_; }
100 bool was_redirected() { return was_redirected_; } 100 bool was_redirected() { return was_redirected_; }
101 int frame_tree_node_id() { return frame_tree_node_id_; } 101 int frame_tree_node_id() { return frame_tree_node_id_; }
102 102
103 const GURL& last_committed_url() { return last_committed_url_; } 103 const GURL& last_committed_url() { return last_committed_url_; }
104 104
105 ui::PageTransition page_transition() { return page_transition_; } 105 ui::PageTransition page_transition() { return page_transition_; }
106 106
107 private: 107 private:
108 // A reference to the NavigationHandle so this class will track only 108 // A reference to the NavigationHandle so this class will track only
109 // one navigation at a time. It is set at DidStartNavigation and cleared 109 // one navigation at a time. It is set at DidStartNavigation and cleared
110 // at DidFinishNavigation before the NavigationHandle is destroyed. 110 // at DidFinishNavigation before the NavigationHandle is destroyed.
111 NavigationHandle* handle_; 111 NavigationHandle* handle_;
112 bool has_committed_; 112 bool has_committed_;
113 bool is_error_; 113 bool is_error_;
114 bool is_main_frame_; 114 bool is_main_frame_;
115 bool is_parent_main_frame_; 115 bool is_parent_main_frame_;
116 bool is_renderer_initiated_; 116 bool is_renderer_initiated_;
117 bool is_synchronous_; 117 bool is_same_page_;
118 bool is_srcdoc_; 118 bool is_srcdoc_;
119 bool was_redirected_; 119 bool was_redirected_;
120 int frame_tree_node_id_; 120 int frame_tree_node_id_;
121 ui::PageTransition page_transition_; 121 ui::PageTransition page_transition_;
122 GURL expected_start_url_; 122 GURL expected_start_url_;
123 GURL last_committed_url_; 123 GURL last_committed_url_;
124 }; 124 };
125 125
126 // A test NavigationThrottle that will return pre-determined checks and run 126 // A test NavigationThrottle that will return pre-determined checks and run
127 // callbacks when the various NavigationThrottle methods are called. It is 127 // callbacks when the various NavigationThrottle methods are called. It is
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 NavigationHandleObserver observer(shell()->web_contents(), 511 NavigationHandleObserver observer(shell()->web_contents(),
512 GURL(url::kAboutBlankURL)); 512 GURL(url::kAboutBlankURL));
513 513
514 EXPECT_TRUE(NavigateToURL(shell(), url)); 514 EXPECT_TRUE(NavigateToURL(shell(), url));
515 515
516 EXPECT_TRUE(observer.has_committed()); 516 EXPECT_TRUE(observer.has_committed());
517 EXPECT_FALSE(observer.is_error()); 517 EXPECT_FALSE(observer.is_error());
518 EXPECT_TRUE(observer.is_srcdoc()); 518 EXPECT_TRUE(observer.is_srcdoc());
519 } 519 }
520 520
521 // Ensure that the IsSynchronousNavigation() method on NavigationHandle behaves 521 // Ensure that the IsSamePage() method on NavigationHandle behaves correctly.
522 // correctly. 522 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySamePage) {
523 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySynchronous) {
524 GURL url(embedded_test_server()->GetURL( 523 GURL url(embedded_test_server()->GetURL(
525 "a.com", "/cross_site_iframe_factory.html?a(a())")); 524 "a.com", "/cross_site_iframe_factory.html?a(a())"));
526 EXPECT_TRUE(NavigateToURL(shell(), url)); 525 EXPECT_TRUE(NavigateToURL(shell(), url));
527 526
528 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 527 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
529 ->GetFrameTree() 528 ->GetFrameTree()
530 ->root(); 529 ->root();
530 {
531 NavigationHandleObserver observer(
532 shell()->web_contents(),
533 embedded_test_server()->GetURL("a.com", "/foo"));
534 EXPECT_TRUE(ExecuteScript(root->child_at(0),
535 "window.history.pushState({}, '', 'foo');"));
531 536
532 NavigationHandleObserver observer( 537 EXPECT_TRUE(observer.has_committed());
533 shell()->web_contents(), embedded_test_server()->GetURL("a.com", "/bar")); 538 EXPECT_FALSE(observer.is_error());
534 EXPECT_TRUE(ExecuteScript(root->child_at(0), 539 EXPECT_TRUE(observer.is_same_page());
535 "window.history.pushState({}, '', 'bar');")); 540 }
541 {
542 NavigationHandleObserver observer(
543 shell()->web_contents(),
544 embedded_test_server()->GetURL("a.com", "/bar"));
545 EXPECT_TRUE(ExecuteScript(root->child_at(0),
546 "window.history.replaceState({}, '', 'bar');"));
536 547
537 EXPECT_TRUE(observer.has_committed()); 548 EXPECT_TRUE(observer.has_committed());
538 EXPECT_FALSE(observer.is_error()); 549 EXPECT_FALSE(observer.is_error());
539 EXPECT_TRUE(observer.is_synchronous()); 550 EXPECT_TRUE(observer.is_same_page());
551 }
552 {
553 NavigationHandleObserver observer(
554 shell()->web_contents(),
555 embedded_test_server()->GetURL("a.com", "/bar#frag"));
556 EXPECT_TRUE(
557 ExecuteScript(root->child_at(0), "window.location.replace('#frag');"));
558
559 EXPECT_TRUE(observer.has_committed());
560 EXPECT_FALSE(observer.is_error());
561 EXPECT_TRUE(observer.is_same_page());
562 }
563
564 GURL about_blank_url(url::kAboutBlankURL);
565 {
566 NavigationHandleObserver observer(shell()->web_contents(), about_blank_url);
567 EXPECT_TRUE(ExecuteScript(
568 root, "document.body.appendChild(document.createElement('iframe'));"));
569
570 EXPECT_TRUE(observer.has_committed());
571 EXPECT_FALSE(observer.is_error());
572 EXPECT_FALSE(observer.is_same_page());
573 EXPECT_EQ(about_blank_url, observer.last_committed_url());
574 }
575 {
576 NavigationHandleObserver observer(shell()->web_contents(), about_blank_url);
577 NavigateFrameToURL(root->child_at(0), about_blank_url);
578
579 EXPECT_TRUE(observer.has_committed());
580 EXPECT_FALSE(observer.is_error());
581 EXPECT_FALSE(observer.is_same_page());
582 EXPECT_EQ(about_blank_url, observer.last_committed_url());
583 }
540 } 584 }
541 585
542 // Ensure that a NavigationThrottle can cancel the navigation at navigation 586 // Ensure that a NavigationThrottle can cancel the navigation at navigation
543 // start. 587 // start.
544 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, ThrottleCancelStart) { 588 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, ThrottleCancelStart) {
545 GURL start_url(embedded_test_server()->GetURL("/title1.html")); 589 GURL start_url(embedded_test_server()->GetURL("/title1.html"));
546 EXPECT_TRUE(NavigateToURL(shell(), start_url)); 590 EXPECT_TRUE(NavigateToURL(shell(), start_url));
547 591
548 GURL redirect_url( 592 GURL redirect_url(
549 embedded_test_server()->GetURL("/cross-site/bar.com/title2.html")); 593 embedded_test_server()->GetURL("/cross-site/bar.com/title2.html"));
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, 902 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest,
859 StartUrlIsHttpsUpgradedCrossSite) { 903 StartUrlIsHttpsUpgradedCrossSite) {
860 GURL start_url( 904 GURL start_url(
861 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); 905 embedded_test_server()->GetURL("/https_upgrade_cross_site.html"));
862 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); 906 GURL cross_site_iframe_secure_url("https://other.com/title1.html");
863 907
864 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); 908 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url);
865 } 909 }
866 910
867 } // namespace content 911 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/frame_host/navigation_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698