| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 10 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 11 #include "content/browser/frame_host/frame_tree.h" | 11 #include "content/browser/frame_host/frame_tree.h" |
| 12 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" |
| 13 #include "content/browser/frame_host/render_frame_proxy_host.h" | 13 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 14 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 14 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | |
| 21 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
| 23 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 24 #include "content/public/test/test_navigation_observer.h" | 23 #include "content/public/test/test_navigation_observer.h" |
| 25 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 26 #include "content/shell/browser/shell.h" | 25 #include "content/shell/browser/shell.h" |
| 27 #include "content/test/content_browser_test_utils_internal.h" | 26 #include "content/test/content_browser_test_utils_internal.h" |
| 28 #include "content/test/test_frame_navigation_observer.h" | 27 #include "content/test/test_frame_navigation_observer.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 31 | 30 |
| 32 namespace content { | 31 namespace content { |
| 33 | 32 |
| 34 class SitePerProcessWebContentsObserver: public WebContentsObserver { | |
| 35 public: | |
| 36 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | |
| 37 : WebContentsObserver(web_contents), | |
| 38 navigation_succeeded_(false) {} | |
| 39 ~SitePerProcessWebContentsObserver() override {} | |
| 40 | |
| 41 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, | |
| 42 const GURL& validated_url, | |
| 43 bool is_error_page, | |
| 44 bool is_iframe_srcdoc) override { | |
| 45 navigation_succeeded_ = false; | |
| 46 } | |
| 47 | |
| 48 void DidFailProvisionalLoad( | |
| 49 RenderFrameHost* render_frame_host, | |
| 50 const GURL& validated_url, | |
| 51 int error_code, | |
| 52 const base::string16& error_description) override { | |
| 53 navigation_url_ = validated_url; | |
| 54 navigation_succeeded_ = false; | |
| 55 } | |
| 56 | |
| 57 void DidCommitProvisionalLoadForFrame( | |
| 58 RenderFrameHost* render_frame_host, | |
| 59 const GURL& url, | |
| 60 ui::PageTransition transition_type) override { | |
| 61 navigation_url_ = url; | |
| 62 navigation_succeeded_ = true; | |
| 63 } | |
| 64 | |
| 65 const GURL& navigation_url() const { | |
| 66 return navigation_url_; | |
| 67 } | |
| 68 | |
| 69 int navigation_succeeded() const { return navigation_succeeded_; } | |
| 70 | |
| 71 private: | |
| 72 GURL navigation_url_; | |
| 73 bool navigation_succeeded_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(SitePerProcessWebContentsObserver); | |
| 76 }; | |
| 77 | |
| 78 class RedirectNotificationObserver : public NotificationObserver { | 33 class RedirectNotificationObserver : public NotificationObserver { |
| 79 public: | 34 public: |
| 80 // Register to listen for notifications of the given type from either a | 35 // Register to listen for notifications of the given type from either a |
| 81 // specific source, or from all sources if |source| is | 36 // specific source, or from all sources if |source| is |
| 82 // NotificationService::AllSources(). | 37 // NotificationService::AllSources(). |
| 83 RedirectNotificationObserver(int notification_type, | 38 RedirectNotificationObserver(int notification_type, |
| 84 const NotificationSource& source); | 39 const NotificationSource& source); |
| 85 ~RedirectNotificationObserver() override; | 40 ~RedirectNotificationObserver() override; |
| 86 | 41 |
| 87 // Wait until the specified notification occurs. If the notification was | 42 // Wait until the specified notification occurs. If the notification was |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // correct documents are committed. | 186 // correct documents are committed. |
| 232 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { | 187 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
| 233 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 188 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 234 NavigateToURL(shell(), main_url); | 189 NavigateToURL(shell(), main_url); |
| 235 | 190 |
| 236 // It is safe to obtain the root frame tree node here, as it doesn't change. | 191 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 237 FrameTreeNode* root = | 192 FrameTreeNode* root = |
| 238 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 193 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 239 GetFrameTree()->root(); | 194 GetFrameTree()->root(); |
| 240 | 195 |
| 241 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 196 TestNavigationObserver observer(shell()->web_contents()); |
| 242 | 197 |
| 243 // Load same-site page into iframe. | 198 // Load same-site page into iframe. |
| 244 FrameTreeNode* child = root->child_at(0); | 199 FrameTreeNode* child = root->child_at(0); |
| 245 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 200 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 246 NavigateFrameToURL(child, http_url); | 201 NavigateFrameToURL(child, http_url); |
| 247 EXPECT_EQ(http_url, observer.navigation_url()); | 202 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 248 EXPECT_TRUE(observer.navigation_succeeded()); | 203 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 249 { | 204 { |
| 250 // There should be only one RenderWidgetHost when there are no | 205 // There should be only one RenderWidgetHost when there are no |
| 251 // cross-process iframes. | 206 // cross-process iframes. |
| 252 std::set<RenderWidgetHostView*> views_set = | 207 std::set<RenderWidgetHostView*> views_set = |
| 253 static_cast<WebContentsImpl*>(shell()->web_contents()) | 208 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 254 ->GetRenderWidgetHostViewsInTree(); | 209 ->GetRenderWidgetHostViewsInTree(); |
| 255 EXPECT_EQ(1U, views_set.size()); | 210 EXPECT_EQ(1U, views_set.size()); |
| 256 } | 211 } |
| 257 RenderFrameProxyHost* proxy_to_parent = | 212 RenderFrameProxyHost* proxy_to_parent = |
| 258 child->render_manager()->GetRenderFrameProxyHost( | 213 child->render_manager()->GetRenderFrameProxyHost( |
| 259 shell()->web_contents()->GetSiteInstance()); | 214 shell()->web_contents()->GetSiteInstance()); |
| 260 EXPECT_FALSE(proxy_to_parent); | 215 EXPECT_FALSE(proxy_to_parent); |
| 261 | 216 |
| 262 // Load cross-site page into iframe. | 217 // Load cross-site page into iframe. |
| 263 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 218 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 264 NavigateFrameToURL(root->child_at(0), url); | 219 NavigateFrameToURL(root->child_at(0), url); |
| 265 // Verify that the navigation succeeded and the expected URL was loaded. | 220 // Verify that the navigation succeeded and the expected URL was loaded. |
| 266 EXPECT_TRUE(observer.navigation_succeeded()); | 221 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 267 EXPECT_EQ(url, observer.navigation_url()); | 222 EXPECT_EQ(url, observer.last_navigation_url()); |
| 268 | 223 |
| 269 // Ensure that we have created a new process for the subframe. | 224 // Ensure that we have created a new process for the subframe. |
| 270 ASSERT_EQ(2U, root->child_count()); | 225 ASSERT_EQ(2U, root->child_count()); |
| 271 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); | 226 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); |
| 272 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); | 227 RenderViewHost* rvh = child->current_frame_host()->render_view_host(); |
| 273 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); | 228 RenderProcessHost* rph = child->current_frame_host()->GetProcess(); |
| 274 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); | 229 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh); |
| 275 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); | 230 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); |
| 276 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); | 231 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph); |
| 277 { | 232 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 288 // The out-of-process iframe should have its own RenderWidgetHost, | 243 // The out-of-process iframe should have its own RenderWidgetHost, |
| 289 // independent of any RenderViewHost. | 244 // independent of any RenderViewHost. |
| 290 EXPECT_NE( | 245 EXPECT_NE( |
| 291 rvh->GetView(), | 246 rvh->GetView(), |
| 292 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); | 247 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); |
| 293 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); | 248 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); |
| 294 | 249 |
| 295 // Load another cross-site page into the same iframe. | 250 // Load another cross-site page into the same iframe. |
| 296 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 251 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 297 NavigateFrameToURL(root->child_at(0), url); | 252 NavigateFrameToURL(root->child_at(0), url); |
| 298 EXPECT_TRUE(observer.navigation_succeeded()); | 253 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 299 EXPECT_EQ(url, observer.navigation_url()); | 254 EXPECT_EQ(url, observer.last_navigation_url()); |
| 300 | 255 |
| 301 // Check again that a new process is created and is different from the | 256 // Check again that a new process is created and is different from the |
| 302 // top level one and the previous one. | 257 // top level one and the previous one. |
| 303 ASSERT_EQ(2U, root->child_count()); | 258 ASSERT_EQ(2U, root->child_count()); |
| 304 child = root->child_at(0); | 259 child = root->child_at(0); |
| 305 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), | 260 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), |
| 306 child->current_frame_host()->render_view_host()); | 261 child->current_frame_host()->render_view_host()); |
| 307 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); | 262 EXPECT_NE(rvh, child->current_frame_host()->render_view_host()); |
| 308 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 263 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 309 child->current_frame_host()->GetSiteInstance()); | 264 child->current_frame_host()->GetSiteInstance()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 330 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 285 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 331 DISABLED_NavigateRemoteFrame) { | 286 DISABLED_NavigateRemoteFrame) { |
| 332 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 287 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 333 NavigateToURL(shell(), main_url); | 288 NavigateToURL(shell(), main_url); |
| 334 | 289 |
| 335 // It is safe to obtain the root frame tree node here, as it doesn't change. | 290 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 336 FrameTreeNode* root = | 291 FrameTreeNode* root = |
| 337 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 292 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 338 GetFrameTree()->root(); | 293 GetFrameTree()->root(); |
| 339 | 294 |
| 340 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 295 TestNavigationObserver observer(shell()->web_contents()); |
| 341 | 296 |
| 342 // Load same-site page into iframe. | 297 // Load same-site page into iframe. |
| 343 FrameTreeNode* child = root->child_at(0); | 298 FrameTreeNode* child = root->child_at(0); |
| 344 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 299 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 345 NavigateFrameToURL(child, http_url); | 300 NavigateFrameToURL(child, http_url); |
| 346 EXPECT_EQ(http_url, observer.navigation_url()); | 301 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 347 EXPECT_TRUE(observer.navigation_succeeded()); | 302 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 348 | 303 |
| 349 // Load cross-site page into iframe. | 304 // Load cross-site page into iframe. |
| 350 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 305 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 351 NavigateFrameToURL(root->child_at(0), url); | 306 NavigateFrameToURL(root->child_at(0), url); |
| 352 EXPECT_TRUE(observer.navigation_succeeded()); | 307 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 353 EXPECT_EQ(url, observer.navigation_url()); | 308 EXPECT_EQ(url, observer.last_navigation_url()); |
| 354 | 309 |
| 355 // Ensure that we have created a new process for the subframe. | 310 // Ensure that we have created a new process for the subframe. |
| 356 ASSERT_EQ(2U, root->child_count()); | 311 ASSERT_EQ(2U, root->child_count()); |
| 357 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); | 312 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); |
| 358 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); | 313 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); |
| 359 | 314 |
| 360 // Emulate the main frame changing the src of the iframe such that it | 315 // Emulate the main frame changing the src of the iframe such that it |
| 361 // navigates cross-site. | 316 // navigates cross-site. |
| 362 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 317 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 363 NavigateIframeToURL(shell()->web_contents(), "test", url); | 318 NavigateIframeToURL(shell()->web_contents(), "test", url); |
| 364 EXPECT_TRUE(observer.navigation_succeeded()); | 319 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 365 EXPECT_EQ(url, observer.navigation_url()); | 320 EXPECT_EQ(url, observer.last_navigation_url()); |
| 366 | 321 |
| 367 // Check again that a new process is created and is different from the | 322 // Check again that a new process is created and is different from the |
| 368 // top level one and the previous one. | 323 // top level one and the previous one. |
| 369 ASSERT_EQ(2U, root->child_count()); | 324 ASSERT_EQ(2U, root->child_count()); |
| 370 child = root->child_at(0); | 325 child = root->child_at(0); |
| 371 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 326 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 372 child->current_frame_host()->GetSiteInstance()); | 327 child->current_frame_host()->GetSiteInstance()); |
| 373 EXPECT_NE(site_instance, | 328 EXPECT_NE(site_instance, |
| 374 child->current_frame_host()->GetSiteInstance()); | 329 child->current_frame_host()->GetSiteInstance()); |
| 375 | 330 |
| 376 // Navigate back to the parent's origin and ensure we return to the | 331 // Navigate back to the parent's origin and ensure we return to the |
| 377 // parent's process. | 332 // parent's process. |
| 378 NavigateFrameToURL(child, http_url); | 333 NavigateFrameToURL(child, http_url); |
| 379 EXPECT_EQ(http_url, observer.navigation_url()); | 334 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 380 EXPECT_TRUE(observer.navigation_succeeded()); | 335 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 381 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 336 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 382 child->current_frame_host()->GetSiteInstance()); | 337 child->current_frame_host()->GetSiteInstance()); |
| 383 } | 338 } |
| 384 | 339 |
| 385 // In A-embed-B-embed-C scenario, verify that killing process B clears proxies | 340 // In A-embed-B-embed-C scenario, verify that killing process B clears proxies |
| 386 // of C from the tree. | 341 // of C from the tree. |
| 387 // | 342 // |
| 388 // 1 A A | 343 // 1 A A |
| 389 // / \ / \ / \ . | 344 // / \ / \ / \ . |
| 390 // 2 3 -> B A -> Kill B -> B* A | 345 // 2 3 -> B A -> Kill B -> B* A |
| 391 // / / | 346 // / / |
| 392 // 4 C | 347 // 4 C |
| 393 // | 348 // |
| 394 // node1 is the root. | 349 // node1 is the root. |
| 395 // Initially, both node1.proxy_hosts_ and node3.proxy_hosts_ contain C. | 350 // Initially, both node1.proxy_hosts_ and node3.proxy_hosts_ contain C. |
| 396 // After we kill B, make sure proxies for C are cleared. | 351 // After we kill B, make sure proxies for C are cleared. |
| 397 // | 352 // |
| 398 // TODO(lazyboy): Once http://crbug.com/432107 is fixed, we should also make | 353 // TODO(lazyboy): Once http://crbug.com/432107 is fixed, we should also make |
| 399 // sure that proxies for B are not cleared when we kill B. | 354 // sure that proxies for B are not cleared when we kill B. |
| 400 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 355 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 401 KillingRendererClearsDescendantProxies) { | 356 KillingRendererClearsDescendantProxies) { |
| 402 GURL main_url( | 357 GURL main_url( |
| 403 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); | 358 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); |
| 404 NavigateToURL(shell(), main_url); | 359 NavigateToURL(shell(), main_url); |
| 405 | 360 |
| 406 // It is safe to obtain the root frame tree node here, as it doesn't change. | 361 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 407 FrameTreeNode* root = | 362 FrameTreeNode* root = |
| 408 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 363 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 409 GetFrameTree()->root(); | 364 GetFrameTree()->root(); |
| 410 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 365 TestNavigationObserver observer(shell()->web_contents()); |
| 411 | 366 |
| 412 ASSERT_EQ(2U, root->child_count()); | 367 ASSERT_EQ(2U, root->child_count()); |
| 413 | 368 |
| 414 // Navigate the second subframe (node3) to a local frame. | 369 // Navigate the second subframe (node3) to a local frame. |
| 415 GURL site_a_url(embedded_test_server()->GetURL("/title1.html")); | 370 GURL site_a_url(embedded_test_server()->GetURL("/title1.html")); |
| 416 NavigateFrameToURL(root->child_at(1), site_a_url); | 371 NavigateFrameToURL(root->child_at(1), site_a_url); |
| 417 | 372 |
| 418 // Navigate the first subframe (node2) to a cross-site page with two | 373 // Navigate the first subframe (node2) to a cross-site page with two |
| 419 // subframes. | 374 // subframes. |
| 420 // NavigateFrameToURL can't be used here because it doesn't guarantee that | 375 // NavigateFrameToURL can't be used here because it doesn't guarantee that |
| 421 // FrameTreeNodes will have been created for child frames when it returns. | 376 // FrameTreeNodes will have been created for child frames when it returns. |
| 422 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); | 377 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); |
| 423 GURL site_b_url( | 378 GURL site_b_url( |
| 424 embedded_test_server()->GetURL( | 379 embedded_test_server()->GetURL( |
| 425 "bar.com", "/frame_tree/page_with_one_frame.html")); | 380 "bar.com", "/frame_tree/page_with_one_frame.html")); |
| 426 NavigationController::LoadURLParams params_b(site_b_url); | 381 NavigationController::LoadURLParams params_b(site_b_url); |
| 427 params_b.transition_type = ui::PAGE_TRANSITION_LINK; | 382 params_b.transition_type = ui::PAGE_TRANSITION_LINK; |
| 428 params_b.frame_tree_node_id = root->child_at(0)->frame_tree_node_id(); | 383 params_b.frame_tree_node_id = root->child_at(0)->frame_tree_node_id(); |
| 429 root->child_at(0)->navigator()->GetController()->LoadURLWithParams(params_b); | 384 root->child_at(0)->navigator()->GetController()->LoadURLWithParams(params_b); |
| 430 frame_observer.Wait(); | 385 frame_observer.Wait(); |
| 431 | 386 |
| 432 // We can't use a SitePerProcessWebContentsObserver to verify the URL here, | 387 // We can't use a TestNavigationObserver to verify the URL here, |
| 433 // since the frame has children that may have clobbered it in the observer. | 388 // since the frame has children that may have clobbered it in the observer. |
| 434 EXPECT_EQ(site_b_url, root->child_at(0)->current_url()); | 389 EXPECT_EQ(site_b_url, root->child_at(0)->current_url()); |
| 435 | 390 |
| 436 // Ensure that a new process is created for node2. | 391 // Ensure that a new process is created for node2. |
| 437 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 392 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 438 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 393 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 439 // Ensure that a new process is *not* created for node3. | 394 // Ensure that a new process is *not* created for node3. |
| 440 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 395 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 441 root->child_at(1)->current_frame_host()->GetSiteInstance()); | 396 root->child_at(1)->current_frame_host()->GetSiteInstance()); |
| 442 | 397 |
| 443 ASSERT_EQ(1U, root->child_at(0)->child_count()); | 398 ASSERT_EQ(1U, root->child_at(0)->child_count()); |
| 444 | 399 |
| 445 // Navigate node4 to cross-site-page. | 400 // Navigate node4 to cross-site-page. |
| 446 FrameTreeNode* node4 = root->child_at(0)->child_at(0); | 401 FrameTreeNode* node4 = root->child_at(0)->child_at(0); |
| 447 GURL site_c_url(embedded_test_server()->GetURL("baz.com", "/title2.html")); | 402 GURL site_c_url(embedded_test_server()->GetURL("baz.com", "/title2.html")); |
| 448 NavigateFrameToURL(node4, site_c_url); | 403 NavigateFrameToURL(node4, site_c_url); |
| 449 EXPECT_TRUE(observer.navigation_succeeded()); | 404 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 450 EXPECT_EQ(site_c_url, observer.navigation_url()); | 405 EXPECT_EQ(site_c_url, observer.last_navigation_url()); |
| 451 | 406 |
| 452 // |site_instance_c| is expected to go away once we kill |child_process_b| | 407 // |site_instance_c| is expected to go away once we kill |child_process_b| |
| 453 // below, so create a local scope so we can extend the lifetime of | 408 // below, so create a local scope so we can extend the lifetime of |
| 454 // |site_instance_c| with a refptr. | 409 // |site_instance_c| with a refptr. |
| 455 { | 410 { |
| 456 SiteInstance* site_instance_b = | 411 SiteInstance* site_instance_b = |
| 457 root->child_at(0)->current_frame_host()->GetSiteInstance(); | 412 root->child_at(0)->current_frame_host()->GetSiteInstance(); |
| 458 scoped_refptr<SiteInstanceImpl> site_instance_c = | 413 scoped_refptr<SiteInstanceImpl> site_instance_c = |
| 459 node4->current_frame_host()->GetSiteInstance(); | 414 node4->current_frame_host()->GetSiteInstance(); |
| 460 | 415 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 net::SpawnedTestServer::kLocalhost, | 514 net::SpawnedTestServer::kLocalhost, |
| 560 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 515 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 561 ASSERT_TRUE(https_server.Start()); | 516 ASSERT_TRUE(https_server.Start()); |
| 562 | 517 |
| 563 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 518 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 564 GURL http_url(test_server()->GetURL("files/title1.html")); | 519 GURL http_url(test_server()->GetURL("files/title1.html")); |
| 565 GURL https_url(https_server.GetURL("files/title1.html")); | 520 GURL https_url(https_server.GetURL("files/title1.html")); |
| 566 | 521 |
| 567 NavigateToURL(shell(), main_url); | 522 NavigateToURL(shell(), main_url); |
| 568 | 523 |
| 569 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 524 TestNavigationObserver observer(shell()->web_contents()); |
| 570 { | 525 { |
| 571 // Load cross-site client-redirect page into Iframe. | 526 // Load cross-site client-redirect page into Iframe. |
| 572 // Should be blocked. | 527 // Should be blocked. |
| 573 GURL client_redirect_https_url(https_server.GetURL( | 528 GURL client_redirect_https_url(https_server.GetURL( |
| 574 "client-redirect?files/title1.html")); | 529 "client-redirect?files/title1.html")); |
| 575 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 530 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 576 client_redirect_https_url)); | 531 client_redirect_https_url)); |
| 577 // DidFailProvisionalLoad when navigating to client_redirect_https_url. | 532 // DidFailProvisionalLoad when navigating to client_redirect_https_url. |
| 578 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); | 533 EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
| 579 EXPECT_FALSE(observer.navigation_succeeded()); | 534 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 580 } | 535 } |
| 581 | 536 |
| 582 { | 537 { |
| 583 // Load cross-site server-redirect page into Iframe, | 538 // Load cross-site server-redirect page into Iframe, |
| 584 // which redirects to same-site page. | 539 // which redirects to same-site page. |
| 585 GURL server_redirect_http_url(https_server.GetURL( | 540 GURL server_redirect_http_url(https_server.GetURL( |
| 586 "server-redirect?" + http_url.spec())); | 541 "server-redirect?" + http_url.spec())); |
| 587 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 542 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 588 server_redirect_http_url)); | 543 server_redirect_http_url)); |
| 589 EXPECT_EQ(observer.navigation_url(), http_url); | 544 EXPECT_EQ(observer.last_navigation_url(), http_url); |
| 590 EXPECT_TRUE(observer.navigation_succeeded()); | 545 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 591 } | 546 } |
| 592 | 547 |
| 593 { | 548 { |
| 594 // Load cross-site server-redirect page into Iframe, | 549 // Load cross-site server-redirect page into Iframe, |
| 595 // which redirects to cross-site page. | 550 // which redirects to cross-site page. |
| 596 GURL server_redirect_http_url(https_server.GetURL( | 551 GURL server_redirect_http_url(https_server.GetURL( |
| 597 "server-redirect?files/title1.html")); | 552 "server-redirect?files/title1.html")); |
| 598 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 553 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 599 server_redirect_http_url)); | 554 server_redirect_http_url)); |
| 600 // DidFailProvisionalLoad when navigating to https_url. | 555 // DidFailProvisionalLoad when navigating to https_url. |
| 601 EXPECT_EQ(observer.navigation_url(), https_url); | 556 EXPECT_EQ(observer.last_navigation_url(), https_url); |
| 602 EXPECT_FALSE(observer.navigation_succeeded()); | 557 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 603 } | 558 } |
| 604 | 559 |
| 605 { | 560 { |
| 606 // Load same-site server-redirect page into Iframe, | 561 // Load same-site server-redirect page into Iframe, |
| 607 // which redirects to cross-site page. | 562 // which redirects to cross-site page. |
| 608 GURL server_redirect_http_url(test_server()->GetURL( | 563 GURL server_redirect_http_url(test_server()->GetURL( |
| 609 "server-redirect?" + https_url.spec())); | 564 "server-redirect?" + https_url.spec())); |
| 610 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 565 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 611 server_redirect_http_url)); | 566 server_redirect_http_url)); |
| 612 | 567 |
| 613 EXPECT_EQ(observer.navigation_url(), https_url); | 568 EXPECT_EQ(observer.last_navigation_url(), https_url); |
| 614 EXPECT_FALSE(observer.navigation_succeeded()); | 569 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 615 } | 570 } |
| 616 | 571 |
| 617 { | 572 { |
| 618 // Load same-site client-redirect page into Iframe, | 573 // Load same-site client-redirect page into Iframe, |
| 619 // which redirects to cross-site page. | 574 // which redirects to cross-site page. |
| 620 GURL client_redirect_http_url(test_server()->GetURL( | 575 GURL client_redirect_http_url(test_server()->GetURL( |
| 621 "client-redirect?" + https_url.spec())); | 576 "client-redirect?" + https_url.spec())); |
| 622 | 577 |
| 623 RedirectNotificationObserver load_observer2( | 578 RedirectNotificationObserver load_observer2( |
| 624 NOTIFICATION_LOAD_STOP, | 579 NOTIFICATION_LOAD_STOP, |
| 625 Source<NavigationController>( | 580 Source<NavigationController>( |
| 626 &shell()->web_contents()->GetController())); | 581 &shell()->web_contents()->GetController())); |
| 627 | 582 |
| 628 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 583 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 629 client_redirect_http_url)); | 584 client_redirect_http_url)); |
| 630 | 585 |
| 631 // Same-site Client-Redirect Page should be loaded successfully. | 586 // Same-site Client-Redirect Page should be loaded successfully. |
| 632 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 587 EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
| 633 EXPECT_TRUE(observer.navigation_succeeded()); | 588 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 634 | 589 |
| 635 // Redirecting to Cross-site Page should be blocked. | 590 // Redirecting to Cross-site Page should be blocked. |
| 636 load_observer2.Wait(); | 591 load_observer2.Wait(); |
| 637 EXPECT_EQ(observer.navigation_url(), https_url); | 592 EXPECT_EQ(observer.last_navigation_url(), https_url); |
| 638 EXPECT_FALSE(observer.navigation_succeeded()); | 593 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 639 } | 594 } |
| 640 | 595 |
| 641 { | 596 { |
| 642 // Load same-site server-redirect page into Iframe, | 597 // Load same-site server-redirect page into Iframe, |
| 643 // which redirects to same-site page. | 598 // which redirects to same-site page. |
| 644 GURL server_redirect_http_url(test_server()->GetURL( | 599 GURL server_redirect_http_url(test_server()->GetURL( |
| 645 "server-redirect?files/title1.html")); | 600 "server-redirect?files/title1.html")); |
| 646 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 601 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 647 server_redirect_http_url)); | 602 server_redirect_http_url)); |
| 648 EXPECT_EQ(observer.navigation_url(), http_url); | 603 EXPECT_EQ(observer.last_navigation_url(), http_url); |
| 649 EXPECT_TRUE(observer.navigation_succeeded()); | 604 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 650 } | 605 } |
| 651 | 606 |
| 652 { | 607 { |
| 653 // Load same-site client-redirect page into Iframe, | 608 // Load same-site client-redirect page into Iframe, |
| 654 // which redirects to same-site page. | 609 // which redirects to same-site page. |
| 655 GURL client_redirect_http_url(test_server()->GetURL( | 610 GURL client_redirect_http_url(test_server()->GetURL( |
| 656 "client-redirect?" + http_url.spec())); | 611 "client-redirect?" + http_url.spec())); |
| 657 RedirectNotificationObserver load_observer2( | 612 RedirectNotificationObserver load_observer2( |
| 658 NOTIFICATION_LOAD_STOP, | 613 NOTIFICATION_LOAD_STOP, |
| 659 Source<NavigationController>( | 614 Source<NavigationController>( |
| 660 &shell()->web_contents()->GetController())); | 615 &shell()->web_contents()->GetController())); |
| 661 | 616 |
| 662 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 617 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 663 client_redirect_http_url)); | 618 client_redirect_http_url)); |
| 664 | 619 |
| 665 // Same-site Client-Redirect Page should be loaded successfully. | 620 // Same-site Client-Redirect Page should be loaded successfully. |
| 666 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 621 EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
| 667 EXPECT_TRUE(observer.navigation_succeeded()); | 622 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 668 | 623 |
| 669 // Redirecting to Same-site Page should be loaded successfully. | 624 // Redirecting to Same-site Page should be loaded successfully. |
| 670 load_observer2.Wait(); | 625 load_observer2.Wait(); |
| 671 EXPECT_EQ(observer.navigation_url(), http_url); | 626 EXPECT_EQ(observer.last_navigation_url(), http_url); |
| 672 EXPECT_TRUE(observer.navigation_succeeded()); | 627 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 673 } | 628 } |
| 674 } | 629 } |
| 675 | 630 |
| 676 // TODO(nasko): Disable this test until out-of-process iframes is ready and the | 631 // TODO(nasko): Disable this test until out-of-process iframes is ready and the |
| 677 // security checks are back in place. | 632 // security checks are back in place. |
| 678 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run | 633 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run |
| 679 // on Android (http://crbug.com/187570). | 634 // on Android (http://crbug.com/187570). |
| 680 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 635 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 681 DISABLED_CrossSiteIframeRedirectTwice) { | 636 DISABLED_CrossSiteIframeRedirectTwice) { |
| 682 ASSERT_TRUE(test_server()->Start()); | 637 ASSERT_TRUE(test_server()->Start()); |
| 683 net::SpawnedTestServer https_server( | 638 net::SpawnedTestServer https_server( |
| 684 net::SpawnedTestServer::TYPE_HTTPS, | 639 net::SpawnedTestServer::TYPE_HTTPS, |
| 685 net::SpawnedTestServer::kLocalhost, | 640 net::SpawnedTestServer::kLocalhost, |
| 686 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 641 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 687 ASSERT_TRUE(https_server.Start()); | 642 ASSERT_TRUE(https_server.Start()); |
| 688 | 643 |
| 689 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 644 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 690 GURL http_url(test_server()->GetURL("files/title1.html")); | 645 GURL http_url(test_server()->GetURL("files/title1.html")); |
| 691 GURL https_url(https_server.GetURL("files/title1.html")); | 646 GURL https_url(https_server.GetURL("files/title1.html")); |
| 692 | 647 |
| 693 NavigateToURL(shell(), main_url); | 648 NavigateToURL(shell(), main_url); |
| 694 | 649 |
| 695 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 650 TestNavigationObserver observer(shell()->web_contents()); |
| 696 { | 651 { |
| 697 // Load client-redirect page pointing to a cross-site client-redirect page, | 652 // Load client-redirect page pointing to a cross-site client-redirect page, |
| 698 // which eventually redirects back to same-site page. | 653 // which eventually redirects back to same-site page. |
| 699 GURL client_redirect_https_url(https_server.GetURL( | 654 GURL client_redirect_https_url(https_server.GetURL( |
| 700 "client-redirect?" + http_url.spec())); | 655 "client-redirect?" + http_url.spec())); |
| 701 GURL client_redirect_http_url(test_server()->GetURL( | 656 GURL client_redirect_http_url(test_server()->GetURL( |
| 702 "client-redirect?" + client_redirect_https_url.spec())); | 657 "client-redirect?" + client_redirect_https_url.spec())); |
| 703 | 658 |
| 704 // We should wait until second client redirect get cancelled. | 659 // We should wait until second client redirect get cancelled. |
| 705 RedirectNotificationObserver load_observer2( | 660 RedirectNotificationObserver load_observer2( |
| 706 NOTIFICATION_LOAD_STOP, | 661 NOTIFICATION_LOAD_STOP, |
| 707 Source<NavigationController>( | 662 Source<NavigationController>( |
| 708 &shell()->web_contents()->GetController())); | 663 &shell()->web_contents()->GetController())); |
| 709 | 664 |
| 710 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 665 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 711 client_redirect_http_url)); | 666 client_redirect_http_url)); |
| 712 | 667 |
| 713 // DidFailProvisionalLoad when navigating to client_redirect_https_url. | 668 // DidFailProvisionalLoad when navigating to client_redirect_https_url. |
| 714 load_observer2.Wait(); | 669 load_observer2.Wait(); |
| 715 EXPECT_EQ(observer.navigation_url(), client_redirect_https_url); | 670 EXPECT_EQ(observer.last_navigation_url(), client_redirect_https_url); |
| 716 EXPECT_FALSE(observer.navigation_succeeded()); | 671 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 717 } | 672 } |
| 718 | 673 |
| 719 { | 674 { |
| 720 // Load server-redirect page pointing to a cross-site server-redirect page, | 675 // Load server-redirect page pointing to a cross-site server-redirect page, |
| 721 // which eventually redirect back to same-site page. | 676 // which eventually redirect back to same-site page. |
| 722 GURL server_redirect_https_url(https_server.GetURL( | 677 GURL server_redirect_https_url(https_server.GetURL( |
| 723 "server-redirect?" + http_url.spec())); | 678 "server-redirect?" + http_url.spec())); |
| 724 GURL server_redirect_http_url(test_server()->GetURL( | 679 GURL server_redirect_http_url(test_server()->GetURL( |
| 725 "server-redirect?" + server_redirect_https_url.spec())); | 680 "server-redirect?" + server_redirect_https_url.spec())); |
| 726 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 681 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 727 server_redirect_http_url)); | 682 server_redirect_http_url)); |
| 728 EXPECT_EQ(observer.navigation_url(), http_url); | 683 EXPECT_EQ(observer.last_navigation_url(), http_url); |
| 729 EXPECT_TRUE(observer.navigation_succeeded()); | 684 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 730 } | 685 } |
| 731 | 686 |
| 732 { | 687 { |
| 733 // Load server-redirect page pointing to a cross-site server-redirect page, | 688 // Load server-redirect page pointing to a cross-site server-redirect page, |
| 734 // which eventually redirects back to cross-site page. | 689 // which eventually redirects back to cross-site page. |
| 735 GURL server_redirect_https_url(https_server.GetURL( | 690 GURL server_redirect_https_url(https_server.GetURL( |
| 736 "server-redirect?" + https_url.spec())); | 691 "server-redirect?" + https_url.spec())); |
| 737 GURL server_redirect_http_url(test_server()->GetURL( | 692 GURL server_redirect_http_url(test_server()->GetURL( |
| 738 "server-redirect?" + server_redirect_https_url.spec())); | 693 "server-redirect?" + server_redirect_https_url.spec())); |
| 739 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 694 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 740 server_redirect_http_url)); | 695 server_redirect_http_url)); |
| 741 | 696 |
| 742 // DidFailProvisionalLoad when navigating to https_url. | 697 // DidFailProvisionalLoad when navigating to https_url. |
| 743 EXPECT_EQ(observer.navigation_url(), https_url); | 698 EXPECT_EQ(observer.last_navigation_url(), https_url); |
| 744 EXPECT_FALSE(observer.navigation_succeeded()); | 699 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 745 } | 700 } |
| 746 | 701 |
| 747 { | 702 { |
| 748 // Load server-redirect page pointing to a cross-site client-redirect page, | 703 // Load server-redirect page pointing to a cross-site client-redirect page, |
| 749 // which eventually redirects back to same-site page. | 704 // which eventually redirects back to same-site page. |
| 750 GURL client_redirect_http_url(https_server.GetURL( | 705 GURL client_redirect_http_url(https_server.GetURL( |
| 751 "client-redirect?" + http_url.spec())); | 706 "client-redirect?" + http_url.spec())); |
| 752 GURL server_redirect_http_url(test_server()->GetURL( | 707 GURL server_redirect_http_url(test_server()->GetURL( |
| 753 "server-redirect?" + client_redirect_http_url.spec())); | 708 "server-redirect?" + client_redirect_http_url.spec())); |
| 754 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", | 709 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test", |
| 755 server_redirect_http_url)); | 710 server_redirect_http_url)); |
| 756 | 711 |
| 757 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 712 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 758 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 713 EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
| 759 EXPECT_FALSE(observer.navigation_succeeded()); | 714 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 760 } | 715 } |
| 761 } | 716 } |
| 762 | 717 |
| 763 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are | 718 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are |
| 764 // created in the FrameTree skipping the subtree of the navigating frame. | 719 // created in the FrameTree skipping the subtree of the navigating frame. |
| 765 // | 720 // |
| 766 // Disabled on Mac due to flakiness on ASAN. http://crbug.com/425248 | 721 // Disabled on Mac due to flakiness on ASAN. http://crbug.com/425248 |
| 767 // Disabled on Windows due to flakiness on Win 7 bot. http://crbug.com/444563 | 722 // Disabled on Windows due to flakiness on Win 7 bot. http://crbug.com/444563 |
| 768 #if defined(OS_MACOSX) || defined(OS_WIN) | 723 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 769 #define MAYBE_ProxyCreationSkipsSubtree DISABLED_ProxyCreationSkipsSubtree | 724 #define MAYBE_ProxyCreationSkipsSubtree DISABLED_ProxyCreationSkipsSubtree |
| 770 #else | 725 #else |
| 771 #define MAYBE_ProxyCreationSkipsSubtree ProxyCreationSkipsSubtree | 726 #define MAYBE_ProxyCreationSkipsSubtree ProxyCreationSkipsSubtree |
| 772 #endif | 727 #endif |
| 773 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 728 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 774 MAYBE_ProxyCreationSkipsSubtree) { | 729 MAYBE_ProxyCreationSkipsSubtree) { |
| 775 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 730 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 776 NavigateToURL(shell(), main_url); | 731 NavigateToURL(shell(), main_url); |
| 777 | 732 |
| 778 // It is safe to obtain the root frame tree node here, as it doesn't change. | 733 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 779 FrameTreeNode* root = | 734 FrameTreeNode* root = |
| 780 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 735 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 781 GetFrameTree()->root(); | 736 GetFrameTree()->root(); |
| 782 | 737 |
| 783 EXPECT_TRUE(root->child_at(1) != NULL); | 738 EXPECT_TRUE(root->child_at(1) != NULL); |
| 784 EXPECT_EQ(2U, root->child_at(1)->child_count()); | 739 EXPECT_EQ(2U, root->child_at(1)->child_count()); |
| 785 | 740 |
| 786 { | 741 { |
| 787 // Load same-site page into iframe. | 742 // Load same-site page into iframe. |
| 788 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 743 TestNavigationObserver observer(shell()->web_contents()); |
| 789 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 744 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 790 NavigateFrameToURL(root->child_at(0), http_url); | 745 NavigateFrameToURL(root->child_at(0), http_url); |
| 791 EXPECT_EQ(http_url, observer.navigation_url()); | 746 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 792 EXPECT_TRUE(observer.navigation_succeeded()); | 747 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 793 RenderFrameProxyHost* proxy_to_parent = | 748 RenderFrameProxyHost* proxy_to_parent = |
| 794 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( | 749 root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
| 795 shell()->web_contents()->GetSiteInstance()); | 750 shell()->web_contents()->GetSiteInstance()); |
| 796 EXPECT_FALSE(proxy_to_parent); | 751 EXPECT_FALSE(proxy_to_parent); |
| 797 } | 752 } |
| 798 | 753 |
| 799 // Create the cross-site URL to navigate to. | 754 // Create the cross-site URL to navigate to. |
| 800 GURL cross_site_url = | 755 GURL cross_site_url = |
| 801 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); | 756 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); |
| 802 | 757 |
| 803 // Load cross-site page into the second iframe without waiting for the | 758 // Load cross-site page into the second iframe without waiting for the |
| 804 // navigation to complete. Once LoadURLWithParams returns, we would expect | 759 // navigation to complete. Once LoadURLWithParams returns, we would expect |
| 805 // proxies to have been created in the frame tree, but children of the | 760 // proxies to have been created in the frame tree, but children of the |
| 806 // navigating frame to still be present. The reason is that we don't run the | 761 // navigating frame to still be present. The reason is that we don't run the |
| 807 // message loop, so no IPCs that alter the frame tree can be processed. | 762 // message loop, so no IPCs that alter the frame tree can be processed. |
| 808 FrameTreeNode* child = root->child_at(1); | 763 FrameTreeNode* child = root->child_at(1); |
| 809 SiteInstance* site = NULL; | 764 SiteInstance* site = NULL; |
| 810 { | 765 { |
| 811 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 766 TestNavigationObserver observer(shell()->web_contents()); |
| 812 TestFrameNavigationObserver navigation_observer(child); | 767 TestFrameNavigationObserver navigation_observer(child); |
| 813 NavigationController::LoadURLParams params(cross_site_url); | 768 NavigationController::LoadURLParams params(cross_site_url); |
| 814 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 769 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 815 params.frame_tree_node_id = child->frame_tree_node_id(); | 770 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 816 child->navigator()->GetController()->LoadURLWithParams(params); | 771 child->navigator()->GetController()->LoadURLWithParams(params); |
| 817 EXPECT_TRUE(child->render_manager()->pending_frame_host()); | 772 EXPECT_TRUE(child->render_manager()->pending_frame_host()); |
| 818 | 773 |
| 819 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); | 774 site = child->render_manager()->pending_frame_host()->GetSiteInstance(); |
| 820 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | 775 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); |
| 821 | 776 |
| 822 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); | 777 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site)); |
| 823 EXPECT_TRUE( | 778 EXPECT_TRUE( |
| 824 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); | 779 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site)); |
| 825 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); | 780 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site)); |
| 826 for (size_t i = 0; i < child->child_count(); ++i) { | 781 for (size_t i = 0; i < child->child_count(); ++i) { |
| 827 EXPECT_FALSE( | 782 EXPECT_FALSE( |
| 828 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); | 783 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site)); |
| 829 } | 784 } |
| 830 // Now that the verification is done, run the message loop and wait for the | 785 // Now that the verification is done, run the message loop and wait for the |
| 831 // navigation to complete. | 786 // navigation to complete. |
| 832 navigation_observer.Wait(); | 787 navigation_observer.Wait(); |
| 833 EXPECT_FALSE(child->render_manager()->pending_frame_host()); | 788 EXPECT_FALSE(child->render_manager()->pending_frame_host()); |
| 834 EXPECT_TRUE(observer.navigation_succeeded()); | 789 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 835 EXPECT_EQ(cross_site_url, observer.navigation_url()); | 790 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 836 } | 791 } |
| 837 | 792 |
| 838 // Load another cross-site page into the same iframe. | 793 // Load another cross-site page into the same iframe. |
| 839 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); | 794 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); |
| 840 { | 795 { |
| 841 // Perform the same checks as the first cross-site navigation, since | 796 // Perform the same checks as the first cross-site navigation, since |
| 842 // there have been issues in subsequent cross-site navigations. Also ensure | 797 // there have been issues in subsequent cross-site navigations. Also ensure |
| 843 // that the SiteInstance has properly changed. | 798 // that the SiteInstance has properly changed. |
| 844 // TODO(nasko): Once we have proper cleanup of resources, add code to | 799 // TODO(nasko): Once we have proper cleanup of resources, add code to |
| 845 // verify that the intermediate SiteInstance/RenderFrameHost have been | 800 // verify that the intermediate SiteInstance/RenderFrameHost have been |
| 846 // properly cleaned up. | 801 // properly cleaned up. |
| 847 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 802 TestNavigationObserver observer(shell()->web_contents()); |
| 848 TestFrameNavigationObserver navigation_observer(child); | 803 TestFrameNavigationObserver navigation_observer(child); |
| 849 NavigationController::LoadURLParams params(cross_site_url); | 804 NavigationController::LoadURLParams params(cross_site_url); |
| 850 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 805 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 851 params.frame_tree_node_id = child->frame_tree_node_id(); | 806 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 852 child->navigator()->GetController()->LoadURLWithParams(params); | 807 child->navigator()->GetController()->LoadURLWithParams(params); |
| 853 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); | 808 EXPECT_TRUE(child->render_manager()->pending_frame_host() != NULL); |
| 854 | 809 |
| 855 SiteInstance* site2 = | 810 SiteInstance* site2 = |
| 856 child->render_manager()->pending_frame_host()->GetSiteInstance(); | 811 child->render_manager()->pending_frame_host()->GetSiteInstance(); |
| 857 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | 812 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); |
| 858 EXPECT_NE(site, site2); | 813 EXPECT_NE(site, site2); |
| 859 | 814 |
| 860 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); | 815 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site2)); |
| 861 EXPECT_TRUE( | 816 EXPECT_TRUE( |
| 862 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); | 817 root->child_at(0)->render_manager()->GetRenderFrameProxyHost(site2)); |
| 863 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); | 818 EXPECT_FALSE(child->render_manager()->GetRenderFrameProxyHost(site2)); |
| 864 for (size_t i = 0; i < child->child_count(); ++i) { | 819 for (size_t i = 0; i < child->child_count(); ++i) { |
| 865 EXPECT_FALSE( | 820 EXPECT_FALSE( |
| 866 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); | 821 child->child_at(i)->render_manager()->GetRenderFrameProxyHost(site2)); |
| 867 } | 822 } |
| 868 | 823 |
| 869 navigation_observer.Wait(); | 824 navigation_observer.Wait(); |
| 870 EXPECT_TRUE(observer.navigation_succeeded()); | 825 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 871 EXPECT_EQ(cross_site_url, observer.navigation_url()); | 826 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 872 EXPECT_EQ(0U, child->child_count()); | 827 EXPECT_EQ(0U, child->child_count()); |
| 873 } | 828 } |
| 874 } | 829 } |
| 875 | 830 |
| 876 // Verify that origin replication works for an A-embed-B-embed-C hierarchy. | 831 // Verify that origin replication works for an A-embed-B-embed-C hierarchy. |
| 877 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { | 832 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
| 878 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 833 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 879 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 834 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 880 | 835 |
| 881 // It is safe to obtain the root frame tree node here, as it doesn't change. | 836 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 882 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 837 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 883 ->GetFrameTree() | 838 ->GetFrameTree() |
| 884 ->root(); | 839 ->root(); |
| 885 | 840 |
| 886 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 841 TestNavigationObserver observer(shell()->web_contents()); |
| 887 | 842 |
| 888 // Navigate the first subframe to a cross-site page with two subframes. | 843 // Navigate the first subframe to a cross-site page with two subframes. |
| 889 // NavigateFrameToURL can't be used here because it doesn't guarantee that | 844 // NavigateFrameToURL can't be used here because it doesn't guarantee that |
| 890 // FrameTreeNodes will have been created for child frames when it returns. | 845 // FrameTreeNodes will have been created for child frames when it returns. |
| 891 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 4); | 846 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 4); |
| 892 GURL foo_url( | 847 GURL foo_url( |
| 893 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html")); | 848 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html")); |
| 894 NavigationController::LoadURLParams params(foo_url); | 849 NavigationController::LoadURLParams params(foo_url); |
| 895 params.transition_type = ui::PAGE_TRANSITION_LINK; | 850 params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 896 params.frame_tree_node_id = root->child_at(0)->frame_tree_node_id(); | 851 params.frame_tree_node_id = root->child_at(0)->frame_tree_node_id(); |
| 897 root->child_at(0)->navigator()->GetController()->LoadURLWithParams(params); | 852 root->child_at(0)->navigator()->GetController()->LoadURLWithParams(params); |
| 898 frame_observer.Wait(); | 853 frame_observer.Wait(); |
| 899 | 854 |
| 900 // We can't use a SitePerProcessWebContentsObserver to verify the URL here, | 855 // We can't use a TestNavigationObserver to verify the URL here, |
| 901 // since the frame has children that may have clobbered it in the observer. | 856 // since the frame has children that may have clobbered it in the observer. |
| 902 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); | 857 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
| 903 | 858 |
| 904 // Ensure that a new process is created for the subframe. | 859 // Ensure that a new process is created for the subframe. |
| 905 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 860 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 906 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 861 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 907 | 862 |
| 908 // Load cross-site page into subframe's subframe. | 863 // Load cross-site page into subframe's subframe. |
| 909 ASSERT_EQ(2U, root->child_at(0)->child_count()); | 864 ASSERT_EQ(2U, root->child_at(0)->child_count()); |
| 910 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); | 865 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); |
| 911 NavigateFrameToURL(root->child_at(0)->child_at(0), bar_url); | 866 NavigateFrameToURL(root->child_at(0)->child_at(0), bar_url); |
| 912 EXPECT_TRUE(observer.navigation_succeeded()); | 867 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 913 EXPECT_EQ(bar_url, observer.navigation_url()); | 868 EXPECT_EQ(bar_url, observer.last_navigation_url()); |
| 914 | 869 |
| 915 // Check that a new process is created and is different from the top one and | 870 // Check that a new process is created and is different from the top one and |
| 916 // the middle one. | 871 // the middle one. |
| 917 FrameTreeNode* bottom_child = root->child_at(0)->child_at(0); | 872 FrameTreeNode* bottom_child = root->child_at(0)->child_at(0); |
| 918 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 873 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 919 bottom_child->current_frame_host()->GetSiteInstance()); | 874 bottom_child->current_frame_host()->GetSiteInstance()); |
| 920 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(), | 875 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(), |
| 921 bottom_child->current_frame_host()->GetSiteInstance()); | 876 bottom_child->current_frame_host()->GetSiteInstance()); |
| 922 | 877 |
| 923 // Check that foo.com frame's location.ancestorOrigins contains the correct | 878 // Check that foo.com frame's location.ancestorOrigins contains the correct |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // Check that iframe sandbox flags are replicated correctly. | 917 // Check that iframe sandbox flags are replicated correctly. |
| 963 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsReplication) { | 918 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsReplication) { |
| 964 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 919 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
| 965 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 920 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 966 | 921 |
| 967 // It is safe to obtain the root frame tree node here, as it doesn't change. | 922 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 968 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 923 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 969 ->GetFrameTree() | 924 ->GetFrameTree() |
| 970 ->root(); | 925 ->root(); |
| 971 | 926 |
| 972 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 927 TestNavigationObserver observer(shell()->web_contents()); |
| 973 | 928 |
| 974 // Navigate the second (sandboxed) subframe to a cross-site page with a | 929 // Navigate the second (sandboxed) subframe to a cross-site page with a |
| 975 // subframe. Use RenderFrameHostCreatedObserver to guarantee that all | 930 // subframe. Use RenderFrameHostCreatedObserver to guarantee that all |
| 976 // FrameTreeNodes are created for child frames. | 931 // FrameTreeNodes are created for child frames. |
| 977 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 4); | 932 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 4); |
| 978 GURL foo_url( | 933 GURL foo_url( |
| 979 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html")); | 934 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html")); |
| 980 NavigateFrameToURL(root->child_at(1), foo_url); | 935 NavigateFrameToURL(root->child_at(1), foo_url); |
| 981 frame_observer.Wait(); | 936 frame_observer.Wait(); |
| 982 | 937 |
| 983 // We can't use a SitePerProcessWebContentsObserver to verify the URL here, | 938 // We can't use a TestNavigationObserver to verify the URL here, |
| 984 // since the frame has children that may have clobbered it in the observer. | 939 // since the frame has children that may have clobbered it in the observer. |
| 985 EXPECT_EQ(foo_url, root->child_at(1)->current_url()); | 940 EXPECT_EQ(foo_url, root->child_at(1)->current_url()); |
| 986 | 941 |
| 987 // Load cross-site page into subframe's subframe. | 942 // Load cross-site page into subframe's subframe. |
| 988 ASSERT_EQ(2U, root->child_at(1)->child_count()); | 943 ASSERT_EQ(2U, root->child_at(1)->child_count()); |
| 989 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); | 944 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); |
| 990 NavigateFrameToURL(root->child_at(1)->child_at(0), bar_url); | 945 NavigateFrameToURL(root->child_at(1)->child_at(0), bar_url); |
| 991 EXPECT_TRUE(observer.navigation_succeeded()); | 946 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 992 EXPECT_EQ(bar_url, observer.navigation_url()); | 947 EXPECT_EQ(bar_url, observer.last_navigation_url()); |
| 993 | 948 |
| 994 // Opening a popup in the sandboxed foo.com iframe should fail. | 949 // Opening a popup in the sandboxed foo.com iframe should fail. |
| 995 bool success = false; | 950 bool success = false; |
| 996 EXPECT_TRUE( | 951 EXPECT_TRUE( |
| 997 ExecuteScriptAndExtractBool(root->child_at(1)->current_frame_host(), | 952 ExecuteScriptAndExtractBool(root->child_at(1)->current_frame_host(), |
| 998 "window.domAutomationController.send(" | 953 "window.domAutomationController.send(" |
| 999 "!window.open('data:text/html,dataurl'));", | 954 "!window.open('data:text/html,dataurl'));", |
| 1000 &success)); | 955 &success)); |
| 1001 EXPECT_TRUE(success); | 956 EXPECT_TRUE(success); |
| 1002 EXPECT_EQ(Shell::windows().size(), 1u); | 957 EXPECT_EQ(Shell::windows().size(), 1u); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 // Verify that a child frame can retrieve the name property set by its parent. | 1018 // Verify that a child frame can retrieve the name property set by its parent. |
| 1064 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, WindowNameReplication) { | 1019 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, WindowNameReplication) { |
| 1065 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); | 1020 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); |
| 1066 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 1021 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 1067 | 1022 |
| 1068 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1023 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1069 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1024 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1070 ->GetFrameTree() | 1025 ->GetFrameTree() |
| 1071 ->root(); | 1026 ->root(); |
| 1072 | 1027 |
| 1073 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 1028 TestNavigationObserver observer(shell()->web_contents()); |
| 1074 | 1029 |
| 1075 // Load cross-site page into iframe. | 1030 // Load cross-site page into iframe. |
| 1076 GURL frame_url = | 1031 GURL frame_url = |
| 1077 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); | 1032 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); |
| 1078 NavigateFrameToURL(root->child_at(0), frame_url); | 1033 NavigateFrameToURL(root->child_at(0), frame_url); |
| 1079 EXPECT_TRUE(observer.navigation_succeeded()); | 1034 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1080 EXPECT_EQ(frame_url, observer.navigation_url()); | 1035 EXPECT_EQ(frame_url, observer.last_navigation_url()); |
| 1081 | 1036 |
| 1082 // Ensure that a new process is created for the subframe. | 1037 // Ensure that a new process is created for the subframe. |
| 1083 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 1038 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 1084 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 1039 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 1085 | 1040 |
| 1086 // Check that the window.name seen by the frame matches the name attribute | 1041 // Check that the window.name seen by the frame matches the name attribute |
| 1087 // specified by its parent in the iframe tag. | 1042 // specified by its parent in the iframe tag. |
| 1088 std::string result; | 1043 std::string result; |
| 1089 EXPECT_TRUE(ExecuteScriptAndExtractString( | 1044 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1090 root->child_at(0)->current_frame_host(), | 1045 root->child_at(0)->current_frame_host(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1102 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 1057 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1103 DISABLED_NavigateRemoteToDataURL) { | 1058 DISABLED_NavigateRemoteToDataURL) { |
| 1104 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1059 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 1105 NavigateToURL(shell(), main_url); | 1060 NavigateToURL(shell(), main_url); |
| 1106 | 1061 |
| 1107 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1062 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1108 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1063 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1109 ->GetFrameTree() | 1064 ->GetFrameTree() |
| 1110 ->root(); | 1065 ->root(); |
| 1111 | 1066 |
| 1112 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 1067 TestNavigationObserver observer(shell()->web_contents()); |
| 1113 | 1068 |
| 1114 // Load cross-site page into iframe. | 1069 // Load cross-site page into iframe. |
| 1115 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | 1070 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); |
| 1116 NavigateFrameToURL(root->child_at(0), url); | 1071 NavigateFrameToURL(root->child_at(0), url); |
| 1117 EXPECT_TRUE(observer.navigation_succeeded()); | 1072 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1118 EXPECT_EQ(url, observer.navigation_url()); | 1073 EXPECT_EQ(url, observer.last_navigation_url()); |
| 1119 | 1074 |
| 1120 // Ensure that we have created a new process for the subframe. | 1075 // Ensure that we have created a new process for the subframe. |
| 1121 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 1076 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 1122 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 1077 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 1123 | 1078 |
| 1124 // Navigate iframe to a data URL. The navigation happens from a script in the | 1079 // Navigate iframe to a data URL. The navigation happens from a script in the |
| 1125 // parent frame, so the data URL should be committed in the same SiteInstance | 1080 // parent frame, so the data URL should be committed in the same SiteInstance |
| 1126 // as the parent frame. | 1081 // as the parent frame. |
| 1127 GURL data_url("data:text/html,dataurl"); | 1082 GURL data_url("data:text/html,dataurl"); |
| 1128 std::string script = base::StringPrintf( | 1083 std::string script = base::StringPrintf( |
| 1129 "setTimeout(function() {" | 1084 "setTimeout(function() {" |
| 1130 "var iframe = document.getElementById('test');" | 1085 "var iframe = document.getElementById('test');" |
| 1131 "iframe.onload = function() { document.title = 'LOADED'; };" | 1086 "iframe.onload = function() { document.title = 'LOADED'; };" |
| 1132 "iframe.src=\"%s\";" | 1087 "iframe.src=\"%s\";" |
| 1133 "},0);", | 1088 "},0);", |
| 1134 data_url.spec().c_str()); | 1089 data_url.spec().c_str()); |
| 1135 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | 1090 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); |
| 1136 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | 1091 TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
| 1137 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 1092 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 1138 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | 1093 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); |
| 1139 EXPECT_TRUE(observer.navigation_succeeded()); | 1094 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1140 EXPECT_EQ(data_url, observer.navigation_url()); | 1095 EXPECT_EQ(data_url, observer.last_navigation_url()); |
| 1141 | 1096 |
| 1142 // Ensure that we have navigated using the top level process. | 1097 // Ensure that we have navigated using the top level process. |
| 1143 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 1098 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 1144 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 1099 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 1145 } | 1100 } |
| 1146 | 1101 |
| 1147 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. | 1102 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. |
| 1148 // Disabled due to the same reason as NavigateRemoteToDataURL. | 1103 // Disabled due to the same reason as NavigateRemoteToDataURL. |
| 1149 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 1104 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1150 DISABLED_NavigateRemoteToBlankURL) { | 1105 DISABLED_NavigateRemoteToBlankURL) { |
| 1151 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1106 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 1152 NavigateToURL(shell(), main_url); | 1107 NavigateToURL(shell(), main_url); |
| 1153 | 1108 |
| 1154 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1109 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1155 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1110 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1156 ->GetFrameTree() | 1111 ->GetFrameTree() |
| 1157 ->root(); | 1112 ->root(); |
| 1158 | 1113 |
| 1159 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 1114 TestNavigationObserver observer(shell()->web_contents()); |
| 1160 | 1115 |
| 1161 // Load cross-site page into iframe. | 1116 // Load cross-site page into iframe. |
| 1162 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | 1117 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); |
| 1163 NavigateFrameToURL(root->child_at(0), url); | 1118 NavigateFrameToURL(root->child_at(0), url); |
| 1164 EXPECT_TRUE(observer.navigation_succeeded()); | 1119 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1165 EXPECT_EQ(url, observer.navigation_url()); | 1120 EXPECT_EQ(url, observer.last_navigation_url()); |
| 1166 | 1121 |
| 1167 // Ensure that we have created a new process for the subframe. | 1122 // Ensure that we have created a new process for the subframe. |
| 1168 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 1123 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 1169 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 1124 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 1170 | 1125 |
| 1171 // Navigate iframe to about:blank. The navigation happens from a script in the | 1126 // Navigate iframe to about:blank. The navigation happens from a script in the |
| 1172 // parent frame, so it should be committed in the same SiteInstance as the | 1127 // parent frame, so it should be committed in the same SiteInstance as the |
| 1173 // parent frame. | 1128 // parent frame. |
| 1174 GURL about_blank_url("about:blank"); | 1129 GURL about_blank_url("about:blank"); |
| 1175 std::string script = base::StringPrintf( | 1130 std::string script = base::StringPrintf( |
| 1176 "setTimeout(function() {" | 1131 "setTimeout(function() {" |
| 1177 "var iframe = document.getElementById('test');" | 1132 "var iframe = document.getElementById('test');" |
| 1178 "iframe.onload = function() { document.title = 'LOADED'; };" | 1133 "iframe.onload = function() { document.title = 'LOADED'; };" |
| 1179 "iframe.src=\"%s\";" | 1134 "iframe.src=\"%s\";" |
| 1180 "},0);", | 1135 "},0);", |
| 1181 about_blank_url.spec().c_str()); | 1136 about_blank_url.spec().c_str()); |
| 1182 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | 1137 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); |
| 1183 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | 1138 TitleWatcher title_watcher(shell()->web_contents(), passed_string); |
| 1184 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 1139 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
| 1185 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | 1140 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); |
| 1186 EXPECT_TRUE(observer.navigation_succeeded()); | 1141 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1187 EXPECT_EQ(about_blank_url, observer.navigation_url()); | 1142 EXPECT_EQ(about_blank_url, observer.last_navigation_url()); |
| 1188 | 1143 |
| 1189 // Ensure that we have navigated using the top level process. | 1144 // Ensure that we have navigated using the top level process. |
| 1190 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 1145 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 1191 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 1146 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 1192 } | 1147 } |
| 1193 | 1148 |
| 1194 // Ensure that navigating subframes in --site-per-process mode properly fires | 1149 // Ensure that navigating subframes in --site-per-process mode properly fires |
| 1195 // the DidStopLoading event on WebContentsObserver. | 1150 // the DidStopLoading event on WebContentsObserver. |
| 1196 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { | 1151 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { |
| 1197 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1152 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 1198 NavigateToURL(shell(), main_url); | 1153 NavigateToURL(shell(), main_url); |
| 1199 | 1154 |
| 1200 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1155 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1201 FrameTreeNode* root = | 1156 FrameTreeNode* root = |
| 1202 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1157 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1203 GetFrameTree()->root(); | 1158 GetFrameTree()->root(); |
| 1204 | 1159 |
| 1205 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 1160 TestNavigationObserver observer(shell()->web_contents()); |
| 1206 | 1161 |
| 1207 // Load same-site page into iframe. | 1162 // Load same-site page into iframe. |
| 1208 FrameTreeNode* child = root->child_at(0); | 1163 FrameTreeNode* child = root->child_at(0); |
| 1209 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 1164 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 1210 NavigateFrameToURL(child, http_url); | 1165 NavigateFrameToURL(child, http_url); |
| 1211 EXPECT_EQ(http_url, observer.navigation_url()); | 1166 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 1212 EXPECT_TRUE(observer.navigation_succeeded()); | 1167 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1213 | 1168 |
| 1214 // Load cross-site page into iframe. | 1169 // Load cross-site page into iframe. |
| 1215 TestNavigationObserver nav_observer(shell()->web_contents(), 1); | 1170 TestNavigationObserver nav_observer(shell()->web_contents(), 1); |
| 1216 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 1171 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 1217 NavigationController::LoadURLParams params(url); | 1172 NavigationController::LoadURLParams params(url); |
| 1218 params.transition_type = ui::PAGE_TRANSITION_LINK; | 1173 params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 1219 params.frame_tree_node_id = child->frame_tree_node_id(); | 1174 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 1220 child->navigator()->GetController()->LoadURLWithParams(params); | 1175 child->navigator()->GetController()->LoadURLWithParams(params); |
| 1221 nav_observer.Wait(); | 1176 nav_observer.Wait(); |
| 1222 | 1177 |
| 1223 // Verify that the navigation succeeded and the expected URL was loaded. | 1178 // Verify that the navigation succeeded and the expected URL was loaded. |
| 1224 EXPECT_TRUE(observer.navigation_succeeded()); | 1179 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1225 EXPECT_EQ(url, observer.navigation_url()); | 1180 EXPECT_EQ(url, observer.last_navigation_url()); |
| 1226 } | 1181 } |
| 1227 | 1182 |
| 1228 } // namespace content | 1183 } // namespace content |
| OLD | NEW |