| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 99 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 100 SetupCrossSiteRedirector(embedded_test_server()); | 100 SetupCrossSiteRedirector(embedded_test_server()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Returns a URL on foo.com with the given path. | 103 // Returns a URL on foo.com with the given path. |
| 104 GURL GetCrossSiteURL(const std::string& path) { | 104 GURL GetCrossSiteURL(const std::string& path) { |
| 105 GURL cross_site_url(test_server()->GetURL(path)); | 105 GURL cross_site_url(test_server()->GetURL(path)); |
| 106 return cross_site_url.ReplaceComponents(replace_host_); | 106 return cross_site_url.ReplaceComponents(replace_host_); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void NavigateToPageWithLinks(Shell* shell) { |
| 110 EXPECT_TRUE(NavigateToURL( |
| 111 shell, embedded_test_server()->GetURL("/click-noreferrer-links.html"))); |
| 112 std::string script = "setOriginForLinks('" + |
| 113 embedded_test_server()->base_url().spec() + "');"; |
| 114 EXPECT_TRUE(ExecuteScript(shell->web_contents(), script)); |
| 115 } |
| 116 |
| 109 protected: | 117 protected: |
| 110 std::string foo_com_; | 118 std::string foo_com_; |
| 111 GURL::Replacements replace_host_; | 119 GURL::Replacements replace_host_; |
| 112 net::HostPortPair foo_host_port_; | 120 net::HostPortPair foo_host_port_; |
| 113 }; | 121 }; |
| 114 | 122 |
| 115 // Web pages should not have script access to the swapped out page. | 123 // Web pages should not have script access to the swapped out page. |
| 116 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, NoScriptAccessAfterSwapOut) { | 124 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, NoScriptAccessAfterSwapOut) { |
| 117 StartServer(); | 125 StartEmbeddedServer(); |
| 118 | 126 |
| 119 // Load a page with links that open in a new window. | 127 // Load a page with links that open in a new window. |
| 120 std::string replacement_path; | 128 NavigateToPageWithLinks(shell()); |
| 121 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 122 "files/click-noreferrer-links.html", | |
| 123 foo_host_port_, | |
| 124 &replacement_path)); | |
| 125 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 126 | 129 |
| 127 // Get the original SiteInstance for later comparison. | 130 // Get the original SiteInstance for later comparison. |
| 128 scoped_refptr<SiteInstance> orig_site_instance( | 131 scoped_refptr<SiteInstance> orig_site_instance( |
| 129 shell()->web_contents()->GetSiteInstance()); | 132 shell()->web_contents()->GetSiteInstance()); |
| 130 EXPECT_TRUE(orig_site_instance.get() != NULL); | 133 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 131 | 134 |
| 132 // Open a same-site link in a new window. | 135 // Open a same-site link in a new window. |
| 133 ShellAddedObserver new_shell_observer; | 136 ShellAddedObserver new_shell_observer; |
| 134 bool success = false; | 137 bool success = false; |
| 135 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 138 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 136 shell()->web_contents(), | 139 shell()->web_contents(), |
| 137 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 140 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 138 &success)); | 141 &success)); |
| 139 EXPECT_TRUE(success); | 142 EXPECT_TRUE(success); |
| 140 Shell* new_shell = new_shell_observer.GetShell(); | 143 Shell* new_shell = new_shell_observer.GetShell(); |
| 141 | 144 |
| 142 // Wait for the navigation in the new window to finish, if it hasn't. | 145 // Wait for the navigation in the new window to finish, if it hasn't. |
| 143 WaitForLoadStop(new_shell->web_contents()); | 146 WaitForLoadStop(new_shell->web_contents()); |
| 144 EXPECT_EQ("/files/navigate_opener.html", | 147 EXPECT_EQ("/navigate_opener.html", |
| 145 new_shell->web_contents()->GetLastCommittedURL().path()); | 148 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 146 | 149 |
| 147 // Should have the same SiteInstance. | 150 // Should have the same SiteInstance. |
| 148 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); | 151 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); |
| 149 | 152 |
| 150 // We should have access to the opened window's location. | 153 // We should have access to the opened window's location. |
| 151 success = false; | 154 success = false; |
| 152 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 155 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 153 shell()->web_contents(), | 156 shell()->web_contents(), |
| 154 "window.domAutomationController.send(testScriptAccessToWindow());", | 157 "window.domAutomationController.send(testScriptAccessToWindow());", |
| 155 &success)); | 158 &success)); |
| 156 EXPECT_TRUE(success); | 159 EXPECT_TRUE(success); |
| 157 | 160 |
| 158 // Now navigate the new window to a different site. | 161 // Now navigate the new window to a different site. |
| 159 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 162 NavigateToURL(new_shell, |
| 163 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 160 scoped_refptr<SiteInstance> new_site_instance( | 164 scoped_refptr<SiteInstance> new_site_instance( |
| 161 new_shell->web_contents()->GetSiteInstance()); | 165 new_shell->web_contents()->GetSiteInstance()); |
| 162 EXPECT_NE(orig_site_instance, new_site_instance); | 166 EXPECT_NE(orig_site_instance, new_site_instance); |
| 163 | 167 |
| 164 // We should no longer have script access to the opened window's location. | 168 // We should no longer have script access to the opened window's location. |
| 165 success = false; | 169 success = false; |
| 166 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 170 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 167 shell()->web_contents(), | 171 shell()->web_contents(), |
| 168 "window.domAutomationController.send(testScriptAccessToWindow());", | 172 "window.domAutomationController.send(testScriptAccessToWindow());", |
| 169 &success)); | 173 &success)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 190 shell()->web_contents(), | 194 shell()->web_contents(), |
| 191 "window.domAutomationController.send(testScriptAccessToWindow());", | 195 "window.domAutomationController.send(testScriptAccessToWindow());", |
| 192 &success)); | 196 &success)); |
| 193 EXPECT_TRUE(success); | 197 EXPECT_TRUE(success); |
| 194 } | 198 } |
| 195 | 199 |
| 196 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 200 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
| 197 // and target=_blank should create a new SiteInstance. | 201 // and target=_blank should create a new SiteInstance. |
| 198 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 202 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 199 SwapProcessWithRelNoreferrerAndTargetBlank) { | 203 SwapProcessWithRelNoreferrerAndTargetBlank) { |
| 200 StartServer(); | 204 StartEmbeddedServer(); |
| 201 | 205 |
| 202 // Load a page with links that open in a new window. | 206 NavigateToPageWithLinks(shell()); |
| 203 std::string replacement_path; | |
| 204 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 205 "files/click-noreferrer-links.html", | |
| 206 foo_host_port_, | |
| 207 &replacement_path)); | |
| 208 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 209 | 207 |
| 210 // Get the original SiteInstance for later comparison. | 208 // Get the original SiteInstance for later comparison. |
| 211 scoped_refptr<SiteInstance> orig_site_instance( | 209 scoped_refptr<SiteInstance> orig_site_instance( |
| 212 shell()->web_contents()->GetSiteInstance()); | 210 shell()->web_contents()->GetSiteInstance()); |
| 213 EXPECT_TRUE(orig_site_instance.get() != NULL); | 211 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 214 | 212 |
| 215 // Test clicking a rel=noreferrer + target=blank link. | 213 // Test clicking a rel=noreferrer + target=blank link. |
| 216 ShellAddedObserver new_shell_observer; | 214 ShellAddedObserver new_shell_observer; |
| 217 bool success = false; | 215 bool success = false; |
| 218 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 216 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 219 shell()->web_contents(), | 217 shell()->web_contents(), |
| 220 "window.domAutomationController.send(clickNoRefTargetBlankLink());", | 218 "window.domAutomationController.send(clickNoRefTargetBlankLink());", |
| 221 &success)); | 219 &success)); |
| 222 EXPECT_TRUE(success); | 220 EXPECT_TRUE(success); |
| 223 | 221 |
| 224 // Wait for the window to open. | 222 // Wait for the window to open. |
| 225 Shell* new_shell = new_shell_observer.GetShell(); | 223 Shell* new_shell = new_shell_observer.GetShell(); |
| 226 | 224 |
| 227 EXPECT_EQ("/files/title2.html", | 225 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
| 228 new_shell->web_contents()->GetVisibleURL().path()); | |
| 229 | 226 |
| 230 // Wait for the cross-site transition in the new tab to finish. | 227 // Wait for the cross-site transition in the new tab to finish. |
| 231 WaitForLoadStop(new_shell->web_contents()); | 228 WaitForLoadStop(new_shell->web_contents()); |
| 232 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 229 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 233 new_shell->web_contents()); | 230 new_shell->web_contents()); |
| 234 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 231 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
| 235 pending_render_view_host()); | 232 pending_render_view_host()); |
| 236 | 233 |
| 237 // Should have a new SiteInstance. | 234 // Should have a new SiteInstance. |
| 238 scoped_refptr<SiteInstance> noref_blank_site_instance( | 235 scoped_refptr<SiteInstance> noref_blank_site_instance( |
| 239 new_shell->web_contents()->GetSiteInstance()); | 236 new_shell->web_contents()->GetSiteInstance()); |
| 240 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 237 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
| 241 } | 238 } |
| 242 | 239 |
| 243 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) | 240 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) |
| 244 // for rel=noreferrer links in new windows, even to same site pages and named | 241 // for rel=noreferrer links in new windows, even to same site pages and named |
| 245 // targets. | 242 // targets. |
| 246 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 243 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 247 SwapProcessWithSameSiteRelNoreferrer) { | 244 SwapProcessWithSameSiteRelNoreferrer) { |
| 248 StartServer(); | 245 StartEmbeddedServer(); |
| 249 | 246 |
| 250 // Load a page with links that open in a new window. | 247 // Load a page with links that open in a new window. |
| 251 std::string replacement_path; | 248 NavigateToPageWithLinks(shell()); |
| 252 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 253 "files/click-noreferrer-links.html", | |
| 254 foo_host_port_, | |
| 255 &replacement_path)); | |
| 256 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 257 | 249 |
| 258 // Get the original SiteInstance for later comparison. | 250 // Get the original SiteInstance for later comparison. |
| 259 scoped_refptr<SiteInstance> orig_site_instance( | 251 scoped_refptr<SiteInstance> orig_site_instance( |
| 260 shell()->web_contents()->GetSiteInstance()); | 252 shell()->web_contents()->GetSiteInstance()); |
| 261 EXPECT_TRUE(orig_site_instance.get() != NULL); | 253 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 262 | 254 |
| 263 // Test clicking a same-site rel=noreferrer + target=foo link. | 255 // Test clicking a same-site rel=noreferrer + target=foo link. |
| 264 ShellAddedObserver new_shell_observer; | 256 ShellAddedObserver new_shell_observer; |
| 265 bool success = false; | 257 bool success = false; |
| 266 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 258 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 267 shell()->web_contents(), | 259 shell()->web_contents(), |
| 268 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | 260 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
| 269 &success)); | 261 &success)); |
| 270 EXPECT_TRUE(success); | 262 EXPECT_TRUE(success); |
| 271 | 263 |
| 272 // Wait for the window to open. | 264 // Wait for the window to open. |
| 273 Shell* new_shell = new_shell_observer.GetShell(); | 265 Shell* new_shell = new_shell_observer.GetShell(); |
| 274 | 266 |
| 275 // Opens in new window. | 267 // Opens in new window. |
| 276 EXPECT_EQ("/files/title2.html", | 268 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
| 277 new_shell->web_contents()->GetVisibleURL().path()); | |
| 278 | 269 |
| 279 // Wait for the cross-site transition in the new tab to finish. | 270 // Wait for the cross-site transition in the new tab to finish. |
| 280 WaitForLoadStop(new_shell->web_contents()); | 271 WaitForLoadStop(new_shell->web_contents()); |
| 281 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 272 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 282 new_shell->web_contents()); | 273 new_shell->web_contents()); |
| 283 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 274 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
| 284 pending_render_view_host()); | 275 pending_render_view_host()); |
| 285 | 276 |
| 286 // Should have a new SiteInstance (in a new BrowsingInstance). | 277 // Should have a new SiteInstance (in a new BrowsingInstance). |
| 287 scoped_refptr<SiteInstance> noref_blank_site_instance( | 278 scoped_refptr<SiteInstance> noref_blank_site_instance( |
| 288 new_shell->web_contents()->GetSiteInstance()); | 279 new_shell->web_contents()->GetSiteInstance()); |
| 289 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 280 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
| 290 } | 281 } |
| 291 | 282 |
| 292 // Test for crbug.com/24447. Following a cross-site link with just | 283 // Test for crbug.com/24447. Following a cross-site link with just |
| 293 // target=_blank should not create a new SiteInstance, unless we | 284 // target=_blank should not create a new SiteInstance, unless we |
| 294 // are running in --site-per-process mode. | 285 // are running in --site-per-process mode. |
| 295 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 286 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 296 DontSwapProcessWithOnlyTargetBlank) { | 287 DontSwapProcessWithOnlyTargetBlank) { |
| 297 StartServer(); | 288 StartEmbeddedServer(); |
| 298 | 289 |
| 299 // Load a page with links that open in a new window. | 290 // Load a page with links that open in a new window. |
| 300 std::string replacement_path; | 291 NavigateToPageWithLinks(shell()); |
| 301 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 302 "files/click-noreferrer-links.html", | |
| 303 foo_host_port_, | |
| 304 &replacement_path)); | |
| 305 EXPECT_TRUE(NavigateToURL(shell(), test_server()->GetURL(replacement_path))); | |
| 306 | 292 |
| 307 // Get the original SiteInstance for later comparison. | 293 // Get the original SiteInstance for later comparison. |
| 308 scoped_refptr<SiteInstance> orig_site_instance( | 294 scoped_refptr<SiteInstance> orig_site_instance( |
| 309 shell()->web_contents()->GetSiteInstance()); | 295 shell()->web_contents()->GetSiteInstance()); |
| 310 EXPECT_TRUE(orig_site_instance.get() != NULL); | 296 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 311 | 297 |
| 312 // Test clicking a target=blank link. | 298 // Test clicking a target=blank link. |
| 313 ShellAddedObserver new_shell_observer; | 299 ShellAddedObserver new_shell_observer; |
| 314 bool success = false; | 300 bool success = false; |
| 315 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 301 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 316 shell()->web_contents(), | 302 shell()->web_contents(), |
| 317 "window.domAutomationController.send(clickTargetBlankLink());", | 303 "window.domAutomationController.send(clickTargetBlankLink());", |
| 318 &success)); | 304 &success)); |
| 319 EXPECT_TRUE(success); | 305 EXPECT_TRUE(success); |
| 320 | 306 |
| 321 // Wait for the window to open. | 307 // Wait for the window to open. |
| 322 Shell* new_shell = new_shell_observer.GetShell(); | 308 Shell* new_shell = new_shell_observer.GetShell(); |
| 323 | 309 |
| 324 // Wait for the cross-site transition in the new tab to finish. | 310 // Wait for the cross-site transition in the new tab to finish. |
| 325 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); | 311 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); |
| 326 EXPECT_EQ("/files/title2.html", | 312 EXPECT_EQ("/title2.html", |
| 327 new_shell->web_contents()->GetLastCommittedURL().path()); | 313 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 328 | 314 |
| 329 // Should have the same SiteInstance unless we're in site-per-process mode. | 315 // Should have the same SiteInstance unless we're in site-per-process mode. |
| 330 scoped_refptr<SiteInstance> blank_site_instance( | 316 scoped_refptr<SiteInstance> blank_site_instance( |
| 331 new_shell->web_contents()->GetSiteInstance()); | 317 new_shell->web_contents()->GetSiteInstance()); |
| 332 if (AreAllSitesIsolatedForTesting()) | 318 if (AreAllSitesIsolatedForTesting()) |
| 333 EXPECT_NE(orig_site_instance, blank_site_instance); | 319 EXPECT_NE(orig_site_instance, blank_site_instance); |
| 334 else | 320 else |
| 335 EXPECT_EQ(orig_site_instance, blank_site_instance); | 321 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 336 } | 322 } |
| 337 | 323 |
| 338 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 324 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
| 339 // and no target=_blank should not create a new SiteInstance. | 325 // and no target=_blank should not create a new SiteInstance. |
| 340 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 326 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 341 DontSwapProcessWithOnlyRelNoreferrer) { | 327 DontSwapProcessWithOnlyRelNoreferrer) { |
| 342 StartServer(); | 328 StartEmbeddedServer(); |
| 343 | 329 |
| 344 // Load a page with links that open in a new window. | 330 // Load a page with links that open in a new window. |
| 345 std::string replacement_path; | 331 NavigateToPageWithLinks(shell()); |
| 346 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 347 "files/click-noreferrer-links.html", | |
| 348 foo_host_port_, | |
| 349 &replacement_path)); | |
| 350 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 351 | 332 |
| 352 // Get the original SiteInstance for later comparison. | 333 // Get the original SiteInstance for later comparison. |
| 353 scoped_refptr<SiteInstance> orig_site_instance( | 334 scoped_refptr<SiteInstance> orig_site_instance( |
| 354 shell()->web_contents()->GetSiteInstance()); | 335 shell()->web_contents()->GetSiteInstance()); |
| 355 EXPECT_TRUE(orig_site_instance.get() != NULL); | 336 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 356 | 337 |
| 357 // Test clicking a rel=noreferrer link. | 338 // Test clicking a rel=noreferrer link. |
| 358 bool success = false; | 339 bool success = false; |
| 359 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 340 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 360 shell()->web_contents(), | 341 shell()->web_contents(), |
| 361 "window.domAutomationController.send(clickNoRefLink());", | 342 "window.domAutomationController.send(clickNoRefLink());", |
| 362 &success)); | 343 &success)); |
| 363 EXPECT_TRUE(success); | 344 EXPECT_TRUE(success); |
| 364 | 345 |
| 365 // Wait for the cross-site transition in the current tab to finish. | 346 // Wait for the cross-site transition in the current tab to finish. |
| 366 WaitForLoadStop(shell()->web_contents()); | 347 WaitForLoadStop(shell()->web_contents()); |
| 367 | 348 |
| 368 // Opens in same window. | 349 // Opens in same window. |
| 369 EXPECT_EQ(1u, Shell::windows().size()); | 350 EXPECT_EQ(1u, Shell::windows().size()); |
| 370 EXPECT_EQ("/files/title2.html", | 351 EXPECT_EQ("/title2.html", |
| 371 shell()->web_contents()->GetLastCommittedURL().path()); | 352 shell()->web_contents()->GetLastCommittedURL().path()); |
| 372 | 353 |
| 373 // Should have the same SiteInstance unless we're in site-per-process mode. | 354 // Should have the same SiteInstance unless we're in site-per-process mode. |
| 374 scoped_refptr<SiteInstance> noref_site_instance( | 355 scoped_refptr<SiteInstance> noref_site_instance( |
| 375 shell()->web_contents()->GetSiteInstance()); | 356 shell()->web_contents()->GetSiteInstance()); |
| 376 if (AreAllSitesIsolatedForTesting()) | 357 if (AreAllSitesIsolatedForTesting()) |
| 377 EXPECT_NE(orig_site_instance, noref_site_instance); | 358 EXPECT_NE(orig_site_instance, noref_site_instance); |
| 378 else | 359 else |
| 379 EXPECT_EQ(orig_site_instance, noref_site_instance); | 360 EXPECT_EQ(orig_site_instance, noref_site_instance); |
| 380 } | 361 } |
| 381 | 362 |
| 382 // Test for crbug.com/116192. Targeted links should still work after the | 363 // Test for crbug.com/116192. Targeted links should still work after the |
| 383 // named target window has swapped processes. | 364 // named target window has swapped processes. |
| 384 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 365 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 385 AllowTargetedNavigationsAfterSwap) { | 366 AllowTargetedNavigationsAfterSwap) { |
| 386 StartServer(); | 367 StartEmbeddedServer(); |
| 387 | 368 |
| 388 // Load a page with links that open in a new window. | 369 // Load a page with links that open in a new window. |
| 389 std::string replacement_path; | 370 NavigateToPageWithLinks(shell()); |
| 390 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 391 "files/click-noreferrer-links.html", | |
| 392 foo_host_port_, | |
| 393 &replacement_path)); | |
| 394 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 395 | 371 |
| 396 // Get the original SiteInstance for later comparison. | 372 // Get the original SiteInstance for later comparison. |
| 397 scoped_refptr<SiteInstance> orig_site_instance( | 373 scoped_refptr<SiteInstance> orig_site_instance( |
| 398 shell()->web_contents()->GetSiteInstance()); | 374 shell()->web_contents()->GetSiteInstance()); |
| 399 EXPECT_TRUE(orig_site_instance.get() != NULL); | 375 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 400 | 376 |
| 401 // Test clicking a target=foo link. | 377 // Test clicking a target=foo link. |
| 402 ShellAddedObserver new_shell_observer; | 378 ShellAddedObserver new_shell_observer; |
| 403 bool success = false; | 379 bool success = false; |
| 404 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 380 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 405 shell()->web_contents(), | 381 shell()->web_contents(), |
| 406 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 382 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 407 &success)); | 383 &success)); |
| 408 EXPECT_TRUE(success); | 384 EXPECT_TRUE(success); |
| 409 Shell* new_shell = new_shell_observer.GetShell(); | 385 Shell* new_shell = new_shell_observer.GetShell(); |
| 410 | 386 |
| 411 // Wait for the navigation in the new tab to finish, if it hasn't. | 387 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 412 WaitForLoadStop(new_shell->web_contents()); | 388 WaitForLoadStop(new_shell->web_contents()); |
| 413 EXPECT_EQ("/files/navigate_opener.html", | 389 EXPECT_EQ("/navigate_opener.html", |
| 414 new_shell->web_contents()->GetLastCommittedURL().path()); | 390 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 415 | 391 |
| 416 // Should have the same SiteInstance. | 392 // Should have the same SiteInstance. |
| 417 scoped_refptr<SiteInstance> blank_site_instance( | 393 scoped_refptr<SiteInstance> blank_site_instance( |
| 418 new_shell->web_contents()->GetSiteInstance()); | 394 new_shell->web_contents()->GetSiteInstance()); |
| 419 EXPECT_EQ(orig_site_instance, blank_site_instance); | 395 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 420 | 396 |
| 421 // Now navigate the new tab to a different site. | 397 // Now navigate the new tab to a different site. |
| 422 GURL cross_site_url(GetCrossSiteURL("files/title1.html")); | 398 GURL cross_site_url( |
| 399 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 423 NavigateToURL(new_shell, cross_site_url); | 400 NavigateToURL(new_shell, cross_site_url); |
| 424 scoped_refptr<SiteInstance> new_site_instance( | 401 scoped_refptr<SiteInstance> new_site_instance( |
| 425 new_shell->web_contents()->GetSiteInstance()); | 402 new_shell->web_contents()->GetSiteInstance()); |
| 426 EXPECT_NE(orig_site_instance, new_site_instance); | 403 EXPECT_NE(orig_site_instance, new_site_instance); |
| 427 | 404 |
| 428 // Clicking the original link in the first tab should cause us to swap back. | 405 // Clicking the original link in the first tab should cause us to swap back. |
| 429 TestNavigationObserver navigation_observer(new_shell->web_contents()); | 406 TestNavigationObserver navigation_observer(new_shell->web_contents()); |
| 430 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 407 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 431 shell()->web_contents(), | 408 shell()->web_contents(), |
| 432 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 409 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 455 | 432 |
| 456 // Test that setting the opener to null in a window affects cross-process | 433 // Test that setting the opener to null in a window affects cross-process |
| 457 // navigations, including those to existing entries. http://crbug.com/156669. | 434 // navigations, including those to existing entries. http://crbug.com/156669. |
| 458 // This test crashes under ThreadSanitizer, http://crbug.com/356758. | 435 // This test crashes under ThreadSanitizer, http://crbug.com/356758. |
| 459 #if defined(THREAD_SANITIZER) | 436 #if defined(THREAD_SANITIZER) |
| 460 #define MAYBE_DisownOpener DISABLED_DisownOpener | 437 #define MAYBE_DisownOpener DISABLED_DisownOpener |
| 461 #else | 438 #else |
| 462 #define MAYBE_DisownOpener DisownOpener | 439 #define MAYBE_DisownOpener DisownOpener |
| 463 #endif | 440 #endif |
| 464 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) { | 441 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) { |
| 465 StartServer(); | 442 StartEmbeddedServer(); |
| 466 | 443 |
| 467 // Load a page with links that open in a new window. | 444 // Load a page with links that open in a new window. |
| 468 std::string replacement_path; | 445 NavigateToPageWithLinks(shell()); |
| 469 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 470 "files/click-noreferrer-links.html", | |
| 471 foo_host_port_, | |
| 472 &replacement_path)); | |
| 473 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 474 | 446 |
| 475 // Get the original SiteInstance for later comparison. | 447 // Get the original SiteInstance for later comparison. |
| 476 scoped_refptr<SiteInstance> orig_site_instance( | 448 scoped_refptr<SiteInstance> orig_site_instance( |
| 477 shell()->web_contents()->GetSiteInstance()); | 449 shell()->web_contents()->GetSiteInstance()); |
| 478 EXPECT_TRUE(orig_site_instance.get() != NULL); | 450 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 479 | 451 |
| 480 // Test clicking a target=_blank link. | 452 // Test clicking a target=_blank link. |
| 481 ShellAddedObserver new_shell_observer; | 453 ShellAddedObserver new_shell_observer; |
| 482 bool success = false; | 454 bool success = false; |
| 483 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 455 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 484 shell()->web_contents(), | 456 shell()->web_contents(), |
| 485 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 457 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
| 486 &success)); | 458 &success)); |
| 487 EXPECT_TRUE(success); | 459 EXPECT_TRUE(success); |
| 488 Shell* new_shell = new_shell_observer.GetShell(); | 460 Shell* new_shell = new_shell_observer.GetShell(); |
| 489 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 461 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
| 490 | 462 |
| 491 // Wait for the navigation in the new tab to finish, if it hasn't. | 463 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 492 WaitForLoadStop(new_shell->web_contents()); | 464 WaitForLoadStop(new_shell->web_contents()); |
| 493 EXPECT_EQ("/files/title2.html", | 465 EXPECT_EQ("/title2.html", |
| 494 new_shell->web_contents()->GetLastCommittedURL().path()); | 466 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 495 | 467 |
| 496 // Should have the same SiteInstance. | 468 // Should have the same SiteInstance. |
| 497 scoped_refptr<SiteInstance> blank_site_instance( | 469 scoped_refptr<SiteInstance> blank_site_instance( |
| 498 new_shell->web_contents()->GetSiteInstance()); | 470 new_shell->web_contents()->GetSiteInstance()); |
| 499 EXPECT_EQ(orig_site_instance, blank_site_instance); | 471 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 500 | 472 |
| 501 // Now navigate the new tab to a different site. | 473 // Now navigate the new tab to a different site. |
| 502 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 474 GURL cross_site_url( |
| 475 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 476 NavigateToURL(new_shell, cross_site_url); |
| 503 scoped_refptr<SiteInstance> new_site_instance( | 477 scoped_refptr<SiteInstance> new_site_instance( |
| 504 new_shell->web_contents()->GetSiteInstance()); | 478 new_shell->web_contents()->GetSiteInstance()); |
| 505 EXPECT_NE(orig_site_instance, new_site_instance); | 479 EXPECT_NE(orig_site_instance, new_site_instance); |
| 506 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 480 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
| 507 | 481 |
| 508 // Now disown the opener. | 482 // Now disown the opener. |
| 509 EXPECT_TRUE(ExecuteScript(new_shell->web_contents(), | 483 EXPECT_TRUE(ExecuteScript(new_shell->web_contents(), |
| 510 "window.opener = null;")); | 484 "window.opener = null;")); |
| 511 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 485 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
| 512 | 486 |
| 513 // Go back and ensure the opener is still null. | 487 // Go back and ensure the opener is still null. |
| 514 { | 488 { |
| 515 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); | 489 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); |
| 516 new_shell->web_contents()->GetController().GoBack(); | 490 new_shell->web_contents()->GetController().GoBack(); |
| 517 back_nav_load_observer.Wait(); | 491 back_nav_load_observer.Wait(); |
| 518 } | 492 } |
| 519 success = false; | 493 success = false; |
| 520 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 494 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 521 new_shell->web_contents(), | 495 new_shell->web_contents(), |
| 522 "window.domAutomationController.send(window.opener == null);", | 496 "window.domAutomationController.send(window.opener == null);", |
| 523 &success)); | 497 &success)); |
| 524 EXPECT_TRUE(success); | 498 EXPECT_TRUE(success); |
| 525 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 499 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
| 526 | 500 |
| 527 // Now navigate forward again (creating a new process) and check opener. | 501 // Now navigate forward again (creating a new process) and check opener. |
| 528 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 502 NavigateToURL(new_shell, cross_site_url); |
| 529 success = false; | 503 success = false; |
| 530 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 504 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 531 new_shell->web_contents(), | 505 new_shell->web_contents(), |
| 532 "window.domAutomationController.send(window.opener == null);", | 506 "window.domAutomationController.send(window.opener == null);", |
| 533 &success)); | 507 &success)); |
| 534 EXPECT_TRUE(success); | 508 EXPECT_TRUE(success); |
| 535 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 509 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
| 536 } | 510 } |
| 537 | 511 |
| 538 // Test that subframes can disown their openers. http://crbug.com/225528. | 512 // Test that subframes can disown their openers. http://crbug.com/225528. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 // navigating the source and target windows to different sites. | 595 // navigating the source and target windows to different sites. |
| 622 // Specifically: | 596 // Specifically: |
| 623 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. | 597 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. |
| 624 // 2) Fail to post a message from "foo" to opener with the wrong target origin. | 598 // 2) Fail to post a message from "foo" to opener with the wrong target origin. |
| 625 // 3) Post a message from "foo" to opener, which replies back to "foo". | 599 // 3) Post a message from "foo" to opener, which replies back to "foo". |
| 626 // 4) Post a message from _blank to "foo". | 600 // 4) Post a message from _blank to "foo". |
| 627 // 5) Post a message from "foo" to a subframe of opener, which replies back. | 601 // 5) Post a message from "foo" to a subframe of opener, which replies back. |
| 628 // 6) Post a message from _blank to a subframe of "foo". | 602 // 6) Post a message from _blank to a subframe of "foo". |
| 629 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 603 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 630 SupportCrossProcessPostMessage) { | 604 SupportCrossProcessPostMessage) { |
| 631 StartServer(); | 605 StartEmbeddedServer(); |
| 632 | 606 |
| 633 // Load a page with links that open in a new window. | 607 // Load a page with links that open in a new window. |
| 634 std::string replacement_path; | 608 NavigateToPageWithLinks(shell()); |
| 635 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 636 "files/click-noreferrer-links.html", | |
| 637 foo_host_port_, | |
| 638 &replacement_path)); | |
| 639 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 640 | 609 |
| 641 // Get the original SiteInstance and RVHM for later comparison. | 610 // Get the original SiteInstance and RVHM for later comparison. |
| 642 WebContents* opener_contents = shell()->web_contents(); | 611 WebContents* opener_contents = shell()->web_contents(); |
| 643 scoped_refptr<SiteInstance> orig_site_instance( | 612 scoped_refptr<SiteInstance> orig_site_instance( |
| 644 opener_contents->GetSiteInstance()); | 613 opener_contents->GetSiteInstance()); |
| 645 EXPECT_TRUE(orig_site_instance.get() != NULL); | 614 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 646 RenderFrameHostManager* opener_manager = static_cast<WebContentsImpl*>( | 615 RenderFrameHostManager* opener_manager = static_cast<WebContentsImpl*>( |
| 647 opener_contents)->GetRenderManagerForTesting(); | 616 opener_contents)->GetRenderManagerForTesting(); |
| 648 | 617 |
| 649 // 1) Open two more windows, one named. These initially have openers but no | 618 // 1) Open two more windows, one named. These initially have openers but no |
| 650 // reference to each other. We will later post a message between them. | 619 // reference to each other. We will later post a message between them. |
| 651 | 620 |
| 652 // First, a named target=foo window. | 621 // First, a named target=foo window. |
| 653 ShellAddedObserver new_shell_observer; | 622 ShellAddedObserver new_shell_observer; |
| 654 bool success = false; | 623 bool success = false; |
| 655 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 624 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 656 opener_contents, | 625 opener_contents, |
| 657 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 626 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 658 &success)); | 627 &success)); |
| 659 EXPECT_TRUE(success); | 628 EXPECT_TRUE(success); |
| 660 Shell* new_shell = new_shell_observer.GetShell(); | 629 Shell* new_shell = new_shell_observer.GetShell(); |
| 661 | 630 |
| 662 // Wait for the navigation in the new window to finish, if it hasn't, then | 631 // Wait for the navigation in the new window to finish, if it hasn't, then |
| 663 // send it to post_message.html on a different site. | 632 // send it to post_message.html on a different site. |
| 664 WebContents* foo_contents = new_shell->web_contents(); | 633 WebContents* foo_contents = new_shell->web_contents(); |
| 665 WaitForLoadStop(foo_contents); | 634 WaitForLoadStop(foo_contents); |
| 666 EXPECT_EQ("/files/navigate_opener.html", | 635 EXPECT_EQ("/navigate_opener.html", |
| 667 foo_contents->GetLastCommittedURL().path()); | 636 foo_contents->GetLastCommittedURL().path()); |
| 668 NavigateToURL(new_shell, GetCrossSiteURL("files/post_message.html")); | 637 NavigateToURL(new_shell, embedded_test_server()->GetURL( |
| 638 "foo.com", "/post_message.html")); |
| 669 scoped_refptr<SiteInstance> foo_site_instance( | 639 scoped_refptr<SiteInstance> foo_site_instance( |
| 670 foo_contents->GetSiteInstance()); | 640 foo_contents->GetSiteInstance()); |
| 671 EXPECT_NE(orig_site_instance, foo_site_instance); | 641 EXPECT_NE(orig_site_instance, foo_site_instance); |
| 672 | 642 |
| 673 // Second, a target=_blank window. | 643 // Second, a target=_blank window. |
| 674 ShellAddedObserver new_shell_observer2; | 644 ShellAddedObserver new_shell_observer2; |
| 675 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 645 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 676 shell()->web_contents(), | 646 shell()->web_contents(), |
| 677 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 647 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
| 678 &success)); | 648 &success)); |
| 679 EXPECT_TRUE(success); | 649 EXPECT_TRUE(success); |
| 680 | 650 |
| 681 // Wait for the navigation in the new window to finish, if it hasn't, then | 651 // Wait for the navigation in the new window to finish, if it hasn't, then |
| 682 // send it to post_message.html on the original site. | 652 // send it to post_message.html on the original site. |
| 683 Shell* new_shell2 = new_shell_observer2.GetShell(); | 653 Shell* new_shell2 = new_shell_observer2.GetShell(); |
| 684 WebContents* new_contents = new_shell2->web_contents(); | 654 WebContents* new_contents = new_shell2->web_contents(); |
| 685 WaitForLoadStop(new_contents); | 655 WaitForLoadStop(new_contents); |
| 686 EXPECT_EQ("/files/title2.html", new_contents->GetLastCommittedURL().path()); | 656 EXPECT_EQ("/title2.html", new_contents->GetLastCommittedURL().path()); |
| 687 NavigateToURL(new_shell2, test_server()->GetURL("files/post_message.html")); | 657 NavigateToURL(new_shell2, |
| 658 embedded_test_server()->GetURL("/post_message.html")); |
| 688 EXPECT_EQ(orig_site_instance.get(), new_contents->GetSiteInstance()); | 659 EXPECT_EQ(orig_site_instance.get(), new_contents->GetSiteInstance()); |
| 689 RenderFrameHostManager* new_manager = | 660 RenderFrameHostManager* new_manager = |
| 690 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); | 661 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); |
| 691 | 662 |
| 692 // We now have three windows. The opener should have a swapped out RVH | 663 // We now have three windows. The opener should have a swapped out RVH |
| 693 // for the new SiteInstance, but the _blank window should not. | 664 // for the new SiteInstance, but the _blank window should not. |
| 694 EXPECT_EQ(3u, Shell::windows().size()); | 665 EXPECT_EQ(3u, Shell::windows().size()); |
| 695 EXPECT_TRUE( | 666 EXPECT_TRUE( |
| 696 opener_manager->GetSwappedOutRenderViewHost(foo_site_instance.get())); | 667 opener_manager->GetSwappedOutRenderViewHost(foo_site_instance.get())); |
| 697 EXPECT_FALSE( | 668 EXPECT_FALSE( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 // messages which contain Transferables and get intercepted by | 733 // messages which contain Transferables and get intercepted by |
| 763 // RenderViewImpl::willCheckAndDispatchMessageEvent (because the RenderView is | 734 // RenderViewImpl::willCheckAndDispatchMessageEvent (because the RenderView is |
| 764 // swapped out) should work. | 735 // swapped out) should work. |
| 765 // Specifically: | 736 // Specifically: |
| 766 // 1) Create 2 windows (opener and "foo") and send "foo" cross-process. | 737 // 1) Create 2 windows (opener and "foo") and send "foo" cross-process. |
| 767 // 2) Post a message containing a message port from opener to "foo". | 738 // 2) Post a message containing a message port from opener to "foo". |
| 768 // 3) Post a message from "foo" back to opener via the passed message port. | 739 // 3) Post a message from "foo" back to opener via the passed message port. |
| 769 // The test will be enabled when the feature implementation lands. | 740 // The test will be enabled when the feature implementation lands. |
| 770 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 741 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 771 SupportCrossProcessPostMessageWithMessagePort) { | 742 SupportCrossProcessPostMessageWithMessagePort) { |
| 772 StartServer(); | 743 StartEmbeddedServer(); |
| 773 | 744 |
| 774 // Load a page with links that open in a new window. | 745 // Load a page with links that open in a new window. |
| 775 std::string replacement_path; | 746 NavigateToPageWithLinks(shell()); |
| 776 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 777 "files/click-noreferrer-links.html", | |
| 778 foo_host_port_, | |
| 779 &replacement_path)); | |
| 780 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 781 | 747 |
| 782 // Get the original SiteInstance and RVHM for later comparison. | 748 // Get the original SiteInstance and RVHM for later comparison. |
| 783 WebContents* opener_contents = shell()->web_contents(); | 749 WebContents* opener_contents = shell()->web_contents(); |
| 784 scoped_refptr<SiteInstance> orig_site_instance( | 750 scoped_refptr<SiteInstance> orig_site_instance( |
| 785 opener_contents->GetSiteInstance()); | 751 opener_contents->GetSiteInstance()); |
| 786 EXPECT_TRUE(orig_site_instance.get() != NULL); | 752 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 787 RenderFrameHostManager* opener_manager = static_cast<WebContentsImpl*>( | 753 RenderFrameHostManager* opener_manager = static_cast<WebContentsImpl*>( |
| 788 opener_contents)->GetRenderManagerForTesting(); | 754 opener_contents)->GetRenderManagerForTesting(); |
| 789 | 755 |
| 790 // 1) Open a named target=foo window. We will later post a message between the | 756 // 1) Open a named target=foo window. We will later post a message between the |
| 791 // opener and the new window. | 757 // opener and the new window. |
| 792 ShellAddedObserver new_shell_observer; | 758 ShellAddedObserver new_shell_observer; |
| 793 bool success = false; | 759 bool success = false; |
| 794 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 760 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 795 opener_contents, | 761 opener_contents, |
| 796 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 762 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 797 &success)); | 763 &success)); |
| 798 EXPECT_TRUE(success); | 764 EXPECT_TRUE(success); |
| 799 Shell* new_shell = new_shell_observer.GetShell(); | 765 Shell* new_shell = new_shell_observer.GetShell(); |
| 800 | 766 |
| 801 // Wait for the navigation in the new window to finish, if it hasn't, then | 767 // Wait for the navigation in the new window to finish, if it hasn't, then |
| 802 // send it to post_message.html on a different site. | 768 // send it to post_message.html on a different site. |
| 803 WebContents* foo_contents = new_shell->web_contents(); | 769 WebContents* foo_contents = new_shell->web_contents(); |
| 804 WaitForLoadStop(foo_contents); | 770 WaitForLoadStop(foo_contents); |
| 805 EXPECT_EQ("/files/navigate_opener.html", | 771 EXPECT_EQ("/navigate_opener.html", |
| 806 foo_contents->GetLastCommittedURL().path()); | 772 foo_contents->GetLastCommittedURL().path()); |
| 807 NavigateToURL(new_shell, GetCrossSiteURL("files/post_message.html")); | 773 NavigateToURL(new_shell, embedded_test_server()->GetURL( |
| 774 "foo.com", "/post_message.html")); |
| 808 scoped_refptr<SiteInstance> foo_site_instance( | 775 scoped_refptr<SiteInstance> foo_site_instance( |
| 809 foo_contents->GetSiteInstance()); | 776 foo_contents->GetSiteInstance()); |
| 810 EXPECT_NE(orig_site_instance, foo_site_instance); | 777 EXPECT_NE(orig_site_instance, foo_site_instance); |
| 811 | 778 |
| 812 // We now have two windows. The opener should have a swapped out RVH | 779 // We now have two windows. The opener should have a swapped out RVH |
| 813 // for the new SiteInstance. | 780 // for the new SiteInstance. |
| 814 EXPECT_EQ(2u, Shell::windows().size()); | 781 EXPECT_EQ(2u, Shell::windows().size()); |
| 815 EXPECT_TRUE( | 782 EXPECT_TRUE( |
| 816 opener_manager->GetSwappedOutRenderViewHost(foo_site_instance.get())); | 783 opener_manager->GetSwappedOutRenderViewHost(foo_site_instance.get())); |
| 817 | 784 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 EXPECT_EQ(1, foo_received_messages_with_port); | 816 EXPECT_EQ(1, foo_received_messages_with_port); |
| 850 EXPECT_EQ(1, opener_received_messages_via_port); | 817 EXPECT_EQ(1, opener_received_messages_via_port); |
| 851 EXPECT_EQ(ASCIIToUTF16("msg-with-port"), foo_contents->GetTitle()); | 818 EXPECT_EQ(ASCIIToUTF16("msg-with-port"), foo_contents->GetTitle()); |
| 852 EXPECT_EQ(ASCIIToUTF16("msg-back-via-port"), opener_contents->GetTitle()); | 819 EXPECT_EQ(ASCIIToUTF16("msg-back-via-port"), opener_contents->GetTitle()); |
| 853 } | 820 } |
| 854 | 821 |
| 855 // Test for crbug.com/116192. Navigations to a window's opener should | 822 // Test for crbug.com/116192. Navigations to a window's opener should |
| 856 // still work after a process swap. | 823 // still work after a process swap. |
| 857 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 824 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 858 AllowTargetedNavigationsInOpenerAfterSwap) { | 825 AllowTargetedNavigationsInOpenerAfterSwap) { |
| 859 StartServer(); | 826 StartEmbeddedServer(); |
| 860 | 827 |
| 861 // Load a page with links that open in a new window. | 828 // Load a page with links that open in a new window. |
| 862 std::string replacement_path; | 829 NavigateToPageWithLinks(shell()); |
| 863 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 864 "files/click-noreferrer-links.html", | |
| 865 foo_host_port_, | |
| 866 &replacement_path)); | |
| 867 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 868 | 830 |
| 869 // Get the original tab and SiteInstance for later comparison. | 831 // Get the original tab and SiteInstance for later comparison. |
| 870 WebContents* orig_contents = shell()->web_contents(); | 832 WebContents* orig_contents = shell()->web_contents(); |
| 871 scoped_refptr<SiteInstance> orig_site_instance( | 833 scoped_refptr<SiteInstance> orig_site_instance( |
| 872 orig_contents->GetSiteInstance()); | 834 orig_contents->GetSiteInstance()); |
| 873 EXPECT_TRUE(orig_site_instance.get() != NULL); | 835 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 874 | 836 |
| 875 // Test clicking a target=foo link. | 837 // Test clicking a target=foo link. |
| 876 ShellAddedObserver new_shell_observer; | 838 ShellAddedObserver new_shell_observer; |
| 877 bool success = false; | 839 bool success = false; |
| 878 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 840 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 879 orig_contents, | 841 orig_contents, |
| 880 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 842 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 881 &success)); | 843 &success)); |
| 882 EXPECT_TRUE(success); | 844 EXPECT_TRUE(success); |
| 883 Shell* new_shell = new_shell_observer.GetShell(); | 845 Shell* new_shell = new_shell_observer.GetShell(); |
| 884 | 846 |
| 885 // Wait for the navigation in the new window to finish, if it hasn't. | 847 // Wait for the navigation in the new window to finish, if it hasn't. |
| 886 WaitForLoadStop(new_shell->web_contents()); | 848 WaitForLoadStop(new_shell->web_contents()); |
| 887 EXPECT_EQ("/files/navigate_opener.html", | 849 EXPECT_EQ("/navigate_opener.html", |
| 888 new_shell->web_contents()->GetLastCommittedURL().path()); | 850 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 889 | 851 |
| 890 // Should have the same SiteInstance. | 852 // Should have the same SiteInstance. |
| 891 scoped_refptr<SiteInstance> blank_site_instance( | 853 scoped_refptr<SiteInstance> blank_site_instance( |
| 892 new_shell->web_contents()->GetSiteInstance()); | 854 new_shell->web_contents()->GetSiteInstance()); |
| 893 EXPECT_EQ(orig_site_instance, blank_site_instance); | 855 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 894 | 856 |
| 895 // Now navigate the original (opener) tab to a different site. | 857 // Now navigate the original (opener) tab to a different site. |
| 896 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 858 NavigateToURL(shell(), |
| 859 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 897 scoped_refptr<SiteInstance> new_site_instance( | 860 scoped_refptr<SiteInstance> new_site_instance( |
| 898 shell()->web_contents()->GetSiteInstance()); | 861 shell()->web_contents()->GetSiteInstance()); |
| 899 EXPECT_NE(orig_site_instance, new_site_instance); | 862 EXPECT_NE(orig_site_instance, new_site_instance); |
| 900 | 863 |
| 901 // The opened tab should be able to navigate the opener back to its process. | 864 // The opened tab should be able to navigate the opener back to its process. |
| 902 TestNavigationObserver navigation_observer(orig_contents); | 865 TestNavigationObserver navigation_observer(orig_contents); |
| 903 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 866 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 904 new_shell->web_contents(), | 867 new_shell->web_contents(), |
| 905 "window.domAutomationController.send(navigateOpener());", | 868 "window.domAutomationController.send(navigateOpener());", |
| 906 &success)); | 869 &success)); |
| 907 EXPECT_TRUE(success); | 870 EXPECT_TRUE(success); |
| 908 navigation_observer.Wait(); | 871 navigation_observer.Wait(); |
| 909 | 872 |
| 910 // Should have swapped back into this process. | 873 // Should have swapped back into this process. |
| 911 scoped_refptr<SiteInstance> revisit_site_instance( | 874 scoped_refptr<SiteInstance> revisit_site_instance( |
| 912 shell()->web_contents()->GetSiteInstance()); | 875 shell()->web_contents()->GetSiteInstance()); |
| 913 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 876 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
| 914 } | 877 } |
| 915 | 878 |
| 916 // Test that subframes do not crash when sending a postMessage to the top frame | 879 // Test that subframes do not crash when sending a postMessage to the top frame |
| 917 // from an unload handler while the top frame is being swapped out as part of | 880 // from an unload handler while the top frame is being swapped out as part of |
| 918 // navigating cross-process. https://crbug.com/475651. | 881 // navigating cross-process. https://crbug.com/475651. |
| 919 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 882 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 920 PostMessageFromSubframeUnloadHandler) { | 883 PostMessageFromSubframeUnloadHandler) { |
| 921 StartServer(); | 884 StartEmbeddedServer(); |
| 922 | 885 |
| 923 GURL frame_url(test_server()->GetURL("files/post_message.html")); | 886 GURL frame_url(embedded_test_server()->GetURL("/post_message.html")); |
| 924 GURL main_url("data:text/html,<iframe name='foo' src='" + frame_url.spec() + | 887 GURL main_url("data:text/html,<iframe name='foo' src='" + frame_url.spec() + |
| 925 "'></iframe>"); | 888 "'></iframe>"); |
| 926 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 889 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 927 | 890 |
| 928 // Get the original SiteInstance for later comparison. | 891 // Get the original SiteInstance for later comparison. |
| 929 scoped_refptr<SiteInstance> orig_site_instance( | 892 scoped_refptr<SiteInstance> orig_site_instance( |
| 930 shell()->web_contents()->GetSiteInstance()); | 893 shell()->web_contents()->GetSiteInstance()); |
| 931 EXPECT_NE(nullptr, orig_site_instance.get()); | 894 EXPECT_NE(nullptr, orig_site_instance.get()); |
| 932 | 895 |
| 933 // It is safe to obtain the root frame tree node here, as it doesn't change. | 896 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 934 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 897 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 935 ->GetFrameTree() | 898 ->GetFrameTree() |
| 936 ->root(); | 899 ->root(); |
| 937 ASSERT_EQ(1U, root->child_count()); | 900 ASSERT_EQ(1U, root->child_count()); |
| 938 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); | 901 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); |
| 939 | 902 |
| 940 // Register an unload handler that sends a postMessage to the top frame. | 903 // Register an unload handler that sends a postMessage to the top frame. |
| 941 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 904 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), |
| 942 "registerUnload();")); | 905 "registerUnload();")); |
| 943 | 906 |
| 944 // Navigate the top frame cross-site. This will cause the top frame to be | 907 // Navigate the top frame cross-site. This will cause the top frame to be |
| 945 // swapped out and run unload handlers, and the original renderer process | 908 // swapped out and run unload handlers, and the original renderer process |
| 946 // should then terminate since it's not rendering any other frames. | 909 // should then terminate since it's not rendering any other frames. |
| 947 RenderProcessHostWatcher exit_observer( | 910 RenderProcessHostWatcher exit_observer( |
| 948 root->current_frame_host()->GetProcess(), | 911 root->current_frame_host()->GetProcess(), |
| 949 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 912 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
| 950 EXPECT_TRUE(NavigateToURL(shell(), GetCrossSiteURL("files/title1.html"))); | 913 EXPECT_TRUE(NavigateToURL( |
| 914 shell(), embedded_test_server()->GetURL("foo.com", "/title1.html"))); |
| 951 scoped_refptr<SiteInstance> new_site_instance( | 915 scoped_refptr<SiteInstance> new_site_instance( |
| 952 shell()->web_contents()->GetSiteInstance()); | 916 shell()->web_contents()->GetSiteInstance()); |
| 953 EXPECT_NE(orig_site_instance, new_site_instance); | 917 EXPECT_NE(orig_site_instance, new_site_instance); |
| 954 | 918 |
| 955 // Ensure that the original renderer process exited cleanly without crashing. | 919 // Ensure that the original renderer process exited cleanly without crashing. |
| 956 exit_observer.Wait(); | 920 exit_observer.Wait(); |
| 957 EXPECT_EQ(true, exit_observer.did_exit_normally()); | 921 EXPECT_EQ(true, exit_observer.did_exit_normally()); |
| 958 } | 922 } |
| 959 | 923 |
| 960 // Test that opening a new window in the same SiteInstance and then navigating | 924 // Test that opening a new window in the same SiteInstance and then navigating |
| 961 // both windows to a different SiteInstance allows the first process to exit. | 925 // both windows to a different SiteInstance allows the first process to exit. |
| 962 // See http://crbug.com/126333. | 926 // See http://crbug.com/126333. |
| 963 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 927 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 964 ProcessExitWithSwappedOutViews) { | 928 ProcessExitWithSwappedOutViews) { |
| 965 StartServer(); | 929 StartEmbeddedServer(); |
| 966 | 930 |
| 967 // Load a page with links that open in a new window. | 931 // Load a page with links that open in a new window. |
| 968 std::string replacement_path; | 932 NavigateToPageWithLinks(shell()); |
| 969 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 970 "files/click-noreferrer-links.html", | |
| 971 foo_host_port_, | |
| 972 &replacement_path)); | |
| 973 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 974 | 933 |
| 975 // Get the original SiteInstance for later comparison. | 934 // Get the original SiteInstance for later comparison. |
| 976 scoped_refptr<SiteInstance> orig_site_instance( | 935 scoped_refptr<SiteInstance> orig_site_instance( |
| 977 shell()->web_contents()->GetSiteInstance()); | 936 shell()->web_contents()->GetSiteInstance()); |
| 978 EXPECT_TRUE(orig_site_instance.get() != NULL); | 937 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 979 | 938 |
| 980 // Test clicking a target=foo link. | 939 // Test clicking a target=foo link. |
| 981 ShellAddedObserver new_shell_observer; | 940 ShellAddedObserver new_shell_observer; |
| 982 bool success = false; | 941 bool success = false; |
| 983 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 942 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 984 shell()->web_contents(), | 943 shell()->web_contents(), |
| 985 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 944 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 986 &success)); | 945 &success)); |
| 987 EXPECT_TRUE(success); | 946 EXPECT_TRUE(success); |
| 988 Shell* new_shell = new_shell_observer.GetShell(); | 947 Shell* new_shell = new_shell_observer.GetShell(); |
| 989 | 948 |
| 990 // Wait for the navigation in the new window to finish, if it hasn't. | 949 // Wait for the navigation in the new window to finish, if it hasn't. |
| 991 WaitForLoadStop(new_shell->web_contents()); | 950 WaitForLoadStop(new_shell->web_contents()); |
| 992 EXPECT_EQ("/files/navigate_opener.html", | 951 EXPECT_EQ("/navigate_opener.html", |
| 993 new_shell->web_contents()->GetLastCommittedURL().path()); | 952 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 994 | 953 |
| 995 // Should have the same SiteInstance. | 954 // Should have the same SiteInstance. |
| 996 scoped_refptr<SiteInstance> opened_site_instance( | 955 scoped_refptr<SiteInstance> opened_site_instance( |
| 997 new_shell->web_contents()->GetSiteInstance()); | 956 new_shell->web_contents()->GetSiteInstance()); |
| 998 EXPECT_EQ(orig_site_instance, opened_site_instance); | 957 EXPECT_EQ(orig_site_instance, opened_site_instance); |
| 999 | 958 |
| 1000 // Now navigate the opened window to a different site. | 959 // Now navigate the opened window to a different site. |
| 1001 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 960 GURL cross_site_url( |
| 961 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 962 NavigateToURL(new_shell, cross_site_url); |
| 1002 scoped_refptr<SiteInstance> new_site_instance( | 963 scoped_refptr<SiteInstance> new_site_instance( |
| 1003 new_shell->web_contents()->GetSiteInstance()); | 964 new_shell->web_contents()->GetSiteInstance()); |
| 1004 EXPECT_NE(orig_site_instance, new_site_instance); | 965 EXPECT_NE(orig_site_instance, new_site_instance); |
| 1005 | 966 |
| 1006 // The original process should still be alive, since it is still used in the | 967 // The original process should still be alive, since it is still used in the |
| 1007 // first window. | 968 // first window. |
| 1008 RenderProcessHost* orig_process = orig_site_instance->GetProcess(); | 969 RenderProcessHost* orig_process = orig_site_instance->GetProcess(); |
| 1009 EXPECT_TRUE(orig_process->HasConnection()); | 970 EXPECT_TRUE(orig_process->HasConnection()); |
| 1010 | 971 |
| 1011 // Navigate the first window to a different site as well. The original | 972 // Navigate the first window to a different site as well. The original |
| 1012 // process should exit, since all of its views are now swapped out. | 973 // process should exit, since all of its views are now swapped out. |
| 1013 RenderProcessHostWatcher exit_observer( | 974 RenderProcessHostWatcher exit_observer( |
| 1014 orig_process, | 975 orig_process, |
| 1015 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 976 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
| 1016 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 977 NavigateToURL(shell(), cross_site_url); |
| 1017 exit_observer.Wait(); | 978 exit_observer.Wait(); |
| 1018 scoped_refptr<SiteInstance> new_site_instance2( | 979 scoped_refptr<SiteInstance> new_site_instance2( |
| 1019 shell()->web_contents()->GetSiteInstance()); | 980 shell()->web_contents()->GetSiteInstance()); |
| 1020 EXPECT_EQ(new_site_instance, new_site_instance2); | 981 EXPECT_EQ(new_site_instance, new_site_instance2); |
| 1021 } | 982 } |
| 1022 | 983 |
| 1023 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 984 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
| 1024 // error should not make us ignore future renderer-initiated navigations. | 985 // error should not make us ignore future renderer-initiated navigations. |
| 1025 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { | 986 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { |
| 1026 StartServer(); | 987 StartServer(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 // Crashes under ThreadSanitizer, http://crbug.com/356758. | 1113 // Crashes under ThreadSanitizer, http://crbug.com/356758. |
| 1153 #if defined(THREAD_SANITIZER) | 1114 #if defined(THREAD_SANITIZER) |
| 1154 #define MAYBE_BackForwardNotStale DISABLED_BackForwardNotStale | 1115 #define MAYBE_BackForwardNotStale DISABLED_BackForwardNotStale |
| 1155 #else | 1116 #else |
| 1156 #define MAYBE_BackForwardNotStale BackForwardNotStale | 1117 #define MAYBE_BackForwardNotStale BackForwardNotStale |
| 1157 #endif | 1118 #endif |
| 1158 // Test for http://crbug.com/93427. Ensure that cross-site navigations | 1119 // Test for http://crbug.com/93427. Ensure that cross-site navigations |
| 1159 // do not cause back/forward navigations to be considered stale by the | 1120 // do not cause back/forward navigations to be considered stale by the |
| 1160 // renderer. | 1121 // renderer. |
| 1161 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_BackForwardNotStale) { | 1122 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_BackForwardNotStale) { |
| 1162 StartServer(); | 1123 StartEmbeddedServer(); |
| 1163 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 1124 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 1164 | 1125 |
| 1165 // Visit a page on first site. | 1126 // Visit a page on first site. |
| 1166 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 1127 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 1167 | 1128 |
| 1168 // Visit three pages on second site. | 1129 // Visit three pages on second site. |
| 1169 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 1130 NavigateToURL(shell(), |
| 1170 NavigateToURL(shell(), GetCrossSiteURL("files/title2.html")); | 1131 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1171 NavigateToURL(shell(), GetCrossSiteURL("files/title3.html")); | 1132 NavigateToURL(shell(), |
| 1133 embedded_test_server()->GetURL("foo.com", "/title2.html")); |
| 1134 NavigateToURL(shell(), |
| 1135 embedded_test_server()->GetURL("foo.com", "/title3.html")); |
| 1172 | 1136 |
| 1173 // History is now [blank, A1, B1, B2, *B3]. | 1137 // History is now [blank, A1, B1, B2, *B3]. |
| 1174 WebContents* contents = shell()->web_contents(); | 1138 WebContents* contents = shell()->web_contents(); |
| 1175 EXPECT_EQ(5, contents->GetController().GetEntryCount()); | 1139 EXPECT_EQ(5, contents->GetController().GetEntryCount()); |
| 1176 | 1140 |
| 1177 // Open another window in same process to keep this process alive. | 1141 // Open another window in same process to keep this process alive. |
| 1178 Shell* new_shell = CreateBrowser(); | 1142 Shell* new_shell = CreateBrowser(); |
| 1179 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 1143 NavigateToURL(new_shell, |
| 1144 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1180 | 1145 |
| 1181 // Go back three times to first site. | 1146 // Go back three times to first site. |
| 1182 { | 1147 { |
| 1183 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); | 1148 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); |
| 1184 shell()->web_contents()->GetController().GoBack(); | 1149 shell()->web_contents()->GetController().GoBack(); |
| 1185 back_nav_load_observer.Wait(); | 1150 back_nav_load_observer.Wait(); |
| 1186 } | 1151 } |
| 1187 { | 1152 { |
| 1188 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); | 1153 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); |
| 1189 shell()->web_contents()->GetController().GoBack(); | 1154 shell()->web_contents()->GetController().GoBack(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 TestNavigationObserver forward_nav_load_observer(shell()->web_contents()); | 1189 TestNavigationObserver forward_nav_load_observer(shell()->web_contents()); |
| 1225 shell()->web_contents()->GetController().GoToIndex(4); | 1190 shell()->web_contents()->GetController().GoToIndex(4); |
| 1226 forward_nav_load_observer.Wait(); | 1191 forward_nav_load_observer.Wait(); |
| 1227 } | 1192 } |
| 1228 } | 1193 } |
| 1229 | 1194 |
| 1230 // Test for http://crbug.com/130016. | 1195 // Test for http://crbug.com/130016. |
| 1231 // Swapping out a render view should update its visiblity state. | 1196 // Swapping out a render view should update its visiblity state. |
| 1232 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1197 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1233 SwappedOutViewHasCorrectVisibilityState) { | 1198 SwappedOutViewHasCorrectVisibilityState) { |
| 1234 // This test is invalid in --site-per-process mode, as swapped-out is no | 1199 // This test is invalid in when swapped out is disabled. |
| 1235 // longer used. | |
| 1236 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) | 1200 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) |
| 1237 return; | 1201 return; |
| 1238 StartServer(); | 1202 StartEmbeddedServer(); |
| 1239 | 1203 |
| 1240 // Load a page with links that open in a new window. | 1204 // Load a page with links that open in a new window. |
| 1241 std::string replacement_path; | 1205 NavigateToPageWithLinks(shell()); |
| 1242 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 1243 "files/click-noreferrer-links.html", | |
| 1244 foo_host_port_, | |
| 1245 &replacement_path)); | |
| 1246 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 1247 | 1206 |
| 1248 // Open a same-site link in a new widnow. | 1207 // Open a same-site link in a new widnow. |
| 1249 ShellAddedObserver new_shell_observer; | 1208 ShellAddedObserver new_shell_observer; |
| 1250 bool success = false; | 1209 bool success = false; |
| 1251 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1210 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1252 shell()->web_contents(), | 1211 shell()->web_contents(), |
| 1253 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 1212 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 1254 &success)); | 1213 &success)); |
| 1255 EXPECT_TRUE(success); | 1214 EXPECT_TRUE(success); |
| 1256 Shell* new_shell = new_shell_observer.GetShell(); | 1215 Shell* new_shell = new_shell_observer.GetShell(); |
| 1257 | 1216 |
| 1258 // Wait for the navigation in the new tab to finish, if it hasn't. | 1217 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 1259 WaitForLoadStop(new_shell->web_contents()); | 1218 WaitForLoadStop(new_shell->web_contents()); |
| 1260 EXPECT_EQ("/files/navigate_opener.html", | 1219 EXPECT_EQ("/navigate_opener.html", |
| 1261 new_shell->web_contents()->GetLastCommittedURL().path()); | 1220 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 1262 | 1221 |
| 1263 RenderViewHost* rvh = new_shell->web_contents()->GetRenderViewHost(); | 1222 RenderViewHost* rvh = new_shell->web_contents()->GetRenderViewHost(); |
| 1264 | 1223 |
| 1265 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1224 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1266 rvh, | 1225 rvh, |
| 1267 "window.domAutomationController.send(" | 1226 "window.domAutomationController.send(" |
| 1268 " document.visibilityState == 'visible');", | 1227 " document.visibilityState == 'visible');", |
| 1269 &success)); | 1228 &success)); |
| 1270 EXPECT_TRUE(success); | 1229 EXPECT_TRUE(success); |
| 1271 | 1230 |
| 1272 // Now navigate the new window to a different site. This should swap out the | 1231 // Now navigate the new window to a different site. This should swap out the |
| 1273 // tab's existing RenderView, causing it become hidden. | 1232 // tab's existing RenderView, causing it become hidden. |
| 1274 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 1233 NavigateToURL(new_shell, |
| 1234 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1275 | 1235 |
| 1276 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1236 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1277 rvh, | 1237 rvh, |
| 1278 "window.domAutomationController.send(" | 1238 "window.domAutomationController.send(" |
| 1279 " document.visibilityState == 'hidden');", | 1239 " document.visibilityState == 'hidden');", |
| 1280 &success)); | 1240 &success)); |
| 1281 EXPECT_TRUE(success); | 1241 EXPECT_TRUE(success); |
| 1282 | 1242 |
| 1283 // Going back should make the previously swapped-out view to become visible | 1243 // Going back should make the previously swapped-out view to become visible |
| 1284 // again. | 1244 // again. |
| 1285 { | 1245 { |
| 1286 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); | 1246 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); |
| 1287 new_shell->web_contents()->GetController().GoBack(); | 1247 new_shell->web_contents()->GetController().GoBack(); |
| 1288 back_nav_load_observer.Wait(); | 1248 back_nav_load_observer.Wait(); |
| 1289 } | 1249 } |
| 1290 | 1250 |
| 1291 EXPECT_EQ("/files/navigate_opener.html", | 1251 EXPECT_EQ("/navigate_opener.html", |
| 1292 new_shell->web_contents()->GetLastCommittedURL().path()); | 1252 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 1293 | 1253 |
| 1294 EXPECT_EQ(rvh, new_shell->web_contents()->GetRenderViewHost()); | 1254 EXPECT_EQ(rvh, new_shell->web_contents()->GetRenderViewHost()); |
| 1295 | 1255 |
| 1296 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1256 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1297 rvh, | 1257 rvh, |
| 1298 "window.domAutomationController.send(" | 1258 "window.domAutomationController.send(" |
| 1299 " document.visibilityState == 'visible');", | 1259 " document.visibilityState == 'visible');", |
| 1300 &success)); | 1260 &success)); |
| 1301 EXPECT_TRUE(success); | 1261 EXPECT_TRUE(success); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1330 #else | 1290 #else |
| 1331 #define MAYBE_LeakingRenderViewHosts LeakingRenderViewHosts | 1291 #define MAYBE_LeakingRenderViewHosts LeakingRenderViewHosts |
| 1332 #endif | 1292 #endif |
| 1333 // Test for crbug.com/90867. Make sure we don't leak render view hosts since | 1293 // Test for crbug.com/90867. Make sure we don't leak render view hosts since |
| 1334 // they may cause crashes or memory corruptions when trying to call dead | 1294 // they may cause crashes or memory corruptions when trying to call dead |
| 1335 // delegate_. This test also verifies crbug.com/117420 and crbug.com/143255 to | 1295 // delegate_. This test also verifies crbug.com/117420 and crbug.com/143255 to |
| 1336 // ensure that a separate SiteInstance is created when navigating to view-source | 1296 // ensure that a separate SiteInstance is created when navigating to view-source |
| 1337 // URLs, regardless of current URL. | 1297 // URLs, regardless of current URL. |
| 1338 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1298 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1339 MAYBE_LeakingRenderViewHosts) { | 1299 MAYBE_LeakingRenderViewHosts) { |
| 1340 StartServer(); | 1300 StartEmbeddedServer(); |
| 1341 | 1301 |
| 1342 // Observe the created render_view_host's to make sure they will not leak. | 1302 // Observe the created render_view_host's to make sure they will not leak. |
| 1343 RenderViewHostDestructionObserver rvh_observers(shell()->web_contents()); | 1303 RenderViewHostDestructionObserver rvh_observers(shell()->web_contents()); |
| 1344 | 1304 |
| 1345 GURL navigated_url(test_server()->GetURL("files/title2.html")); | 1305 GURL navigated_url(embedded_test_server()->GetURL("/title2.html")); |
| 1346 GURL view_source_url(kViewSourceScheme + std::string(":") + | 1306 GURL view_source_url(kViewSourceScheme + std::string(":") + |
| 1347 navigated_url.spec()); | 1307 navigated_url.spec()); |
| 1348 | 1308 |
| 1349 // Let's ensure that when we start with a blank window, navigating away to a | 1309 // Let's ensure that when we start with a blank window, navigating away to a |
| 1350 // view-source URL, we create a new SiteInstance. | 1310 // view-source URL, we create a new SiteInstance. |
| 1351 RenderViewHost* blank_rvh = shell()->web_contents()->GetRenderViewHost(); | 1311 RenderViewHost* blank_rvh = shell()->web_contents()->GetRenderViewHost(); |
| 1352 SiteInstance* blank_site_instance = blank_rvh->GetSiteInstance(); | 1312 SiteInstance* blank_site_instance = blank_rvh->GetSiteInstance(); |
| 1353 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), GURL::EmptyGURL()); | 1313 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), GURL::EmptyGURL()); |
| 1354 EXPECT_EQ(blank_site_instance->GetSiteURL(), GURL::EmptyGURL()); | 1314 EXPECT_EQ(blank_site_instance->GetSiteURL(), GURL::EmptyGURL()); |
| 1355 rvh_observers.EnsureRVHGetsDestructed(blank_rvh); | 1315 rvh_observers.EnsureRVHGetsDestructed(blank_rvh); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1375 NavigateToURL(shell(), view_source_url); | 1335 NavigateToURL(shell(), view_source_url); |
| 1376 rvh_observers.EnsureRVHGetsDestructed( | 1336 rvh_observers.EnsureRVHGetsDestructed( |
| 1377 shell()->web_contents()->GetRenderViewHost()); | 1337 shell()->web_contents()->GetRenderViewHost()); |
| 1378 SiteInstance* site_instance2 = shell()->web_contents()-> | 1338 SiteInstance* site_instance2 = shell()->web_contents()-> |
| 1379 GetRenderViewHost()->GetSiteInstance(); | 1339 GetRenderViewHost()->GetSiteInstance(); |
| 1380 | 1340 |
| 1381 // Ensure that view-source navigations force a new SiteInstance. | 1341 // Ensure that view-source navigations force a new SiteInstance. |
| 1382 EXPECT_NE(site_instance1, site_instance2); | 1342 EXPECT_NE(site_instance1, site_instance2); |
| 1383 | 1343 |
| 1384 // Now navigate to a different instance so that we swap out again. | 1344 // Now navigate to a different instance so that we swap out again. |
| 1385 NavigateToURL(shell(), GetCrossSiteURL("files/title2.html")); | 1345 NavigateToURL(shell(), |
| 1346 embedded_test_server()->GetURL("foo.com", "/title2.html")); |
| 1386 rvh_observers.EnsureRVHGetsDestructed( | 1347 rvh_observers.EnsureRVHGetsDestructed( |
| 1387 shell()->web_contents()->GetRenderViewHost()); | 1348 shell()->web_contents()->GetRenderViewHost()); |
| 1388 | 1349 |
| 1389 // This used to leak a render view host. | 1350 // This used to leak a render view host. |
| 1390 shell()->Close(); | 1351 shell()->Close(); |
| 1391 | 1352 |
| 1392 RunAllPendingInMessageLoop(); // Needed on ChromeOS. | 1353 RunAllPendingInMessageLoop(); // Needed on ChromeOS. |
| 1393 | 1354 |
| 1394 EXPECT_EQ(0U, rvh_observers.GetNumberOfWatchedRenderViewHosts()); | 1355 EXPECT_EQ(0U, rvh_observers.GetNumberOfWatchedRenderViewHosts()); |
| 1395 } | 1356 } |
| 1396 | 1357 |
| 1397 // Test for crbug.com/143155. Frame tree updates during unload should not | 1358 // Test for crbug.com/143155. Frame tree updates during unload should not |
| 1398 // interrupt the intended navigation and show swappedout:// instead. | 1359 // interrupt the intended navigation and show swappedout:// instead. |
| 1399 // Specifically: | 1360 // Specifically: |
| 1400 // 1) Open 2 tabs in an HTTP SiteInstance, with a subframe in the opener. | 1361 // 1) Open 2 tabs in an HTTP SiteInstance, with a subframe in the opener. |
| 1401 // 2) Send the second tab to a different foo.com SiteInstance. | 1362 // 2) Send the second tab to a different foo.com SiteInstance. |
| 1402 // This creates a swapped out opener for the first tab in the foo process. | 1363 // This creates a swapped out opener for the first tab in the foo process. |
| 1403 // 3) Navigate the first tab to the foo.com SiteInstance, and have the first | 1364 // 3) Navigate the first tab to the foo.com SiteInstance, and have the first |
| 1404 // tab's unload handler remove its frame. | 1365 // tab's unload handler remove its frame. |
| 1405 // This used to cause an update to the frame tree of the swapped out RV, | 1366 // This used to cause an update to the frame tree of the swapped out RV, |
| 1406 // just as it was navigating to a real page. That pre-empted the real | 1367 // just as it was navigating to a real page. That pre-empted the real |
| 1407 // navigation and visibly sent the tab to swappedout://. | 1368 // navigation and visibly sent the tab to swappedout://. |
| 1408 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1369 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1409 DontPreemptNavigationWithFrameTreeUpdate) { | 1370 DontPreemptNavigationWithFrameTreeUpdate) { |
| 1410 StartServer(); | 1371 StartEmbeddedServer(); |
| 1411 | 1372 |
| 1412 // 1. Load a page that deletes its iframe during unload. | 1373 // 1. Load a page that deletes its iframe during unload. |
| 1413 NavigateToURL(shell(), | 1374 NavigateToURL(shell(), |
| 1414 test_server()->GetURL("files/remove_frame_on_unload.html")); | 1375 embedded_test_server()->GetURL("/remove_frame_on_unload.html")); |
| 1415 | 1376 |
| 1416 // Get the original SiteInstance for later comparison. | 1377 // Get the original SiteInstance for later comparison. |
| 1417 scoped_refptr<SiteInstance> orig_site_instance( | 1378 scoped_refptr<SiteInstance> orig_site_instance( |
| 1418 shell()->web_contents()->GetSiteInstance()); | 1379 shell()->web_contents()->GetSiteInstance()); |
| 1419 | 1380 |
| 1420 // Open a same-site page in a new window. | 1381 // Open a same-site page in a new window. |
| 1421 ShellAddedObserver new_shell_observer; | 1382 ShellAddedObserver new_shell_observer; |
| 1422 bool success = false; | 1383 bool success = false; |
| 1423 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1384 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1424 shell()->web_contents(), | 1385 shell()->web_contents(), |
| 1425 "window.domAutomationController.send(openWindow());", | 1386 "window.domAutomationController.send(openWindow());", |
| 1426 &success)); | 1387 &success)); |
| 1427 EXPECT_TRUE(success); | 1388 EXPECT_TRUE(success); |
| 1428 Shell* new_shell = new_shell_observer.GetShell(); | 1389 Shell* new_shell = new_shell_observer.GetShell(); |
| 1429 | 1390 |
| 1430 // Wait for the navigation in the new window to finish, if it hasn't. | 1391 // Wait for the navigation in the new window to finish, if it hasn't. |
| 1431 WaitForLoadStop(new_shell->web_contents()); | 1392 WaitForLoadStop(new_shell->web_contents()); |
| 1432 EXPECT_EQ("/files/title1.html", | 1393 EXPECT_EQ("/title1.html", |
| 1433 new_shell->web_contents()->GetLastCommittedURL().path()); | 1394 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 1434 | 1395 |
| 1435 // Should have the same SiteInstance. | 1396 // Should have the same SiteInstance. |
| 1436 EXPECT_EQ(orig_site_instance.get(), | 1397 EXPECT_EQ(orig_site_instance.get(), |
| 1437 new_shell->web_contents()->GetSiteInstance()); | 1398 new_shell->web_contents()->GetSiteInstance()); |
| 1438 | 1399 |
| 1439 // 2. Send the second tab to a different process. | 1400 // 2. Send the second tab to a different process. |
| 1440 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 1401 GURL cross_site_url( |
| 1402 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 1403 NavigateToURL(new_shell, cross_site_url); |
| 1441 scoped_refptr<SiteInstance> new_site_instance( | 1404 scoped_refptr<SiteInstance> new_site_instance( |
| 1442 new_shell->web_contents()->GetSiteInstance()); | 1405 new_shell->web_contents()->GetSiteInstance()); |
| 1443 EXPECT_NE(orig_site_instance, new_site_instance); | 1406 EXPECT_NE(orig_site_instance, new_site_instance); |
| 1444 | 1407 |
| 1445 // 3. Send the first tab to the second tab's process. | 1408 // 3. Send the first tab to the second tab's process. |
| 1446 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 1409 NavigateToURL(shell(), cross_site_url); |
| 1447 | 1410 |
| 1448 // Make sure it ends up at the right page. | 1411 // Make sure it ends up at the right page. |
| 1449 WaitForLoadStop(shell()->web_contents()); | 1412 WaitForLoadStop(shell()->web_contents()); |
| 1450 EXPECT_EQ(GetCrossSiteURL("files/title1.html"), | 1413 EXPECT_EQ(cross_site_url, shell()->web_contents()->GetLastCommittedURL()); |
| 1451 shell()->web_contents()->GetLastCommittedURL()); | |
| 1452 EXPECT_EQ(new_site_instance.get(), | 1414 EXPECT_EQ(new_site_instance.get(), |
| 1453 shell()->web_contents()->GetSiteInstance()); | 1415 shell()->web_contents()->GetSiteInstance()); |
| 1454 } | 1416 } |
| 1455 | 1417 |
| 1456 // Ensure that renderer-side debug URLs do not cause a process swap, since they | 1418 // Ensure that renderer-side debug URLs do not cause a process swap, since they |
| 1457 // are meant to run in the current page. We had a bug where we expected a | 1419 // are meant to run in the current page. We had a bug where we expected a |
| 1458 // BrowsingInstance swap to occur on pages like view-source and extensions, | 1420 // BrowsingInstance swap to occur on pages like view-source and extensions, |
| 1459 // which broke chrome://crash and javascript: URLs. | 1421 // which broke chrome://crash and javascript: URLs. |
| 1460 // See http://crbug.com/335503. | 1422 // See http://crbug.com/335503. |
| 1461 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, RendererDebugURLsDontSwap) { | 1423 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, RendererDebugURLsDontSwap) { |
| 1462 ASSERT_TRUE(test_server()->Start()); | 1424 StartEmbeddedServer(); |
| 1463 | 1425 |
| 1464 GURL original_url(test_server()->GetURL("files/title2.html")); | 1426 GURL original_url(embedded_test_server()->GetURL("/title2.html")); |
| 1465 GURL view_source_url(kViewSourceScheme + std::string(":") + | 1427 GURL view_source_url(kViewSourceScheme + std::string(":") + |
| 1466 original_url.spec()); | 1428 original_url.spec()); |
| 1467 | 1429 |
| 1468 NavigateToURL(shell(), view_source_url); | 1430 NavigateToURL(shell(), view_source_url); |
| 1469 | 1431 |
| 1470 // Check that javascript: URLs work. | 1432 // Check that javascript: URLs work. |
| 1471 base::string16 expected_title = ASCIIToUTF16("msg"); | 1433 base::string16 expected_title = ASCIIToUTF16("msg"); |
| 1472 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1434 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 1473 shell()->LoadURL(GURL("javascript:document.title='msg'")); | 1435 shell()->LoadURL(GURL("javascript:document.title='msg'")); |
| 1474 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 1436 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 // Test that we still swap processes for BrowsingInstance changes even in | 1560 // Test that we still swap processes for BrowsingInstance changes even in |
| 1599 // --process-per-tab mode. See http://crbug.com/343017. | 1561 // --process-per-tab mode. See http://crbug.com/343017. |
| 1600 // Disabled on Android: http://crbug.com/345873. | 1562 // Disabled on Android: http://crbug.com/345873. |
| 1601 // Crashes under ThreadSanitizer, http://crbug.com/356758. | 1563 // Crashes under ThreadSanitizer, http://crbug.com/356758. |
| 1602 #if defined(OS_ANDROID) || defined(THREAD_SANITIZER) | 1564 #if defined(OS_ANDROID) || defined(THREAD_SANITIZER) |
| 1603 #define MAYBE_BackFromWebUI DISABLED_BackFromWebUI | 1565 #define MAYBE_BackFromWebUI DISABLED_BackFromWebUI |
| 1604 #else | 1566 #else |
| 1605 #define MAYBE_BackFromWebUI BackFromWebUI | 1567 #define MAYBE_BackFromWebUI BackFromWebUI |
| 1606 #endif | 1568 #endif |
| 1607 IN_PROC_BROWSER_TEST_F(RFHMProcessPerTabTest, MAYBE_BackFromWebUI) { | 1569 IN_PROC_BROWSER_TEST_F(RFHMProcessPerTabTest, MAYBE_BackFromWebUI) { |
| 1608 ASSERT_TRUE(test_server()->Start()); | 1570 StartEmbeddedServer(); |
| 1609 GURL original_url(test_server()->GetURL("files/title2.html")); | 1571 GURL original_url(embedded_test_server()->GetURL("/title2.html")); |
| 1610 NavigateToURL(shell(), original_url); | 1572 NavigateToURL(shell(), original_url); |
| 1611 | 1573 |
| 1612 // Visit a WebUI page with bindings. | 1574 // Visit a WebUI page with bindings. |
| 1613 GURL webui_url(GURL(std::string(kChromeUIScheme) + "://" + | 1575 GURL webui_url(GURL(std::string(kChromeUIScheme) + "://" + |
| 1614 std::string(kChromeUIGpuHost))); | 1576 std::string(kChromeUIGpuHost))); |
| 1615 NavigateToURL(shell(), webui_url); | 1577 NavigateToURL(shell(), webui_url); |
| 1616 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1578 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 1617 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1579 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
| 1618 | 1580 |
| 1619 // Go back and ensure we have no WebUI bindings. | 1581 // Go back and ensure we have no WebUI bindings. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 } | 1636 } |
| 1675 | 1637 |
| 1676 // crbug.com/424526 | 1638 // crbug.com/424526 |
| 1677 // The test loads a WebUI page in rocess-per-tab mode, then navigates to a blank | 1639 // The test loads a WebUI page in rocess-per-tab mode, then navigates to a blank |
| 1678 // page and then to a regular page. The bug reproduces if blank page is visited | 1640 // page and then to a regular page. The bug reproduces if blank page is visited |
| 1679 // in between WebUI and regular page. | 1641 // in between WebUI and regular page. |
| 1680 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1642 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1681 ForceSwapAfterWebUIBindings) { | 1643 ForceSwapAfterWebUIBindings) { |
| 1682 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1644 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1683 switches::kProcessPerTab); | 1645 switches::kProcessPerTab); |
| 1684 ASSERT_TRUE(test_server()->Start()); | 1646 StartEmbeddedServer(); |
| 1685 | 1647 |
| 1686 const GURL web_ui_url(std::string(kChromeUIScheme) + "://" + | 1648 const GURL web_ui_url(std::string(kChromeUIScheme) + "://" + |
| 1687 std::string(kChromeUIGpuHost)); | 1649 std::string(kChromeUIGpuHost)); |
| 1688 NavigateToURL(shell(), web_ui_url); | 1650 NavigateToURL(shell(), web_ui_url); |
| 1689 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1651 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 1690 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1652 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
| 1691 | 1653 |
| 1692 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 1654 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 1693 | 1655 |
| 1694 GURL regular_page_url(test_server()->GetURL("files/title2.html")); | 1656 GURL regular_page_url(embedded_test_server()->GetURL("/title2.html")); |
| 1695 NavigateToURL(shell(), regular_page_url); | 1657 NavigateToURL(shell(), regular_page_url); |
| 1696 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1658 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 1697 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1659 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
| 1698 } | 1660 } |
| 1699 | 1661 |
| 1700 class FileChooserDelegate : public WebContentsDelegate { | 1662 class FileChooserDelegate : public WebContentsDelegate { |
| 1701 public: | 1663 public: |
| 1702 FileChooserDelegate(const base::FilePath& file) | 1664 FileChooserDelegate(const base::FilePath& file) |
| 1703 : file_(file), file_chosen_(false) {} | 1665 : file_(file), file_chosen_(false) {} |
| 1704 | 1666 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2060 EXPECT_TRUE( | 2022 EXPECT_TRUE( |
| 2061 ExecuteScript(foo_shell->web_contents(), "window.opener = window;")); | 2023 ExecuteScript(foo_shell->web_contents(), "window.opener = window;")); |
| 2062 EXPECT_EQ(bar_root, foo_root->opener()); | 2024 EXPECT_EQ(bar_root, foo_root->opener()); |
| 2063 } | 2025 } |
| 2064 | 2026 |
| 2065 // Tests that when a popup is opened, which is then navigated cross-process and | 2027 // Tests that when a popup is opened, which is then navigated cross-process and |
| 2066 // back, it can be still accessed through the original window reference in | 2028 // back, it can be still accessed through the original window reference in |
| 2067 // JavaScript. See https://crbug.com/537657 | 2029 // JavaScript. See https://crbug.com/537657 |
| 2068 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2030 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2069 PopupKeepsWindowReferenceCrossProcesAndBack) { | 2031 PopupKeepsWindowReferenceCrossProcesAndBack) { |
| 2070 StartServer(); | 2032 StartEmbeddedServer(); |
| 2071 | 2033 |
| 2072 // Load a page with links that open in a new window. | 2034 // Load a page with links that open in a new window. |
| 2073 std::string replacement_path; | 2035 NavigateToPageWithLinks(shell()); |
| 2074 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 2075 "files/click-noreferrer-links.html", | |
| 2076 foo_host_port_, | |
| 2077 &replacement_path)); | |
| 2078 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 2079 | 2036 |
| 2080 // Click a target=foo link to open a popup. | 2037 // Click a target=foo link to open a popup. |
| 2081 ShellAddedObserver new_shell_observer; | 2038 ShellAddedObserver new_shell_observer; |
| 2082 bool success = false; | 2039 bool success = false; |
| 2083 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2040 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2084 shell()->web_contents(), | 2041 shell()->web_contents(), |
| 2085 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 2042 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 2086 &success)); | 2043 &success)); |
| 2087 EXPECT_TRUE(success); | 2044 EXPECT_TRUE(success); |
| 2088 Shell* new_shell = new_shell_observer.GetShell(); | 2045 Shell* new_shell = new_shell_observer.GetShell(); |
| 2089 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 2046 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
| 2090 | 2047 |
| 2091 // Wait for the navigation in the popup to finish, if it hasn't. | 2048 // Wait for the navigation in the popup to finish, if it hasn't. |
| 2092 WaitForLoadStop(new_shell->web_contents()); | 2049 WaitForLoadStop(new_shell->web_contents()); |
| 2093 EXPECT_EQ("/files/navigate_opener.html", | 2050 EXPECT_EQ("/navigate_opener.html", |
| 2094 new_shell->web_contents()->GetLastCommittedURL().path()); | 2051 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 2095 | 2052 |
| 2096 // Capture the window reference, so we can check that accessing its location | 2053 // Capture the window reference, so we can check that accessing its location |
| 2097 // works after navigating cross-process and back. | 2054 // works after navigating cross-process and back. |
| 2098 GURL expected_url = new_shell->web_contents()->GetLastCommittedURL(); | 2055 GURL expected_url = new_shell->web_contents()->GetLastCommittedURL(); |
| 2099 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 2056 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 2100 "saveWindowReference();")); | 2057 "saveWindowReference();")); |
| 2101 | 2058 |
| 2102 // Now navigate the popup to a different site and then go back. | 2059 // Now navigate the popup to a different site and then go back. |
| 2103 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); | 2060 NavigateToURL(new_shell, |
| 2061 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 2104 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); | 2062 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); |
| 2105 new_shell->web_contents()->GetController().GoBack(); | 2063 new_shell->web_contents()->GetController().GoBack(); |
| 2106 back_nav_load_observer.Wait(); | 2064 back_nav_load_observer.Wait(); |
| 2107 | 2065 |
| 2108 // Check that the location.href window attribute is accessible and is correct. | 2066 // Check that the location.href window attribute is accessible and is correct. |
| 2109 std::string result; | 2067 std::string result; |
| 2110 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2068 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2111 shell()->web_contents(), | 2069 shell()->web_contents(), |
| 2112 "window.domAutomationController.send(getLastOpenedWindowLocation());", | 2070 "window.domAutomationController.send(getLastOpenedWindowLocation());", |
| 2113 &result)); | 2071 &result)); |
| 2114 EXPECT_EQ(expected_url.spec(), result); | 2072 EXPECT_EQ(expected_url.spec(), result); |
| 2115 } | 2073 } |
| 2116 | 2074 |
| 2117 | 2075 |
| 2118 } // namespace content | 2076 } // namespace content |
| OLD | NEW |