| 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 "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 18 matching lines...) Expand all Loading... |
| 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_same_page_(false), | 38 is_same_page_(false), |
| 39 is_srcdoc_(false), | |
| 40 was_redirected_(false), | 39 was_redirected_(false), |
| 41 frame_tree_node_id_(-1), | 40 frame_tree_node_id_(-1), |
| 42 page_transition_(ui::PAGE_TRANSITION_LINK), | 41 page_transition_(ui::PAGE_TRANSITION_LINK), |
| 43 expected_start_url_(expected_start_url) {} | 42 expected_start_url_(expected_start_url) {} |
| 44 | 43 |
| 45 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 44 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
| 46 if (handle_ || navigation_handle->GetURL() != expected_start_url_) | 45 if (handle_ || navigation_handle->GetURL() != expected_start_url_) |
| 47 return; | 46 return; |
| 48 | 47 |
| 49 handle_ = navigation_handle; | 48 handle_ = navigation_handle; |
| 50 has_committed_ = false; | 49 has_committed_ = false; |
| 51 is_error_ = false; | 50 is_error_ = false; |
| 52 page_transition_ = ui::PAGE_TRANSITION_LINK; | 51 page_transition_ = ui::PAGE_TRANSITION_LINK; |
| 53 last_committed_url_ = GURL(); | 52 last_committed_url_ = GURL(); |
| 54 | 53 |
| 55 is_main_frame_ = navigation_handle->IsInMainFrame(); | 54 is_main_frame_ = navigation_handle->IsInMainFrame(); |
| 56 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); | 55 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); |
| 57 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); | 56 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); |
| 58 is_same_page_ = navigation_handle->IsSamePage(); | 57 is_same_page_ = navigation_handle->IsSamePage(); |
| 59 is_srcdoc_ = navigation_handle->IsSrcdoc(); | |
| 60 was_redirected_ = navigation_handle->WasServerRedirect(); | 58 was_redirected_ = navigation_handle->WasServerRedirect(); |
| 61 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); | 59 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 62 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| 65 if (navigation_handle != handle_) | 63 if (navigation_handle != handle_) |
| 66 return; | 64 return; |
| 67 | 65 |
| 68 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); | 66 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); |
| 69 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); | 67 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); |
| 70 DCHECK_EQ(is_same_page_, navigation_handle->IsSamePage()); | 68 DCHECK_EQ(is_same_page_, navigation_handle->IsSamePage()); |
| 71 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); | 69 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); |
| 72 DCHECK_EQ(is_srcdoc_, navigation_handle->IsSrcdoc()); | |
| 73 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); | 70 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); |
| 74 | 71 |
| 75 was_redirected_ = navigation_handle->WasServerRedirect(); | 72 was_redirected_ = navigation_handle->WasServerRedirect(); |
| 76 | 73 |
| 77 if (navigation_handle->HasCommitted()) { | 74 if (navigation_handle->HasCommitted()) { |
| 78 has_committed_ = true; | 75 has_committed_ = true; |
| 79 if (!navigation_handle->IsErrorPage()) { | 76 if (!navigation_handle->IsErrorPage()) { |
| 80 page_transition_ = navigation_handle->GetPageTransition(); | 77 page_transition_ = navigation_handle->GetPageTransition(); |
| 81 last_committed_url_ = navigation_handle->GetURL(); | 78 last_committed_url_ = navigation_handle->GetURL(); |
| 82 } else { | 79 } else { |
| 83 is_error_ = true; | 80 is_error_ = true; |
| 84 } | 81 } |
| 85 } else { | 82 } else { |
| 86 has_committed_ = false; | 83 has_committed_ = false; |
| 87 is_error_ = true; | 84 is_error_ = true; |
| 88 } | 85 } |
| 89 | 86 |
| 90 handle_ = nullptr; | 87 handle_ = nullptr; |
| 91 } | 88 } |
| 92 | 89 |
| 93 bool has_committed() { return has_committed_; } | 90 bool has_committed() { return has_committed_; } |
| 94 bool is_error() { return is_error_; } | 91 bool is_error() { return is_error_; } |
| 95 bool is_main_frame() { return is_main_frame_; } | 92 bool is_main_frame() { return is_main_frame_; } |
| 96 bool is_parent_main_frame() { return is_parent_main_frame_; } | 93 bool is_parent_main_frame() { return is_parent_main_frame_; } |
| 97 bool is_renderer_initiated() { return is_renderer_initiated_; } | 94 bool is_renderer_initiated() { return is_renderer_initiated_; } |
| 98 bool is_same_page() { return is_same_page_; } | 95 bool is_same_page() { return is_same_page_; } |
| 99 bool is_srcdoc() { return is_srcdoc_; } | |
| 100 bool was_redirected() { return was_redirected_; } | 96 bool was_redirected() { return was_redirected_; } |
| 101 int frame_tree_node_id() { return frame_tree_node_id_; } | 97 int frame_tree_node_id() { return frame_tree_node_id_; } |
| 102 | 98 |
| 103 const GURL& last_committed_url() { return last_committed_url_; } | 99 const GURL& last_committed_url() { return last_committed_url_; } |
| 104 | 100 |
| 105 ui::PageTransition page_transition() { return page_transition_; } | 101 ui::PageTransition page_transition() { return page_transition_; } |
| 106 | 102 |
| 107 private: | 103 private: |
| 108 // A reference to the NavigationHandle so this class will track only | 104 // A reference to the NavigationHandle so this class will track only |
| 109 // one navigation at a time. It is set at DidStartNavigation and cleared | 105 // one navigation at a time. It is set at DidStartNavigation and cleared |
| 110 // at DidFinishNavigation before the NavigationHandle is destroyed. | 106 // at DidFinishNavigation before the NavigationHandle is destroyed. |
| 111 NavigationHandle* handle_; | 107 NavigationHandle* handle_; |
| 112 bool has_committed_; | 108 bool has_committed_; |
| 113 bool is_error_; | 109 bool is_error_; |
| 114 bool is_main_frame_; | 110 bool is_main_frame_; |
| 115 bool is_parent_main_frame_; | 111 bool is_parent_main_frame_; |
| 116 bool is_renderer_initiated_; | 112 bool is_renderer_initiated_; |
| 117 bool is_same_page_; | 113 bool is_same_page_; |
| 118 bool is_srcdoc_; | |
| 119 bool was_redirected_; | 114 bool was_redirected_; |
| 120 int frame_tree_node_id_; | 115 int frame_tree_node_id_; |
| 121 ui::PageTransition page_transition_; | 116 ui::PageTransition page_transition_; |
| 122 GURL expected_start_url_; | 117 GURL expected_start_url_; |
| 123 GURL last_committed_url_; | 118 GURL last_committed_url_; |
| 124 }; | 119 }; |
| 125 | 120 |
| 126 // A test NavigationThrottle that will return pre-determined checks and run | 121 // A test NavigationThrottle that will return pre-determined checks and run |
| 127 // callbacks when the various NavigationThrottle methods are called. It is | 122 // callbacks when the various NavigationThrottle methods are called. It is |
| 128 // not instantiated directly but through a TestNavigationThrottleInstaller. | 123 // not instantiated directly but through a TestNavigationThrottleInstaller. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 embedded_test_server()->GetURL("a.com", "/bar")); | 492 embedded_test_server()->GetURL("a.com", "/bar")); |
| 498 EXPECT_TRUE(ExecuteScript(root->child_at(0), | 493 EXPECT_TRUE(ExecuteScript(root->child_at(0), |
| 499 "window.history.pushState({}, '', 'bar');")); | 494 "window.history.pushState({}, '', 'bar');")); |
| 500 | 495 |
| 501 EXPECT_TRUE(observer.has_committed()); | 496 EXPECT_TRUE(observer.has_committed()); |
| 502 EXPECT_FALSE(observer.is_error()); | 497 EXPECT_FALSE(observer.is_error()); |
| 503 EXPECT_TRUE(observer.is_renderer_initiated()); | 498 EXPECT_TRUE(observer.is_renderer_initiated()); |
| 504 } | 499 } |
| 505 } | 500 } |
| 506 | 501 |
| 507 // Ensure that the IsSrcdoc() method on NavigationHandle behaves correctly. | 502 // Ensure that methods on NavigationHandle behave correctly with an iframe that |
| 503 // navigates to its srcdoc attribute. |
| 508 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) { | 504 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySrcdoc) { |
| 509 GURL url(embedded_test_server()->GetURL( | 505 GURL url(embedded_test_server()->GetURL( |
| 510 "/frame_tree/page_with_srcdoc_frame.html")); | 506 "/frame_tree/page_with_srcdoc_frame.html")); |
| 511 NavigationHandleObserver observer(shell()->web_contents(), | 507 NavigationHandleObserver observer(shell()->web_contents(), |
| 512 GURL(url::kAboutBlankURL)); | 508 GURL(kAboutSrcDocURL)); |
| 513 | 509 |
| 514 EXPECT_TRUE(NavigateToURL(shell(), url)); | 510 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 515 | 511 |
| 516 EXPECT_TRUE(observer.has_committed()); | 512 EXPECT_TRUE(observer.has_committed()); |
| 517 EXPECT_FALSE(observer.is_error()); | 513 EXPECT_FALSE(observer.is_error()); |
| 518 EXPECT_TRUE(observer.is_srcdoc()); | 514 EXPECT_EQ(GURL(kAboutSrcDocURL), observer.last_committed_url()); |
| 519 } | 515 } |
| 520 | 516 |
| 521 // Ensure that the IsSamePage() method on NavigationHandle behaves correctly. | 517 // Ensure that the IsSamePage() method on NavigationHandle behaves correctly. |
| 522 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySamePage) { | 518 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, VerifySamePage) { |
| 523 GURL url(embedded_test_server()->GetURL( | 519 GURL url(embedded_test_server()->GetURL( |
| 524 "a.com", "/cross_site_iframe_factory.html?a(a())")); | 520 "a.com", "/cross_site_iframe_factory.html?a(a())")); |
| 525 EXPECT_TRUE(NavigateToURL(shell(), url)); | 521 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 526 | 522 |
| 527 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 523 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 528 ->GetFrameTree() | 524 ->GetFrameTree() |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, | 898 IN_PROC_BROWSER_TEST_F(NavigationHandleImplHttpsUpgradeBrowserTest, |
| 903 StartUrlIsHttpsUpgradedCrossSite) { | 899 StartUrlIsHttpsUpgradedCrossSite) { |
| 904 GURL start_url( | 900 GURL start_url( |
| 905 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); | 901 embedded_test_server()->GetURL("/https_upgrade_cross_site.html")); |
| 906 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); | 902 GURL cross_site_iframe_secure_url("https://other.com/title1.html"); |
| 907 | 903 |
| 908 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); | 904 CheckHttpsUpgradedIframeNavigation(start_url, cross_site_iframe_secure_url); |
| 909 } | 905 } |
| 910 | 906 |
| 911 } // namespace content | 907 } // namespace content |
| OLD | NEW |