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..f1b138d185b5e16f356fc9ad449c49bdd269aa13 100644 |
--- a/content/browser/site_per_process_browsertest.cc |
+++ b/content/browser/site_per_process_browsertest.cc |
@@ -16,10 +16,10 @@ |
#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" |
+#include "content/public/test/test_navigation_observer.h" |
#include "content/public/test/test_utils.h" |
#include "content/shell/browser/shell.h" |
#include "content/test/content_browser_test_utils_internal.h" |
@@ -29,50 +29,6 @@ |
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: |
// Register to listen for notifications of the given type from either a |
@@ -208,14 +164,14 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver 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.navigation_url()); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
{ |
// There should be only one RenderWidgetHost when there are no |
// cross-process iframes. |
@@ -233,8 +189,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
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.navigation_succeeded()); |
- EXPECT_EQ(url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(url, observer.last_navigation_url()); |
// Ensure that we have created a new process for the subframe. |
ASSERT_EQ(2U, root->child_count()); |
@@ -262,8 +218,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
// 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.navigation_succeeded()); |
- EXPECT_EQ(url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(url, observer.last_navigation_url()); |
// Check again that a new process is created and is different from the |
// top level one and the previous one. |
@@ -301,20 +257,20 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { |
static_cast<WebContentsImpl*>(shell()->web_contents())-> |
GetFrameTree()->root(); |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver 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.navigation_url()); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.last_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.navigation_succeeded()); |
- EXPECT_EQ(url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(url, observer.last_navigation_url()); |
// Ensure that we have created a new process for the subframe. |
ASSERT_EQ(2U, root->child_count()); |
@@ -325,8 +281,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { |
// navigates cross-site. |
url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
NavigateIframeToURL(shell(), url, "test"); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
- EXPECT_EQ(url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(url, observer.last_navigation_url()); |
// Check again that a new process is created and is different from the |
// top level one and the previous one. |
@@ -340,8 +296,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { |
// 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.navigation_url()); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
child->current_frame_host()->GetSiteInstance()); |
} |
@@ -432,7 +388,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
NavigateToURL(shell(), main_url); |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver observer(shell()->web_contents()); |
{ |
// Load cross-site client-redirect page into Iframe. |
// Should be blocked. |
@@ -441,8 +397,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(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()); |
+ EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -452,8 +408,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
"server-redirect?" + http_url.spec())); |
EXPECT_TRUE(NavigateIframeToURL(shell(), |
server_redirect_http_url, "test")); |
- EXPECT_EQ(observer.navigation_url(), http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -464,8 +420,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(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()); |
+ EXPECT_EQ(observer.last_navigation_url(), https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -476,8 +432,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(NavigateIframeToURL(shell(), |
server_redirect_http_url, "test")); |
- EXPECT_EQ(observer.navigation_url(), https_url); |
- EXPECT_FALSE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -495,13 +451,13 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
client_redirect_http_url, "test")); |
// Same-site Client-Redirect Page should be loaded successfully. |
- EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
// Redirecting to Cross-site Page should be blocked. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.navigation_url(), https_url); |
- EXPECT_FALSE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -511,8 +467,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
"server-redirect?files/title1.html")); |
EXPECT_TRUE(NavigateIframeToURL(shell(), |
server_redirect_http_url, "test")); |
- EXPECT_EQ(observer.navigation_url(), http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -529,13 +485,13 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
client_redirect_http_url, "test")); |
// Same-site Client-Redirect Page should be loaded successfully. |
- EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
// Redirecting to Same-site Page should be loaded successfully. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.navigation_url(), http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
} |
} |
@@ -558,7 +514,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
NavigateToURL(shell(), main_url); |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver observer(shell()->web_contents()); |
{ |
// Load client-redirect page pointing to a cross-site client-redirect page, |
// which eventually redirects back to same-site page. |
@@ -577,8 +533,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
// DidFailProvisionalLoad when navigating to client_redirect_https_url. |
load_observer2.Wait(); |
- EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); |
- EXPECT_FALSE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -590,8 +546,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
"server-redirect?" + server_redirect_https_url.spec())); |
EXPECT_TRUE(NavigateIframeToURL(shell(), |
server_redirect_http_url, "test")); |
- EXPECT_EQ(observer.navigation_url(), http_url); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), http_url); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -604,8 +560,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(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()); |
+ EXPECT_EQ(observer.last_navigation_url(), https_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
{ |
@@ -618,8 +574,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
// DidFailProvisionalLoad when navigating to client_redirect_http_url. |
- EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
- EXPECT_FALSE(observer.navigation_succeeded()); |
+ EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
} |
} |
@@ -647,11 +603,11 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
{ |
// Load same-site page into iframe. |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver 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.navigation_url()); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
+ EXPECT_EQ(http_url, observer.last_navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
RenderFrameProxyHost* proxy_to_parent = |
root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
shell()->web_contents()->GetSiteInstance()); |
@@ -670,7 +626,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
FrameTreeNode* child = root->child_at(1); |
SiteInstance* site = NULL; |
{ |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver observer(shell()->web_contents()); |
TestFrameNavigationObserver navigation_observer(child); |
NavigationController::LoadURLParams params(cross_site_url); |
params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
@@ -693,8 +649,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
// navigation to complete. |
navigation_observer.Wait(); |
EXPECT_FALSE(child->render_manager()->pending_frame_host()); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
- EXPECT_EQ(cross_site_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
} |
// Load another cross-site page into the same iframe. |
@@ -706,7 +662,7 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
// TODO(nasko): Once we have proper cleanup of resources, add code to |
// verify that the intermediate SiteInstance/RenderFrameHost have been |
// properly cleaned up. |
- SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
+ TestNavigationObserver observer(shell()->web_contents()); |
TestFrameNavigationObserver navigation_observer(child); |
NavigationController::LoadURLParams params(cross_site_url); |
params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
@@ -729,8 +685,8 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
} |
navigation_observer.Wait(); |
- EXPECT_TRUE(observer.navigation_succeeded()); |
- EXPECT_EQ(cross_site_url, observer.navigation_url()); |
+ EXPECT_TRUE(observer.last_navigation_succeeded()); |
+ EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
EXPECT_EQ(0U, child->child_count()); |
} |
} |