| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_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/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/render_view_host_observer.h" | 24 #include "content/public/browser/render_view_host_observer.h" |
| 25 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
| 26 #include "content/public/test/browser_test_utils.h" |
| 26 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 27 #include "net/test/test_server.h" | 28 #include "net/test/test_server.h" |
| 28 | 29 |
| 29 using content::RenderViewHost; | 30 using content::RenderViewHost; |
| 30 using content::SiteInstance; | 31 using content::SiteInstance; |
| 31 | 32 |
| 32 class RenderViewHostManagerTest : public InProcessBrowserTest { | 33 class RenderViewHostManagerTest : public InProcessBrowserTest { |
| 33 public: | 34 public: |
| 34 RenderViewHostManagerTest() {} | 35 RenderViewHostManagerTest() {} |
| 35 | 36 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 | 67 |
| 67 // Get the original SiteInstance for later comparison. | 68 // Get the original SiteInstance for later comparison. |
| 68 scoped_refptr<SiteInstance> orig_site_instance( | 69 scoped_refptr<SiteInstance> orig_site_instance( |
| 69 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 70 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 70 EXPECT_TRUE(orig_site_instance != NULL); | 71 EXPECT_TRUE(orig_site_instance != NULL); |
| 71 | 72 |
| 72 // Open a same-site link in a new tab. | 73 // Open a same-site link in a new tab. |
| 73 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 74 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 74 content::Source<content::WebContentsDelegate>(browser()))); | 75 content::Source<content::WebContentsDelegate>(browser()))); |
| 75 bool success = false; | 76 bool success = false; |
| 76 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 77 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 77 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 78 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 78 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 79 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 79 &success)); | 80 &success)); |
| 80 EXPECT_TRUE(success); | 81 EXPECT_TRUE(success); |
| 81 new_tab_observer.Wait(); | 82 new_tab_observer.Wait(); |
| 82 | 83 |
| 83 // Opens in new tab. | 84 // Opens in new tab. |
| 84 EXPECT_EQ(2, browser()->tab_count()); | 85 EXPECT_EQ(2, browser()->tab_count()); |
| 85 EXPECT_EQ(1, browser()->active_index()); | 86 EXPECT_EQ(1, browser()->active_index()); |
| 86 | 87 |
| 87 // Wait for the navigation in the new tab to finish, if it hasn't. | 88 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 88 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 89 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); |
| 89 EXPECT_EQ("/files/navigate_opener.html", | 90 EXPECT_EQ("/files/navigate_opener.html", |
| 90 chrome::GetActiveWebContents(browser())->GetURL().path()); | 91 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 91 EXPECT_EQ(1, browser()->active_index()); | 92 EXPECT_EQ(1, browser()->active_index()); |
| 92 | 93 |
| 93 // Should have the same SiteInstance. | 94 // Should have the same SiteInstance. |
| 94 scoped_refptr<SiteInstance> blank_site_instance( | 95 scoped_refptr<SiteInstance> blank_site_instance( |
| 95 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 96 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 96 EXPECT_EQ(orig_site_instance, blank_site_instance); | 97 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 97 | 98 |
| 98 // We should have access to the opened tab's location. | 99 // We should have access to the opened tab's location. |
| 99 chrome::ActivateTabAt(browser(), 0, true); | 100 chrome::ActivateTabAt(browser(), 0, true); |
| 100 success = false; | 101 success = false; |
| 101 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 102 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 102 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 103 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 103 L"window.domAutomationController.send(testScriptAccessToWindow());", | 104 L"window.domAutomationController.send(testScriptAccessToWindow());", |
| 104 &success)); | 105 &success)); |
| 105 EXPECT_TRUE(success); | 106 EXPECT_TRUE(success); |
| 106 | 107 |
| 107 // Now navigate the new tab to a different site. | 108 // Now navigate the new tab to a different site. |
| 108 chrome::ActivateTabAt(browser(), 1, true); | 109 chrome::ActivateTabAt(browser(), 1, true); |
| 109 ui_test_utils::NavigateToURL(browser(), | 110 ui_test_utils::NavigateToURL(browser(), |
| 110 https_server.GetURL("files/title1.html")); | 111 https_server.GetURL("files/title1.html")); |
| 111 scoped_refptr<SiteInstance> new_site_instance( | 112 scoped_refptr<SiteInstance> new_site_instance( |
| 112 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 113 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 113 EXPECT_NE(orig_site_instance, new_site_instance); | 114 EXPECT_NE(orig_site_instance, new_site_instance); |
| 114 | 115 |
| 115 // We should no longer have script access to the opened tab's location. | 116 // We should no longer have script access to the opened tab's location. |
| 116 chrome::ActivateTabAt(browser(), 0, true); | 117 chrome::ActivateTabAt(browser(), 0, true); |
| 117 success = false; | 118 success = false; |
| 118 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 119 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 119 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 120 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 120 L"window.domAutomationController.send(testScriptAccessToWindow());", | 121 L"window.domAutomationController.send(testScriptAccessToWindow());", |
| 121 &success)); | 122 &success)); |
| 122 EXPECT_FALSE(success); | 123 EXPECT_FALSE(success); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 126 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
| 126 // and target=_blank should create a new SiteInstance. | 127 // and target=_blank should create a new SiteInstance. |
| 127 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 128 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 128 SwapProcessWithRelNoreferrerAndTargetBlank) { | 129 SwapProcessWithRelNoreferrerAndTargetBlank) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 ui_test_utils::NavigateToURL(browser(), | 144 ui_test_utils::NavigateToURL(browser(), |
| 144 test_server()->GetURL(replacement_path)); | 145 test_server()->GetURL(replacement_path)); |
| 145 | 146 |
| 146 // Get the original SiteInstance for later comparison. | 147 // Get the original SiteInstance for later comparison. |
| 147 scoped_refptr<SiteInstance> orig_site_instance( | 148 scoped_refptr<SiteInstance> orig_site_instance( |
| 148 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 149 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 149 EXPECT_TRUE(orig_site_instance != NULL); | 150 EXPECT_TRUE(orig_site_instance != NULL); |
| 150 | 151 |
| 151 // Test clicking a rel=noreferrer + target=blank link. | 152 // Test clicking a rel=noreferrer + target=blank link. |
| 152 bool success = false; | 153 bool success = false; |
| 153 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 154 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 154 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 155 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 155 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", | 156 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
| 156 &success)); | 157 &success)); |
| 157 EXPECT_TRUE(success); | 158 EXPECT_TRUE(success); |
| 158 | 159 |
| 159 // Wait for the tab to open. | 160 // Wait for the tab to open. |
| 160 if (browser()->tab_count() < 2) | 161 if (browser()->tab_count() < 2) |
| 161 ui_test_utils::WaitForNewTab(browser()); | 162 ui_test_utils::WaitForNewTab(browser()); |
| 162 | 163 |
| 163 // Opens in new tab. | 164 // Opens in new tab. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 ui_test_utils::NavigateToURL(browser(), | 202 ui_test_utils::NavigateToURL(browser(), |
| 202 test_server()->GetURL(replacement_path)); | 203 test_server()->GetURL(replacement_path)); |
| 203 | 204 |
| 204 // Get the original SiteInstance for later comparison. | 205 // Get the original SiteInstance for later comparison. |
| 205 scoped_refptr<SiteInstance> orig_site_instance( | 206 scoped_refptr<SiteInstance> orig_site_instance( |
| 206 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 207 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 207 EXPECT_TRUE(orig_site_instance != NULL); | 208 EXPECT_TRUE(orig_site_instance != NULL); |
| 208 | 209 |
| 209 // Test clicking a same-site rel=noreferrer + target=foo link. | 210 // Test clicking a same-site rel=noreferrer + target=foo link. |
| 210 bool success = false; | 211 bool success = false; |
| 211 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 212 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 212 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 213 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 213 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | 214 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
| 214 &success)); | 215 &success)); |
| 215 EXPECT_TRUE(success); | 216 EXPECT_TRUE(success); |
| 216 | 217 |
| 217 // Wait for the tab to open. | 218 // Wait for the tab to open. |
| 218 if (browser()->tab_count() < 2) | 219 if (browser()->tab_count() < 2) |
| 219 ui_test_utils::WaitForNewTab(browser()); | 220 ui_test_utils::WaitForNewTab(browser()); |
| 220 | 221 |
| 221 // Opens in new tab. | 222 // Opens in new tab. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 ui_test_utils::NavigateToURL(browser(), | 259 ui_test_utils::NavigateToURL(browser(), |
| 259 test_server()->GetURL(replacement_path)); | 260 test_server()->GetURL(replacement_path)); |
| 260 | 261 |
| 261 // Get the original SiteInstance for later comparison. | 262 // Get the original SiteInstance for later comparison. |
| 262 scoped_refptr<SiteInstance> orig_site_instance( | 263 scoped_refptr<SiteInstance> orig_site_instance( |
| 263 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 264 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 264 EXPECT_TRUE(orig_site_instance != NULL); | 265 EXPECT_TRUE(orig_site_instance != NULL); |
| 265 | 266 |
| 266 // Test clicking a target=blank link. | 267 // Test clicking a target=blank link. |
| 267 bool success = false; | 268 bool success = false; |
| 268 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 269 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 269 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 270 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 270 L"window.domAutomationController.send(clickTargetBlankLink());", | 271 L"window.domAutomationController.send(clickTargetBlankLink());", |
| 271 &success)); | 272 &success)); |
| 272 EXPECT_TRUE(success); | 273 EXPECT_TRUE(success); |
| 273 | 274 |
| 274 // Wait for the tab to open. | 275 // Wait for the tab to open. |
| 275 if (browser()->tab_count() < 2) | 276 if (browser()->tab_count() < 2) |
| 276 ui_test_utils::WaitForNewTab(browser()); | 277 ui_test_utils::WaitForNewTab(browser()); |
| 277 | 278 |
| 278 // Opens in new tab. | 279 // Opens in new tab. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 ui_test_utils::NavigateToURL(browser(), | 312 ui_test_utils::NavigateToURL(browser(), |
| 312 test_server()->GetURL(replacement_path)); | 313 test_server()->GetURL(replacement_path)); |
| 313 | 314 |
| 314 // Get the original SiteInstance for later comparison. | 315 // Get the original SiteInstance for later comparison. |
| 315 scoped_refptr<SiteInstance> orig_site_instance( | 316 scoped_refptr<SiteInstance> orig_site_instance( |
| 316 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 317 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 317 EXPECT_TRUE(orig_site_instance != NULL); | 318 EXPECT_TRUE(orig_site_instance != NULL); |
| 318 | 319 |
| 319 // Test clicking a rel=noreferrer link. | 320 // Test clicking a rel=noreferrer link. |
| 320 bool success = false; | 321 bool success = false; |
| 321 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 322 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 322 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 323 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 323 L"window.domAutomationController.send(clickNoRefLink());", | 324 L"window.domAutomationController.send(clickNoRefLink());", |
| 324 &success)); | 325 &success)); |
| 325 EXPECT_TRUE(success); | 326 EXPECT_TRUE(success); |
| 326 | 327 |
| 327 // Wait for the cross-site transition in the current tab to finish. | 328 // Wait for the cross-site transition in the current tab to finish. |
| 328 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 329 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); |
| 329 | 330 |
| 330 // Opens in same tab. | 331 // Opens in same tab. |
| 331 EXPECT_EQ(1, browser()->tab_count()); | 332 EXPECT_EQ(1, browser()->tab_count()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 362 | 363 |
| 363 // Get the original SiteInstance for later comparison. | 364 // Get the original SiteInstance for later comparison. |
| 364 scoped_refptr<SiteInstance> orig_site_instance( | 365 scoped_refptr<SiteInstance> orig_site_instance( |
| 365 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 366 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 366 EXPECT_TRUE(orig_site_instance != NULL); | 367 EXPECT_TRUE(orig_site_instance != NULL); |
| 367 | 368 |
| 368 // Test clicking a target=foo link. | 369 // Test clicking a target=foo link. |
| 369 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 370 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 370 content::Source<content::WebContentsDelegate>(browser()))); | 371 content::Source<content::WebContentsDelegate>(browser()))); |
| 371 bool success = false; | 372 bool success = false; |
| 372 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 373 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 373 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 374 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 374 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 375 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 375 &success)); | 376 &success)); |
| 376 EXPECT_TRUE(success); | 377 EXPECT_TRUE(success); |
| 377 new_tab_observer.Wait(); | 378 new_tab_observer.Wait(); |
| 378 | 379 |
| 379 // Opens in new tab. | 380 // Opens in new tab. |
| 380 EXPECT_EQ(2, browser()->tab_count()); | 381 EXPECT_EQ(2, browser()->tab_count()); |
| 381 EXPECT_EQ(1, browser()->active_index()); | 382 EXPECT_EQ(1, browser()->active_index()); |
| 382 | 383 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 398 scoped_refptr<SiteInstance> new_site_instance( | 399 scoped_refptr<SiteInstance> new_site_instance( |
| 399 new_contents->GetSiteInstance()); | 400 new_contents->GetSiteInstance()); |
| 400 EXPECT_NE(orig_site_instance, new_site_instance); | 401 EXPECT_NE(orig_site_instance, new_site_instance); |
| 401 | 402 |
| 402 // Clicking the original link in the first tab should cause us to swap back. | 403 // Clicking the original link in the first tab should cause us to swap back. |
| 403 chrome::ActivateTabAt(browser(), 0, true); | 404 chrome::ActivateTabAt(browser(), 0, true); |
| 404 content::WindowedNotificationObserver navigation_observer( | 405 content::WindowedNotificationObserver navigation_observer( |
| 405 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 406 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 406 content::Source<content::NavigationController>( | 407 content::Source<content::NavigationController>( |
| 407 &new_contents->GetController())); | 408 &new_contents->GetController())); |
| 408 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 409 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 409 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 410 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 410 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 411 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 411 &success)); | 412 &success)); |
| 412 EXPECT_TRUE(success); | 413 EXPECT_TRUE(success); |
| 413 navigation_observer.Wait(); | 414 navigation_observer.Wait(); |
| 414 | 415 |
| 415 // Should have swapped back and shown the new tab again. | 416 // Should have swapped back and shown the new tab again. |
| 416 EXPECT_EQ(1, browser()->active_index()); | 417 EXPECT_EQ(1, browser()->active_index()); |
| 417 scoped_refptr<SiteInstance> revisit_site_instance( | 418 scoped_refptr<SiteInstance> revisit_site_instance( |
| 418 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 419 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 419 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 420 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
| 420 | 421 |
| 421 // If it navigates away to another process, the original window should | 422 // If it navigates away to another process, the original window should |
| 422 // still be able to close it (using a cross-process close message). | 423 // still be able to close it (using a cross-process close message). |
| 423 ui_test_utils::NavigateToURL(browser(), | 424 ui_test_utils::NavigateToURL(browser(), |
| 424 https_server.GetURL("files/title1.html")); | 425 https_server.GetURL("files/title1.html")); |
| 425 EXPECT_EQ(new_site_instance, | 426 EXPECT_EQ(new_site_instance, |
| 426 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 427 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 427 chrome::ActivateTabAt(browser(), 0, true); | 428 chrome::ActivateTabAt(browser(), 0, true); |
| 428 content::WindowedNotificationObserver close_observer( | 429 content::WindowedNotificationObserver close_observer( |
| 429 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 430 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 430 content::Source<content::WebContents>(new_contents)); | 431 content::Source<content::WebContents>(new_contents)); |
| 431 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 432 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 432 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 433 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 433 L"window.domAutomationController.send(testCloseWindow());", | 434 L"window.domAutomationController.send(testCloseWindow());", |
| 434 &success)); | 435 &success)); |
| 435 EXPECT_TRUE(success); | 436 EXPECT_TRUE(success); |
| 436 close_observer.Wait(); | 437 close_observer.Wait(); |
| 437 } | 438 } |
| 438 | 439 |
| 439 // Test for crbug.com/99202. PostMessage calls should still work after | 440 // Test for crbug.com/99202. PostMessage calls should still work after |
| 440 // navigating the source and target windows to different sites. | 441 // navigating the source and target windows to different sites. |
| 441 // Specifically: | 442 // Specifically: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 472 static_cast<WebContentsImpl*>(opener_contents)-> | 473 static_cast<WebContentsImpl*>(opener_contents)-> |
| 473 GetRenderManagerForTesting(); | 474 GetRenderManagerForTesting(); |
| 474 | 475 |
| 475 // 1) Open two more windows, one named. These initially have openers but no | 476 // 1) Open two more windows, one named. These initially have openers but no |
| 476 // reference to each other. We will later post a message between them. | 477 // reference to each other. We will later post a message between them. |
| 477 | 478 |
| 478 // First, a named target=foo window. | 479 // First, a named target=foo window. |
| 479 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 480 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 480 content::Source<content::WebContentsDelegate>(browser()))); | 481 content::Source<content::WebContentsDelegate>(browser()))); |
| 481 bool success = false; | 482 bool success = false; |
| 482 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 483 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 483 opener_contents->GetRenderViewHost(), L"", | 484 opener_contents->GetRenderViewHost(), L"", |
| 484 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 485 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 485 &success)); | 486 &success)); |
| 486 EXPECT_TRUE(success); | 487 EXPECT_TRUE(success); |
| 487 new_tab_observer.Wait(); | 488 new_tab_observer.Wait(); |
| 488 | 489 |
| 489 // Wait for the navigation in the new tab to finish, if it hasn't, then | 490 // Wait for the navigation in the new tab to finish, if it hasn't, then |
| 490 // send it to post_message.html on a different site. | 491 // send it to post_message.html on a different site. |
| 491 content::WebContents* foo_contents = chrome::GetActiveWebContents(browser()); | 492 content::WebContents* foo_contents = chrome::GetActiveWebContents(browser()); |
| 492 ui_test_utils::WaitForLoadStop(foo_contents); | 493 ui_test_utils::WaitForLoadStop(foo_contents); |
| 493 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); | 494 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); |
| 494 EXPECT_EQ(1, browser()->active_index()); | 495 EXPECT_EQ(1, browser()->active_index()); |
| 495 ui_test_utils::NavigateToURL(browser(), | 496 ui_test_utils::NavigateToURL(browser(), |
| 496 https_server.GetURL("files/post_message.html")); | 497 https_server.GetURL("files/post_message.html")); |
| 497 scoped_refptr<SiteInstance> foo_site_instance( | 498 scoped_refptr<SiteInstance> foo_site_instance( |
| 498 foo_contents->GetSiteInstance()); | 499 foo_contents->GetSiteInstance()); |
| 499 EXPECT_NE(orig_site_instance, foo_site_instance); | 500 EXPECT_NE(orig_site_instance, foo_site_instance); |
| 500 | 501 |
| 501 // Second, a target=_blank window. | 502 // Second, a target=_blank window. |
| 502 chrome::ActivateTabAt(browser(), 0, true); | 503 chrome::ActivateTabAt(browser(), 0, true); |
| 503 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer2(( | 504 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer2(( |
| 504 content::Source<content::WebContentsDelegate>(browser()))); | 505 content::Source<content::WebContentsDelegate>(browser()))); |
| 505 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 506 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 506 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 507 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 507 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 508 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
| 508 &success)); | 509 &success)); |
| 509 EXPECT_TRUE(success); | 510 EXPECT_TRUE(success); |
| 510 new_tab_observer2.Wait(); | 511 new_tab_observer2.Wait(); |
| 511 | 512 |
| 512 // Wait for the navigation in the new tab to finish, if it hasn't, then | 513 // Wait for the navigation in the new tab to finish, if it hasn't, then |
| 513 // send it to post_message.html on the original site. | 514 // send it to post_message.html on the original site. |
| 514 content::WebContents* new_contents = chrome::GetActiveWebContents(browser()); | 515 content::WebContents* new_contents = chrome::GetActiveWebContents(browser()); |
| 515 ui_test_utils::WaitForLoadStop(new_contents); | 516 ui_test_utils::WaitForLoadStop(new_contents); |
| 516 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); | 517 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); |
| 517 EXPECT_EQ(1, browser()->active_index()); | 518 EXPECT_EQ(1, browser()->active_index()); |
| 518 ui_test_utils::NavigateToURL( | 519 ui_test_utils::NavigateToURL( |
| 519 browser(), test_server()->GetURL("files/post_message.html")); | 520 browser(), test_server()->GetURL("files/post_message.html")); |
| 520 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); | 521 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); |
| 521 RenderViewHostManager* new_manager = | 522 RenderViewHostManager* new_manager = |
| 522 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); | 523 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); |
| 523 | 524 |
| 524 // We now have three windows. The opener should have a swapped out RVH | 525 // We now have three windows. The opener should have a swapped out RVH |
| 525 // for the new SiteInstance, but the _blank window should not. | 526 // for the new SiteInstance, but the _blank window should not. |
| 526 EXPECT_EQ(3, browser()->tab_count()); | 527 EXPECT_EQ(3, browser()->tab_count()); |
| 527 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 528 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
| 528 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 529 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
| 529 | 530 |
| 530 // 2) Fail to post a message from the foo window to the opener if the target | 531 // 2) Fail to post a message from the foo window to the opener if the target |
| 531 // origin is wrong. We won't see an error, but we can check for the right | 532 // origin is wrong. We won't see an error, but we can check for the right |
| 532 // number of received messages below. | 533 // number of received messages below. |
| 533 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 534 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 534 foo_contents->GetRenderViewHost(), L"", | 535 foo_contents->GetRenderViewHost(), L"", |
| 535 L"window.domAutomationController.send(postToOpener('msg'," | 536 L"window.domAutomationController.send(postToOpener('msg'," |
| 536 L"'http://google.com'));", | 537 L"'http://google.com'));", |
| 537 &success)); | 538 &success)); |
| 538 EXPECT_TRUE(success); | 539 EXPECT_TRUE(success); |
| 539 | 540 |
| 540 // 3) Post a message from the foo window to the opener. The opener will | 541 // 3) Post a message from the foo window to the opener. The opener will |
| 541 // reply, causing the foo window to update its own title. | 542 // reply, causing the foo window to update its own title. |
| 542 content::WindowedNotificationObserver title_observer( | 543 content::WindowedNotificationObserver title_observer( |
| 543 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 544 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 544 content::Source<content::WebContents>(foo_contents)); | 545 content::Source<content::WebContents>(foo_contents)); |
| 545 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 546 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 546 foo_contents->GetRenderViewHost(), L"", | 547 foo_contents->GetRenderViewHost(), L"", |
| 547 L"window.domAutomationController.send(postToOpener('msg','*'));", | 548 L"window.domAutomationController.send(postToOpener('msg','*'));", |
| 548 &success)); | 549 &success)); |
| 549 EXPECT_TRUE(success); | 550 EXPECT_TRUE(success); |
| 550 title_observer.Wait(); | 551 title_observer.Wait(); |
| 551 | 552 |
| 552 // We should have received only 1 message in the opener and "foo" tabs, | 553 // We should have received only 1 message in the opener and "foo" tabs, |
| 553 // and updated the title. | 554 // and updated the title. |
| 554 int opener_received_messages = 0; | 555 int opener_received_messages = 0; |
| 555 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( | 556 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractInt( |
| 556 opener_contents->GetRenderViewHost(), L"", | 557 opener_contents->GetRenderViewHost(), L"", |
| 557 L"window.domAutomationController.send(window.receivedMessages);", | 558 L"window.domAutomationController.send(window.receivedMessages);", |
| 558 &opener_received_messages)); | 559 &opener_received_messages)); |
| 559 int foo_received_messages = 0; | 560 int foo_received_messages = 0; |
| 560 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( | 561 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractInt( |
| 561 foo_contents->GetRenderViewHost(), L"", | 562 foo_contents->GetRenderViewHost(), L"", |
| 562 L"window.domAutomationController.send(window.receivedMessages);", | 563 L"window.domAutomationController.send(window.receivedMessages);", |
| 563 &foo_received_messages)); | 564 &foo_received_messages)); |
| 564 EXPECT_EQ(1, foo_received_messages); | 565 EXPECT_EQ(1, foo_received_messages); |
| 565 EXPECT_EQ(1, opener_received_messages); | 566 EXPECT_EQ(1, opener_received_messages); |
| 566 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); | 567 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); |
| 567 | 568 |
| 568 // 4) Now post a message from the _blank window to the foo window. The | 569 // 4) Now post a message from the _blank window to the foo window. The |
| 569 // foo window will update its title and will not reply. | 570 // foo window will update its title and will not reply. |
| 570 content::WindowedNotificationObserver title_observer2( | 571 content::WindowedNotificationObserver title_observer2( |
| 571 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 572 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 572 content::Source<content::WebContents>(foo_contents)); | 573 content::Source<content::WebContents>(foo_contents)); |
| 573 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 574 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 574 new_contents->GetRenderViewHost(), L"", | 575 new_contents->GetRenderViewHost(), L"", |
| 575 L"window.domAutomationController.send(postToFoo('msg2'));", | 576 L"window.domAutomationController.send(postToFoo('msg2'));", |
| 576 &success)); | 577 &success)); |
| 577 EXPECT_TRUE(success); | 578 EXPECT_TRUE(success); |
| 578 title_observer2.Wait(); | 579 title_observer2.Wait(); |
| 579 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); | 580 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); |
| 580 | 581 |
| 581 // This postMessage should have created a swapped out RVH for the new | 582 // This postMessage should have created a swapped out RVH for the new |
| 582 // SiteInstance in the target=_blank window. | 583 // SiteInstance in the target=_blank window. |
| 583 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 584 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 607 // Get the original tab and SiteInstance for later comparison. | 608 // Get the original tab and SiteInstance for later comparison. |
| 608 content::WebContents* orig_contents = chrome::GetActiveWebContents(browser()); | 609 content::WebContents* orig_contents = chrome::GetActiveWebContents(browser()); |
| 609 scoped_refptr<SiteInstance> orig_site_instance( | 610 scoped_refptr<SiteInstance> orig_site_instance( |
| 610 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 611 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 611 EXPECT_TRUE(orig_site_instance != NULL); | 612 EXPECT_TRUE(orig_site_instance != NULL); |
| 612 | 613 |
| 613 // Test clicking a target=foo link. | 614 // Test clicking a target=foo link. |
| 614 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 615 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 615 content::Source<content::WebContentsDelegate>(browser()))); | 616 content::Source<content::WebContentsDelegate>(browser()))); |
| 616 bool success = false; | 617 bool success = false; |
| 617 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 618 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 618 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 619 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 619 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 620 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 620 &success)); | 621 &success)); |
| 621 EXPECT_TRUE(success); | 622 EXPECT_TRUE(success); |
| 622 new_tab_observer.Wait(); | 623 new_tab_observer.Wait(); |
| 623 | 624 |
| 624 // Opens in new tab. | 625 // Opens in new tab. |
| 625 EXPECT_EQ(2, browser()->tab_count()); | 626 EXPECT_EQ(2, browser()->tab_count()); |
| 626 EXPECT_EQ(1, browser()->active_index()); | 627 EXPECT_EQ(1, browser()->active_index()); |
| 627 | 628 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 643 scoped_refptr<SiteInstance> new_site_instance( | 644 scoped_refptr<SiteInstance> new_site_instance( |
| 644 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 645 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 645 EXPECT_NE(orig_site_instance, new_site_instance); | 646 EXPECT_NE(orig_site_instance, new_site_instance); |
| 646 | 647 |
| 647 // The opened tab should be able to navigate the opener back to its process. | 648 // The opened tab should be able to navigate the opener back to its process. |
| 648 chrome::ActivateTabAt(browser(), 1, true); | 649 chrome::ActivateTabAt(browser(), 1, true); |
| 649 content::WindowedNotificationObserver navigation_observer( | 650 content::WindowedNotificationObserver navigation_observer( |
| 650 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 651 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 651 content::Source<content::NavigationController>( | 652 content::Source<content::NavigationController>( |
| 652 &orig_contents->GetController())); | 653 &orig_contents->GetController())); |
| 653 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 654 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 654 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 655 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 655 L"window.domAutomationController.send(navigateOpener());", | 656 L"window.domAutomationController.send(navigateOpener());", |
| 656 &success)); | 657 &success)); |
| 657 EXPECT_TRUE(success); | 658 EXPECT_TRUE(success); |
| 658 navigation_observer.Wait(); | 659 navigation_observer.Wait(); |
| 659 | 660 |
| 660 // Active tab should not have changed. | 661 // Active tab should not have changed. |
| 661 EXPECT_EQ(1, browser()->active_index()); | 662 EXPECT_EQ(1, browser()->active_index()); |
| 662 | 663 |
| 663 // Should have swapped back into this process. | 664 // Should have swapped back into this process. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 691 | 692 |
| 692 // Get the original SiteInstance for later comparison. | 693 // Get the original SiteInstance for later comparison. |
| 693 scoped_refptr<SiteInstance> orig_site_instance( | 694 scoped_refptr<SiteInstance> orig_site_instance( |
| 694 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 695 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 695 EXPECT_TRUE(orig_site_instance != NULL); | 696 EXPECT_TRUE(orig_site_instance != NULL); |
| 696 | 697 |
| 697 // Test clicking a target=foo link. | 698 // Test clicking a target=foo link. |
| 698 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 699 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 699 content::Source<content::WebContentsDelegate>(browser()))); | 700 content::Source<content::WebContentsDelegate>(browser()))); |
| 700 bool success = false; | 701 bool success = false; |
| 701 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 702 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 702 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 703 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 703 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 704 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 704 &success)); | 705 &success)); |
| 705 EXPECT_TRUE(success); | 706 EXPECT_TRUE(success); |
| 706 new_tab_observer.Wait(); | 707 new_tab_observer.Wait(); |
| 707 | 708 |
| 708 // Opens in new tab. | 709 // Opens in new tab. |
| 709 EXPECT_EQ(2, browser()->tab_count()); | 710 EXPECT_EQ(2, browser()->tab_count()); |
| 710 EXPECT_EQ(1, browser()->active_index()); | 711 EXPECT_EQ(1, browser()->active_index()); |
| 711 | 712 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 783 chrome::GetActiveWebContents(browser())->GetSiteInstance()); |
| 783 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 784 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
| 784 EXPECT_EQ("/nocontent", | 785 EXPECT_EQ("/nocontent", |
| 785 chrome::GetActiveWebContents(browser())->GetURL().path()); | 786 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 786 EXPECT_EQ("/files/click-noreferrer-links.html", | 787 EXPECT_EQ("/files/click-noreferrer-links.html", |
| 787 chrome::GetActiveWebContents(browser())->GetController(). | 788 chrome::GetActiveWebContents(browser())->GetController(). |
| 788 GetLastCommittedEntry()->GetVirtualURL().path()); | 789 GetLastCommittedEntry()->GetVirtualURL().path()); |
| 789 | 790 |
| 790 // Renderer-initiated navigations should work. | 791 // Renderer-initiated navigations should work. |
| 791 bool success = false; | 792 bool success = false; |
| 792 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 793 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 793 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 794 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 794 L"window.domAutomationController.send(clickNoRefLink());", | 795 L"window.domAutomationController.send(clickNoRefLink());", |
| 795 &success)); | 796 &success)); |
| 796 EXPECT_TRUE(success); | 797 EXPECT_TRUE(success); |
| 797 | 798 |
| 798 // Wait for the cross-site transition in the current tab to finish. | 799 // Wait for the cross-site transition in the current tab to finish. |
| 799 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 800 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); |
| 800 | 801 |
| 801 // Opens in same tab. | 802 // Opens in same tab. |
| 802 EXPECT_EQ(1, browser()->tab_count()); | 803 EXPECT_EQ(1, browser()->tab_count()); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 "files/click-noreferrer-links.html", | 955 "files/click-noreferrer-links.html", |
| 955 https_server.host_port_pair(), | 956 https_server.host_port_pair(), |
| 956 &replacement_path)); | 957 &replacement_path)); |
| 957 ui_test_utils::NavigateToURL(browser(), | 958 ui_test_utils::NavigateToURL(browser(), |
| 958 test_server()->GetURL(replacement_path)); | 959 test_server()->GetURL(replacement_path)); |
| 959 | 960 |
| 960 // Open a same-site link in a new tab. | 961 // Open a same-site link in a new tab. |
| 961 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 962 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
| 962 content::Source<content::WebContentsDelegate>(browser()))); | 963 content::Source<content::WebContentsDelegate>(browser()))); |
| 963 bool success = false; | 964 bool success = false; |
| 964 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 965 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 965 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 966 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 966 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 967 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 967 &success)); | 968 &success)); |
| 968 EXPECT_TRUE(success); | 969 EXPECT_TRUE(success); |
| 969 new_tab_observer.Wait(); | 970 new_tab_observer.Wait(); |
| 970 | 971 |
| 971 // Opens in new tab. | 972 // Opens in new tab. |
| 972 EXPECT_EQ(2, browser()->tab_count()); | 973 EXPECT_EQ(2, browser()->tab_count()); |
| 973 EXPECT_EQ(1, browser()->active_index()); | 974 EXPECT_EQ(1, browser()->active_index()); |
| 974 | 975 |
| 975 // Wait for the navigation in the new tab to finish, if it hasn't. | 976 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 976 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 977 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser())); |
| 977 EXPECT_EQ("/files/navigate_opener.html", | 978 EXPECT_EQ("/files/navigate_opener.html", |
| 978 chrome::GetActiveWebContents(browser())->GetURL().path()); | 979 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 979 EXPECT_EQ(1, browser()->active_index()); | 980 EXPECT_EQ(1, browser()->active_index()); |
| 980 | 981 |
| 981 RenderViewHost* rvh = | 982 RenderViewHost* rvh = |
| 982 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 983 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
| 983 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 984 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 984 rvh, L"", | 985 rvh, L"", |
| 985 L"window.domAutomationController.send(" | 986 L"window.domAutomationController.send(" |
| 986 L"document.webkitVisibilityState == 'visible');", | 987 L"document.webkitVisibilityState == 'visible');", |
| 987 &success)); | 988 &success)); |
| 988 EXPECT_TRUE(success); | 989 EXPECT_TRUE(success); |
| 989 | 990 |
| 990 // Now navigate the new tab to a different site. This should swap out the | 991 // Now navigate the new tab to a different site. This should swap out the |
| 991 // tab's existing RenderView, causing it become hidden. | 992 // tab's existing RenderView, causing it become hidden. |
| 992 chrome::ActivateTabAt(browser(), 1, true); | 993 chrome::ActivateTabAt(browser(), 1, true); |
| 993 ui_test_utils::NavigateToURL(browser(), | 994 ui_test_utils::NavigateToURL(browser(), |
| 994 https_server.GetURL("files/title1.html")); | 995 https_server.GetURL("files/title1.html")); |
| 995 | 996 |
| 996 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 997 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 997 rvh, L"", | 998 rvh, L"", |
| 998 L"window.domAutomationController.send(" | 999 L"window.domAutomationController.send(" |
| 999 L"document.webkitVisibilityState == 'hidden');", | 1000 L"document.webkitVisibilityState == 'hidden');", |
| 1000 &success)); | 1001 &success)); |
| 1001 EXPECT_TRUE(success); | 1002 EXPECT_TRUE(success); |
| 1002 | 1003 |
| 1003 // Going back should make the previously swapped-out view to become visible | 1004 // Going back should make the previously swapped-out view to become visible |
| 1004 // again. | 1005 // again. |
| 1005 { | 1006 { |
| 1006 content::WindowedNotificationObserver back_nav_load_observer( | 1007 content::WindowedNotificationObserver back_nav_load_observer( |
| 1007 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1008 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1008 content::Source<content::NavigationController>( | 1009 content::Source<content::NavigationController>( |
| 1009 &chrome::GetActiveWebContents(browser())->GetController())); | 1010 &chrome::GetActiveWebContents(browser())->GetController())); |
| 1010 chrome::GoBack(browser(), CURRENT_TAB); | 1011 chrome::GoBack(browser(), CURRENT_TAB); |
| 1011 back_nav_load_observer.Wait(); | 1012 back_nav_load_observer.Wait(); |
| 1012 } | 1013 } |
| 1013 | 1014 |
| 1014 | 1015 |
| 1015 EXPECT_EQ("/files/navigate_opener.html", | 1016 EXPECT_EQ("/files/navigate_opener.html", |
| 1016 chrome::GetActiveWebContents(browser())->GetURL().path()); | 1017 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 1017 | 1018 |
| 1018 EXPECT_EQ(rvh, chrome::GetActiveWebContents(browser())->GetRenderViewHost()); | 1019 EXPECT_EQ(rvh, chrome::GetActiveWebContents(browser())->GetRenderViewHost()); |
| 1019 | 1020 |
| 1020 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1021 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 1021 rvh, L"", | 1022 rvh, L"", |
| 1022 L"window.domAutomationController.send(" | 1023 L"window.domAutomationController.send(" |
| 1023 L"document.webkitVisibilityState == 'visible');", | 1024 L"document.webkitVisibilityState == 'visible');", |
| 1024 &success)); | 1025 &success)); |
| 1025 EXPECT_TRUE(success); | 1026 EXPECT_TRUE(success); |
| 1026 } | 1027 } |
| 1027 | 1028 |
| 1028 // This class holds onto RenderViewHostObservers for as long as their observed | 1029 // This class holds onto RenderViewHostObservers for as long as their observed |
| 1029 // RenderViewHosts are alive. This allows us to confirm that all hosts have | 1030 // RenderViewHosts are alive. This allows us to confirm that all hosts have |
| 1030 // properly been shutdown. | 1031 // properly been shutdown. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 // Now navigate to a different instance so that we swap out again. | 1113 // Now navigate to a different instance so that we swap out again. |
| 1113 ui_test_utils::NavigateToURL(browser(), | 1114 ui_test_utils::NavigateToURL(browser(), |
| 1114 https_server.GetURL("files/title2.html")); | 1115 https_server.GetURL("files/title2.html")); |
| 1115 rvh_observers.AddObserverToRVH(chrome::GetActiveWebContents(browser())-> | 1116 rvh_observers.AddObserverToRVH(chrome::GetActiveWebContents(browser())-> |
| 1116 GetRenderViewHost()); | 1117 GetRenderViewHost()); |
| 1117 | 1118 |
| 1118 // This used to leak a render view host. | 1119 // This used to leak a render view host. |
| 1119 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser())); | 1120 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser())); |
| 1120 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 1121 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
| 1121 } | 1122 } |
| OLD | NEW |