OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/browser.h" | 5 #include "chrome/browser/browser.h" |
6 #include "chrome/browser/tab_contents/tab_contents.h" | |
7 #include "chrome/browser/download/download_manager.h" | 6 #include "chrome/browser/download/download_manager.h" |
8 #include "chrome/browser/profile.h" | 7 #include "chrome/browser/profile.h" |
| 8 #include "chrome/browser/renderer_host/site_instance.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" |
9 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/notification_details.h" | 12 #include "chrome/common/notification_details.h" |
12 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
13 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
14 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
15 #include "chrome/common/notification_type.h" | 16 #include "chrome/common/notification_type.h" |
16 #include "chrome/common/extensions/extension_error_reporter.h" | 17 #include "chrome/common/extensions/extension_error_reporter.h" |
17 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
18 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
19 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
20 | 21 |
21 class RenderViewHostManagerTest : public InProcessBrowserTest { | 22 class RenderViewHostManagerTest : public InProcessBrowserTest { |
22 public: | 23 public: |
23 RenderViewHostManagerTest() { | 24 RenderViewHostManagerTest() { |
24 EnableDOMAutomation(); | 25 EnableDOMAutomation(); |
25 } | 26 } |
26 }; | 27 }; |
27 | 28 |
| 29 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
| 30 // and target=_blank should create a new SiteInstance. Links with either |
| 31 // rel=noreferrer or target=_blank (but not both) should not create a new |
| 32 // SiteInstance. |
| 33 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 34 SwapProcessOnRelNoreferrerWithTargetBlank) { |
| 35 // Start two servers with different sites. |
| 36 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 37 scoped_refptr<HTTPTestServer> http_server = |
| 38 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 39 scoped_refptr<HTTPSTestServer> https_server = |
| 40 HTTPSTestServer::CreateGoodServer(kDocRoot); |
| 41 |
| 42 // Load a page with links that open in a new window. |
| 43 ui_test_utils::NavigateToURL(browser(), http_server->TestServerPageW( |
| 44 L"files/click-noreferrer-links.html")); |
| 45 |
| 46 // Get the original SiteInstance for later comparison. |
| 47 scoped_refptr<SiteInstance> orig_site_instance( |
| 48 browser()->GetSelectedTabContents()->GetSiteInstance()); |
| 49 EXPECT_TRUE(orig_site_instance != NULL); |
| 50 |
| 51 // 1. Test clicking a rel=noreferrer + target=blank link. |
| 52 bool success = false; |
| 53 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 54 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 55 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
| 56 &success)); |
| 57 EXPECT_TRUE(success); |
| 58 // Opens in new tab. |
| 59 EXPECT_EQ(2, browser()->tab_count()); |
| 60 EXPECT_EQ(1, browser()->selected_index()); |
| 61 |
| 62 // Wait for the cross-site transition to finish. |
| 63 ui_test_utils::WaitForLoadStop( |
| 64 &(browser()->GetSelectedTabContents()->controller())); |
| 65 |
| 66 // Should have a new SiteInstance. |
| 67 scoped_refptr<SiteInstance> noref_blank_site_instance( |
| 68 browser()->GetSelectedTabContents()->GetSiteInstance()); |
| 69 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
| 70 |
| 71 // Close the tab to try another link. |
| 72 browser()->CloseTab(); |
| 73 |
| 74 // 2. Test clicking a target=blank link. |
| 75 success = false; |
| 76 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 77 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 78 L"window.domAutomationController.send(clickTargetBlankLink());", |
| 79 &success)); |
| 80 EXPECT_TRUE(success); |
| 81 // Opens in new tab. |
| 82 EXPECT_EQ(2, browser()->tab_count()); |
| 83 EXPECT_EQ(1, browser()->selected_index()); |
| 84 |
| 85 // Wait for the cross-site transition to finish. |
| 86 ui_test_utils::WaitForLoadStop( |
| 87 &(browser()->GetSelectedTabContents()->controller())); |
| 88 |
| 89 // Should have the same SiteInstance. |
| 90 scoped_refptr<SiteInstance> blank_site_instance( |
| 91 browser()->GetSelectedTabContents()->GetSiteInstance()); |
| 92 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 93 |
| 94 // Close the tab to try another link. |
| 95 browser()->CloseTab(); |
| 96 |
| 97 // 3. Test clicking a rel=noreferrer link. |
| 98 success = false; |
| 99 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 100 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 101 L"window.domAutomationController.send(clickNoRefLink());", |
| 102 &success)); |
| 103 EXPECT_TRUE(success); |
| 104 // Opens in same tab. |
| 105 EXPECT_EQ(1, browser()->tab_count()); |
| 106 EXPECT_EQ(0, browser()->selected_index()); |
| 107 |
| 108 // Wait for the cross-site transition to finish. |
| 109 ui_test_utils::WaitForLoadStop( |
| 110 &(browser()->GetSelectedTabContents()->controller())); |
| 111 |
| 112 // Should have the same SiteInstance. |
| 113 scoped_refptr<SiteInstance> noref_site_instance( |
| 114 browser()->GetSelectedTabContents()->GetSiteInstance()); |
| 115 EXPECT_EQ(orig_site_instance, noref_site_instance); |
| 116 } |
| 117 |
28 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 118 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
29 // after download of a file while viewing another chrome://. | 119 // after download of a file while viewing another chrome://. |
30 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 120 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
31 DISABLED_ChromeURLAfterDownload) { | 121 DISABLED_ChromeURLAfterDownload) { |
32 GURL downloads_url("chrome://downloads"); | 122 GURL downloads_url("chrome://downloads"); |
33 GURL extensions_url("chrome://extensions"); | 123 GURL extensions_url("chrome://extensions"); |
34 FilePath zip_download; | 124 FilePath zip_download; |
35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); | 125 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); |
36 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); | 126 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); |
37 GURL zip_url = net::FilePathToFileURL(zip_download); | 127 GURL zip_url = net::FilePathToFileURL(zip_download); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 &result)); | 192 &result)); |
103 EXPECT_TRUE(result); | 193 EXPECT_TRUE(result); |
104 ui_test_utils::NavigateToURL(browser(), zip_url); | 194 ui_test_utils::NavigateToURL(browser(), zip_url); |
105 | 195 |
106 ui_test_utils::WaitForDownloadCount( | 196 ui_test_utils::WaitForDownloadCount( |
107 browser()->profile()->GetDownloadManager(), 1); | 197 browser()->profile()->GetDownloadManager(), 1); |
108 | 198 |
109 browser()->CloseWindow(); | 199 browser()->CloseWindow(); |
110 BrowserClosedObserver wait_for_close(browser()); | 200 BrowserClosedObserver wait_for_close(browser()); |
111 } | 201 } |
OLD | NEW |