OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 std::string replacement_path; | 53 std::string replacement_path; |
54 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 54 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
55 "files/click-noreferrer-links.html", | 55 "files/click-noreferrer-links.html", |
56 https_server.host_port_pair(), | 56 https_server.host_port_pair(), |
57 &replacement_path)); | 57 &replacement_path)); |
58 ui_test_utils::NavigateToURL(browser(), | 58 ui_test_utils::NavigateToURL(browser(), |
59 test_server()->GetURL(replacement_path)); | 59 test_server()->GetURL(replacement_path)); |
60 | 60 |
61 // Get the original SiteInstance for later comparison. | 61 // Get the original SiteInstance for later comparison. |
62 scoped_refptr<SiteInstance> orig_site_instance( | 62 scoped_refptr<SiteInstance> orig_site_instance( |
63 browser()->GetSelectedTabContents()->GetSiteInstance()); | 63 browser()->GetSelectedWebContents()->GetSiteInstance()); |
64 EXPECT_TRUE(orig_site_instance != NULL); | 64 EXPECT_TRUE(orig_site_instance != NULL); |
65 | 65 |
66 // Test clicking a rel=noreferrer + target=blank link. | 66 // Test clicking a rel=noreferrer + target=blank link. |
67 bool success = false; | 67 bool success = false; |
68 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 68 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
69 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 69 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
70 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", | 70 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
71 &success)); | 71 &success)); |
72 EXPECT_TRUE(success); | 72 EXPECT_TRUE(success); |
73 | 73 |
74 // Wait for the tab to open. | 74 // Wait for the tab to open. |
75 if (browser()->tab_count() < 2) | 75 if (browser()->tab_count() < 2) |
76 ui_test_utils::WaitForNewTab(browser()); | 76 ui_test_utils::WaitForNewTab(browser()); |
77 | 77 |
78 // Opens in new tab. | 78 // Opens in new tab. |
79 EXPECT_EQ(2, browser()->tab_count()); | 79 EXPECT_EQ(2, browser()->tab_count()); |
80 EXPECT_EQ(1, browser()->active_index()); | 80 EXPECT_EQ(1, browser()->active_index()); |
81 EXPECT_EQ("/files/title2.html", | 81 EXPECT_EQ("/files/title2.html", |
82 browser()->GetSelectedTabContents()->GetURL().path()); | 82 browser()->GetSelectedWebContents()->GetURL().path()); |
83 | 83 |
84 // Wait for the cross-site transition in the new tab to finish. | 84 // Wait for the cross-site transition in the new tab to finish. |
85 ui_test_utils::WaitForLoadStop(browser()->GetSelectedTabContents()); | 85 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
86 EXPECT_FALSE(browser()->GetSelectedTabContents()-> | 86 EXPECT_FALSE(browser()->GetSelectedWebContents()-> |
87 GetRenderManagerForTesting()->pending_render_view_host()); | 87 GetRenderManagerForTesting()->pending_render_view_host()); |
88 | 88 |
89 // Should have a new SiteInstance. | 89 // Should have a new SiteInstance. |
90 scoped_refptr<SiteInstance> noref_blank_site_instance( | 90 scoped_refptr<SiteInstance> noref_blank_site_instance( |
91 browser()->GetSelectedTabContents()->GetSiteInstance()); | 91 browser()->GetSelectedWebContents()->GetSiteInstance()); |
92 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 92 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
93 } | 93 } |
94 | 94 |
95 // Test for crbug.com/24447. Following a cross-site link with just | 95 // Test for crbug.com/24447. Following a cross-site link with just |
96 // target=_blank should not create a new SiteInstance. | 96 // target=_blank should not create a new SiteInstance. |
97 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 97 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
98 DontSwapProcessWithOnlyTargetBlank) { | 98 DontSwapProcessWithOnlyTargetBlank) { |
99 // Start two servers with different sites. | 99 // Start two servers with different sites. |
100 ASSERT_TRUE(test_server()->Start()); | 100 ASSERT_TRUE(test_server()->Start()); |
101 net::TestServer https_server( | 101 net::TestServer https_server( |
102 net::TestServer::TYPE_HTTPS, | 102 net::TestServer::TYPE_HTTPS, |
103 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 103 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
104 ASSERT_TRUE(https_server.Start()); | 104 ASSERT_TRUE(https_server.Start()); |
105 | 105 |
106 // Load a page with links that open in a new window. | 106 // Load a page with links that open in a new window. |
107 std::string replacement_path; | 107 std::string replacement_path; |
108 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 108 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
109 "files/click-noreferrer-links.html", | 109 "files/click-noreferrer-links.html", |
110 https_server.host_port_pair(), | 110 https_server.host_port_pair(), |
111 &replacement_path)); | 111 &replacement_path)); |
112 ui_test_utils::NavigateToURL(browser(), | 112 ui_test_utils::NavigateToURL(browser(), |
113 test_server()->GetURL(replacement_path)); | 113 test_server()->GetURL(replacement_path)); |
114 | 114 |
115 // Get the original SiteInstance for later comparison. | 115 // Get the original SiteInstance for later comparison. |
116 scoped_refptr<SiteInstance> orig_site_instance( | 116 scoped_refptr<SiteInstance> orig_site_instance( |
117 browser()->GetSelectedTabContents()->GetSiteInstance()); | 117 browser()->GetSelectedWebContents()->GetSiteInstance()); |
118 EXPECT_TRUE(orig_site_instance != NULL); | 118 EXPECT_TRUE(orig_site_instance != NULL); |
119 | 119 |
120 // Test clicking a target=blank link. | 120 // Test clicking a target=blank link. |
121 bool success = false; | 121 bool success = false; |
122 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 122 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
123 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 123 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
124 L"window.domAutomationController.send(clickTargetBlankLink());", | 124 L"window.domAutomationController.send(clickTargetBlankLink());", |
125 &success)); | 125 &success)); |
126 EXPECT_TRUE(success); | 126 EXPECT_TRUE(success); |
127 | 127 |
128 // Wait for the tab to open. | 128 // Wait for the tab to open. |
129 if (browser()->tab_count() < 2) | 129 if (browser()->tab_count() < 2) |
130 ui_test_utils::WaitForNewTab(browser()); | 130 ui_test_utils::WaitForNewTab(browser()); |
131 | 131 |
132 // Opens in new tab. | 132 // Opens in new tab. |
133 EXPECT_EQ(2, browser()->tab_count()); | 133 EXPECT_EQ(2, browser()->tab_count()); |
134 EXPECT_EQ(1, browser()->active_index()); | 134 EXPECT_EQ(1, browser()->active_index()); |
135 | 135 |
136 // Wait for the cross-site transition in the new tab to finish. | 136 // Wait for the cross-site transition in the new tab to finish. |
137 ui_test_utils::WaitForLoadStop(browser()->GetSelectedTabContents()); | 137 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
138 EXPECT_EQ("/files/title2.html", | 138 EXPECT_EQ("/files/title2.html", |
139 browser()->GetSelectedTabContents()->GetURL().path()); | 139 browser()->GetSelectedWebContents()->GetURL().path()); |
140 | 140 |
141 // Should have the same SiteInstance. | 141 // Should have the same SiteInstance. |
142 scoped_refptr<SiteInstance> blank_site_instance( | 142 scoped_refptr<SiteInstance> blank_site_instance( |
143 browser()->GetSelectedTabContents()->GetSiteInstance()); | 143 browser()->GetSelectedWebContents()->GetSiteInstance()); |
144 EXPECT_EQ(orig_site_instance, blank_site_instance); | 144 EXPECT_EQ(orig_site_instance, blank_site_instance); |
145 } | 145 } |
146 | 146 |
147 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 147 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
148 // and no target=_blank should not create a new SiteInstance. | 148 // and no target=_blank should not create a new SiteInstance. |
149 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 149 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
150 DontSwapProcessWithOnlyRelNoreferrer) { | 150 DontSwapProcessWithOnlyRelNoreferrer) { |
151 // Start two servers with different sites. | 151 // Start two servers with different sites. |
152 ASSERT_TRUE(test_server()->Start()); | 152 ASSERT_TRUE(test_server()->Start()); |
153 net::TestServer https_server( | 153 net::TestServer https_server( |
154 net::TestServer::TYPE_HTTPS, | 154 net::TestServer::TYPE_HTTPS, |
155 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 155 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
156 ASSERT_TRUE(https_server.Start()); | 156 ASSERT_TRUE(https_server.Start()); |
157 | 157 |
158 // Load a page with links that open in a new window. | 158 // Load a page with links that open in a new window. |
159 std::string replacement_path; | 159 std::string replacement_path; |
160 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 160 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
161 "files/click-noreferrer-links.html", | 161 "files/click-noreferrer-links.html", |
162 https_server.host_port_pair(), | 162 https_server.host_port_pair(), |
163 &replacement_path)); | 163 &replacement_path)); |
164 ui_test_utils::NavigateToURL(browser(), | 164 ui_test_utils::NavigateToURL(browser(), |
165 test_server()->GetURL(replacement_path)); | 165 test_server()->GetURL(replacement_path)); |
166 | 166 |
167 // Get the original SiteInstance for later comparison. | 167 // Get the original SiteInstance for later comparison. |
168 scoped_refptr<SiteInstance> orig_site_instance( | 168 scoped_refptr<SiteInstance> orig_site_instance( |
169 browser()->GetSelectedTabContents()->GetSiteInstance()); | 169 browser()->GetSelectedWebContents()->GetSiteInstance()); |
170 EXPECT_TRUE(orig_site_instance != NULL); | 170 EXPECT_TRUE(orig_site_instance != NULL); |
171 | 171 |
172 // Test clicking a rel=noreferrer link. | 172 // Test clicking a rel=noreferrer link. |
173 bool success = false; | 173 bool success = false; |
174 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 174 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
175 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 175 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
176 L"window.domAutomationController.send(clickNoRefLink());", | 176 L"window.domAutomationController.send(clickNoRefLink());", |
177 &success)); | 177 &success)); |
178 EXPECT_TRUE(success); | 178 EXPECT_TRUE(success); |
179 | 179 |
180 // Wait for the cross-site transition in the current tab to finish. | 180 // Wait for the cross-site transition in the current tab to finish. |
181 ui_test_utils::WaitForLoadStop(browser()->GetSelectedTabContents()); | 181 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
182 | 182 |
183 // Opens in same tab. | 183 // Opens in same tab. |
184 EXPECT_EQ(1, browser()->tab_count()); | 184 EXPECT_EQ(1, browser()->tab_count()); |
185 EXPECT_EQ(0, browser()->active_index()); | 185 EXPECT_EQ(0, browser()->active_index()); |
186 EXPECT_EQ("/files/title2.html", | 186 EXPECT_EQ("/files/title2.html", |
187 browser()->GetSelectedTabContents()->GetURL().path()); | 187 browser()->GetSelectedWebContents()->GetURL().path()); |
188 | 188 |
189 // Should have the same SiteInstance. | 189 // Should have the same SiteInstance. |
190 scoped_refptr<SiteInstance> noref_site_instance( | 190 scoped_refptr<SiteInstance> noref_site_instance( |
191 browser()->GetSelectedTabContents()->GetSiteInstance()); | 191 browser()->GetSelectedWebContents()->GetSiteInstance()); |
192 EXPECT_EQ(orig_site_instance, noref_site_instance); | 192 EXPECT_EQ(orig_site_instance, noref_site_instance); |
193 } | 193 } |
194 | 194 |
195 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 195 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
196 // error should not make us ignore future renderer-initiated navigations. | 196 // error should not make us ignore future renderer-initiated navigations. |
197 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { | 197 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { |
198 // Start two servers with different sites. | 198 // Start two servers with different sites. |
199 ASSERT_TRUE(test_server()->Start()); | 199 ASSERT_TRUE(test_server()->Start()); |
200 net::TestServer https_server( | 200 net::TestServer https_server( |
201 net::TestServer::TYPE_HTTPS, | 201 net::TestServer::TYPE_HTTPS, |
202 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 202 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
203 ASSERT_TRUE(https_server.Start()); | 203 ASSERT_TRUE(https_server.Start()); |
204 | 204 |
205 // Load a page with links that open in a new window. | 205 // Load a page with links that open in a new window. |
206 // The links will point to the HTTPS server. | 206 // The links will point to the HTTPS server. |
207 std::string replacement_path; | 207 std::string replacement_path; |
208 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 208 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
209 "files/click-noreferrer-links.html", | 209 "files/click-noreferrer-links.html", |
210 https_server.host_port_pair(), | 210 https_server.host_port_pair(), |
211 &replacement_path)); | 211 &replacement_path)); |
212 ui_test_utils::NavigateToURL(browser(), | 212 ui_test_utils::NavigateToURL(browser(), |
213 test_server()->GetURL(replacement_path)); | 213 test_server()->GetURL(replacement_path)); |
214 | 214 |
215 // Get the original SiteInstance for later comparison. | 215 // Get the original SiteInstance for later comparison. |
216 scoped_refptr<SiteInstance> orig_site_instance( | 216 scoped_refptr<SiteInstance> orig_site_instance( |
217 browser()->GetSelectedTabContents()->GetSiteInstance()); | 217 browser()->GetSelectedWebContents()->GetSiteInstance()); |
218 EXPECT_TRUE(orig_site_instance != NULL); | 218 EXPECT_TRUE(orig_site_instance != NULL); |
219 | 219 |
220 // Load a cross-site page that fails with a 204 error. | 220 // Load a cross-site page that fails with a 204 error. |
221 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); | 221 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); |
222 | 222 |
223 // We should still be looking at the normal page. | 223 // We should still be looking at the normal page. |
224 scoped_refptr<SiteInstance> post_nav_site_instance( | 224 scoped_refptr<SiteInstance> post_nav_site_instance( |
225 browser()->GetSelectedTabContents()->GetSiteInstance()); | 225 browser()->GetSelectedWebContents()->GetSiteInstance()); |
226 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 226 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
227 EXPECT_EQ("/files/click-noreferrer-links.html", | 227 EXPECT_EQ("/files/click-noreferrer-links.html", |
228 browser()->GetSelectedTabContents()->GetURL().path()); | 228 browser()->GetSelectedWebContents()->GetURL().path()); |
229 | 229 |
230 // Renderer-initiated navigations should work. | 230 // Renderer-initiated navigations should work. |
231 bool success = false; | 231 bool success = false; |
232 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 232 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
233 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 233 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
234 L"window.domAutomationController.send(clickNoRefLink());", | 234 L"window.domAutomationController.send(clickNoRefLink());", |
235 &success)); | 235 &success)); |
236 EXPECT_TRUE(success); | 236 EXPECT_TRUE(success); |
237 | 237 |
238 // Wait for the cross-site transition in the current tab to finish. | 238 // Wait for the cross-site transition in the current tab to finish. |
239 ui_test_utils::WaitForLoadStop(browser()->GetSelectedTabContents()); | 239 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
240 | 240 |
241 // Opens in same tab. | 241 // Opens in same tab. |
242 EXPECT_EQ(1, browser()->tab_count()); | 242 EXPECT_EQ(1, browser()->tab_count()); |
243 EXPECT_EQ(0, browser()->active_index()); | 243 EXPECT_EQ(0, browser()->active_index()); |
244 EXPECT_EQ("/files/title2.html", | 244 EXPECT_EQ("/files/title2.html", |
245 browser()->GetSelectedTabContents()->GetURL().path()); | 245 browser()->GetSelectedWebContents()->GetURL().path()); |
246 | 246 |
247 // Should have the same SiteInstance. | 247 // Should have the same SiteInstance. |
248 scoped_refptr<SiteInstance> noref_site_instance( | 248 scoped_refptr<SiteInstance> noref_site_instance( |
249 browser()->GetSelectedTabContents()->GetSiteInstance()); | 249 browser()->GetSelectedWebContents()->GetSiteInstance()); |
250 EXPECT_EQ(orig_site_instance, noref_site_instance); | 250 EXPECT_EQ(orig_site_instance, noref_site_instance); |
251 } | 251 } |
252 | 252 |
253 // This class holds onto RenderViewHostObservers for as long as their observed | 253 // This class holds onto RenderViewHostObservers for as long as their observed |
254 // RenderViewHosts are alive. This allows us to confirm that all hosts have | 254 // RenderViewHosts are alive. This allows us to confirm that all hosts have |
255 // properly been shutdown. | 255 // properly been shutdown. |
256 class RenderViewHostObserverArray { | 256 class RenderViewHostObserverArray { |
257 public: | 257 public: |
258 ~RenderViewHostObserverArray() { | 258 ~RenderViewHostObserverArray() { |
259 // In case some would be left in there with a dead pointer to us. | 259 // In case some would be left in there with a dead pointer to us. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // a running browser. | 309 // a running browser. |
310 AddBlankTabAndShow(browser()); | 310 AddBlankTabAndShow(browser()); |
311 | 311 |
312 // Load a random page and then navigate to view-source: of it. | 312 // Load a random page and then navigate to view-source: of it. |
313 // This is one way to cause two rvh instances for the same instance id. | 313 // This is one way to cause two rvh instances for the same instance id. |
314 GURL navigated_url(test_server()->GetURL("files/title2.html")); | 314 GURL navigated_url(test_server()->GetURL("files/title2.html")); |
315 ui_test_utils::NavigateToURL(browser(), navigated_url); | 315 ui_test_utils::NavigateToURL(browser(), navigated_url); |
316 | 316 |
317 // Observe the newly created render_view_host to make sure it will not leak. | 317 // Observe the newly created render_view_host to make sure it will not leak. |
318 RenderViewHostObserverArray rvh_observers; | 318 RenderViewHostObserverArray rvh_observers; |
319 rvh_observers.AddObserverToRVH(browser()->GetSelectedTabContents()-> | 319 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> |
320 GetRenderViewHost()); | 320 GetRenderViewHost()); |
321 | 321 |
322 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + | 322 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + |
323 navigated_url.spec()); | 323 navigated_url.spec()); |
324 ui_test_utils::NavigateToURL(browser(), view_source_url); | 324 ui_test_utils::NavigateToURL(browser(), view_source_url); |
325 rvh_observers.AddObserverToRVH(browser()->GetSelectedTabContents()-> | 325 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> |
326 GetRenderViewHost()); | 326 GetRenderViewHost()); |
327 | 327 |
328 // Now navigate to a different instance so that we swap out again. | 328 // Now navigate to a different instance so that we swap out again. |
329 ui_test_utils::NavigateToURL(browser(), | 329 ui_test_utils::NavigateToURL(browser(), |
330 https_server.GetURL("files/title2.html")); | 330 https_server.GetURL("files/title2.html")); |
331 rvh_observers.AddObserverToRVH(browser()->GetSelectedTabContents()-> | 331 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> |
332 GetRenderViewHost()); | 332 GetRenderViewHost()); |
333 | 333 |
334 // This used to leak a render view host. | 334 // This used to leak a render view host. |
335 browser()->CloseTabContents(browser()->GetSelectedTabContents()); | 335 browser()->CloseTabContents(browser()->GetSelectedWebContents()); |
336 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 336 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
337 } | 337 } |
OLD | NEW |