Chromium Code Reviews| 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 5f5d0c8fb7327a0f5fde19756cdd65978e2efcfa..486f6a5ffa55f549cb2dd8c98396ede25e168718 100644 |
| --- a/content/browser/frame_host/navigation_handle_impl_browsertest.cc |
| +++ b/content/browser/frame_host/navigation_handle_impl_browsertest.cc |
| @@ -6,6 +6,7 @@ |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/common/request_context_type.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/content_browser_test.h" |
| #include "content/public/test/content_browser_test_utils.h" |
| @@ -146,20 +147,41 @@ class TestNavigationThrottle : public NavigationThrottle { |
| void Resume() { navigation_handle()->Resume(); } |
| + RequestContextType fetch_request_context_type() { |
| + return fetch_request_context_type_; |
| + } |
| + |
| private: |
| // NavigationThrottle implementation. |
| NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
| + NavigationHandleImpl* navigation_handle_impl = |
| + static_cast<NavigationHandleImpl*>(navigation_handle()); |
| + CHECK_NE(REQUEST_CONTEXT_TYPE_UNSPECIFIED, |
|
nasko
2016/07/21 22:04:35
Why would it be unspecified? At the start of the r
carlosk
2016/07/22 12:51:26
The only thing we know here is that it should have
|
| + navigation_handle_impl->fetch_request_context_type()); |
| + fetch_request_context_type_ = |
| + navigation_handle_impl->fetch_request_context_type(); |
| + |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, did_call_will_start_); |
| return will_start_result_; |
| } |
| NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { |
| + NavigationHandleImpl* navigation_handle_impl = |
| + static_cast<NavigationHandleImpl*>(navigation_handle()); |
| + CHECK_EQ(fetch_request_context_type_, |
| + navigation_handle_impl->fetch_request_context_type()); |
| + |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| did_call_will_redirect_); |
| return will_redirect_result_; |
| } |
| NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { |
| + NavigationHandleImpl* navigation_handle_impl = |
| + static_cast<NavigationHandleImpl*>(navigation_handle()); |
| + CHECK_EQ(fetch_request_context_type_, |
| + navigation_handle_impl->fetch_request_context_type()); |
| + |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| did_call_will_process_); |
| return will_process_result_; |
| @@ -171,6 +193,7 @@ class TestNavigationThrottle : public NavigationThrottle { |
| base::Closure did_call_will_start_; |
| base::Closure did_call_will_redirect_; |
| base::Closure did_call_will_process_; |
| + RequestContextType fetch_request_context_type_; |
| }; |
| // Install a TestNavigationThrottle on all following requests and allows waiting |
| @@ -654,6 +677,62 @@ IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, ThrottleDefer) { |
| GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
| } |
| +// Checks that the RequestContextType value is properly set. |
| +IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
| + VerifyRequestContextType) { |
| + GURL main_url(embedded_test_server()->GetURL( |
| + "a.com", "/cross_site_iframe_factory.html?a(b(c))")); |
|
clamy
2016/07/21 11:30:21
I'm not sure I see the point of testing frame c he
nasko
2016/07/21 22:04:35
Actually, testing a frame that is not direct child
carlosk
2016/07/22 12:51:26
Oh well... I had removed the testing of the extra
clamy
2016/07/22 13:51:31
I think it's normal that a navigation to an image
carlosk
2016/07/22 16:00:29
Acknowledged.
|
| + GURL b_url(embedded_test_server()->GetURL( |
| + "b.com", "/cross_site_iframe_factory.html?b(c())")); |
| + GURL c_url(embedded_test_server()->GetURL( |
| + "c.com", "/cross_site_iframe_factory.html?c()")); |
| + |
| + TestNavigationThrottleInstaller installer( |
| + shell()->web_contents(), NavigationThrottle::PROCEED, |
| + NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
| + TestNavigationManager main_manager(shell()->web_contents(), main_url); |
| + TestNavigationManager b_manager(shell()->web_contents(), b_url); |
| + TestNavigationManager c_manager(shell()->web_contents(), c_url); |
| + NavigationStartUrlRecorder url_recorder(shell()->web_contents()); |
| + TestNavigationThrottle* last_throttle = nullptr; |
| + |
| + // Waits until the end of the main frame navigation. |
| + shell()->LoadURL(main_url); |
| + main_manager.WaitForWillStartRequest(); |
| + // Checks the navigation is the one expected for the main frame. |
| + EXPECT_NE(last_throttle, installer.navigation_throttle()); |
| + EXPECT_EQ(main_url, url_recorder.urls().back()); |
| + EXPECT_EQ(1ul, url_recorder.urls().size()); |
| + // Checks the main frame RequestContextType. |
| + EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| + installer.navigation_throttle()->fetch_request_context_type()); |
| + last_throttle = installer.navigation_throttle(); |
| + |
| + // Ditto for frame b. |
| + main_manager.WaitForNavigationFinished(); |
| + b_manager.WaitForWillStartRequest(); |
| + EXPECT_NE(last_throttle, installer.navigation_throttle()); |
| + EXPECT_EQ(b_url, url_recorder.urls().back()); |
| + EXPECT_EQ(2ul, url_recorder.urls().size()); |
| + EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| + installer.navigation_throttle()->fetch_request_context_type()); |
| + last_throttle = installer.navigation_throttle(); |
| + |
| + // Ditto for frame c. |
| + b_manager.WaitForNavigationFinished(); |
| + c_manager.WaitForWillStartRequest(); |
| + EXPECT_NE(last_throttle, installer.navigation_throttle()); |
| + EXPECT_EQ(c_url, url_recorder.urls().back()); |
| + EXPECT_EQ(3ul, url_recorder.urls().size()); |
| + EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION, |
| + installer.navigation_throttle()->fetch_request_context_type()); |
| + last_throttle = installer.navigation_throttle(); |
| + |
| + // Lets the final navigation finish so that we conclude running the checks |
| + // that happen in TestNavigationThrottle. |
| + c_manager.WaitForNavigationFinished(); |
| +} |
| + |
| // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded |
| // URL from the very beginning of the navigation. |
| class NavigationHandleImplHttpsUpgradeBrowserTest |