| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/site_instance_impl.h" | 11 #include "content/browser/site_instance_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/content_constants_internal.h" | 13 #include "content/common/content_constants_internal.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host_observer.h" | 21 #include "content/public/browser/render_view_host_observer.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 26 #include "content/shell/shell.h" | 27 #include "content/shell/shell.h" |
| 27 #include "content/test/content_browser_test.h" | 28 #include "content/test/content_browser_test.h" |
| 28 #include "content/test/content_browser_test_utils.h" | 29 #include "content/test/content_browser_test_utils.h" |
| 29 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 30 #include "net/test/spawned_test_server/spawned_test_server.h" | 31 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // Opens in same window. | 307 // Opens in same window. |
| 307 EXPECT_EQ(1u, Shell::windows().size()); | 308 EXPECT_EQ(1u, Shell::windows().size()); |
| 308 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); | 309 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
| 309 | 310 |
| 310 // Should have the same SiteInstance. | 311 // Should have the same SiteInstance. |
| 311 scoped_refptr<SiteInstance> noref_site_instance( | 312 scoped_refptr<SiteInstance> noref_site_instance( |
| 312 shell()->web_contents()->GetSiteInstance()); | 313 shell()->web_contents()->GetSiteInstance()); |
| 313 EXPECT_EQ(orig_site_instance, noref_site_instance); | 314 EXPECT_EQ(orig_site_instance, noref_site_instance); |
| 314 } | 315 } |
| 315 | 316 |
| 317 namespace { |
| 318 |
| 319 class WebContentsDestroyedObserver : public WebContentsObserver { |
| 320 public: |
| 321 WebContentsDestroyedObserver(WebContents* web_contents, |
| 322 const base::Closure& callback) |
| 323 : WebContentsObserver(web_contents), |
| 324 callback_(callback) { |
| 325 } |
| 326 |
| 327 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { |
| 328 callback_.Run(); |
| 329 } |
| 330 |
| 331 private: |
| 332 base::Closure callback_; |
| 333 |
| 334 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedObserver); |
| 335 }; |
| 336 |
| 337 } // namespace |
| 338 |
| 316 // Test for crbug.com/116192. Targeted links should still work after the | 339 // Test for crbug.com/116192. Targeted links should still work after the |
| 317 // named target window has swapped processes. | 340 // named target window has swapped processes. |
| 318 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 341 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 319 AllowTargetedNavigationsAfterSwap) { | 342 AllowTargetedNavigationsAfterSwap) { |
| 320 // Start two servers with different sites. | 343 // Start two servers with different sites. |
| 321 ASSERT_TRUE(test_server()->Start()); | 344 ASSERT_TRUE(test_server()->Start()); |
| 322 net::SpawnedTestServer https_server( | 345 net::SpawnedTestServer https_server( |
| 323 net::SpawnedTestServer::TYPE_HTTPS, | 346 net::SpawnedTestServer::TYPE_HTTPS, |
| 324 net::SpawnedTestServer::kLocalhost, | 347 net::SpawnedTestServer::kLocalhost, |
| 325 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 348 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // Should have swapped back and shown the new window again. | 402 // Should have swapped back and shown the new window again. |
| 380 scoped_refptr<SiteInstance> revisit_site_instance( | 403 scoped_refptr<SiteInstance> revisit_site_instance( |
| 381 new_shell->web_contents()->GetSiteInstance()); | 404 new_shell->web_contents()->GetSiteInstance()); |
| 382 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 405 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
| 383 | 406 |
| 384 // If it navigates away to another process, the original window should | 407 // If it navigates away to another process, the original window should |
| 385 // still be able to close it (using a cross-process close message). | 408 // still be able to close it (using a cross-process close message). |
| 386 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 409 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
| 387 EXPECT_EQ(new_site_instance, | 410 EXPECT_EQ(new_site_instance, |
| 388 new_shell->web_contents()->GetSiteInstance()); | 411 new_shell->web_contents()->GetSiteInstance()); |
| 389 WindowedNotificationObserver close_observer( | 412 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
| 390 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 413 WebContentsDestroyedObserver close_observer(new_shell->web_contents(), |
| 391 Source<WebContents>(new_shell->web_contents())); | 414 loop_runner->QuitClosure()); |
| 392 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 415 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 393 shell()->web_contents(), | 416 shell()->web_contents(), |
| 394 "window.domAutomationController.send(testCloseWindow());", | 417 "window.domAutomationController.send(testCloseWindow());", |
| 395 &success)); | 418 &success)); |
| 396 EXPECT_TRUE(success); | 419 EXPECT_TRUE(success); |
| 397 close_observer.Wait(); | 420 loop_runner->Run(); |
| 398 } | 421 } |
| 399 | 422 |
| 400 // Test that setting the opener to null in a window affects cross-process | 423 // Test that setting the opener to null in a window affects cross-process |
| 401 // navigations, including those to existing entries. http://crbug.com/156669. | 424 // navigations, including those to existing entries. http://crbug.com/156669. |
| 402 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DisownOpener) { | 425 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DisownOpener) { |
| 403 // Start two servers with different sites. | 426 // Start two servers with different sites. |
| 404 ASSERT_TRUE(test_server()->Start()); | 427 ASSERT_TRUE(test_server()->Start()); |
| 405 net::SpawnedTestServer https_server( | 428 net::SpawnedTestServer https_server( |
| 406 net::SpawnedTestServer::TYPE_HTTPS, | 429 net::SpawnedTestServer::TYPE_HTTPS, |
| 407 net::SpawnedTestServer::kLocalhost, | 430 net::SpawnedTestServer::kLocalhost, |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); | 1223 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
| 1201 | 1224 |
| 1202 // Make sure it ends up at the right page. | 1225 // Make sure it ends up at the right page. |
| 1203 WaitForLoadStop(shell()->web_contents()); | 1226 WaitForLoadStop(shell()->web_contents()); |
| 1204 EXPECT_EQ(https_server.GetURL("files/title1.html"), | 1227 EXPECT_EQ(https_server.GetURL("files/title1.html"), |
| 1205 shell()->web_contents()->GetURL()); | 1228 shell()->web_contents()->GetURL()); |
| 1206 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); | 1229 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); |
| 1207 } | 1230 } |
| 1208 | 1231 |
| 1209 } // namespace content | 1232 } // namespace content |
| OLD | NEW |