OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 std::string replacement_path; | 58 std::string replacement_path; |
59 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 59 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
60 "files/click-noreferrer-links.html", | 60 "files/click-noreferrer-links.html", |
61 https_server.host_port_pair(), | 61 https_server.host_port_pair(), |
62 &replacement_path)); | 62 &replacement_path)); |
63 ui_test_utils::NavigateToURL(browser(), | 63 ui_test_utils::NavigateToURL(browser(), |
64 test_server()->GetURL(replacement_path)); | 64 test_server()->GetURL(replacement_path)); |
65 | 65 |
66 // Get the original SiteInstance for later comparison. | 66 // Get the original SiteInstance for later comparison. |
67 scoped_refptr<SiteInstance> orig_site_instance( | 67 scoped_refptr<SiteInstance> orig_site_instance( |
68 browser()->GetSelectedWebContents()->GetSiteInstance()); | 68 browser()->GetActiveWebContents()->GetSiteInstance()); |
69 EXPECT_TRUE(orig_site_instance != NULL); | 69 EXPECT_TRUE(orig_site_instance != NULL); |
70 | 70 |
71 // Open a same-site link in a new tab. | 71 // Open a same-site link in a new tab. |
72 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 72 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
73 content::Source<content::WebContentsDelegate>(browser()))); | 73 content::Source<content::WebContentsDelegate>(browser()))); |
74 bool success = false; | 74 bool success = false; |
75 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 75 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
76 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 76 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
77 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 77 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
78 &success)); | 78 &success)); |
79 EXPECT_TRUE(success); | 79 EXPECT_TRUE(success); |
80 new_tab_observer.Wait(); | 80 new_tab_observer.Wait(); |
81 | 81 |
82 // Opens in new tab. | 82 // Opens in new tab. |
83 EXPECT_EQ(2, browser()->tab_count()); | 83 EXPECT_EQ(2, browser()->tab_count()); |
84 EXPECT_EQ(1, browser()->active_index()); | 84 EXPECT_EQ(1, browser()->active_index()); |
85 | 85 |
86 // Wait for the navigation in the new tab to finish, if it hasn't. | 86 // Wait for the navigation in the new tab to finish, if it hasn't. |
87 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 87 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
88 EXPECT_EQ("/files/navigate_opener.html", | 88 EXPECT_EQ("/files/navigate_opener.html", |
89 browser()->GetSelectedWebContents()->GetURL().path()); | 89 browser()->GetActiveWebContents()->GetURL().path()); |
90 EXPECT_EQ(1, browser()->active_index()); | 90 EXPECT_EQ(1, browser()->active_index()); |
91 | 91 |
92 // Should have the same SiteInstance. | 92 // Should have the same SiteInstance. |
93 scoped_refptr<SiteInstance> blank_site_instance( | 93 scoped_refptr<SiteInstance> blank_site_instance( |
94 browser()->GetSelectedWebContents()->GetSiteInstance()); | 94 browser()->GetActiveWebContents()->GetSiteInstance()); |
95 EXPECT_EQ(orig_site_instance, blank_site_instance); | 95 EXPECT_EQ(orig_site_instance, blank_site_instance); |
96 | 96 |
97 // We should have access to the opened tab's location. | 97 // We should have access to the opened tab's location. |
98 browser()->ActivateTabAt(0, true); | 98 browser()->ActivateTabAt(0, true); |
99 success = false; | 99 success = false; |
100 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 100 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
101 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 101 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
102 L"window.domAutomationController.send(testScriptAccessToWindow());", | 102 L"window.domAutomationController.send(testScriptAccessToWindow());", |
103 &success)); | 103 &success)); |
104 EXPECT_TRUE(success); | 104 EXPECT_TRUE(success); |
105 | 105 |
106 // Now navigate the new tab to a different site. | 106 // Now navigate the new tab to a different site. |
107 browser()->ActivateTabAt(1, true); | 107 browser()->ActivateTabAt(1, true); |
108 ui_test_utils::NavigateToURL(browser(), | 108 ui_test_utils::NavigateToURL(browser(), |
109 https_server.GetURL("files/title1.html")); | 109 https_server.GetURL("files/title1.html")); |
110 scoped_refptr<SiteInstance> new_site_instance( | 110 scoped_refptr<SiteInstance> new_site_instance( |
111 browser()->GetSelectedWebContents()->GetSiteInstance()); | 111 browser()->GetActiveWebContents()->GetSiteInstance()); |
112 EXPECT_NE(orig_site_instance, new_site_instance); | 112 EXPECT_NE(orig_site_instance, new_site_instance); |
113 | 113 |
114 // We should no longer have script access to the opened tab's location. | 114 // We should no longer have script access to the opened tab's location. |
115 browser()->ActivateTabAt(0, true); | 115 browser()->ActivateTabAt(0, true); |
116 success = false; | 116 success = false; |
117 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 117 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
118 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 118 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
119 L"window.domAutomationController.send(testScriptAccessToWindow());", | 119 L"window.domAutomationController.send(testScriptAccessToWindow());", |
120 &success)); | 120 &success)); |
121 EXPECT_FALSE(success); | 121 EXPECT_FALSE(success); |
122 } | 122 } |
123 | 123 |
124 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 124 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
125 // and target=_blank should create a new SiteInstance. | 125 // and target=_blank should create a new SiteInstance. |
126 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 126 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
127 SwapProcessWithRelNoreferrerAndTargetBlank) { | 127 SwapProcessWithRelNoreferrerAndTargetBlank) { |
128 // Start two servers with different sites. | 128 // Start two servers with different sites. |
129 ASSERT_TRUE(test_server()->Start()); | 129 ASSERT_TRUE(test_server()->Start()); |
130 net::TestServer https_server( | 130 net::TestServer https_server( |
131 net::TestServer::TYPE_HTTPS, | 131 net::TestServer::TYPE_HTTPS, |
132 net::TestServer::kLocalhost, | 132 net::TestServer::kLocalhost, |
133 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 133 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
134 ASSERT_TRUE(https_server.Start()); | 134 ASSERT_TRUE(https_server.Start()); |
135 | 135 |
136 // Load a page with links that open in a new window. | 136 // Load a page with links that open in a new window. |
137 std::string replacement_path; | 137 std::string replacement_path; |
138 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 138 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
139 "files/click-noreferrer-links.html", | 139 "files/click-noreferrer-links.html", |
140 https_server.host_port_pair(), | 140 https_server.host_port_pair(), |
141 &replacement_path)); | 141 &replacement_path)); |
142 ui_test_utils::NavigateToURL(browser(), | 142 ui_test_utils::NavigateToURL(browser(), |
143 test_server()->GetURL(replacement_path)); | 143 test_server()->GetURL(replacement_path)); |
144 | 144 |
145 // Get the original SiteInstance for later comparison. | 145 // Get the original SiteInstance for later comparison. |
146 scoped_refptr<SiteInstance> orig_site_instance( | 146 scoped_refptr<SiteInstance> orig_site_instance( |
147 browser()->GetSelectedWebContents()->GetSiteInstance()); | 147 browser()->GetActiveWebContents()->GetSiteInstance()); |
148 EXPECT_TRUE(orig_site_instance != NULL); | 148 EXPECT_TRUE(orig_site_instance != NULL); |
149 | 149 |
150 // Test clicking a rel=noreferrer + target=blank link. | 150 // Test clicking a rel=noreferrer + target=blank link. |
151 bool success = false; | 151 bool success = false; |
152 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 152 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
153 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 153 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
154 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", | 154 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
155 &success)); | 155 &success)); |
156 EXPECT_TRUE(success); | 156 EXPECT_TRUE(success); |
157 | 157 |
158 // Wait for the tab to open. | 158 // Wait for the tab to open. |
159 if (browser()->tab_count() < 2) | 159 if (browser()->tab_count() < 2) |
160 ui_test_utils::WaitForNewTab(browser()); | 160 ui_test_utils::WaitForNewTab(browser()); |
161 | 161 |
162 // Opens in new tab. | 162 // Opens in new tab. |
163 EXPECT_EQ(2, browser()->tab_count()); | 163 EXPECT_EQ(2, browser()->tab_count()); |
164 EXPECT_EQ(1, browser()->active_index()); | 164 EXPECT_EQ(1, browser()->active_index()); |
165 EXPECT_EQ("/files/title2.html", | 165 EXPECT_EQ("/files/title2.html", |
166 browser()->GetSelectedWebContents()->GetURL().path()); | 166 browser()->GetActiveWebContents()->GetURL().path()); |
167 | 167 |
168 // Wait for the cross-site transition in the new tab to finish. | 168 // Wait for the cross-site transition in the new tab to finish. |
169 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 169 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
170 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 170 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
171 browser()->GetSelectedWebContents()); | 171 browser()->GetActiveWebContents()); |
172 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 172 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
173 pending_render_view_host()); | 173 pending_render_view_host()); |
174 | 174 |
175 // Should have a new SiteInstance. | 175 // Should have a new SiteInstance. |
176 scoped_refptr<SiteInstance> noref_blank_site_instance( | 176 scoped_refptr<SiteInstance> noref_blank_site_instance( |
177 browser()->GetSelectedWebContents()->GetSiteInstance()); | 177 browser()->GetActiveWebContents()->GetSiteInstance()); |
178 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 178 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
179 } | 179 } |
180 | 180 |
181 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) | 181 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) |
182 // for rel=noreferrer links in new windows, even to same site pages and named | 182 // for rel=noreferrer links in new windows, even to same site pages and named |
183 // targets. | 183 // targets. |
184 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 184 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
185 SwapProcessWithSameSiteRelNoreferrer) { | 185 SwapProcessWithSameSiteRelNoreferrer) { |
186 // Start two servers with different sites. | 186 // Start two servers with different sites. |
187 ASSERT_TRUE(test_server()->Start()); | 187 ASSERT_TRUE(test_server()->Start()); |
188 net::TestServer https_server( | 188 net::TestServer https_server( |
189 net::TestServer::TYPE_HTTPS, | 189 net::TestServer::TYPE_HTTPS, |
190 net::TestServer::kLocalhost, | 190 net::TestServer::kLocalhost, |
191 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 191 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
192 ASSERT_TRUE(https_server.Start()); | 192 ASSERT_TRUE(https_server.Start()); |
193 | 193 |
194 // Load a page with links that open in a new window. | 194 // Load a page with links that open in a new window. |
195 std::string replacement_path; | 195 std::string replacement_path; |
196 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 196 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
197 "files/click-noreferrer-links.html", | 197 "files/click-noreferrer-links.html", |
198 https_server.host_port_pair(), | 198 https_server.host_port_pair(), |
199 &replacement_path)); | 199 &replacement_path)); |
200 ui_test_utils::NavigateToURL(browser(), | 200 ui_test_utils::NavigateToURL(browser(), |
201 test_server()->GetURL(replacement_path)); | 201 test_server()->GetURL(replacement_path)); |
202 | 202 |
203 // Get the original SiteInstance for later comparison. | 203 // Get the original SiteInstance for later comparison. |
204 scoped_refptr<SiteInstance> orig_site_instance( | 204 scoped_refptr<SiteInstance> orig_site_instance( |
205 browser()->GetSelectedWebContents()->GetSiteInstance()); | 205 browser()->GetActiveWebContents()->GetSiteInstance()); |
206 EXPECT_TRUE(orig_site_instance != NULL); | 206 EXPECT_TRUE(orig_site_instance != NULL); |
207 | 207 |
208 // Test clicking a same-site rel=noreferrer + target=foo link. | 208 // Test clicking a same-site rel=noreferrer + target=foo link. |
209 bool success = false; | 209 bool success = false; |
210 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 210 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
211 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 211 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
212 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | 212 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
213 &success)); | 213 &success)); |
214 EXPECT_TRUE(success); | 214 EXPECT_TRUE(success); |
215 | 215 |
216 // Wait for the tab to open. | 216 // Wait for the tab to open. |
217 if (browser()->tab_count() < 2) | 217 if (browser()->tab_count() < 2) |
218 ui_test_utils::WaitForNewTab(browser()); | 218 ui_test_utils::WaitForNewTab(browser()); |
219 | 219 |
220 // Opens in new tab. | 220 // Opens in new tab. |
221 EXPECT_EQ(2, browser()->tab_count()); | 221 EXPECT_EQ(2, browser()->tab_count()); |
222 EXPECT_EQ(1, browser()->active_index()); | 222 EXPECT_EQ(1, browser()->active_index()); |
223 EXPECT_EQ("/files/title2.html", | 223 EXPECT_EQ("/files/title2.html", |
224 browser()->GetSelectedWebContents()->GetURL().path()); | 224 browser()->GetActiveWebContents()->GetURL().path()); |
225 | 225 |
226 // Wait for the cross-site transition in the new tab to finish. | 226 // Wait for the cross-site transition in the new tab to finish. |
227 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 227 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
228 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 228 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
229 browser()->GetSelectedWebContents()); | 229 browser()->GetActiveWebContents()); |
230 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 230 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
231 pending_render_view_host()); | 231 pending_render_view_host()); |
232 | 232 |
233 // Should have a new SiteInstance (in a new BrowsingInstance). | 233 // Should have a new SiteInstance (in a new BrowsingInstance). |
234 scoped_refptr<SiteInstance> noref_blank_site_instance( | 234 scoped_refptr<SiteInstance> noref_blank_site_instance( |
235 browser()->GetSelectedWebContents()->GetSiteInstance()); | 235 browser()->GetActiveWebContents()->GetSiteInstance()); |
236 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 236 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
237 } | 237 } |
238 | 238 |
239 // Test for crbug.com/24447. Following a cross-site link with just | 239 // Test for crbug.com/24447. Following a cross-site link with just |
240 // target=_blank should not create a new SiteInstance. | 240 // target=_blank should not create a new SiteInstance. |
241 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 241 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
242 DontSwapProcessWithOnlyTargetBlank) { | 242 DontSwapProcessWithOnlyTargetBlank) { |
243 // Start two servers with different sites. | 243 // Start two servers with different sites. |
244 ASSERT_TRUE(test_server()->Start()); | 244 ASSERT_TRUE(test_server()->Start()); |
245 net::TestServer https_server( | 245 net::TestServer https_server( |
246 net::TestServer::TYPE_HTTPS, | 246 net::TestServer::TYPE_HTTPS, |
247 net::TestServer::kLocalhost, | 247 net::TestServer::kLocalhost, |
248 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 248 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
249 ASSERT_TRUE(https_server.Start()); | 249 ASSERT_TRUE(https_server.Start()); |
250 | 250 |
251 // Load a page with links that open in a new window. | 251 // Load a page with links that open in a new window. |
252 std::string replacement_path; | 252 std::string replacement_path; |
253 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 253 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
254 "files/click-noreferrer-links.html", | 254 "files/click-noreferrer-links.html", |
255 https_server.host_port_pair(), | 255 https_server.host_port_pair(), |
256 &replacement_path)); | 256 &replacement_path)); |
257 ui_test_utils::NavigateToURL(browser(), | 257 ui_test_utils::NavigateToURL(browser(), |
258 test_server()->GetURL(replacement_path)); | 258 test_server()->GetURL(replacement_path)); |
259 | 259 |
260 // Get the original SiteInstance for later comparison. | 260 // Get the original SiteInstance for later comparison. |
261 scoped_refptr<SiteInstance> orig_site_instance( | 261 scoped_refptr<SiteInstance> orig_site_instance( |
262 browser()->GetSelectedWebContents()->GetSiteInstance()); | 262 browser()->GetActiveWebContents()->GetSiteInstance()); |
263 EXPECT_TRUE(orig_site_instance != NULL); | 263 EXPECT_TRUE(orig_site_instance != NULL); |
264 | 264 |
265 // Test clicking a target=blank link. | 265 // Test clicking a target=blank link. |
266 bool success = false; | 266 bool success = false; |
267 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 267 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
268 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 268 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
269 L"window.domAutomationController.send(clickTargetBlankLink());", | 269 L"window.domAutomationController.send(clickTargetBlankLink());", |
270 &success)); | 270 &success)); |
271 EXPECT_TRUE(success); | 271 EXPECT_TRUE(success); |
272 | 272 |
273 // Wait for the tab to open. | 273 // Wait for the tab to open. |
274 if (browser()->tab_count() < 2) | 274 if (browser()->tab_count() < 2) |
275 ui_test_utils::WaitForNewTab(browser()); | 275 ui_test_utils::WaitForNewTab(browser()); |
276 | 276 |
277 // Opens in new tab. | 277 // Opens in new tab. |
278 EXPECT_EQ(2, browser()->tab_count()); | 278 EXPECT_EQ(2, browser()->tab_count()); |
279 EXPECT_EQ(1, browser()->active_index()); | 279 EXPECT_EQ(1, browser()->active_index()); |
280 | 280 |
281 // Wait for the cross-site transition in the new tab to finish. | 281 // Wait for the cross-site transition in the new tab to finish. |
282 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 282 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
283 EXPECT_EQ("/files/title2.html", | 283 EXPECT_EQ("/files/title2.html", |
284 browser()->GetSelectedWebContents()->GetURL().path()); | 284 browser()->GetActiveWebContents()->GetURL().path()); |
285 | 285 |
286 // Should have the same SiteInstance. | 286 // Should have the same SiteInstance. |
287 scoped_refptr<SiteInstance> blank_site_instance( | 287 scoped_refptr<SiteInstance> blank_site_instance( |
288 browser()->GetSelectedWebContents()->GetSiteInstance()); | 288 browser()->GetActiveWebContents()->GetSiteInstance()); |
289 EXPECT_EQ(orig_site_instance, blank_site_instance); | 289 EXPECT_EQ(orig_site_instance, blank_site_instance); |
290 } | 290 } |
291 | 291 |
292 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 292 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
293 // and no target=_blank should not create a new SiteInstance. | 293 // and no target=_blank should not create a new SiteInstance. |
294 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 294 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
295 DontSwapProcessWithOnlyRelNoreferrer) { | 295 DontSwapProcessWithOnlyRelNoreferrer) { |
296 // Start two servers with different sites. | 296 // Start two servers with different sites. |
297 ASSERT_TRUE(test_server()->Start()); | 297 ASSERT_TRUE(test_server()->Start()); |
298 net::TestServer https_server( | 298 net::TestServer https_server( |
299 net::TestServer::TYPE_HTTPS, | 299 net::TestServer::TYPE_HTTPS, |
300 net::TestServer::kLocalhost, | 300 net::TestServer::kLocalhost, |
301 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 301 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
302 ASSERT_TRUE(https_server.Start()); | 302 ASSERT_TRUE(https_server.Start()); |
303 | 303 |
304 // Load a page with links that open in a new window. | 304 // Load a page with links that open in a new window. |
305 std::string replacement_path; | 305 std::string replacement_path; |
306 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 306 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
307 "files/click-noreferrer-links.html", | 307 "files/click-noreferrer-links.html", |
308 https_server.host_port_pair(), | 308 https_server.host_port_pair(), |
309 &replacement_path)); | 309 &replacement_path)); |
310 ui_test_utils::NavigateToURL(browser(), | 310 ui_test_utils::NavigateToURL(browser(), |
311 test_server()->GetURL(replacement_path)); | 311 test_server()->GetURL(replacement_path)); |
312 | 312 |
313 // Get the original SiteInstance for later comparison. | 313 // Get the original SiteInstance for later comparison. |
314 scoped_refptr<SiteInstance> orig_site_instance( | 314 scoped_refptr<SiteInstance> orig_site_instance( |
315 browser()->GetSelectedWebContents()->GetSiteInstance()); | 315 browser()->GetActiveWebContents()->GetSiteInstance()); |
316 EXPECT_TRUE(orig_site_instance != NULL); | 316 EXPECT_TRUE(orig_site_instance != NULL); |
317 | 317 |
318 // Test clicking a rel=noreferrer link. | 318 // Test clicking a rel=noreferrer link. |
319 bool success = false; | 319 bool success = false; |
320 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 320 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
321 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 321 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
322 L"window.domAutomationController.send(clickNoRefLink());", | 322 L"window.domAutomationController.send(clickNoRefLink());", |
323 &success)); | 323 &success)); |
324 EXPECT_TRUE(success); | 324 EXPECT_TRUE(success); |
325 | 325 |
326 // Wait for the cross-site transition in the current tab to finish. | 326 // Wait for the cross-site transition in the current tab to finish. |
327 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 327 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
328 | 328 |
329 // Opens in same tab. | 329 // Opens in same tab. |
330 EXPECT_EQ(1, browser()->tab_count()); | 330 EXPECT_EQ(1, browser()->tab_count()); |
331 EXPECT_EQ(0, browser()->active_index()); | 331 EXPECT_EQ(0, browser()->active_index()); |
332 EXPECT_EQ("/files/title2.html", | 332 EXPECT_EQ("/files/title2.html", |
333 browser()->GetSelectedWebContents()->GetURL().path()); | 333 browser()->GetActiveWebContents()->GetURL().path()); |
334 | 334 |
335 // Should have the same SiteInstance. | 335 // Should have the same SiteInstance. |
336 scoped_refptr<SiteInstance> noref_site_instance( | 336 scoped_refptr<SiteInstance> noref_site_instance( |
337 browser()->GetSelectedWebContents()->GetSiteInstance()); | 337 browser()->GetActiveWebContents()->GetSiteInstance()); |
338 EXPECT_EQ(orig_site_instance, noref_site_instance); | 338 EXPECT_EQ(orig_site_instance, noref_site_instance); |
339 } | 339 } |
340 | 340 |
341 // Test for crbug.com/116192. Targeted links should still work after the | 341 // Test for crbug.com/116192. Targeted links should still work after the |
342 // named target window has swapped processes. | 342 // named target window has swapped processes. |
343 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 343 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
344 AllowTargetedNavigationsAfterSwap) { | 344 AllowTargetedNavigationsAfterSwap) { |
345 // Start two servers with different sites. | 345 // Start two servers with different sites. |
346 ASSERT_TRUE(test_server()->Start()); | 346 ASSERT_TRUE(test_server()->Start()); |
347 net::TestServer https_server( | 347 net::TestServer https_server( |
348 net::TestServer::TYPE_HTTPS, | 348 net::TestServer::TYPE_HTTPS, |
349 net::TestServer::kLocalhost, | 349 net::TestServer::kLocalhost, |
350 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 350 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
351 ASSERT_TRUE(https_server.Start()); | 351 ASSERT_TRUE(https_server.Start()); |
352 | 352 |
353 // Load a page with links that open in a new window. | 353 // Load a page with links that open in a new window. |
354 std::string replacement_path; | 354 std::string replacement_path; |
355 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 355 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
356 "files/click-noreferrer-links.html", | 356 "files/click-noreferrer-links.html", |
357 https_server.host_port_pair(), | 357 https_server.host_port_pair(), |
358 &replacement_path)); | 358 &replacement_path)); |
359 ui_test_utils::NavigateToURL(browser(), | 359 ui_test_utils::NavigateToURL(browser(), |
360 test_server()->GetURL(replacement_path)); | 360 test_server()->GetURL(replacement_path)); |
361 | 361 |
362 // Get the original SiteInstance for later comparison. | 362 // Get the original SiteInstance for later comparison. |
363 scoped_refptr<SiteInstance> orig_site_instance( | 363 scoped_refptr<SiteInstance> orig_site_instance( |
364 browser()->GetSelectedWebContents()->GetSiteInstance()); | 364 browser()->GetActiveWebContents()->GetSiteInstance()); |
365 EXPECT_TRUE(orig_site_instance != NULL); | 365 EXPECT_TRUE(orig_site_instance != NULL); |
366 | 366 |
367 // Test clicking a target=foo link. | 367 // Test clicking a target=foo link. |
368 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 368 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
369 content::Source<content::WebContentsDelegate>(browser()))); | 369 content::Source<content::WebContentsDelegate>(browser()))); |
370 bool success = false; | 370 bool success = false; |
371 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 371 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
372 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 372 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
373 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 373 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
374 &success)); | 374 &success)); |
375 EXPECT_TRUE(success); | 375 EXPECT_TRUE(success); |
376 new_tab_observer.Wait(); | 376 new_tab_observer.Wait(); |
377 | 377 |
378 // Opens in new tab. | 378 // Opens in new tab. |
379 EXPECT_EQ(2, browser()->tab_count()); | 379 EXPECT_EQ(2, browser()->tab_count()); |
380 EXPECT_EQ(1, browser()->active_index()); | 380 EXPECT_EQ(1, browser()->active_index()); |
381 | 381 |
382 // Wait for the navigation in the new tab to finish, if it hasn't. | 382 // Wait for the navigation in the new tab to finish, if it hasn't. |
383 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 383 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
384 EXPECT_EQ("/files/navigate_opener.html", | 384 EXPECT_EQ("/files/navigate_opener.html", |
385 browser()->GetSelectedWebContents()->GetURL().path()); | 385 browser()->GetActiveWebContents()->GetURL().path()); |
386 EXPECT_EQ(1, browser()->active_index()); | 386 EXPECT_EQ(1, browser()->active_index()); |
387 | 387 |
388 // Should have the same SiteInstance. | 388 // Should have the same SiteInstance. |
389 scoped_refptr<SiteInstance> blank_site_instance( | 389 scoped_refptr<SiteInstance> blank_site_instance( |
390 browser()->GetSelectedWebContents()->GetSiteInstance()); | 390 browser()->GetActiveWebContents()->GetSiteInstance()); |
391 EXPECT_EQ(orig_site_instance, blank_site_instance); | 391 EXPECT_EQ(orig_site_instance, blank_site_instance); |
392 | 392 |
393 // Now navigate the new tab to a different site. | 393 // Now navigate the new tab to a different site. |
394 content::WebContents* new_contents = browser()->GetSelectedWebContents(); | 394 content::WebContents* new_contents = browser()->GetActiveWebContents(); |
395 ui_test_utils::NavigateToURL(browser(), | 395 ui_test_utils::NavigateToURL(browser(), |
396 https_server.GetURL("files/title1.html")); | 396 https_server.GetURL("files/title1.html")); |
397 scoped_refptr<SiteInstance> new_site_instance( | 397 scoped_refptr<SiteInstance> new_site_instance( |
398 new_contents->GetSiteInstance()); | 398 new_contents->GetSiteInstance()); |
399 EXPECT_NE(orig_site_instance, new_site_instance); | 399 EXPECT_NE(orig_site_instance, new_site_instance); |
400 | 400 |
401 // Clicking the original link in the first tab should cause us to swap back. | 401 // Clicking the original link in the first tab should cause us to swap back. |
402 browser()->ActivateTabAt(0, true); | 402 browser()->ActivateTabAt(0, true); |
403 ui_test_utils::WindowedNotificationObserver navigation_observer( | 403 ui_test_utils::WindowedNotificationObserver navigation_observer( |
404 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 404 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
405 content::Source<content::NavigationController>( | 405 content::Source<content::NavigationController>( |
406 &new_contents->GetController())); | 406 &new_contents->GetController())); |
407 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 407 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
408 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 408 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
409 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 409 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
410 &success)); | 410 &success)); |
411 EXPECT_TRUE(success); | 411 EXPECT_TRUE(success); |
412 navigation_observer.Wait(); | 412 navigation_observer.Wait(); |
413 | 413 |
414 // Should have swapped back and shown the new tab again. | 414 // Should have swapped back and shown the new tab again. |
415 EXPECT_EQ(1, browser()->active_index()); | 415 EXPECT_EQ(1, browser()->active_index()); |
416 scoped_refptr<SiteInstance> revisit_site_instance( | 416 scoped_refptr<SiteInstance> revisit_site_instance( |
417 browser()->GetSelectedWebContents()->GetSiteInstance()); | 417 browser()->GetActiveWebContents()->GetSiteInstance()); |
418 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 418 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
419 | 419 |
420 // If it navigates away to another process, the original window should | 420 // If it navigates away to another process, the original window should |
421 // still be able to close it (using a cross-process close message). | 421 // still be able to close it (using a cross-process close message). |
422 ui_test_utils::NavigateToURL(browser(), | 422 ui_test_utils::NavigateToURL(browser(), |
423 https_server.GetURL("files/title1.html")); | 423 https_server.GetURL("files/title1.html")); |
424 EXPECT_EQ(new_site_instance, | 424 EXPECT_EQ(new_site_instance, |
425 browser()->GetSelectedWebContents()->GetSiteInstance()); | 425 browser()->GetActiveWebContents()->GetSiteInstance()); |
426 browser()->ActivateTabAt(0, true); | 426 browser()->ActivateTabAt(0, true); |
427 ui_test_utils::WindowedNotificationObserver close_observer( | 427 ui_test_utils::WindowedNotificationObserver close_observer( |
428 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 428 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
429 content::Source<content::WebContents>(new_contents)); | 429 content::Source<content::WebContents>(new_contents)); |
430 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 430 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
431 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 431 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
432 L"window.domAutomationController.send(testCloseWindow());", | 432 L"window.domAutomationController.send(testCloseWindow());", |
433 &success)); | 433 &success)); |
434 EXPECT_TRUE(success); | 434 EXPECT_TRUE(success); |
435 close_observer.Wait(); | 435 close_observer.Wait(); |
436 } | 436 } |
437 | 437 |
438 // Test for crbug.com/99202. PostMessage calls should still work after | 438 // Test for crbug.com/99202. PostMessage calls should still work after |
439 // navigating the source and target windows to different sites. | 439 // navigating the source and target windows to different sites. |
440 // Specifically: | 440 // Specifically: |
441 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. | 441 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. |
(...skipping 13 matching lines...) Expand all Loading... |
455 // Load a page with links that open in a new window. | 455 // Load a page with links that open in a new window. |
456 std::string replacement_path; | 456 std::string replacement_path; |
457 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 457 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
458 "files/click-noreferrer-links.html", | 458 "files/click-noreferrer-links.html", |
459 https_server.host_port_pair(), | 459 https_server.host_port_pair(), |
460 &replacement_path)); | 460 &replacement_path)); |
461 ui_test_utils::NavigateToURL(browser(), | 461 ui_test_utils::NavigateToURL(browser(), |
462 test_server()->GetURL(replacement_path)); | 462 test_server()->GetURL(replacement_path)); |
463 | 463 |
464 // Get the original SiteInstance and RVHM for later comparison. | 464 // Get the original SiteInstance and RVHM for later comparison. |
465 content::WebContents* opener_contents = browser()->GetSelectedWebContents(); | 465 content::WebContents* opener_contents = browser()->GetActiveWebContents(); |
466 scoped_refptr<SiteInstance> orig_site_instance( | 466 scoped_refptr<SiteInstance> orig_site_instance( |
467 opener_contents->GetSiteInstance()); | 467 opener_contents->GetSiteInstance()); |
468 EXPECT_TRUE(orig_site_instance != NULL); | 468 EXPECT_TRUE(orig_site_instance != NULL); |
469 RenderViewHostManager* opener_manager = | 469 RenderViewHostManager* opener_manager = |
470 static_cast<WebContentsImpl*>(opener_contents)-> | 470 static_cast<WebContentsImpl*>(opener_contents)-> |
471 GetRenderManagerForTesting(); | 471 GetRenderManagerForTesting(); |
472 | 472 |
473 // 1) Open two more windows, one named. These initially have openers but no | 473 // 1) Open two more windows, one named. These initially have openers but no |
474 // reference to each other. We will later post a message between them. | 474 // reference to each other. We will later post a message between them. |
475 | 475 |
476 // First, a named target=foo window. | 476 // First, a named target=foo window. |
477 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 477 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
478 content::Source<content::WebContentsDelegate>(browser()))); | 478 content::Source<content::WebContentsDelegate>(browser()))); |
479 bool success = false; | 479 bool success = false; |
480 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 480 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
481 opener_contents->GetRenderViewHost(), L"", | 481 opener_contents->GetRenderViewHost(), L"", |
482 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 482 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
483 &success)); | 483 &success)); |
484 EXPECT_TRUE(success); | 484 EXPECT_TRUE(success); |
485 new_tab_observer.Wait(); | 485 new_tab_observer.Wait(); |
486 | 486 |
487 // Wait for the navigation in the new tab to finish, if it hasn't, then | 487 // Wait for the navigation in the new tab to finish, if it hasn't, then |
488 // send it to post_message.html on a different site. | 488 // send it to post_message.html on a different site. |
489 content::WebContents* foo_contents = browser()->GetSelectedWebContents(); | 489 content::WebContents* foo_contents = browser()->GetActiveWebContents(); |
490 ui_test_utils::WaitForLoadStop(foo_contents); | 490 ui_test_utils::WaitForLoadStop(foo_contents); |
491 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); | 491 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); |
492 EXPECT_EQ(1, browser()->active_index()); | 492 EXPECT_EQ(1, browser()->active_index()); |
493 ui_test_utils::NavigateToURL(browser(), | 493 ui_test_utils::NavigateToURL(browser(), |
494 https_server.GetURL("files/post_message.html")); | 494 https_server.GetURL("files/post_message.html")); |
495 scoped_refptr<SiteInstance> foo_site_instance( | 495 scoped_refptr<SiteInstance> foo_site_instance( |
496 foo_contents->GetSiteInstance()); | 496 foo_contents->GetSiteInstance()); |
497 EXPECT_NE(orig_site_instance, foo_site_instance); | 497 EXPECT_NE(orig_site_instance, foo_site_instance); |
498 | 498 |
499 // Second, a target=_blank window. | 499 // Second, a target=_blank window. |
500 browser()->ActivateTabAt(0, true); | 500 browser()->ActivateTabAt(0, true); |
501 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer2(( | 501 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer2(( |
502 content::Source<content::WebContentsDelegate>(browser()))); | 502 content::Source<content::WebContentsDelegate>(browser()))); |
503 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 503 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
504 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 504 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
505 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 505 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
506 &success)); | 506 &success)); |
507 EXPECT_TRUE(success); | 507 EXPECT_TRUE(success); |
508 new_tab_observer2.Wait(); | 508 new_tab_observer2.Wait(); |
509 | 509 |
510 // Wait for the navigation in the new tab to finish, if it hasn't, then | 510 // Wait for the navigation in the new tab to finish, if it hasn't, then |
511 // send it to post_message.html on the original site. | 511 // send it to post_message.html on the original site. |
512 content::WebContents* new_contents = browser()->GetSelectedWebContents(); | 512 content::WebContents* new_contents = browser()->GetActiveWebContents(); |
513 ui_test_utils::WaitForLoadStop(new_contents); | 513 ui_test_utils::WaitForLoadStop(new_contents); |
514 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); | 514 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); |
515 EXPECT_EQ(1, browser()->active_index()); | 515 EXPECT_EQ(1, browser()->active_index()); |
516 ui_test_utils::NavigateToURL( | 516 ui_test_utils::NavigateToURL( |
517 browser(), test_server()->GetURL("files/post_message.html")); | 517 browser(), test_server()->GetURL("files/post_message.html")); |
518 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); | 518 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); |
519 RenderViewHostManager* new_manager = | 519 RenderViewHostManager* new_manager = |
520 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); | 520 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); |
521 | 521 |
522 // We now have three windows. The opener should have a swapped out RVH | 522 // We now have three windows. The opener should have a swapped out RVH |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 // Load a page with links that open in a new window. | 596 // Load a page with links that open in a new window. |
597 std::string replacement_path; | 597 std::string replacement_path; |
598 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 598 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
599 "files/click-noreferrer-links.html", | 599 "files/click-noreferrer-links.html", |
600 https_server.host_port_pair(), | 600 https_server.host_port_pair(), |
601 &replacement_path)); | 601 &replacement_path)); |
602 ui_test_utils::NavigateToURL(browser(), | 602 ui_test_utils::NavigateToURL(browser(), |
603 test_server()->GetURL(replacement_path)); | 603 test_server()->GetURL(replacement_path)); |
604 | 604 |
605 // Get the original tab and SiteInstance for later comparison. | 605 // Get the original tab and SiteInstance for later comparison. |
606 content::WebContents* orig_contents = browser()->GetSelectedWebContents(); | 606 content::WebContents* orig_contents = browser()->GetActiveWebContents(); |
607 scoped_refptr<SiteInstance> orig_site_instance( | 607 scoped_refptr<SiteInstance> orig_site_instance( |
608 browser()->GetSelectedWebContents()->GetSiteInstance()); | 608 browser()->GetActiveWebContents()->GetSiteInstance()); |
609 EXPECT_TRUE(orig_site_instance != NULL); | 609 EXPECT_TRUE(orig_site_instance != NULL); |
610 | 610 |
611 // Test clicking a target=foo link. | 611 // Test clicking a target=foo link. |
612 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 612 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
613 content::Source<content::WebContentsDelegate>(browser()))); | 613 content::Source<content::WebContentsDelegate>(browser()))); |
614 bool success = false; | 614 bool success = false; |
615 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 615 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
616 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 616 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
617 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 617 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
618 &success)); | 618 &success)); |
619 EXPECT_TRUE(success); | 619 EXPECT_TRUE(success); |
620 new_tab_observer.Wait(); | 620 new_tab_observer.Wait(); |
621 | 621 |
622 // Opens in new tab. | 622 // Opens in new tab. |
623 EXPECT_EQ(2, browser()->tab_count()); | 623 EXPECT_EQ(2, browser()->tab_count()); |
624 EXPECT_EQ(1, browser()->active_index()); | 624 EXPECT_EQ(1, browser()->active_index()); |
625 | 625 |
626 // Wait for the navigation in the new tab to finish, if it hasn't. | 626 // Wait for the navigation in the new tab to finish, if it hasn't. |
627 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 627 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
628 EXPECT_EQ("/files/navigate_opener.html", | 628 EXPECT_EQ("/files/navigate_opener.html", |
629 browser()->GetSelectedWebContents()->GetURL().path()); | 629 browser()->GetActiveWebContents()->GetURL().path()); |
630 EXPECT_EQ(1, browser()->active_index()); | 630 EXPECT_EQ(1, browser()->active_index()); |
631 | 631 |
632 // Should have the same SiteInstance. | 632 // Should have the same SiteInstance. |
633 scoped_refptr<SiteInstance> blank_site_instance( | 633 scoped_refptr<SiteInstance> blank_site_instance( |
634 browser()->GetSelectedWebContents()->GetSiteInstance()); | 634 browser()->GetActiveWebContents()->GetSiteInstance()); |
635 EXPECT_EQ(orig_site_instance, blank_site_instance); | 635 EXPECT_EQ(orig_site_instance, blank_site_instance); |
636 | 636 |
637 // Now navigate the original (opener) tab to a different site. | 637 // Now navigate the original (opener) tab to a different site. |
638 browser()->ActivateTabAt(0, true); | 638 browser()->ActivateTabAt(0, true); |
639 ui_test_utils::NavigateToURL(browser(), | 639 ui_test_utils::NavigateToURL(browser(), |
640 https_server.GetURL("files/title1.html")); | 640 https_server.GetURL("files/title1.html")); |
641 scoped_refptr<SiteInstance> new_site_instance( | 641 scoped_refptr<SiteInstance> new_site_instance( |
642 browser()->GetSelectedWebContents()->GetSiteInstance()); | 642 browser()->GetActiveWebContents()->GetSiteInstance()); |
643 EXPECT_NE(orig_site_instance, new_site_instance); | 643 EXPECT_NE(orig_site_instance, new_site_instance); |
644 | 644 |
645 // The opened tab should be able to navigate the opener back to its process. | 645 // The opened tab should be able to navigate the opener back to its process. |
646 browser()->ActivateTabAt(1, true); | 646 browser()->ActivateTabAt(1, true); |
647 ui_test_utils::WindowedNotificationObserver navigation_observer( | 647 ui_test_utils::WindowedNotificationObserver navigation_observer( |
648 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 648 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
649 content::Source<content::NavigationController>( | 649 content::Source<content::NavigationController>( |
650 &orig_contents->GetController())); | 650 &orig_contents->GetController())); |
651 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 651 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
652 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 652 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
653 L"window.domAutomationController.send(navigateOpener());", | 653 L"window.domAutomationController.send(navigateOpener());", |
654 &success)); | 654 &success)); |
655 EXPECT_TRUE(success); | 655 EXPECT_TRUE(success); |
656 navigation_observer.Wait(); | 656 navigation_observer.Wait(); |
657 | 657 |
658 // Active tab should not have changed. | 658 // Active tab should not have changed. |
659 EXPECT_EQ(1, browser()->active_index()); | 659 EXPECT_EQ(1, browser()->active_index()); |
660 | 660 |
661 // Should have swapped back into this process. | 661 // Should have swapped back into this process. |
662 browser()->ActivateTabAt(0, true); | 662 browser()->ActivateTabAt(0, true); |
663 scoped_refptr<SiteInstance> revisit_site_instance( | 663 scoped_refptr<SiteInstance> revisit_site_instance( |
664 browser()->GetSelectedWebContents()->GetSiteInstance()); | 664 browser()->GetActiveWebContents()->GetSiteInstance()); |
665 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 665 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
666 } | 666 } |
667 | 667 |
668 // Test that opening a new window in the same SiteInstance and then navigating | 668 // Test that opening a new window in the same SiteInstance and then navigating |
669 // both windows to a different SiteInstance allows the first process to exit. | 669 // both windows to a different SiteInstance allows the first process to exit. |
670 // See http://crbug.com/126333. | 670 // See http://crbug.com/126333. |
671 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 671 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
672 ProcessExitWithSwappedOutViews) { | 672 ProcessExitWithSwappedOutViews) { |
673 // Start two servers with different sites. | 673 // Start two servers with different sites. |
674 ASSERT_TRUE(test_server()->Start()); | 674 ASSERT_TRUE(test_server()->Start()); |
675 net::TestServer https_server( | 675 net::TestServer https_server( |
676 net::TestServer::TYPE_HTTPS, | 676 net::TestServer::TYPE_HTTPS, |
677 net::TestServer::kLocalhost, | 677 net::TestServer::kLocalhost, |
678 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 678 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
679 ASSERT_TRUE(https_server.Start()); | 679 ASSERT_TRUE(https_server.Start()); |
680 | 680 |
681 // Load a page with links that open in a new window. | 681 // Load a page with links that open in a new window. |
682 std::string replacement_path; | 682 std::string replacement_path; |
683 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 683 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
684 "files/click-noreferrer-links.html", | 684 "files/click-noreferrer-links.html", |
685 https_server.host_port_pair(), | 685 https_server.host_port_pair(), |
686 &replacement_path)); | 686 &replacement_path)); |
687 ui_test_utils::NavigateToURL(browser(), | 687 ui_test_utils::NavigateToURL(browser(), |
688 test_server()->GetURL(replacement_path)); | 688 test_server()->GetURL(replacement_path)); |
689 | 689 |
690 // Get the original SiteInstance for later comparison. | 690 // Get the original SiteInstance for later comparison. |
691 scoped_refptr<SiteInstance> orig_site_instance( | 691 scoped_refptr<SiteInstance> orig_site_instance( |
692 browser()->GetSelectedWebContents()->GetSiteInstance()); | 692 browser()->GetActiveWebContents()->GetSiteInstance()); |
693 EXPECT_TRUE(orig_site_instance != NULL); | 693 EXPECT_TRUE(orig_site_instance != NULL); |
694 | 694 |
695 // Test clicking a target=foo link. | 695 // Test clicking a target=foo link. |
696 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 696 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
697 content::Source<content::WebContentsDelegate>(browser()))); | 697 content::Source<content::WebContentsDelegate>(browser()))); |
698 bool success = false; | 698 bool success = false; |
699 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 699 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
700 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 700 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
701 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 701 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
702 &success)); | 702 &success)); |
703 EXPECT_TRUE(success); | 703 EXPECT_TRUE(success); |
704 new_tab_observer.Wait(); | 704 new_tab_observer.Wait(); |
705 | 705 |
706 // Opens in new tab. | 706 // Opens in new tab. |
707 EXPECT_EQ(2, browser()->tab_count()); | 707 EXPECT_EQ(2, browser()->tab_count()); |
708 EXPECT_EQ(1, browser()->active_index()); | 708 EXPECT_EQ(1, browser()->active_index()); |
709 | 709 |
710 // Wait for the navigation in the new tab to finish, if it hasn't. | 710 // Wait for the navigation in the new tab to finish, if it hasn't. |
711 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 711 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
712 EXPECT_EQ("/files/navigate_opener.html", | 712 EXPECT_EQ("/files/navigate_opener.html", |
713 browser()->GetSelectedWebContents()->GetURL().path()); | 713 browser()->GetActiveWebContents()->GetURL().path()); |
714 EXPECT_EQ(1, browser()->active_index()); | 714 EXPECT_EQ(1, browser()->active_index()); |
715 | 715 |
716 // Should have the same SiteInstance. | 716 // Should have the same SiteInstance. |
717 scoped_refptr<SiteInstance> opened_site_instance( | 717 scoped_refptr<SiteInstance> opened_site_instance( |
718 browser()->GetSelectedWebContents()->GetSiteInstance()); | 718 browser()->GetActiveWebContents()->GetSiteInstance()); |
719 EXPECT_EQ(orig_site_instance, opened_site_instance); | 719 EXPECT_EQ(orig_site_instance, opened_site_instance); |
720 | 720 |
721 // Now navigate the opened tab to a different site. | 721 // Now navigate the opened tab to a different site. |
722 ui_test_utils::NavigateToURL(browser(), | 722 ui_test_utils::NavigateToURL(browser(), |
723 https_server.GetURL("files/title1.html")); | 723 https_server.GetURL("files/title1.html")); |
724 scoped_refptr<SiteInstance> new_site_instance( | 724 scoped_refptr<SiteInstance> new_site_instance( |
725 browser()->GetSelectedWebContents()->GetSiteInstance()); | 725 browser()->GetActiveWebContents()->GetSiteInstance()); |
726 EXPECT_NE(orig_site_instance, new_site_instance); | 726 EXPECT_NE(orig_site_instance, new_site_instance); |
727 | 727 |
728 // The original process should still be alive, since it is still used in the | 728 // The original process should still be alive, since it is still used in the |
729 // first tab. | 729 // first tab. |
730 content::RenderProcessHost* orig_process = orig_site_instance->GetProcess(); | 730 content::RenderProcessHost* orig_process = orig_site_instance->GetProcess(); |
731 EXPECT_TRUE(orig_process->HasConnection()); | 731 EXPECT_TRUE(orig_process->HasConnection()); |
732 | 732 |
733 // Navigate the first tab to a different site as well. The original process | 733 // Navigate the first tab to a different site as well. The original process |
734 // should exit, since all of its views are now swapped out. | 734 // should exit, since all of its views are now swapped out. |
735 browser()->ActivateTabAt(0, true); | 735 browser()->ActivateTabAt(0, true); |
736 ui_test_utils::WindowedNotificationObserver exit_observer( | 736 ui_test_utils::WindowedNotificationObserver exit_observer( |
737 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 737 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
738 content::Source<content::RenderProcessHost>(orig_process)); | 738 content::Source<content::RenderProcessHost>(orig_process)); |
739 ui_test_utils::NavigateToURL(browser(), | 739 ui_test_utils::NavigateToURL(browser(), |
740 https_server.GetURL("files/title1.html")); | 740 https_server.GetURL("files/title1.html")); |
741 exit_observer.Wait(); | 741 exit_observer.Wait(); |
742 scoped_refptr<SiteInstance> new_site_instance2( | 742 scoped_refptr<SiteInstance> new_site_instance2( |
743 browser()->GetSelectedWebContents()->GetSiteInstance()); | 743 browser()->GetActiveWebContents()->GetSiteInstance()); |
744 EXPECT_EQ(new_site_instance, new_site_instance2); | 744 EXPECT_EQ(new_site_instance, new_site_instance2); |
745 } | 745 } |
746 | 746 |
747 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 747 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
748 // error should not make us ignore future renderer-initiated navigations. | 748 // error should not make us ignore future renderer-initiated navigations. |
749 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { | 749 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { |
750 // Start two servers with different sites. | 750 // Start two servers with different sites. |
751 ASSERT_TRUE(test_server()->Start()); | 751 ASSERT_TRUE(test_server()->Start()); |
752 net::TestServer https_server( | 752 net::TestServer https_server( |
753 net::TestServer::TYPE_HTTPS, | 753 net::TestServer::TYPE_HTTPS, |
754 net::TestServer::kLocalhost, | 754 net::TestServer::kLocalhost, |
755 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 755 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
756 ASSERT_TRUE(https_server.Start()); | 756 ASSERT_TRUE(https_server.Start()); |
757 | 757 |
758 // Load a page with links that open in a new window. | 758 // Load a page with links that open in a new window. |
759 // The links will point to the HTTPS server. | 759 // The links will point to the HTTPS server. |
760 std::string replacement_path; | 760 std::string replacement_path; |
761 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 761 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
762 "files/click-noreferrer-links.html", | 762 "files/click-noreferrer-links.html", |
763 https_server.host_port_pair(), | 763 https_server.host_port_pair(), |
764 &replacement_path)); | 764 &replacement_path)); |
765 ui_test_utils::NavigateToURL(browser(), | 765 ui_test_utils::NavigateToURL(browser(), |
766 test_server()->GetURL(replacement_path)); | 766 test_server()->GetURL(replacement_path)); |
767 | 767 |
768 // Get the original SiteInstance for later comparison. | 768 // Get the original SiteInstance for later comparison. |
769 scoped_refptr<SiteInstance> orig_site_instance( | 769 scoped_refptr<SiteInstance> orig_site_instance( |
770 browser()->GetSelectedWebContents()->GetSiteInstance()); | 770 browser()->GetActiveWebContents()->GetSiteInstance()); |
771 EXPECT_TRUE(orig_site_instance != NULL); | 771 EXPECT_TRUE(orig_site_instance != NULL); |
772 | 772 |
773 // Load a cross-site page that fails with a 204 error. | 773 // Load a cross-site page that fails with a 204 error. |
774 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); | 774 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); |
775 | 775 |
776 // We should still be looking at the normal page. | 776 // We should still be looking at the normal page. |
777 scoped_refptr<SiteInstance> post_nav_site_instance( | 777 scoped_refptr<SiteInstance> post_nav_site_instance( |
778 browser()->GetSelectedWebContents()->GetSiteInstance()); | 778 browser()->GetActiveWebContents()->GetSiteInstance()); |
779 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 779 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
780 EXPECT_EQ("/files/click-noreferrer-links.html", | 780 EXPECT_EQ("/files/click-noreferrer-links.html", |
781 browser()->GetSelectedWebContents()->GetURL().path()); | 781 browser()->GetActiveWebContents()->GetURL().path()); |
782 | 782 |
783 // Renderer-initiated navigations should work. | 783 // Renderer-initiated navigations should work. |
784 bool success = false; | 784 bool success = false; |
785 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 785 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
786 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 786 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
787 L"window.domAutomationController.send(clickNoRefLink());", | 787 L"window.domAutomationController.send(clickNoRefLink());", |
788 &success)); | 788 &success)); |
789 EXPECT_TRUE(success); | 789 EXPECT_TRUE(success); |
790 | 790 |
791 // Wait for the cross-site transition in the current tab to finish. | 791 // Wait for the cross-site transition in the current tab to finish. |
792 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 792 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
793 | 793 |
794 // Opens in same tab. | 794 // Opens in same tab. |
795 EXPECT_EQ(1, browser()->tab_count()); | 795 EXPECT_EQ(1, browser()->tab_count()); |
796 EXPECT_EQ(0, browser()->active_index()); | 796 EXPECT_EQ(0, browser()->active_index()); |
797 EXPECT_EQ("/files/title2.html", | 797 EXPECT_EQ("/files/title2.html", |
798 browser()->GetSelectedWebContents()->GetURL().path()); | 798 browser()->GetActiveWebContents()->GetURL().path()); |
799 | 799 |
800 // Should have the same SiteInstance. | 800 // Should have the same SiteInstance. |
801 scoped_refptr<SiteInstance> noref_site_instance( | 801 scoped_refptr<SiteInstance> noref_site_instance( |
802 browser()->GetSelectedWebContents()->GetSiteInstance()); | 802 browser()->GetActiveWebContents()->GetSiteInstance()); |
803 EXPECT_EQ(orig_site_instance, noref_site_instance); | 803 EXPECT_EQ(orig_site_instance, noref_site_instance); |
804 } | 804 } |
805 | 805 |
806 // Test for http://crbug.com/93427. Ensure that cross-site navigations | 806 // Test for http://crbug.com/93427. Ensure that cross-site navigations |
807 // do not cause back/forward navigations to be considered stale by the | 807 // do not cause back/forward navigations to be considered stale by the |
808 // renderer. | 808 // renderer. |
809 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { | 809 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { |
810 // Start two servers with different sites. | 810 // Start two servers with different sites. |
811 ASSERT_TRUE(test_server()->Start()); | 811 ASSERT_TRUE(test_server()->Start()); |
812 net::TestServer https_server( | 812 net::TestServer https_server( |
(...skipping 28 matching lines...) Expand all Loading... |
841 https_server.GetURL(replacement_path_b2)); | 841 https_server.GetURL(replacement_path_b2)); |
842 std::string replacement_path_b3; | 842 std::string replacement_path_b3; |
843 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 843 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
844 "files/title3.html", | 844 "files/title3.html", |
845 https_server.host_port_pair(), | 845 https_server.host_port_pair(), |
846 &replacement_path_b3)); | 846 &replacement_path_b3)); |
847 ui_test_utils::NavigateToURL(browser(), | 847 ui_test_utils::NavigateToURL(browser(), |
848 https_server.GetURL(replacement_path_b3)); | 848 https_server.GetURL(replacement_path_b3)); |
849 | 849 |
850 // History is now [blank, A1, B1, B2, *B3]. | 850 // History is now [blank, A1, B1, B2, *B3]. |
851 content::WebContents* contents = browser()->GetSelectedWebContents(); | 851 content::WebContents* contents = browser()->GetActiveWebContents(); |
852 EXPECT_EQ(5, contents->GetController().GetEntryCount()); | 852 EXPECT_EQ(5, contents->GetController().GetEntryCount()); |
853 | 853 |
854 // Open another tab in same process to keep this process alive. | 854 // Open another tab in same process to keep this process alive. |
855 ui_test_utils::NavigateToURLWithDisposition( | 855 ui_test_utils::NavigateToURLWithDisposition( |
856 browser(), https_server.GetURL(replacement_path_b1), | 856 browser(), https_server.GetURL(replacement_path_b1), |
857 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 857 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
858 | 858 |
859 // Go back three times to first site. | 859 // Go back three times to first site. |
860 { | 860 { |
861 ui_test_utils::WindowedNotificationObserver back_nav_load_observer( | 861 ui_test_utils::WindowedNotificationObserver back_nav_load_observer( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 https_server.host_port_pair(), | 948 https_server.host_port_pair(), |
949 &replacement_path)); | 949 &replacement_path)); |
950 ui_test_utils::NavigateToURL(browser(), | 950 ui_test_utils::NavigateToURL(browser(), |
951 test_server()->GetURL(replacement_path)); | 951 test_server()->GetURL(replacement_path)); |
952 | 952 |
953 // Open a same-site link in a new tab. | 953 // Open a same-site link in a new tab. |
954 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 954 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( |
955 content::Source<content::WebContentsDelegate>(browser()))); | 955 content::Source<content::WebContentsDelegate>(browser()))); |
956 bool success = false; | 956 bool success = false; |
957 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 957 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
958 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 958 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
959 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 959 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
960 &success)); | 960 &success)); |
961 EXPECT_TRUE(success); | 961 EXPECT_TRUE(success); |
962 new_tab_observer.Wait(); | 962 new_tab_observer.Wait(); |
963 | 963 |
964 // Opens in new tab. | 964 // Opens in new tab. |
965 EXPECT_EQ(2, browser()->tab_count()); | 965 EXPECT_EQ(2, browser()->tab_count()); |
966 EXPECT_EQ(1, browser()->active_index()); | 966 EXPECT_EQ(1, browser()->active_index()); |
967 | 967 |
968 // Wait for the navigation in the new tab to finish, if it hasn't. | 968 // Wait for the navigation in the new tab to finish, if it hasn't. |
969 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 969 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
970 EXPECT_EQ("/files/navigate_opener.html", | 970 EXPECT_EQ("/files/navigate_opener.html", |
971 browser()->GetSelectedWebContents()->GetURL().path()); | 971 browser()->GetActiveWebContents()->GetURL().path()); |
972 EXPECT_EQ(1, browser()->active_index()); | 972 EXPECT_EQ(1, browser()->active_index()); |
973 | 973 |
974 RenderViewHost* rvh = | 974 RenderViewHost* rvh = |
975 browser()->GetSelectedWebContents()->GetRenderViewHost(); | 975 browser()->GetActiveWebContents()->GetRenderViewHost(); |
976 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 976 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
977 rvh, L"", | 977 rvh, L"", |
978 L"window.domAutomationController.send(" | 978 L"window.domAutomationController.send(" |
979 L"document.webkitVisibilityState == 'visible');", | 979 L"document.webkitVisibilityState == 'visible');", |
980 &success)); | 980 &success)); |
981 EXPECT_TRUE(success); | 981 EXPECT_TRUE(success); |
982 | 982 |
983 // Now navigate the new tab to a different site. This should swap out the | 983 // Now navigate the new tab to a different site. This should swap out the |
984 // tab's existing RenderView, causing it become hidden. | 984 // tab's existing RenderView, causing it become hidden. |
985 browser()->ActivateTabAt(1, true); | 985 browser()->ActivateTabAt(1, true); |
986 ui_test_utils::NavigateToURL(browser(), | 986 ui_test_utils::NavigateToURL(browser(), |
987 https_server.GetURL("files/title1.html")); | 987 https_server.GetURL("files/title1.html")); |
988 | 988 |
989 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 989 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
990 rvh, L"", | 990 rvh, L"", |
991 L"window.domAutomationController.send(" | 991 L"window.domAutomationController.send(" |
992 L"document.webkitVisibilityState == 'hidden');", | 992 L"document.webkitVisibilityState == 'hidden');", |
993 &success)); | 993 &success)); |
994 EXPECT_TRUE(success); | 994 EXPECT_TRUE(success); |
995 | 995 |
996 // Going back should make the previously swapped-out view to become visible | 996 // Going back should make the previously swapped-out view to become visible |
997 // again. | 997 // again. |
998 { | 998 { |
999 ui_test_utils::WindowedNotificationObserver back_nav_load_observer( | 999 ui_test_utils::WindowedNotificationObserver back_nav_load_observer( |
1000 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1000 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
1001 content::Source<content::NavigationController>( | 1001 content::Source<content::NavigationController>( |
1002 &browser()->GetSelectedWebContents()->GetController())); | 1002 &browser()->GetActiveWebContents()->GetController())); |
1003 browser()->GoBack(CURRENT_TAB); | 1003 browser()->GoBack(CURRENT_TAB); |
1004 back_nav_load_observer.Wait(); | 1004 back_nav_load_observer.Wait(); |
1005 } | 1005 } |
1006 | 1006 |
1007 | 1007 |
1008 EXPECT_EQ("/files/navigate_opener.html", | 1008 EXPECT_EQ("/files/navigate_opener.html", |
1009 browser()->GetSelectedWebContents()->GetURL().path()); | 1009 browser()->GetActiveWebContents()->GetURL().path()); |
1010 | 1010 |
1011 EXPECT_EQ(rvh, browser()->GetSelectedWebContents()->GetRenderViewHost()); | 1011 EXPECT_EQ(rvh, browser()->GetActiveWebContents()->GetRenderViewHost()); |
1012 | 1012 |
1013 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1013 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1014 rvh, L"", | 1014 rvh, L"", |
1015 L"window.domAutomationController.send(" | 1015 L"window.domAutomationController.send(" |
1016 L"document.webkitVisibilityState == 'visible');", | 1016 L"document.webkitVisibilityState == 'visible');", |
1017 &success)); | 1017 &success)); |
1018 EXPECT_TRUE(success); | 1018 EXPECT_TRUE(success); |
1019 } | 1019 } |
1020 | 1020 |
1021 // This class holds onto RenderViewHostObservers for as long as their observed | 1021 // This class holds onto RenderViewHostObservers for as long as their observed |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 | 1076 |
1077 // Create a new tab so that we can close the one we navigate and still have | 1077 // Create a new tab so that we can close the one we navigate and still have |
1078 // a running browser. | 1078 // a running browser. |
1079 AddBlankTabAndShow(browser()); | 1079 AddBlankTabAndShow(browser()); |
1080 | 1080 |
1081 // Load a random page and then navigate to view-source: of it. | 1081 // Load a random page and then navigate to view-source: of it. |
1082 // This used to cause two RVH instances for the same SiteInstance, which | 1082 // This used to cause two RVH instances for the same SiteInstance, which |
1083 // was a problem. This is no longer the case. | 1083 // was a problem. This is no longer the case. |
1084 GURL navigated_url(test_server()->GetURL("files/title2.html")); | 1084 GURL navigated_url(test_server()->GetURL("files/title2.html")); |
1085 ui_test_utils::NavigateToURL(browser(), navigated_url); | 1085 ui_test_utils::NavigateToURL(browser(), navigated_url); |
1086 SiteInstance* site_instance1 = browser()->GetSelectedWebContents()-> | 1086 SiteInstance* site_instance1 = browser()->GetActiveWebContents()-> |
1087 GetRenderViewHost()->GetSiteInstance(); | 1087 GetRenderViewHost()->GetSiteInstance(); |
1088 | 1088 |
1089 // Observe the newly created render_view_host to make sure it will not leak. | 1089 // Observe the newly created render_view_host to make sure it will not leak. |
1090 RenderViewHostObserverArray rvh_observers; | 1090 RenderViewHostObserverArray rvh_observers; |
1091 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> | 1091 rvh_observers.AddObserverToRVH(browser()->GetActiveWebContents()-> |
1092 GetRenderViewHost()); | 1092 GetRenderViewHost()); |
1093 | 1093 |
1094 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + | 1094 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + |
1095 navigated_url.spec()); | 1095 navigated_url.spec()); |
1096 ui_test_utils::NavigateToURL(browser(), view_source_url); | 1096 ui_test_utils::NavigateToURL(browser(), view_source_url); |
1097 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> | 1097 rvh_observers.AddObserverToRVH(browser()->GetActiveWebContents()-> |
1098 GetRenderViewHost()); | 1098 GetRenderViewHost()); |
1099 SiteInstance* site_instance2 = browser()->GetSelectedWebContents()-> | 1099 SiteInstance* site_instance2 = browser()->GetActiveWebContents()-> |
1100 GetRenderViewHost()->GetSiteInstance(); | 1100 GetRenderViewHost()->GetSiteInstance(); |
1101 | 1101 |
1102 // Ensure that view-source navigations force a new SiteInstance. | 1102 // Ensure that view-source navigations force a new SiteInstance. |
1103 EXPECT_NE(site_instance1, site_instance2); | 1103 EXPECT_NE(site_instance1, site_instance2); |
1104 | 1104 |
1105 // Now navigate to a different instance so that we swap out again. | 1105 // Now navigate to a different instance so that we swap out again. |
1106 ui_test_utils::NavigateToURL(browser(), | 1106 ui_test_utils::NavigateToURL(browser(), |
1107 https_server.GetURL("files/title2.html")); | 1107 https_server.GetURL("files/title2.html")); |
1108 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> | 1108 rvh_observers.AddObserverToRVH(browser()->GetActiveWebContents()-> |
1109 GetRenderViewHost()); | 1109 GetRenderViewHost()); |
1110 | 1110 |
1111 // This used to leak a render view host. | 1111 // This used to leak a render view host. |
1112 browser()->CloseTabContents(browser()->GetSelectedWebContents()); | 1112 browser()->CloseTabContents(browser()->GetActiveWebContents()); |
1113 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 1113 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
1114 } | 1114 } |
OLD | NEW |