Index: content/browser/frame_host/navigation_handle_impl_browsertest.cc |
diff --git a/content/browser/frame_host/navigation_handle_impl_browsertest.cc b/content/browser/frame_host/navigation_handle_impl_browsertest.cc |
index d9ab400ec2e47a47b33fb7fb5f526066d0595c13..172828f6cd00efa09fa71bb684ef6a7a020f2471 100644 |
--- a/content/browser/frame_host/navigation_handle_impl_browsertest.cc |
+++ b/content/browser/frame_host/navigation_handle_impl_browsertest.cc |
@@ -21,9 +21,13 @@ namespace content { |
namespace { |
+// Gathers data from the NavigationHandle assigned to navigations that start |
+// with the expected URL. Overlapping navigations are ignored; create new |
+// instances as needed. |
class NavigationHandleObserver : public WebContentsObserver { |
public: |
- NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) |
+ NavigationHandleObserver(WebContents* web_contents, |
+ const GURL& expected_start_url) |
: WebContentsObserver(web_contents), |
handle_(nullptr), |
has_committed_(false), |
@@ -36,11 +40,13 @@ class NavigationHandleObserver : public WebContentsObserver { |
was_redirected_(false), |
frame_tree_node_id_(-1), |
page_transition_(ui::PAGE_TRANSITION_LINK), |
- expected_url_(expected_url) {} |
+ expected_start_url_(expected_start_url) {} |
void DidStartNavigation(NavigationHandle* navigation_handle) override { |
- if (handle_ || navigation_handle->GetURL() != expected_url_) |
+ if (handle_ || navigation_handle->GetURL() != expected_start_url_) { |
+ last_unmatched_start_url_ = navigation_handle->GetURL(); |
return; |
+ } |
handle_ = navigation_handle; |
has_committed_ = false; |
@@ -96,6 +102,7 @@ class NavigationHandleObserver : public WebContentsObserver { |
bool was_redirected() { return was_redirected_; } |
int frame_tree_node_id() { return frame_tree_node_id_; } |
+ const GURL& last_unmatched_start_url() { return last_unmatched_start_url_; } |
const GURL& last_committed_url() { return last_committed_url_; } |
ui::PageTransition page_transition() { return page_transition_; } |
@@ -115,12 +122,15 @@ class NavigationHandleObserver : public WebContentsObserver { |
bool was_redirected_; |
int frame_tree_node_id_; |
ui::PageTransition page_transition_; |
- GURL expected_url_; |
+ GURL expected_start_url_; |
+ GURL last_unmatched_start_url_; |
GURL last_committed_url_; |
}; |
// A test NavigationThrottle that will return pre-determined checks and run |
-// callbacks when the various NavigationThrottle methods are called. |
+// callbacks when the various NavigationThrottle methods are called. This is |
+// generally not instantiated directly but through a |
+// TestNavigationThrottleInstaller. |
class TestNavigationThrottle : public NavigationThrottle { |
public: |
TestNavigationThrottle( |
@@ -170,7 +180,8 @@ class TestNavigationThrottle : public NavigationThrottle { |
}; |
// Install a TestNavigationThrottle on all requests and allows waiting for |
-// various NavigationThrottle related events. |
+// various NavigationThrottle related events. Waiting is only allows for the |
+// immediately next navigation; create new instances as needed. |
class TestNavigationThrottleInstaller : public WebContentsObserver { |
public: |
TestNavigationThrottleInstaller( |
@@ -191,24 +202,21 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { |
TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } |
void WaitForThrottleWillStart() { |
- if (will_start_called_) |
- return; |
+ CHECK(!will_start_called_); |
will_start_loop_runner_ = new MessageLoopRunner(); |
will_start_loop_runner_->Run(); |
will_start_loop_runner_ = nullptr; |
} |
void WaitForThrottleWillRedirect() { |
- if (will_redirect_called_) |
- return; |
+ CHECK(!will_redirect_called_); |
will_redirect_loop_runner_ = new MessageLoopRunner(); |
will_redirect_loop_runner_->Run(); |
will_redirect_loop_runner_ = nullptr; |
} |
void WaitForThrottleWillProcess() { |
- if (will_process_called_) |
- return; |
+ CHECK(!will_process_called_); |
will_process_loop_runner_ = new MessageLoopRunner(); |
will_process_loop_runner_->Run(); |
will_process_loop_runner_ = nullptr; |
@@ -632,4 +640,65 @@ IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, ThrottleDefer) { |
GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
} |
+// Ensure that the URL received with the provisional load start notification is |
+// already upgraded to HTTPS. |
+IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
+ ProvisionalLoadStartUrlIsHttpsUpgraded) { |
+ GURL start_url(embedded_test_server()->GetURL( |
+ "/navigation_handle_https_upgrade_test.html")); |
+ ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); |
+ |
+ // Builds the expected upgraded URL. |
+ GURL::Replacements replace_scheme; |
+ replace_scheme.SetSchemeStr("https"); |
+ replace_scheme.SetPortStr(""); |
+ GURL iframe_secure_url = embedded_test_server() |
+ ->GetURL("other.com", "/title1.html") |
+ .ReplaceComponents(replace_scheme); |
+ ASSERT_TRUE(iframe_secure_url.SchemeIs(url::kHttpsScheme)); |
+ ASSERT_FALSE(iframe_secure_url.has_port()); |
Mike West
2016/07/04 08:33:25
I'm missing something; how does this work? Don't y
carlosk
2016/07/04 09:22:59
I'm testing only if the URL received by the Naviga
Mike West
2016/07/04 09:31:43
The upgrade should not remove the port. That is, `
carlosk
2016/07/05 09:57:23
I updated the test so that it will check the same
|
+ |
+ NavigationHandleObserver observer_main(shell()->web_contents(), start_url); |
+ NavigationHandleObserver observer_iframe(shell()->web_contents(), |
+ iframe_secure_url); |
+ TestNavigationThrottleInstaller installer_main( |
+ shell()->web_contents(), NavigationThrottle::PROCEED, |
+ NavigationThrottle::PROCEED, NavigationThrottle::DEFER); |
+ |
+ // Start loading the main frame and stop at WillProcess. |
+ shell()->LoadURL(start_url); |
+ installer_main.WaitForThrottleWillProcess(); |
+ EXPECT_EQ(1, installer_main.will_start_called()); |
+ EXPECT_EQ(0, installer_main.will_redirect_called()); |
+ EXPECT_EQ(1, installer_main.will_process_called()); |
+ |
+ // Create a new throttle installer and start the iframe navigation until |
+ // WillStart. |
+ TestNavigationThrottleInstaller installer_iframe( |
+ shell()->web_contents(), NavigationThrottle::DEFER, |
+ NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
+ installer_main.navigation_throttle()->Resume(); |
+ installer_iframe.WaitForThrottleWillStart(); |
+ EXPECT_EQ(1, installer_iframe.will_start_called()); |
+ EXPECT_EQ(0, installer_iframe.will_redirect_called()); |
+ EXPECT_EQ(0, installer_iframe.will_process_called()); |
+ |
+ // Confirm the navigation of the main frame succeeded. |
+ EXPECT_NE(-1, observer_main.frame_tree_node_id()); |
+ EXPECT_EQ(start_url, observer_main.last_committed_url()); |
+ EXPECT_TRUE(observer_main.has_committed()); |
+ EXPECT_TRUE(observer_main.is_main_frame()); |
+ EXPECT_FALSE(observer_main.is_renderer_initiated()); |
+ |
+ // Check that the handle observer did receive the start call with the correct |
+ // URL. |
+ ASSERT_NE(-1, observer_iframe.frame_tree_node_id()) |
+ << "The start URL \"" << observer_iframe.last_unmatched_start_url() |
+ << "\" didn't match the expected \"" << iframe_secure_url << "\""; |
+ EXPECT_FALSE(observer_iframe.has_committed()); |
+ EXPECT_FALSE(observer_iframe.is_main_frame()); |
+ EXPECT_TRUE(observer_iframe.is_parent_main_frame()); |
+ EXPECT_TRUE(observer_iframe.is_renderer_initiated()); |
+} |
+ |
} // namespace content |