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