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 789463e167ad171d276aa252aa4ef1fa706fa2d5..448617f79015332ba8c0f792de99a20e8b71405a 100644 |
--- a/content/browser/site_per_process_browsertest.cc |
+++ b/content/browser/site_per_process_browsertest.cc |
@@ -17,6 +17,7 @@ |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/web_contents_observer.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/content_browser_test_utils.h" |
@@ -29,6 +30,50 @@ |
#include "net/test/embedded_test_server/embedded_test_server.h" |
namespace content { |
+ |
+class SitePerProcessWebContentsObserver: public WebContentsObserver { |
+ public: |
+ explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
+ : WebContentsObserver(web_contents), |
+ navigation_succeeded_(false) {} |
+ ~SitePerProcessWebContentsObserver() override {} |
+ |
+ void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, |
+ const GURL& validated_url, |
+ bool is_error_page, |
+ bool is_iframe_srcdoc) override { |
+ navigation_succeeded_ = false; |
+ } |
+ |
+ void DidFailProvisionalLoad( |
+ RenderFrameHost* render_frame_host, |
+ const GURL& validated_url, |
+ int error_code, |
+ const base::string16& error_description) override { |
+ navigation_url_ = validated_url; |
+ navigation_succeeded_ = false; |
+ } |
+ |
+ void DidCommitProvisionalLoadForFrame( |
+ RenderFrameHost* render_frame_host, |
+ const GURL& url, |
+ ui::PageTransition transition_type) override { |
+ navigation_url_ = url; |
+ navigation_succeeded_ = true; |
+ } |
+ |
+ const GURL& navigation_url() const { |
+ return navigation_url_; |
+ } |
+ |
+ int navigation_succeeded() const { return navigation_succeeded_; } |
+ |
+ private: |
+ GURL navigation_url_; |
+ bool navigation_succeeded_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SitePerProcessWebContentsObserver); |
+}; |
class RedirectNotificationObserver : public NotificationObserver { |
public: |
@@ -193,14 +238,14 @@ |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
// Load same-site page into iframe. |
FrameTreeNode* child = root->child_at(0); |
GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
NavigateFrameToURL(child, http_url); |
- EXPECT_EQ(http_url, observer.last_navigation_url()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
{ |
// There should be only one RenderWidgetHost when there are no |
// cross-process iframes. |
@@ -218,8 +263,8 @@ |
GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
NavigateFrameToURL(root->child_at(0), url); |
// Verify that the navigation succeeded and the expected URL was loaded. |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(url, observer.navigation_url()); |
// Ensure that we have created a new process for the subframe. |
ASSERT_EQ(2U, root->child_count()); |
@@ -250,8 +295,8 @@ |
// Load another cross-site page into the same iframe. |
url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
NavigateFrameToURL(root->child_at(0), url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(url, observer.navigation_url()); |
// Check again that a new process is created and is different from the |
// top level one and the previous one. |
@@ -292,20 +337,20 @@ |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
// Load same-site page into iframe. |
FrameTreeNode* child = root->child_at(0); |
GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
NavigateFrameToURL(child, http_url); |
- EXPECT_EQ(http_url, observer.last_navigation_url()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
// Load cross-site page into iframe. |
GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
NavigateFrameToURL(root->child_at(0), url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(url, observer.navigation_url()); |
// Ensure that we have created a new process for the subframe. |
ASSERT_EQ(2U, root->child_count()); |
@@ -316,8 +361,8 @@ |
// navigates cross-site. |
url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
NavigateIframeToURL(shell()->web_contents(), "test", url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(url, observer.navigation_url()); |
// Check again that a new process is created and is different from the |
// top level one and the previous one. |
@@ -331,8 +376,8 @@ |
// Navigate back to the parent's origin and ensure we return to the |
// parent's process. |
NavigateFrameToURL(child, http_url); |
- EXPECT_EQ(http_url, observer.last_navigation_url()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
child->current_frame_host()->GetSiteInstance()); |
} |
@@ -362,7 +407,7 @@ |
FrameTreeNode* root = |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
ASSERT_EQ(2U, root->child_count()); |
@@ -401,8 +446,8 @@ |
FrameTreeNode* node4 = root->child_at(0)->child_at(0); |
GURL site_c_url(embedded_test_server()->GetURL("baz.com", "/title2.html")); |
NavigateFrameToURL(node4, site_c_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(site_c_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(site_c_url, observer.navigation_url()); |
// |site_instance_c| is expected to go away once we kill |child_process_b| |
// below, so create a local scope so we can extend the lifetime of |
@@ -521,7 +566,7 @@ |
NavigateToURL(shell(), main_url); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
{ |
// Load cross-site client-redirect page into Iframe. |
// Should be blocked. |
@@ -530,8 +575,8 @@ |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
client_redirect_https_url)); |
// DidFailProvisionalLoad when navigating to client_redirect_https_url. |
- EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -541,8 +586,8 @@ |
"server-redirect?" + http_url.spec())); |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
server_redirect_http_url)); |
- EXPECT_EQ(observer.last_navigation_url(), http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
} |
{ |
@@ -553,8 +598,8 @@ |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
server_redirect_http_url)); |
// DidFailProvisionalLoad when navigating to https_url. |
- EXPECT_EQ(observer.last_navigation_url(), https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -565,8 +610,8 @@ |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
server_redirect_http_url)); |
- EXPECT_EQ(observer.last_navigation_url(), https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -584,13 +629,13 @@ |
client_redirect_http_url)); |
// Same-site Client-Redirect Page should be loaded successfully. |
- EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
// Redirecting to Cross-site Page should be blocked. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.last_navigation_url(), https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -600,8 +645,8 @@ |
"server-redirect?files/title1.html")); |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
server_redirect_http_url)); |
- EXPECT_EQ(observer.last_navigation_url(), http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
} |
{ |
@@ -618,13 +663,13 @@ |
client_redirect_http_url)); |
// Same-site Client-Redirect Page should be loaded successfully. |
- EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
// Redirecting to Same-site Page should be loaded successfully. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.last_navigation_url(), http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
} |
} |
@@ -647,7 +692,7 @@ |
NavigateToURL(shell(), main_url); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
{ |
// Load client-redirect page pointing to a cross-site client-redirect page, |
// which eventually redirects back to same-site page. |
@@ -667,8 +712,8 @@ |
// DidFailProvisionalLoad when navigating to client_redirect_https_url. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -680,8 +725,8 @@ |
"server-redirect?" + server_redirect_https_url.spec())); |
EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
server_redirect_http_url)); |
- EXPECT_EQ(observer.last_navigation_url(), http_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), http_url); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
} |
{ |
@@ -695,8 +740,8 @@ |
server_redirect_http_url)); |
// DidFailProvisionalLoad when navigating to https_url. |
- EXPECT_EQ(observer.last_navigation_url(), https_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), https_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
{ |
@@ -710,8 +755,8 @@ |
server_redirect_http_url)); |
// DidFailProvisionalLoad when navigating to client_redirect_http_url. |
- EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
- EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
+ EXPECT_FALSE(observer.navigation_succeeded()); |
} |
} |
@@ -740,11 +785,11 @@ |
{ |
// Load same-site page into iframe. |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
NavigateFrameToURL(root->child_at(0), http_url); |
- EXPECT_EQ(http_url, observer.last_navigation_url()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
RenderFrameProxyHost* proxy_to_parent = |
root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
shell()->web_contents()->GetSiteInstance()); |
@@ -763,7 +808,7 @@ |
FrameTreeNode* child = root->child_at(1); |
SiteInstance* site = NULL; |
{ |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
TestFrameNavigationObserver navigation_observer(child); |
NavigationController::LoadURLParams params(cross_site_url); |
params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
@@ -786,8 +831,8 @@ |
// navigation to complete. |
navigation_observer.Wait(); |
EXPECT_FALSE(child->render_manager()->pending_frame_host()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(cross_site_url, observer.navigation_url()); |
} |
// Load another cross-site page into the same iframe. |
@@ -799,7 +844,7 @@ |
// TODO(nasko): Once we have proper cleanup of resources, add code to |
// verify that the intermediate SiteInstance/RenderFrameHost have been |
// properly cleaned up. |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
TestFrameNavigationObserver navigation_observer(child); |
NavigationController::LoadURLParams params(cross_site_url); |
params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
@@ -822,8 +867,8 @@ |
} |
navigation_observer.Wait(); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(cross_site_url, observer.navigation_url()); |
EXPECT_EQ(0U, child->child_count()); |
} |
} |
@@ -838,7 +883,7 @@ |
->GetFrameTree() |
->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
// Navigate the first subframe to a cross-site page with two subframes. |
// NavigateFrameToURL can't be used here because it doesn't guarantee that |
@@ -864,8 +909,8 @@ |
ASSERT_EQ(2U, root->child_at(0)->child_count()); |
GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); |
NavigateFrameToURL(root->child_at(0)->child_at(0), bar_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(bar_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(bar_url, observer.navigation_url()); |
// Check that a new process is created and is different from the top one and |
// the middle one. |
@@ -924,14 +969,14 @@ |
->GetFrameTree() |
->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
// Load cross-site page into iframe. |
GURL frame_url = |
embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); |
NavigateFrameToURL(root->child_at(0), frame_url); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(frame_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(frame_url, observer.navigation_url()); |
// Ensure that a new process is created for the subframe. |
EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
@@ -963,13 +1008,13 @@ |
->GetFrameTree() |
->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ 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.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_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(), |
@@ -990,8 +1035,8 @@ |
TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(data_url, observer.last_navigation_url()); |
+ 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(), |
@@ -1010,13 +1055,13 @@ |
->GetFrameTree() |
->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ 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.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_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(), |
@@ -1037,8 +1082,8 @@ |
TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(about_blank_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(about_blank_url, observer.navigation_url()); |
// Ensure that we have navigated using the top level process. |
EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
@@ -1056,14 +1101,14 @@ |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- TestNavigationObserver observer(shell()->web_contents()); |
+ SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
// Load same-site page into iframe. |
FrameTreeNode* child = root->child_at(0); |
GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
NavigateFrameToURL(child, http_url); |
- EXPECT_EQ(http_url, observer.last_navigation_url()); |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
// Load cross-site page into iframe. |
TestNavigationObserver nav_observer(shell()->web_contents(), 1); |
@@ -1075,8 +1120,8 @@ |
nav_observer.Wait(); |
// Verify that the navigation succeeded and the expected URL was loaded. |
- EXPECT_TRUE(observer.last_navigation_succeeded()); |
- EXPECT_EQ(url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(url, observer.navigation_url()); |
} |
} // namespace content |