Chromium Code Reviews| Index: content/browser/site_per_process_browsertest.cc |
| diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc |
| index 145a24989e38d3e9a892162161c3f22a647c6f6c..36cc8882b005601d3096ba79786f51cc81ccad02 100644 |
| --- a/content/browser/site_per_process_browsertest.cc |
| +++ b/content/browser/site_per_process_browsertest.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/command_line.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "content/browser/frame_host/cross_process_frame_connector.h" |
| #include "content/browser/frame_host/frame_tree.h" |
| #include "content/browser/frame_host/navigator.h" |
| @@ -165,7 +166,7 @@ void SitePerProcessBrowserTest::StartFrameAtDataURL() { |
| ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); |
| } |
| -bool SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window, |
| +void SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window, |
|
Charlie Reis
2014/12/06 00:18:51
Please don't change this. It's more useful to hav
lfg
2014/12/08 20:45:33
I agree it's more useful to see the test immediate
Charlie Reis
2014/12/09 19:14:37
Ah, good point. Instead, let's return false befor
|
| const GURL& url, |
| std::string iframe_id) { |
| // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
| @@ -182,9 +183,8 @@ bool SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window, |
| NOTIFICATION_NAV_ENTRY_COMMITTED, |
| Source<NavigationController>( |
| &window->web_contents()->GetController())); |
| - bool result = ExecuteScript(window->web_contents(), script); |
| + EXPECT_TRUE(ExecuteScript(window->web_contents(), script)); |
| load_observer.Wait(); |
| - return result; |
| } |
| void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
| @@ -361,10 +361,9 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { |
| std::string foo_com("foo.com"); |
| // Load cross-site page into iframe. |
| - EXPECT_TRUE(NavigateIframeToURL( |
| - shell(), |
| - embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"), |
| - "test")); |
| + NavigateIframeToURL(shell(), embedded_test_server()->GetURL( |
| + "/cross-site/foo.com/title2.html"), |
| + "test"); |
| // Check the subframe process. |
| FrameTreeNode* root = |
| @@ -438,8 +437,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| // Should be blocked. |
| GURL client_redirect_https_url(https_server.GetURL( |
| "client-redirect?files/title1.html")); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - client_redirect_https_url, "test")); |
| + NavigateIframeToURL(shell(), client_redirect_https_url, "test"); |
| // DidFailProvisionalLoad when navigating to client_redirect_https_url. |
| EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); |
| EXPECT_FALSE(observer.navigation_succeeded()); |
| @@ -450,8 +448,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| // which redirects to same-site page. |
| GURL server_redirect_http_url(https_server.GetURL( |
| "server-redirect?" + http_url.spec())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| EXPECT_EQ(observer.navigation_url(), http_url); |
| EXPECT_TRUE(observer.navigation_succeeded()); |
| } |
| @@ -461,8 +458,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| // which redirects to cross-site page. |
| GURL server_redirect_http_url(https_server.GetURL( |
| "server-redirect?files/title1.html")); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| // DidFailProvisionalLoad when navigating to https_url. |
| EXPECT_EQ(observer.navigation_url(), https_url); |
| EXPECT_FALSE(observer.navigation_succeeded()); |
| @@ -473,8 +469,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| // which redirects to cross-site page. |
| GURL server_redirect_http_url(test_server()->GetURL( |
| "server-redirect?" + https_url.spec())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| EXPECT_EQ(observer.navigation_url(), https_url); |
| EXPECT_FALSE(observer.navigation_succeeded()); |
| @@ -491,8 +486,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| Source<NavigationController>( |
| &shell()->web_contents()->GetController())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - client_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), client_redirect_http_url, "test"); |
| // Same-site Client-Redirect Page should be loaded successfully. |
| EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| @@ -507,10 +501,9 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| { |
| // Load same-site server-redirect page into Iframe, |
| // which redirects to same-site page. |
| - GURL server_redirect_http_url(test_server()->GetURL( |
| - "server-redirect?files/title1.html")); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - server_redirect_http_url, "test")); |
| + GURL server_redirect_http_url( |
| + test_server()->GetURL("server-redirect?files/title1.html")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| EXPECT_EQ(observer.navigation_url(), http_url); |
| EXPECT_TRUE(observer.navigation_succeeded()); |
| } |
| @@ -525,8 +518,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| Source<NavigationController>( |
| &shell()->web_contents()->GetController())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - client_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), client_redirect_http_url, "test"); |
| // Same-site Client-Redirect Page should be loaded successfully. |
| EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| @@ -573,7 +565,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| Source<NavigationController>( |
| &shell()->web_contents()->GetController())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), client_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), client_redirect_http_url, "test"); |
| // DidFailProvisionalLoad when navigating to client_redirect_https_url. |
| load_observer2.Wait(); |
| @@ -588,8 +580,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| "server-redirect?" + http_url.spec())); |
| GURL server_redirect_http_url(test_server()->GetURL( |
| "server-redirect?" + server_redirect_https_url.spec())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), |
| - server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| EXPECT_EQ(observer.navigation_url(), http_url); |
| EXPECT_TRUE(observer.navigation_succeeded()); |
| } |
| @@ -601,7 +592,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| "server-redirect?" + https_url.spec())); |
| GURL server_redirect_http_url(test_server()->GetURL( |
| "server-redirect?" + server_redirect_https_url.spec())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| // DidFailProvisionalLoad when navigating to https_url. |
| EXPECT_EQ(observer.navigation_url(), https_url); |
| @@ -615,7 +606,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| "client-redirect?" + http_url.spec())); |
| GURL server_redirect_http_url(test_server()->GetURL( |
| "server-redirect?" + client_redirect_http_url.spec())); |
| - EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
| + NavigateIframeToURL(shell(), server_redirect_http_url, "test"); |
| // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| @@ -735,4 +726,94 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| } |
| } |
| +// Disabled because of http://crbug.com/433012 . |
|
Charlie Reis
2014/12/06 00:18:51
If we can avoid using script to check the title be
lfg
2014/12/08 20:45:33
Yes, it would. If we don't depend on the renderer
|
| +IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| + DISABLED_NavigateRemoteToDataURL) { |
| + GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| + NavigateToURL(shell(), main_url); |
| + |
| + // It is safe to obtain the root frame tree node here, as it doesn't change. |
| + FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree() |
| + ->root(); |
| + |
| + SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
| + |
| + // Load cross-site page into iframe. |
| + GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); |
| + NavigateFrameToURL(root->child_at(0), url); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + EXPECT_EQ(url, observer.navigation_url()); |
| + |
| + // Ensure that we have created a new process for the subframe. |
| + EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| + root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| + |
| + // Navigate iframe to a data URL. The navigation happens from a script in the |
| + // parent renderer, so the data URL should be rendered in the parent renderer. |
| + GURL data_url("data:text/html,dataurl"); |
| + std::string script = base::StringPrintf( |
| + "setTimeout(function() {" |
| + "var iframe = document.getElementById('test');" |
| + "iframe.onload = function() { document.title = 'LOADED'; };" |
|
Charlie Reis
2014/12/06 00:18:51
Can we avoid using the title? I don't understand
lfg
2014/12/08 20:45:33
RenderFrameHostImpl::IsCrossProcessSubframe() retu
Charlie Reis
2014/12/09 19:14:37
Ah! Good find.
We could try to revise that check
|
| + "iframe.src=\"%s\";" |
| + "},0);", |
| + data_url.spec().c_str()); |
| + base::string16 passed_string(base::UTF8ToUTF16("LOADED")); |
| + TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
| + EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| + (void)title_watcher.WaitAndGetTitle(); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + EXPECT_EQ(data_url, observer.navigation_url()); |
| + |
| + // Ensure that we have navigated using the top level process. |
| + EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| + root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| +} |
| + |
| +// Disabled because of http://crbug.com/433012 . |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| + DISABLED_NavigateRemoteBlankURL) { |
|
Charlie Reis
2014/12/06 00:18:51
nit: NavigateRemoteToBlankURL
lfg
2014/12/08 20:45:33
Done.
|
| + GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| + NavigateToURL(shell(), main_url); |
| + |
| + // It is safe to obtain the root frame tree node here, as it doesn't change. |
| + FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree() |
| + ->root(); |
| + |
| + SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
| + |
| + // Load cross-site page into iframe. |
| + GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); |
| + NavigateFrameToURL(root->child_at(0), url); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + EXPECT_EQ(url, observer.navigation_url()); |
| + |
| + // Ensure that we have created a new process for the subframe. |
| + EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| + root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| + |
| + // Navigate iframe to a data URL. The navigation happens from a script in the |
| + // parent renderer, so the data URL should be rendered in the parent renderer. |
| + GURL data_url("about:blank"); |
| + std::string script = base::StringPrintf( |
| + "setTimeout(function() {" |
| + "var iframe = document.getElementById('test');" |
| + "iframe.onload = function() { document.title = 'LOADED'; };" |
| + "iframe.src=\"%s\";" |
| + "},0);", |
| + data_url.spec().c_str()); |
| + base::string16 passed_string(base::UTF8ToUTF16("LOADED")); |
| + TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
| + EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| + (void)title_watcher.WaitAndGetTitle(); |
| + EXPECT_TRUE(observer.navigation_succeeded()); |
| + EXPECT_EQ(data_url, observer.navigation_url()); |
| + |
| + // Ensure that we have navigated using the top level process. |
| + EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| + root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| +} |
| + |
| } // namespace content |