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" | |
10 #include "chrome/browser/ui/browser_commands.h" | |
11 #include "chrome/browser/ui/browser_tabstrip.h" | |
12 #include "chrome/test/base/in_process_browser_test.h" | |
13 #include "chrome/test/base/ui_test_utils.h" | |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 10 #include "content/browser/site_instance_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host_observer.h" | 19 #include "content/public/browser/render_view_host_observer.h" |
20 #include "content/public/browser/web_contents.h" | |
25 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
26 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_utils.h" | |
24 #include "content/shell/shell.h" | |
25 #include "content/test/content_browser_test.h" | |
26 #include "content/test/content_browser_test_utils.h" | |
27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
28 #include "net/test/test_server.h" | 28 #include "net/test/test_server.h" |
29 | 29 |
30 using content::RenderViewHost; | 30 namespace content { |
31 using content::SiteInstance; | |
32 | 31 |
33 class RenderViewHostManagerTest : public InProcessBrowserTest { | 32 class RenderViewHostManagerTest : public ContentBrowserTest { |
34 public: | 33 public: |
35 RenderViewHostManagerTest() {} | 34 RenderViewHostManagerTest() {} |
36 | 35 |
37 static bool GetFilePathWithHostAndPortReplacement( | 36 static bool GetFilePathWithHostAndPortReplacement( |
38 const std::string& original_file_path, | 37 const std::string& original_file_path, |
39 const net::HostPortPair& host_port_pair, | 38 const net::HostPortPair& host_port_pair, |
40 std::string* replacement_path) { | 39 std::string* replacement_path) { |
41 std::vector<net::TestServer::StringPair> replacement_text; | 40 std::vector<net::TestServer::StringPair> replacement_text; |
42 replacement_text.push_back( | 41 replacement_text.push_back( |
43 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); | 42 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); |
44 return net::TestServer::GetFilePathWithReplacements( | 43 return net::TestServer::GetFilePathWithReplacements( |
45 original_file_path, replacement_text, replacement_path); | 44 original_file_path, replacement_text, replacement_path); |
46 } | 45 } |
47 }; | 46 }; |
48 | 47 |
49 // Web pages should not have script access to the swapped out page. | 48 // Web pages should not have script access to the swapped out page. |
50 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, NoScriptAccessAfterSwapOut) { | 49 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, NoScriptAccessAfterSwapOut) { |
51 // Start two servers with different sites. | 50 // Start two servers with different sites. |
52 ASSERT_TRUE(test_server()->Start()); | 51 ASSERT_TRUE(test_server()->Start()); |
53 net::TestServer https_server( | 52 net::TestServer https_server( |
54 net::TestServer::TYPE_HTTPS, | 53 net::TestServer::TYPE_HTTPS, |
55 net::TestServer::kLocalhost, | 54 net::TestServer::kLocalhost, |
56 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 55 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
57 ASSERT_TRUE(https_server.Start()); | 56 ASSERT_TRUE(https_server.Start()); |
58 | 57 |
59 // Load a page with links that open in a new window. | 58 // Load a page with links that open in a new window. |
60 std::string replacement_path; | 59 std::string replacement_path; |
61 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 60 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
62 "files/click-noreferrer-links.html", | 61 "files/click-noreferrer-links.html", |
63 https_server.host_port_pair(), | 62 https_server.host_port_pair(), |
64 &replacement_path)); | 63 &replacement_path)); |
65 ui_test_utils::NavigateToURL(browser(), | 64 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
66 test_server()->GetURL(replacement_path)); | |
67 | 65 |
68 // Get the original SiteInstance for later comparison. | 66 // Get the original SiteInstance for later comparison. |
69 scoped_refptr<SiteInstance> orig_site_instance( | 67 scoped_refptr<SiteInstance> orig_site_instance( |
70 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 68 shell()->web_contents()->GetSiteInstance()); |
71 EXPECT_TRUE(orig_site_instance != NULL); | 69 EXPECT_TRUE(orig_site_instance != NULL); |
72 | 70 |
73 // Open a same-site link in a new tab. | 71 // Open a same-site link in a new window. |
74 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 72 ShellAddedObserver new_shell_observer; |
75 content::Source<content::WebContentsDelegate>(browser()))); | |
76 bool success = false; | 73 bool success = false; |
77 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 74 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
78 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 75 shell()->web_contents()->GetRenderViewHost(), L"", |
79 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 76 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
80 &success)); | 77 &success)); |
81 EXPECT_TRUE(success); | 78 EXPECT_TRUE(success); |
82 new_tab_observer.Wait(); | 79 Shell* new_shell = new_shell_observer.GetShell(); |
83 | 80 |
84 // Opens in new tab. | 81 // Wait for the navigation in the new window to finish, if it hasn't. |
85 EXPECT_EQ(2, browser()->tab_count()); | 82 WaitForLoadStop(new_shell->web_contents()); |
86 EXPECT_EQ(1, browser()->active_index()); | |
87 | |
88 // Wait for the navigation in the new tab to finish, if it hasn't. | |
89 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | |
90 EXPECT_EQ("/files/navigate_opener.html", | 83 EXPECT_EQ("/files/navigate_opener.html", |
91 chrome::GetActiveWebContents(browser())->GetURL().path()); | 84 new_shell->web_contents()->GetURL().path()); |
92 EXPECT_EQ(1, browser()->active_index()); | |
93 | 85 |
94 // Should have the same SiteInstance. | 86 // Should have the same SiteInstance. |
95 scoped_refptr<SiteInstance> blank_site_instance( | 87 scoped_refptr<SiteInstance> blank_site_instance( |
96 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 88 new_shell->web_contents()->GetSiteInstance()); |
97 EXPECT_EQ(orig_site_instance, blank_site_instance); | 89 EXPECT_EQ(orig_site_instance, blank_site_instance); |
98 | 90 |
99 // We should have access to the opened tab's location. | 91 // We should have access to the opened window's location. |
100 chrome::ActivateTabAt(browser(), 0, true); | |
101 success = false; | 92 success = false; |
102 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 93 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
103 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 94 shell()->web_contents()->GetRenderViewHost(), L"", |
104 L"window.domAutomationController.send(testScriptAccessToWindow());", | 95 L"window.domAutomationController.send(testScriptAccessToWindow());", |
105 &success)); | 96 &success)); |
106 EXPECT_TRUE(success); | 97 EXPECT_TRUE(success); |
107 | 98 |
108 // Now navigate the new tab to a different site. | 99 // Now navigate the new window to a different site. |
109 chrome::ActivateTabAt(browser(), 1, true); | 100 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
110 ui_test_utils::NavigateToURL(browser(), | |
111 https_server.GetURL("files/title1.html")); | |
112 scoped_refptr<SiteInstance> new_site_instance( | 101 scoped_refptr<SiteInstance> new_site_instance( |
113 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 102 new_shell->web_contents()->GetSiteInstance()); |
114 EXPECT_NE(orig_site_instance, new_site_instance); | 103 EXPECT_NE(orig_site_instance, new_site_instance); |
115 | 104 |
116 // We should no longer have script access to the opened tab's location. | 105 // We should no longer have script access to the opened window's location. |
117 chrome::ActivateTabAt(browser(), 0, true); | |
118 success = false; | 106 success = false; |
119 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 107 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
120 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 108 shell()->web_contents()->GetRenderViewHost(), L"", |
121 L"window.domAutomationController.send(testScriptAccessToWindow());", | 109 L"window.domAutomationController.send(testScriptAccessToWindow());", |
122 &success)); | 110 &success)); |
123 EXPECT_FALSE(success); | 111 EXPECT_FALSE(success); |
124 } | 112 } |
125 | 113 |
126 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 114 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
127 // and target=_blank should create a new SiteInstance. | 115 // and target=_blank should create a new SiteInstance. |
128 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 116 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
129 SwapProcessWithRelNoreferrerAndTargetBlank) { | 117 SwapProcessWithRelNoreferrerAndTargetBlank) { |
130 // Start two servers with different sites. | 118 // Start two servers with different sites. |
131 ASSERT_TRUE(test_server()->Start()); | 119 ASSERT_TRUE(test_server()->Start()); |
132 net::TestServer https_server( | 120 net::TestServer https_server( |
133 net::TestServer::TYPE_HTTPS, | 121 net::TestServer::TYPE_HTTPS, |
134 net::TestServer::kLocalhost, | 122 net::TestServer::kLocalhost, |
135 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 123 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
136 ASSERT_TRUE(https_server.Start()); | 124 ASSERT_TRUE(https_server.Start()); |
137 | 125 |
138 // Load a page with links that open in a new window. | 126 // Load a page with links that open in a new window. |
139 std::string replacement_path; | 127 std::string replacement_path; |
140 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 128 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
141 "files/click-noreferrer-links.html", | 129 "files/click-noreferrer-links.html", |
142 https_server.host_port_pair(), | 130 https_server.host_port_pair(), |
143 &replacement_path)); | 131 &replacement_path)); |
144 ui_test_utils::NavigateToURL(browser(), | 132 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
145 test_server()->GetURL(replacement_path)); | |
146 | 133 |
147 // Get the original SiteInstance for later comparison. | 134 // Get the original SiteInstance for later comparison. |
148 scoped_refptr<SiteInstance> orig_site_instance( | 135 scoped_refptr<SiteInstance> orig_site_instance( |
149 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 136 shell()->web_contents()->GetSiteInstance()); |
150 EXPECT_TRUE(orig_site_instance != NULL); | 137 EXPECT_TRUE(orig_site_instance != NULL); |
151 | 138 |
152 // Test clicking a rel=noreferrer + target=blank link. | 139 // Test clicking a rel=noreferrer + target=blank link. |
140 ShellAddedObserver new_shell_observer; | |
153 bool success = false; | 141 bool success = false; |
154 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 142 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
155 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 143 shell()->web_contents()->GetRenderViewHost(), L"", |
156 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", | 144 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
157 &success)); | 145 &success)); |
158 EXPECT_TRUE(success); | 146 EXPECT_TRUE(success); |
159 | 147 |
160 // Wait for the tab to open. | 148 // Wait for the window to open. |
161 if (browser()->tab_count() < 2) | 149 Shell* new_shell = new_shell_observer.GetShell(); |
162 ui_test_utils::WaitForNewTab(browser()); | |
163 | 150 |
164 // Opens in new tab. | 151 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); |
165 EXPECT_EQ(2, browser()->tab_count()); | |
166 EXPECT_EQ(1, browser()->active_index()); | |
167 EXPECT_EQ("/files/title2.html", | |
168 chrome::GetActiveWebContents(browser())->GetURL().path()); | |
169 | 152 |
170 // Wait for the cross-site transition in the new tab to finish. | 153 // Wait for the cross-site transition in the new tab to finish. |
171 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 154 WaitForLoadStop(new_shell->web_contents()); |
172 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 155 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
173 chrome::GetActiveWebContents(browser())); | 156 new_shell->web_contents()); |
174 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 157 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
175 pending_render_view_host()); | 158 pending_render_view_host()); |
176 | 159 |
177 // Should have a new SiteInstance. | 160 // Should have a new SiteInstance. |
178 scoped_refptr<SiteInstance> noref_blank_site_instance( | 161 scoped_refptr<SiteInstance> noref_blank_site_instance( |
179 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 162 new_shell->web_contents()->GetSiteInstance()); |
180 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 163 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
181 } | 164 } |
182 | 165 |
183 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) | 166 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) |
184 // for rel=noreferrer links in new windows, even to same site pages and named | 167 // for rel=noreferrer links in new windows, even to same site pages and named |
185 // targets. | 168 // targets. |
186 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 169 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
187 SwapProcessWithSameSiteRelNoreferrer) { | 170 SwapProcessWithSameSiteRelNoreferrer) { |
188 // Start two servers with different sites. | 171 // Start two servers with different sites. |
189 ASSERT_TRUE(test_server()->Start()); | 172 ASSERT_TRUE(test_server()->Start()); |
190 net::TestServer https_server( | 173 net::TestServer https_server( |
191 net::TestServer::TYPE_HTTPS, | 174 net::TestServer::TYPE_HTTPS, |
192 net::TestServer::kLocalhost, | 175 net::TestServer::kLocalhost, |
193 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 176 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
194 ASSERT_TRUE(https_server.Start()); | 177 ASSERT_TRUE(https_server.Start()); |
195 | 178 |
196 // Load a page with links that open in a new window. | 179 // Load a page with links that open in a new window. |
197 std::string replacement_path; | 180 std::string replacement_path; |
198 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 181 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
199 "files/click-noreferrer-links.html", | 182 "files/click-noreferrer-links.html", |
200 https_server.host_port_pair(), | 183 https_server.host_port_pair(), |
201 &replacement_path)); | 184 &replacement_path)); |
202 ui_test_utils::NavigateToURL(browser(), | 185 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
203 test_server()->GetURL(replacement_path)); | |
204 | 186 |
205 // Get the original SiteInstance for later comparison. | 187 // Get the original SiteInstance for later comparison. |
206 scoped_refptr<SiteInstance> orig_site_instance( | 188 scoped_refptr<SiteInstance> orig_site_instance( |
207 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 189 shell()->web_contents()->GetSiteInstance()); |
208 EXPECT_TRUE(orig_site_instance != NULL); | 190 EXPECT_TRUE(orig_site_instance != NULL); |
209 | 191 |
210 // Test clicking a same-site rel=noreferrer + target=foo link. | 192 // Test clicking a same-site rel=noreferrer + target=foo link. |
193 ShellAddedObserver new_shell_observer; | |
211 bool success = false; | 194 bool success = false; |
212 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 195 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
213 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 196 shell()->web_contents()->GetRenderViewHost(), L"", |
214 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | 197 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
215 &success)); | 198 &success)); |
216 EXPECT_TRUE(success); | 199 EXPECT_TRUE(success); |
217 | 200 |
218 // Wait for the tab to open. | 201 // Wait for the window to open. |
219 if (browser()->tab_count() < 2) | 202 Shell* new_shell = new_shell_observer.GetShell(); |
220 ui_test_utils::WaitForNewTab(browser()); | |
221 | 203 |
222 // Opens in new tab. | 204 // Opens in new window. |
223 EXPECT_EQ(2, browser()->tab_count()); | 205 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); |
224 EXPECT_EQ(1, browser()->active_index()); | |
225 EXPECT_EQ("/files/title2.html", | |
226 chrome::GetActiveWebContents(browser())->GetURL().path()); | |
227 | 206 |
228 // Wait for the cross-site transition in the new tab to finish. | 207 // Wait for the cross-site transition in the new tab to finish. |
229 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 208 WaitForLoadStop(new_shell->web_contents()); |
230 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 209 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
231 chrome::GetActiveWebContents(browser())); | 210 new_shell->web_contents()); |
232 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 211 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
233 pending_render_view_host()); | 212 pending_render_view_host()); |
234 | 213 |
235 // Should have a new SiteInstance (in a new BrowsingInstance). | 214 // Should have a new SiteInstance (in a new BrowsingInstance). |
236 scoped_refptr<SiteInstance> noref_blank_site_instance( | 215 scoped_refptr<SiteInstance> noref_blank_site_instance( |
237 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 216 new_shell->web_contents()->GetSiteInstance()); |
238 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 217 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
239 } | 218 } |
240 | 219 |
241 // Test for crbug.com/24447. Following a cross-site link with just | 220 // Test for crbug.com/24447. Following a cross-site link with just |
242 // target=_blank should not create a new SiteInstance. | 221 // target=_blank should not create a new SiteInstance. |
243 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 222 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
244 DontSwapProcessWithOnlyTargetBlank) { | 223 DontSwapProcessWithOnlyTargetBlank) { |
245 // Start two servers with different sites. | 224 // Start two servers with different sites. |
246 ASSERT_TRUE(test_server()->Start()); | 225 ASSERT_TRUE(test_server()->Start()); |
247 net::TestServer https_server( | 226 net::TestServer https_server( |
248 net::TestServer::TYPE_HTTPS, | 227 net::TestServer::TYPE_HTTPS, |
249 net::TestServer::kLocalhost, | 228 net::TestServer::kLocalhost, |
250 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 229 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
251 ASSERT_TRUE(https_server.Start()); | 230 ASSERT_TRUE(https_server.Start()); |
252 | 231 |
253 // Load a page with links that open in a new window. | 232 // Load a page with links that open in a new window. |
254 std::string replacement_path; | 233 std::string replacement_path; |
255 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 234 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
256 "files/click-noreferrer-links.html", | 235 "files/click-noreferrer-links.html", |
257 https_server.host_port_pair(), | 236 https_server.host_port_pair(), |
258 &replacement_path)); | 237 &replacement_path)); |
259 ui_test_utils::NavigateToURL(browser(), | 238 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
260 test_server()->GetURL(replacement_path)); | |
261 | 239 |
262 // Get the original SiteInstance for later comparison. | 240 // Get the original SiteInstance for later comparison. |
263 scoped_refptr<SiteInstance> orig_site_instance( | 241 scoped_refptr<SiteInstance> orig_site_instance( |
264 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 242 shell()->web_contents()->GetSiteInstance()); |
265 EXPECT_TRUE(orig_site_instance != NULL); | 243 EXPECT_TRUE(orig_site_instance != NULL); |
266 | 244 |
267 // Test clicking a target=blank link. | 245 // Test clicking a target=blank link. |
246 ShellAddedObserver new_shell_observer; | |
268 bool success = false; | 247 bool success = false; |
269 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 248 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
270 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 249 shell()->web_contents()->GetRenderViewHost(), L"", |
271 L"window.domAutomationController.send(clickTargetBlankLink());", | 250 L"window.domAutomationController.send(clickTargetBlankLink());", |
272 &success)); | 251 &success)); |
273 EXPECT_TRUE(success); | 252 EXPECT_TRUE(success); |
274 | 253 |
275 // Wait for the tab to open. | 254 // Wait for the window to open. |
276 if (browser()->tab_count() < 2) | 255 Shell* new_shell = new_shell_observer.GetShell(); |
277 ui_test_utils::WaitForNewTab(browser()); | |
278 | |
279 // Opens in new tab. | |
280 EXPECT_EQ(2, browser()->tab_count()); | |
281 EXPECT_EQ(1, browser()->active_index()); | |
282 | 256 |
283 // Wait for the cross-site transition in the new tab to finish. | 257 // Wait for the cross-site transition in the new tab to finish. |
284 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 258 WaitForLoadStop(new_shell->web_contents()); |
285 EXPECT_EQ("/files/title2.html", | 259 EXPECT_EQ("/files/title2.html", |
286 chrome::GetActiveWebContents(browser())->GetURL().path()); | 260 new_shell->web_contents()->GetURL().path()); |
287 | 261 |
288 // Should have the same SiteInstance. | 262 // Should have the same SiteInstance. |
289 scoped_refptr<SiteInstance> blank_site_instance( | 263 scoped_refptr<SiteInstance> blank_site_instance( |
290 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 264 new_shell->web_contents()->GetSiteInstance()); |
291 EXPECT_EQ(orig_site_instance, blank_site_instance); | 265 EXPECT_EQ(orig_site_instance, blank_site_instance); |
292 } | 266 } |
293 | 267 |
294 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 268 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
295 // and no target=_blank should not create a new SiteInstance. | 269 // and no target=_blank should not create a new SiteInstance. |
296 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 270 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
297 DontSwapProcessWithOnlyRelNoreferrer) { | 271 DontSwapProcessWithOnlyRelNoreferrer) { |
298 // Start two servers with different sites. | 272 // Start two servers with different sites. |
299 ASSERT_TRUE(test_server()->Start()); | 273 ASSERT_TRUE(test_server()->Start()); |
300 net::TestServer https_server( | 274 net::TestServer https_server( |
301 net::TestServer::TYPE_HTTPS, | 275 net::TestServer::TYPE_HTTPS, |
302 net::TestServer::kLocalhost, | 276 net::TestServer::kLocalhost, |
303 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 277 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
304 ASSERT_TRUE(https_server.Start()); | 278 ASSERT_TRUE(https_server.Start()); |
305 | 279 |
306 // Load a page with links that open in a new window. | 280 // Load a page with links that open in a new window. |
307 std::string replacement_path; | 281 std::string replacement_path; |
308 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 282 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
309 "files/click-noreferrer-links.html", | 283 "files/click-noreferrer-links.html", |
310 https_server.host_port_pair(), | 284 https_server.host_port_pair(), |
311 &replacement_path)); | 285 &replacement_path)); |
312 ui_test_utils::NavigateToURL(browser(), | 286 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
313 test_server()->GetURL(replacement_path)); | |
314 | 287 |
315 // Get the original SiteInstance for later comparison. | 288 // Get the original SiteInstance for later comparison. |
316 scoped_refptr<SiteInstance> orig_site_instance( | 289 scoped_refptr<SiteInstance> orig_site_instance( |
317 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 290 shell()->web_contents()->GetSiteInstance()); |
318 EXPECT_TRUE(orig_site_instance != NULL); | 291 EXPECT_TRUE(orig_site_instance != NULL); |
319 | 292 |
320 // Test clicking a rel=noreferrer link. | 293 // Test clicking a rel=noreferrer link. |
321 bool success = false; | 294 bool success = false; |
322 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 295 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
323 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 296 shell()->web_contents()->GetRenderViewHost(), L"", |
324 L"window.domAutomationController.send(clickNoRefLink());", | 297 L"window.domAutomationController.send(clickNoRefLink());", |
325 &success)); | 298 &success)); |
326 EXPECT_TRUE(success); | 299 EXPECT_TRUE(success); |
327 | 300 |
328 // Wait for the cross-site transition in the current tab to finish. | 301 // Wait for the cross-site transition in the current tab to finish. |
329 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 302 WaitForLoadStop(shell()->web_contents()); |
330 | 303 |
331 // Opens in same tab. | 304 // Opens in same window. |
332 EXPECT_EQ(1, browser()->tab_count()); | 305 EXPECT_EQ(1u, Shell::windows().size()); |
333 EXPECT_EQ(0, browser()->active_index()); | 306 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
334 EXPECT_EQ("/files/title2.html", | |
335 chrome::GetActiveWebContents(browser())->GetURL().path()); | |
336 | 307 |
337 // Should have the same SiteInstance. | 308 // Should have the same SiteInstance. |
338 scoped_refptr<SiteInstance> noref_site_instance( | 309 scoped_refptr<SiteInstance> noref_site_instance( |
339 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 310 shell()->web_contents()->GetSiteInstance()); |
340 EXPECT_EQ(orig_site_instance, noref_site_instance); | 311 EXPECT_EQ(orig_site_instance, noref_site_instance); |
341 } | 312 } |
342 | 313 |
343 // Test for crbug.com/116192. Targeted links should still work after the | 314 // Test for crbug.com/116192. Targeted links should still work after the |
344 // named target window has swapped processes. | 315 // named target window has swapped processes. |
345 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 316 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
346 AllowTargetedNavigationsAfterSwap) { | 317 AllowTargetedNavigationsAfterSwap) { |
347 // Start two servers with different sites. | 318 // Start two servers with different sites. |
348 ASSERT_TRUE(test_server()->Start()); | 319 ASSERT_TRUE(test_server()->Start()); |
349 net::TestServer https_server( | 320 net::TestServer https_server( |
350 net::TestServer::TYPE_HTTPS, | 321 net::TestServer::TYPE_HTTPS, |
351 net::TestServer::kLocalhost, | 322 net::TestServer::kLocalhost, |
352 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 323 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
353 ASSERT_TRUE(https_server.Start()); | 324 ASSERT_TRUE(https_server.Start()); |
354 | 325 |
355 // Load a page with links that open in a new window. | 326 // Load a page with links that open in a new window. |
356 std::string replacement_path; | 327 std::string replacement_path; |
357 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 328 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
358 "files/click-noreferrer-links.html", | 329 "files/click-noreferrer-links.html", |
359 https_server.host_port_pair(), | 330 https_server.host_port_pair(), |
360 &replacement_path)); | 331 &replacement_path)); |
361 ui_test_utils::NavigateToURL(browser(), | 332 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
362 test_server()->GetURL(replacement_path)); | |
363 | 333 |
364 // Get the original SiteInstance for later comparison. | 334 // Get the original SiteInstance for later comparison. |
365 scoped_refptr<SiteInstance> orig_site_instance( | 335 scoped_refptr<SiteInstance> orig_site_instance( |
366 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 336 shell()->web_contents()->GetSiteInstance()); |
367 EXPECT_TRUE(orig_site_instance != NULL); | 337 EXPECT_TRUE(orig_site_instance != NULL); |
368 | 338 |
369 // Test clicking a target=foo link. | 339 // Test clicking a target=foo link. |
370 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 340 ShellAddedObserver new_shell_observer; |
371 content::Source<content::WebContentsDelegate>(browser()))); | |
372 bool success = false; | 341 bool success = false; |
373 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 342 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
374 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 343 shell()->web_contents()->GetRenderViewHost(), L"", |
375 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 344 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
376 &success)); | 345 &success)); |
377 EXPECT_TRUE(success); | 346 EXPECT_TRUE(success); |
378 new_tab_observer.Wait(); | 347 Shell* new_shell = new_shell_observer.GetShell(); |
379 | |
380 // Opens in new tab. | |
381 EXPECT_EQ(2, browser()->tab_count()); | |
382 EXPECT_EQ(1, browser()->active_index()); | |
383 | 348 |
384 // Wait for the navigation in the new tab to finish, if it hasn't. | 349 // Wait for the navigation in the new tab to finish, if it hasn't. |
385 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 350 WaitForLoadStop(new_shell->web_contents()); |
386 EXPECT_EQ("/files/navigate_opener.html", | 351 EXPECT_EQ("/files/navigate_opener.html", |
387 chrome::GetActiveWebContents(browser())->GetURL().path()); | 352 new_shell->web_contents()->GetURL().path()); |
388 EXPECT_EQ(1, browser()->active_index()); | |
389 | 353 |
390 // Should have the same SiteInstance. | 354 // Should have the same SiteInstance. |
391 scoped_refptr<SiteInstance> blank_site_instance( | 355 scoped_refptr<SiteInstance> blank_site_instance( |
392 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 356 new_shell->web_contents()->GetSiteInstance()); |
393 EXPECT_EQ(orig_site_instance, blank_site_instance); | 357 EXPECT_EQ(orig_site_instance, blank_site_instance); |
394 | 358 |
395 // Now navigate the new tab to a different site. | 359 // Now navigate the new tab to a different site. |
396 content::WebContents* new_contents = chrome::GetActiveWebContents(browser()); | 360 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
397 ui_test_utils::NavigateToURL(browser(), | |
398 https_server.GetURL("files/title1.html")); | |
399 scoped_refptr<SiteInstance> new_site_instance( | 361 scoped_refptr<SiteInstance> new_site_instance( |
400 new_contents->GetSiteInstance()); | 362 new_shell->web_contents()->GetSiteInstance()); |
401 EXPECT_NE(orig_site_instance, new_site_instance); | 363 EXPECT_NE(orig_site_instance, new_site_instance); |
402 | 364 |
403 // Clicking the original link in the first tab should cause us to swap back. | 365 // Clicking the original link in the first tab should cause us to swap back. |
404 chrome::ActivateTabAt(browser(), 0, true); | 366 WindowedNotificationObserver navigation_observer( |
405 content::WindowedNotificationObserver navigation_observer( | 367 NOTIFICATION_NAV_ENTRY_COMMITTED, |
406 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 368 Source<NavigationController>( |
407 content::Source<content::NavigationController>( | 369 &new_shell->web_contents()->GetController())); |
408 &new_contents->GetController())); | 370 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
409 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 371 shell()->web_contents()->GetRenderViewHost(), L"", |
410 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
411 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 372 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
412 &success)); | 373 &success)); |
413 EXPECT_TRUE(success); | 374 EXPECT_TRUE(success); |
414 navigation_observer.Wait(); | 375 navigation_observer.Wait(); |
415 | 376 |
416 // Should have swapped back and shown the new tab again. | 377 // Should have swapped back and shown the new widnow again. |
Charlie Reis
2012/07/30 16:40:01
nit: window
jam
2012/07/30 17:03:50
Done.
| |
417 EXPECT_EQ(1, browser()->active_index()); | |
418 scoped_refptr<SiteInstance> revisit_site_instance( | 378 scoped_refptr<SiteInstance> revisit_site_instance( |
419 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 379 new_shell->web_contents()->GetSiteInstance()); |
420 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 380 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
421 | 381 |
422 // If it navigates away to another process, the original window should | 382 // If it navigates away to another process, the original window should |
423 // still be able to close it (using a cross-process close message). | 383 // still be able to close it (using a cross-process close message). |
424 ui_test_utils::NavigateToURL(browser(), | 384 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
425 https_server.GetURL("files/title1.html")); | |
426 EXPECT_EQ(new_site_instance, | 385 EXPECT_EQ(new_site_instance, |
427 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 386 new_shell->web_contents()->GetSiteInstance()); |
428 chrome::ActivateTabAt(browser(), 0, true); | 387 WindowedNotificationObserver close_observer( |
429 content::WindowedNotificationObserver close_observer( | 388 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
430 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 389 Source<WebContents>(new_shell->web_contents())); |
431 content::Source<content::WebContents>(new_contents)); | 390 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
432 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 391 shell()->web_contents()->GetRenderViewHost(), L"", |
433 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
434 L"window.domAutomationController.send(testCloseWindow());", | 392 L"window.domAutomationController.send(testCloseWindow());", |
435 &success)); | 393 &success)); |
436 EXPECT_TRUE(success); | 394 EXPECT_TRUE(success); |
437 close_observer.Wait(); | 395 close_observer.Wait(); |
438 } | 396 } |
439 | 397 |
440 // Test for crbug.com/99202. PostMessage calls should still work after | 398 // Test for crbug.com/99202. PostMessage calls should still work after |
441 // navigating the source and target windows to different sites. | 399 // navigating the source and target windows to different sites. |
442 // Specifically: | 400 // Specifically: |
443 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. | 401 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. |
444 // 2) Fail to post a message from "foo" to opener with the wrong target origin. | 402 // 2) Fail to post a message from "foo" to opener with the wrong target origin. |
445 // 3) Post a message from "foo" to opener, which replies back to "foo". | 403 // 3) Post a message from "foo" to opener, which replies back to "foo". |
446 // 4) Post a message from _blank to "foo". | 404 // 4) Post a message from _blank to "foo". |
447 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 405 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
448 SupportCrossProcessPostMessage) { | 406 SupportCrossProcessPostMessage) { |
449 // Start two servers with different sites. | 407 // Start two servers with different sites. |
450 ASSERT_TRUE(test_server()->Start()); | 408 ASSERT_TRUE(test_server()->Start()); |
451 net::TestServer https_server( | 409 net::TestServer https_server( |
452 net::TestServer::TYPE_HTTPS, | 410 net::TestServer::TYPE_HTTPS, |
453 net::TestServer::kLocalhost, | 411 net::TestServer::kLocalhost, |
454 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 412 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
455 ASSERT_TRUE(https_server.Start()); | 413 ASSERT_TRUE(https_server.Start()); |
456 | 414 |
457 // Load a page with links that open in a new window. | 415 // Load a page with links that open in a new window. |
458 std::string replacement_path; | 416 std::string replacement_path; |
459 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 417 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
460 "files/click-noreferrer-links.html", | 418 "files/click-noreferrer-links.html", |
461 https_server.host_port_pair(), | 419 https_server.host_port_pair(), |
462 &replacement_path)); | 420 &replacement_path)); |
463 ui_test_utils::NavigateToURL(browser(), | 421 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
464 test_server()->GetURL(replacement_path)); | |
465 | 422 |
466 // Get the original SiteInstance and RVHM for later comparison. | 423 // Get the original SiteInstance and RVHM for later comparison. |
467 content::WebContents* opener_contents = | 424 WebContents* opener_contents = shell()->web_contents(); |
468 chrome::GetActiveWebContents(browser()); | |
469 scoped_refptr<SiteInstance> orig_site_instance( | 425 scoped_refptr<SiteInstance> orig_site_instance( |
470 opener_contents->GetSiteInstance()); | 426 opener_contents->GetSiteInstance()); |
471 EXPECT_TRUE(orig_site_instance != NULL); | 427 EXPECT_TRUE(orig_site_instance != NULL); |
472 RenderViewHostManager* opener_manager = | 428 RenderViewHostManager* opener_manager = |
473 static_cast<WebContentsImpl*>(opener_contents)-> | 429 static_cast<WebContentsImpl*>(opener_contents)-> |
474 GetRenderManagerForTesting(); | 430 GetRenderManagerForTesting(); |
475 | 431 |
476 // 1) Open two more windows, one named. These initially have openers but no | 432 // 1) Open two more windows, one named. These initially have openers but no |
477 // reference to each other. We will later post a message between them. | 433 // reference to each other. We will later post a message between them. |
478 | 434 |
479 // First, a named target=foo window. | 435 // First, a named target=foo window. |
480 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 436 ShellAddedObserver new_shell_observer; |
481 content::Source<content::WebContentsDelegate>(browser()))); | |
482 bool success = false; | 437 bool success = false; |
483 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 438 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
484 opener_contents->GetRenderViewHost(), L"", | 439 opener_contents->GetRenderViewHost(), L"", |
485 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 440 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
486 &success)); | 441 &success)); |
487 EXPECT_TRUE(success); | 442 EXPECT_TRUE(success); |
488 new_tab_observer.Wait(); | 443 Shell* new_shell = new_shell_observer.GetShell(); |
489 | 444 |
490 // Wait for the navigation in the new tab to finish, if it hasn't, then | 445 // Wait for the navigation in the new window to finish, if it hasn't, then |
491 // send it to post_message.html on a different site. | 446 // send it to post_message.html on a different site. |
492 content::WebContents* foo_contents = chrome::GetActiveWebContents(browser()); | 447 WebContents* foo_contents = new_shell->web_contents(); |
493 content::WaitForLoadStop(foo_contents); | 448 WaitForLoadStop(foo_contents); |
494 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); | 449 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); |
495 EXPECT_EQ(1, browser()->active_index()); | 450 NavigateToURL(new_shell, https_server.GetURL("files/post_message.html")); |
496 ui_test_utils::NavigateToURL(browser(), | |
497 https_server.GetURL("files/post_message.html")); | |
498 scoped_refptr<SiteInstance> foo_site_instance( | 451 scoped_refptr<SiteInstance> foo_site_instance( |
499 foo_contents->GetSiteInstance()); | 452 foo_contents->GetSiteInstance()); |
500 EXPECT_NE(orig_site_instance, foo_site_instance); | 453 EXPECT_NE(orig_site_instance, foo_site_instance); |
501 | 454 |
502 // Second, a target=_blank window. | 455 // Second, a target=_blank window. |
503 chrome::ActivateTabAt(browser(), 0, true); | 456 ShellAddedObserver new_shell_observer2; |
504 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer2(( | 457 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
505 content::Source<content::WebContentsDelegate>(browser()))); | 458 shell()->web_contents()->GetRenderViewHost(), L"", |
506 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | |
507 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
508 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 459 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
509 &success)); | 460 &success)); |
510 EXPECT_TRUE(success); | 461 EXPECT_TRUE(success); |
511 new_tab_observer2.Wait(); | |
512 | 462 |
513 // Wait for the navigation in the new tab to finish, if it hasn't, then | 463 // Wait for the navigation in the new window to finish, if it hasn't, then |
514 // send it to post_message.html on the original site. | 464 // send it to post_message.html on the original site. |
515 content::WebContents* new_contents = chrome::GetActiveWebContents(browser()); | 465 Shell* new_shell2 = new_shell_observer2.GetShell(); |
516 content::WaitForLoadStop(new_contents); | 466 WebContents* new_contents = new_shell2->web_contents(); |
467 WaitForLoadStop(new_contents); | |
517 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); | 468 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); |
518 EXPECT_EQ(1, browser()->active_index()); | 469 NavigateToURL(new_shell2, test_server()->GetURL("files/post_message.html")); |
519 ui_test_utils::NavigateToURL( | |
520 browser(), test_server()->GetURL("files/post_message.html")); | |
521 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); | 470 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); |
522 RenderViewHostManager* new_manager = | 471 RenderViewHostManager* new_manager = |
523 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); | 472 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); |
524 | 473 |
525 // We now have three windows. The opener should have a swapped out RVH | 474 // We now have three windows. The opener should have a swapped out RVH |
526 // for the new SiteInstance, but the _blank window should not. | 475 // for the new SiteInstance, but the _blank window should not. |
527 EXPECT_EQ(3, browser()->tab_count()); | 476 EXPECT_EQ(3u, Shell::windows().size()); |
528 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 477 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
529 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 478 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
530 | 479 |
531 // 2) Fail to post a message from the foo window to the opener if the target | 480 // 2) Fail to post a message from the foo window to the opener if the target |
532 // origin is wrong. We won't see an error, but we can check for the right | 481 // origin is wrong. We won't see an error, but we can check for the right |
533 // number of received messages below. | 482 // number of received messages below. |
534 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 483 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
535 foo_contents->GetRenderViewHost(), L"", | 484 foo_contents->GetRenderViewHost(), L"", |
536 L"window.domAutomationController.send(postToOpener('msg'," | 485 L"window.domAutomationController.send(postToOpener('msg'," |
537 L"'http://google.com'));", | 486 L"'http://google.com'));", |
538 &success)); | 487 &success)); |
539 EXPECT_TRUE(success); | 488 EXPECT_TRUE(success); |
540 | 489 |
541 // 3) Post a message from the foo window to the opener. The opener will | 490 // 3) Post a message from the foo window to the opener. The opener will |
542 // reply, causing the foo window to update its own title. | 491 // reply, causing the foo window to update its own title. |
543 content::WindowedNotificationObserver title_observer( | 492 WindowedNotificationObserver title_observer( |
544 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 493 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
545 content::Source<content::WebContents>(foo_contents)); | 494 Source<WebContents>(foo_contents)); |
546 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 495 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
547 foo_contents->GetRenderViewHost(), L"", | 496 foo_contents->GetRenderViewHost(), L"", |
548 L"window.domAutomationController.send(postToOpener('msg','*'));", | 497 L"window.domAutomationController.send(postToOpener('msg','*'));", |
549 &success)); | 498 &success)); |
550 EXPECT_TRUE(success); | 499 EXPECT_TRUE(success); |
551 title_observer.Wait(); | 500 title_observer.Wait(); |
552 | 501 |
553 // We should have received only 1 message in the opener and "foo" tabs, | 502 // We should have received only 1 message in the opener and "foo" tabs, |
554 // and updated the title. | 503 // and updated the title. |
555 int opener_received_messages = 0; | 504 int opener_received_messages = 0; |
556 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractInt( | 505 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( |
557 opener_contents->GetRenderViewHost(), L"", | 506 opener_contents->GetRenderViewHost(), L"", |
558 L"window.domAutomationController.send(window.receivedMessages);", | 507 L"window.domAutomationController.send(window.receivedMessages);", |
559 &opener_received_messages)); | 508 &opener_received_messages)); |
560 int foo_received_messages = 0; | 509 int foo_received_messages = 0; |
561 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractInt( | 510 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( |
562 foo_contents->GetRenderViewHost(), L"", | 511 foo_contents->GetRenderViewHost(), L"", |
563 L"window.domAutomationController.send(window.receivedMessages);", | 512 L"window.domAutomationController.send(window.receivedMessages);", |
564 &foo_received_messages)); | 513 &foo_received_messages)); |
565 EXPECT_EQ(1, foo_received_messages); | 514 EXPECT_EQ(1, foo_received_messages); |
566 EXPECT_EQ(1, opener_received_messages); | 515 EXPECT_EQ(1, opener_received_messages); |
567 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); | 516 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); |
568 | 517 |
569 // 4) Now post a message from the _blank window to the foo window. The | 518 // 4) Now post a message from the _blank window to the foo window. The |
570 // foo window will update its title and will not reply. | 519 // foo window will update its title and will not reply. |
571 content::WindowedNotificationObserver title_observer2( | 520 WindowedNotificationObserver title_observer2( |
572 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 521 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
573 content::Source<content::WebContents>(foo_contents)); | 522 Source<WebContents>(foo_contents)); |
574 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 523 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
575 new_contents->GetRenderViewHost(), L"", | 524 new_contents->GetRenderViewHost(), L"", |
576 L"window.domAutomationController.send(postToFoo('msg2'));", | 525 L"window.domAutomationController.send(postToFoo('msg2'));", |
577 &success)); | 526 &success)); |
578 EXPECT_TRUE(success); | 527 EXPECT_TRUE(success); |
579 title_observer2.Wait(); | 528 title_observer2.Wait(); |
580 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); | 529 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); |
581 | 530 |
582 // This postMessage should have created a swapped out RVH for the new | 531 // This postMessage should have created a swapped out RVH for the new |
583 // SiteInstance in the target=_blank window. | 532 // SiteInstance in the target=_blank window. |
584 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 533 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
585 } | 534 } |
586 | 535 |
587 // Test for crbug.com/116192. Navigations to a window's opener should | 536 // Test for crbug.com/116192. Navigations to a window's opener should |
588 // still work after a process swap. | 537 // still work after a process swap. |
589 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 538 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
590 AllowTargetedNavigationsInOpenerAfterSwap) { | 539 AllowTargetedNavigationsInOpenerAfterSwap) { |
591 // Start two servers with different sites. | 540 // Start two servers with different sites. |
592 ASSERT_TRUE(test_server()->Start()); | 541 ASSERT_TRUE(test_server()->Start()); |
593 net::TestServer https_server( | 542 net::TestServer https_server( |
594 net::TestServer::TYPE_HTTPS, | 543 net::TestServer::TYPE_HTTPS, |
595 net::TestServer::kLocalhost, | 544 net::TestServer::kLocalhost, |
596 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 545 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
597 ASSERT_TRUE(https_server.Start()); | 546 ASSERT_TRUE(https_server.Start()); |
598 | 547 |
599 // Load a page with links that open in a new window. | 548 // Load a page with links that open in a new window. |
600 std::string replacement_path; | 549 std::string replacement_path; |
601 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 550 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
602 "files/click-noreferrer-links.html", | 551 "files/click-noreferrer-links.html", |
603 https_server.host_port_pair(), | 552 https_server.host_port_pair(), |
604 &replacement_path)); | 553 &replacement_path)); |
605 ui_test_utils::NavigateToURL(browser(), | 554 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
606 test_server()->GetURL(replacement_path)); | |
607 | 555 |
608 // Get the original tab and SiteInstance for later comparison. | 556 // Get the original tab and SiteInstance for later comparison. |
609 content::WebContents* orig_contents = chrome::GetActiveWebContents(browser()); | 557 WebContents* orig_contents = shell()->web_contents(); |
610 scoped_refptr<SiteInstance> orig_site_instance( | 558 scoped_refptr<SiteInstance> orig_site_instance( |
611 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 559 orig_contents->GetSiteInstance()); |
612 EXPECT_TRUE(orig_site_instance != NULL); | 560 EXPECT_TRUE(orig_site_instance != NULL); |
613 | 561 |
614 // Test clicking a target=foo link. | 562 // Test clicking a target=foo link. |
615 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 563 ShellAddedObserver new_shell_observer; |
616 content::Source<content::WebContentsDelegate>(browser()))); | |
617 bool success = false; | 564 bool success = false; |
618 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 565 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
619 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 566 orig_contents->GetRenderViewHost(), L"", |
620 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 567 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
621 &success)); | 568 &success)); |
622 EXPECT_TRUE(success); | 569 EXPECT_TRUE(success); |
623 new_tab_observer.Wait(); | 570 Shell* new_shell = new_shell_observer.GetShell(); |
624 | 571 |
625 // Opens in new tab. | 572 // Wait for the navigation in the new window to finish, if it hasn't. |
626 EXPECT_EQ(2, browser()->tab_count()); | 573 WaitForLoadStop(new_shell->web_contents()); |
627 EXPECT_EQ(1, browser()->active_index()); | |
628 | |
629 // Wait for the navigation in the new tab to finish, if it hasn't. | |
630 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | |
631 EXPECT_EQ("/files/navigate_opener.html", | 574 EXPECT_EQ("/files/navigate_opener.html", |
632 chrome::GetActiveWebContents(browser())->GetURL().path()); | 575 new_shell->web_contents()->GetURL().path()); |
633 EXPECT_EQ(1, browser()->active_index()); | |
634 | 576 |
635 // Should have the same SiteInstance. | 577 // Should have the same SiteInstance. |
636 scoped_refptr<SiteInstance> blank_site_instance( | 578 scoped_refptr<SiteInstance> blank_site_instance( |
637 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 579 new_shell->web_contents()->GetSiteInstance()); |
638 EXPECT_EQ(orig_site_instance, blank_site_instance); | 580 EXPECT_EQ(orig_site_instance, blank_site_instance); |
639 | 581 |
640 // Now navigate the original (opener) tab to a different site. | 582 // Now navigate the original (opener) tab to a different site. |
641 chrome::ActivateTabAt(browser(), 0, true); | 583 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
642 ui_test_utils::NavigateToURL(browser(), | |
643 https_server.GetURL("files/title1.html")); | |
644 scoped_refptr<SiteInstance> new_site_instance( | 584 scoped_refptr<SiteInstance> new_site_instance( |
645 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 585 shell()->web_contents()->GetSiteInstance()); |
646 EXPECT_NE(orig_site_instance, new_site_instance); | 586 EXPECT_NE(orig_site_instance, new_site_instance); |
647 | 587 |
648 // The opened tab should be able to navigate the opener back to its process. | 588 // The opened tab should be able to navigate the opener back to its process. |
649 chrome::ActivateTabAt(browser(), 1, true); | 589 WindowedNotificationObserver navigation_observer( |
650 content::WindowedNotificationObserver navigation_observer( | 590 NOTIFICATION_NAV_ENTRY_COMMITTED, |
651 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 591 Source<NavigationController>( |
652 content::Source<content::NavigationController>( | 592 &orig_contents->GetController())); |
653 &orig_contents->GetController())); | 593 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
654 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 594 new_shell->web_contents()->GetRenderViewHost(), L"", |
655 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | |
656 L"window.domAutomationController.send(navigateOpener());", | 595 L"window.domAutomationController.send(navigateOpener());", |
657 &success)); | 596 &success)); |
658 EXPECT_TRUE(success); | 597 EXPECT_TRUE(success); |
659 navigation_observer.Wait(); | 598 navigation_observer.Wait(); |
660 | 599 |
661 // Active tab should not have changed. | |
662 EXPECT_EQ(1, browser()->active_index()); | |
663 | |
664 // Should have swapped back into this process. | 600 // Should have swapped back into this process. |
665 chrome::ActivateTabAt(browser(), 0, true); | |
666 scoped_refptr<SiteInstance> revisit_site_instance( | 601 scoped_refptr<SiteInstance> revisit_site_instance( |
667 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 602 shell()->web_contents()->GetSiteInstance()); |
668 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 603 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
669 } | 604 } |
670 | 605 |
671 // Test that opening a new window in the same SiteInstance and then navigating | 606 // Test that opening a new window in the same SiteInstance and then navigating |
672 // both windows to a different SiteInstance allows the first process to exit. | 607 // both windows to a different SiteInstance allows the first process to exit. |
673 // See http://crbug.com/126333. | 608 // See http://crbug.com/126333. |
674 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 609 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
675 ProcessExitWithSwappedOutViews) { | 610 ProcessExitWithSwappedOutViews) { |
676 // Start two servers with different sites. | 611 // Start two servers with different sites. |
677 ASSERT_TRUE(test_server()->Start()); | 612 ASSERT_TRUE(test_server()->Start()); |
678 net::TestServer https_server( | 613 net::TestServer https_server( |
679 net::TestServer::TYPE_HTTPS, | 614 net::TestServer::TYPE_HTTPS, |
680 net::TestServer::kLocalhost, | 615 net::TestServer::kLocalhost, |
681 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 616 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
682 ASSERT_TRUE(https_server.Start()); | 617 ASSERT_TRUE(https_server.Start()); |
683 | 618 |
684 // Load a page with links that open in a new window. | 619 // Load a page with links that open in a new window. |
685 std::string replacement_path; | 620 std::string replacement_path; |
686 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 621 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
687 "files/click-noreferrer-links.html", | 622 "files/click-noreferrer-links.html", |
688 https_server.host_port_pair(), | 623 https_server.host_port_pair(), |
689 &replacement_path)); | 624 &replacement_path)); |
690 ui_test_utils::NavigateToURL(browser(), | 625 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
691 test_server()->GetURL(replacement_path)); | |
692 | 626 |
693 // Get the original SiteInstance for later comparison. | 627 // Get the original SiteInstance for later comparison. |
694 scoped_refptr<SiteInstance> orig_site_instance( | 628 scoped_refptr<SiteInstance> orig_site_instance( |
695 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 629 shell()->web_contents()->GetSiteInstance()); |
696 EXPECT_TRUE(orig_site_instance != NULL); | 630 EXPECT_TRUE(orig_site_instance != NULL); |
697 | 631 |
698 // Test clicking a target=foo link. | 632 // Test clicking a target=foo link. |
699 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 633 ShellAddedObserver new_shell_observer; |
700 content::Source<content::WebContentsDelegate>(browser()))); | |
701 bool success = false; | 634 bool success = false; |
702 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 635 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
703 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 636 shell()->web_contents()->GetRenderViewHost(), L"", |
704 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 637 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
705 &success)); | 638 &success)); |
706 EXPECT_TRUE(success); | 639 EXPECT_TRUE(success); |
707 new_tab_observer.Wait(); | 640 Shell* new_shell = new_shell_observer.GetShell(); |
708 | 641 |
709 // Opens in new tab. | 642 // Wait for the navigation in the new window to finish, if it hasn't. |
710 EXPECT_EQ(2, browser()->tab_count()); | 643 WaitForLoadStop(new_shell->web_contents()); |
711 EXPECT_EQ(1, browser()->active_index()); | |
712 | |
713 // Wait for the navigation in the new tab to finish, if it hasn't. | |
714 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | |
715 EXPECT_EQ("/files/navigate_opener.html", | 644 EXPECT_EQ("/files/navigate_opener.html", |
716 chrome::GetActiveWebContents(browser())->GetURL().path()); | 645 new_shell->web_contents()->GetURL().path()); |
717 EXPECT_EQ(1, browser()->active_index()); | |
718 | 646 |
719 // Should have the same SiteInstance. | 647 // Should have the same SiteInstance. |
720 scoped_refptr<SiteInstance> opened_site_instance( | 648 scoped_refptr<SiteInstance> opened_site_instance( |
721 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 649 new_shell->web_contents()->GetSiteInstance()); |
722 EXPECT_EQ(orig_site_instance, opened_site_instance); | 650 EXPECT_EQ(orig_site_instance, opened_site_instance); |
723 | 651 |
724 // Now navigate the opened tab to a different site. | 652 // Now navigate the opened window to a different site. |
725 ui_test_utils::NavigateToURL(browser(), | 653 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
726 https_server.GetURL("files/title1.html")); | |
727 scoped_refptr<SiteInstance> new_site_instance( | 654 scoped_refptr<SiteInstance> new_site_instance( |
728 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 655 new_shell->web_contents()->GetSiteInstance()); |
729 EXPECT_NE(orig_site_instance, new_site_instance); | 656 EXPECT_NE(orig_site_instance, new_site_instance); |
730 | 657 |
731 // The original process should still be alive, since it is still used in the | 658 // The original process should still be alive, since it is still used in the |
732 // first tab. | 659 // first window. |
733 content::RenderProcessHost* orig_process = orig_site_instance->GetProcess(); | 660 RenderProcessHost* orig_process = orig_site_instance->GetProcess(); |
734 EXPECT_TRUE(orig_process->HasConnection()); | 661 EXPECT_TRUE(orig_process->HasConnection()); |
735 | 662 |
736 // Navigate the first tab to a different site as well. The original process | 663 // Navigate the first window to a different site as well. The original |
737 // should exit, since all of its views are now swapped out. | 664 // process should exit, since all of its views are now swapped out. |
738 chrome::ActivateTabAt(browser(), 0, true); | 665 WindowedNotificationObserver exit_observer( |
739 content::WindowedNotificationObserver exit_observer( | 666 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
740 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 667 Source<RenderProcessHost>(orig_process)); |
741 content::Source<content::RenderProcessHost>(orig_process)); | 668 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
742 ui_test_utils::NavigateToURL(browser(), | |
743 https_server.GetURL("files/title1.html")); | |
744 exit_observer.Wait(); | 669 exit_observer.Wait(); |
745 scoped_refptr<SiteInstance> new_site_instance2( | 670 scoped_refptr<SiteInstance> new_site_instance2( |
746 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 671 shell()->web_contents()->GetSiteInstance()); |
747 EXPECT_EQ(new_site_instance, new_site_instance2); | 672 EXPECT_EQ(new_site_instance, new_site_instance2); |
748 } | 673 } |
749 | 674 |
750 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 675 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
751 // error should not make us ignore future renderer-initiated navigations. | 676 // error should not make us ignore future renderer-initiated navigations. |
752 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { | 677 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { |
753 // Start two servers with different sites. | 678 // Start two servers with different sites. |
754 ASSERT_TRUE(test_server()->Start()); | 679 ASSERT_TRUE(test_server()->Start()); |
755 net::TestServer https_server( | 680 net::TestServer https_server( |
756 net::TestServer::TYPE_HTTPS, | 681 net::TestServer::TYPE_HTTPS, |
757 net::TestServer::kLocalhost, | 682 net::TestServer::kLocalhost, |
758 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 683 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
759 ASSERT_TRUE(https_server.Start()); | 684 ASSERT_TRUE(https_server.Start()); |
760 | 685 |
761 // Load a page with links that open in a new window. | 686 // Load a page with links that open in a new window. |
762 // The links will point to the HTTPS server. | 687 // The links will point to the HTTPS server. |
763 std::string replacement_path; | 688 std::string replacement_path; |
764 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 689 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
765 "files/click-noreferrer-links.html", | 690 "files/click-noreferrer-links.html", |
766 https_server.host_port_pair(), | 691 https_server.host_port_pair(), |
767 &replacement_path)); | 692 &replacement_path)); |
768 ui_test_utils::NavigateToURL(browser(), | 693 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
769 test_server()->GetURL(replacement_path)); | |
770 | 694 |
771 // Get the original SiteInstance for later comparison. | 695 // Get the original SiteInstance for later comparison. |
772 scoped_refptr<SiteInstance> orig_site_instance( | 696 scoped_refptr<SiteInstance> orig_site_instance( |
773 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 697 shell()->web_contents()->GetSiteInstance()); |
774 EXPECT_TRUE(orig_site_instance != NULL); | 698 EXPECT_TRUE(orig_site_instance != NULL); |
775 | 699 |
776 // Load a cross-site page that fails with a 204 error. | 700 // Load a cross-site page that fails with a 204 error. |
777 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); | 701 NavigateToURL(shell(), https_server.GetURL("nocontent")); |
778 | 702 |
779 // We should still be looking at the normal page. The typed URL will | 703 // We should still be looking at the normal page. The typed URL will |
780 // still be visible until the user clears it manually, but the last | 704 // still be visible until the user clears it manually, but the last |
781 // committed URL will be the previous page. | 705 // committed URL will be the previous page. |
782 scoped_refptr<SiteInstance> post_nav_site_instance( | 706 scoped_refptr<SiteInstance> post_nav_site_instance( |
783 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 707 shell()->web_contents()->GetSiteInstance()); |
784 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 708 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
785 EXPECT_EQ("/nocontent", | 709 EXPECT_EQ("/nocontent", shell()->web_contents()->GetURL().path()); |
786 chrome::GetActiveWebContents(browser())->GetURL().path()); | |
787 EXPECT_EQ("/files/click-noreferrer-links.html", | 710 EXPECT_EQ("/files/click-noreferrer-links.html", |
788 chrome::GetActiveWebContents(browser())->GetController(). | 711 shell()->web_contents()->GetController(). |
789 GetLastCommittedEntry()->GetVirtualURL().path()); | 712 GetLastCommittedEntry()->GetVirtualURL().path()); |
790 | 713 |
791 // Renderer-initiated navigations should work. | 714 // Renderer-initiated navigations should work. |
792 bool success = false; | 715 bool success = false; |
793 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 716 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
794 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 717 shell()->web_contents()->GetRenderViewHost(), L"", |
795 L"window.domAutomationController.send(clickNoRefLink());", | 718 L"window.domAutomationController.send(clickNoRefLink());", |
796 &success)); | 719 &success)); |
797 EXPECT_TRUE(success); | 720 EXPECT_TRUE(success); |
798 | 721 |
799 // Wait for the cross-site transition in the current tab to finish. | 722 // Wait for the cross-site transition in the current tab to finish. |
800 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 723 WaitForLoadStop(shell()->web_contents()); |
801 | 724 |
802 // Opens in same tab. | 725 // Opens in same tab. |
803 EXPECT_EQ(1, browser()->tab_count()); | 726 EXPECT_EQ(1u, Shell::windows().size()); |
804 EXPECT_EQ(0, browser()->active_index()); | 727 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
805 EXPECT_EQ("/files/title2.html", | |
806 chrome::GetActiveWebContents(browser())->GetURL().path()); | |
807 | 728 |
808 // Should have the same SiteInstance. | 729 // Should have the same SiteInstance. |
809 scoped_refptr<SiteInstance> noref_site_instance( | 730 scoped_refptr<SiteInstance> noref_site_instance( |
810 chrome::GetActiveWebContents(browser())->GetSiteInstance()); | 731 shell()->web_contents()->GetSiteInstance()); |
811 EXPECT_EQ(orig_site_instance, noref_site_instance); | 732 EXPECT_EQ(orig_site_instance, noref_site_instance); |
812 } | 733 } |
813 | 734 |
814 // Test for http://crbug.com/93427. Ensure that cross-site navigations | 735 // Test for http://crbug.com/93427. Ensure that cross-site navigations |
815 // do not cause back/forward navigations to be considered stale by the | 736 // do not cause back/forward navigations to be considered stale by the |
816 // renderer. | 737 // renderer. |
817 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { | 738 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { |
739 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | |
740 | |
818 // Start two servers with different sites. | 741 // Start two servers with different sites. |
819 ASSERT_TRUE(test_server()->Start()); | 742 ASSERT_TRUE(test_server()->Start()); |
820 net::TestServer https_server( | 743 net::TestServer https_server( |
821 net::TestServer::TYPE_HTTPS, | 744 net::TestServer::TYPE_HTTPS, |
822 net::TestServer::kLocalhost, | 745 net::TestServer::kLocalhost, |
823 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 746 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
824 ASSERT_TRUE(https_server.Start()); | 747 ASSERT_TRUE(https_server.Start()); |
825 | 748 |
826 // Visit a page on first site. | 749 // Visit a page on first site. |
827 std::string replacement_path_a1; | 750 std::string replacement_path_a1; |
828 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 751 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
829 "files/title1.html", | 752 "files/title1.html", |
830 test_server()->host_port_pair(), | 753 test_server()->host_port_pair(), |
831 &replacement_path_a1)); | 754 &replacement_path_a1)); |
832 ui_test_utils::NavigateToURL(browser(), | 755 NavigateToURL(shell(), test_server()->GetURL(replacement_path_a1)); |
833 test_server()->GetURL(replacement_path_a1)); | |
834 | 756 |
835 // Visit three pages on second site. | 757 // Visit three pages on second site. |
836 std::string replacement_path_b1; | 758 std::string replacement_path_b1; |
837 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 759 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
838 "files/title1.html", | 760 "files/title1.html", |
839 https_server.host_port_pair(), | 761 https_server.host_port_pair(), |
840 &replacement_path_b1)); | 762 &replacement_path_b1)); |
841 ui_test_utils::NavigateToURL(browser(), | 763 NavigateToURL(shell(), https_server.GetURL(replacement_path_b1)); |
842 https_server.GetURL(replacement_path_b1)); | |
843 std::string replacement_path_b2; | 764 std::string replacement_path_b2; |
844 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 765 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
845 "files/title2.html", | 766 "files/title2.html", |
846 https_server.host_port_pair(), | 767 https_server.host_port_pair(), |
847 &replacement_path_b2)); | 768 &replacement_path_b2)); |
848 ui_test_utils::NavigateToURL(browser(), | 769 NavigateToURL(shell(), https_server.GetURL(replacement_path_b2)); |
849 https_server.GetURL(replacement_path_b2)); | |
850 std::string replacement_path_b3; | 770 std::string replacement_path_b3; |
851 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 771 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
852 "files/title3.html", | 772 "files/title3.html", |
853 https_server.host_port_pair(), | 773 https_server.host_port_pair(), |
854 &replacement_path_b3)); | 774 &replacement_path_b3)); |
855 ui_test_utils::NavigateToURL(browser(), | 775 NavigateToURL(shell(), https_server.GetURL(replacement_path_b3)); |
856 https_server.GetURL(replacement_path_b3)); | |
857 | 776 |
858 // History is now [blank, A1, B1, B2, *B3]. | 777 // History is now [blank, A1, B1, B2, *B3]. |
859 content::WebContents* contents = chrome::GetActiveWebContents(browser()); | 778 WebContents* contents = shell()->web_contents(); |
860 EXPECT_EQ(5, contents->GetController().GetEntryCount()); | 779 EXPECT_EQ(5, contents->GetController().GetEntryCount()); |
861 | 780 |
862 // Open another tab in same process to keep this process alive. | 781 // Open another window in same process to keep this process alive. |
863 ui_test_utils::NavigateToURLWithDisposition( | 782 Shell* new_shell = CreateBrowser(); |
864 browser(), https_server.GetURL(replacement_path_b1), | 783 NavigateToURL(new_shell, https_server.GetURL(replacement_path_b1)); |
865 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
866 | 784 |
867 // Go back three times to first site. | 785 // Go back three times to first site. |
868 { | 786 { |
869 content::WindowedNotificationObserver back_nav_load_observer( | 787 WindowedNotificationObserver back_nav_load_observer( |
870 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 788 NOTIFICATION_NAV_ENTRY_COMMITTED, |
871 content::Source<content::NavigationController>( | 789 Source<NavigationController>( |
872 &contents->GetController())); | 790 &contents->GetController())); |
873 chrome::GoBack(browser(), CURRENT_TAB); | 791 shell()->web_contents()->GetController().GoBack(); |
874 back_nav_load_observer.Wait(); | 792 back_nav_load_observer.Wait(); |
875 } | 793 } |
876 { | 794 { |
877 content::WindowedNotificationObserver back_nav_load_observer( | 795 WindowedNotificationObserver back_nav_load_observer( |
878 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 796 NOTIFICATION_NAV_ENTRY_COMMITTED, |
879 content::Source<content::NavigationController>( | 797 Source<NavigationController>( |
880 &contents->GetController())); | 798 &contents->GetController())); |
881 chrome::GoBack(browser(), CURRENT_TAB); | 799 shell()->web_contents()->GetController().GoBack(); |
882 back_nav_load_observer.Wait(); | 800 back_nav_load_observer.Wait(); |
883 } | 801 } |
884 { | 802 { |
885 content::WindowedNotificationObserver back_nav_load_observer( | 803 WindowedNotificationObserver back_nav_load_observer( |
886 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 804 NOTIFICATION_NAV_ENTRY_COMMITTED, |
887 content::Source<content::NavigationController>( | 805 Source<NavigationController>(&contents->GetController())); |
888 &contents->GetController())); | 806 shell()->web_contents()->GetController().GoBack(); |
889 chrome::GoBack(browser(), CURRENT_TAB); | |
890 back_nav_load_observer.Wait(); | 807 back_nav_load_observer.Wait(); |
891 } | 808 } |
892 | 809 |
893 // Now go forward twice to B2. Shouldn't be left spinning. | 810 // Now go forward twice to B2. Shouldn't be left spinning. |
894 { | 811 { |
895 content::WindowedNotificationObserver forward_nav_load_observer( | 812 WindowedNotificationObserver forward_nav_load_observer( |
896 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 813 NOTIFICATION_NAV_ENTRY_COMMITTED, |
897 content::Source<content::NavigationController>( | 814 Source<NavigationController>(&contents->GetController())); |
898 &contents->GetController())); | 815 shell()->web_contents()->GetController().GoForward(); |
899 chrome::GoForward(browser(), CURRENT_TAB); | |
900 forward_nav_load_observer.Wait(); | 816 forward_nav_load_observer.Wait(); |
901 } | 817 } |
902 { | 818 { |
903 content::WindowedNotificationObserver forward_nav_load_observer( | 819 WindowedNotificationObserver forward_nav_load_observer( |
904 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 820 NOTIFICATION_NAV_ENTRY_COMMITTED, |
905 content::Source<content::NavigationController>( | 821 Source<NavigationController>(&contents->GetController())); |
906 &contents->GetController())); | 822 shell()->web_contents()->GetController().GoForward(); |
907 chrome::GoForward(browser(), CURRENT_TAB); | |
908 forward_nav_load_observer.Wait(); | 823 forward_nav_load_observer.Wait(); |
909 } | 824 } |
910 | 825 |
911 // Go back twice to first site. | 826 // Go back twice to first site. |
912 { | 827 { |
913 content::WindowedNotificationObserver back_nav_load_observer( | 828 WindowedNotificationObserver back_nav_load_observer( |
914 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 829 NOTIFICATION_NAV_ENTRY_COMMITTED, |
915 content::Source<content::NavigationController>( | 830 Source<NavigationController>(&contents->GetController())); |
916 &contents->GetController())); | 831 shell()->web_contents()->GetController().GoBack(); |
917 chrome::GoBack(browser(), CURRENT_TAB); | |
918 back_nav_load_observer.Wait(); | 832 back_nav_load_observer.Wait(); |
919 } | 833 } |
920 { | 834 { |
921 content::WindowedNotificationObserver back_nav_load_observer( | 835 WindowedNotificationObserver back_nav_load_observer( |
922 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 836 NOTIFICATION_NAV_ENTRY_COMMITTED, |
923 content::Source<content::NavigationController>( | 837 Source<NavigationController>(&contents->GetController())); |
924 &contents->GetController())); | 838 shell()->web_contents()->GetController().GoBack(); |
925 chrome::GoBack(browser(), CURRENT_TAB); | |
926 back_nav_load_observer.Wait(); | 839 back_nav_load_observer.Wait(); |
927 } | 840 } |
928 | 841 |
929 // Now go forward directly to B3. Shouldn't be left spinning. | 842 // Now go forward directly to B3. Shouldn't be left spinning. |
930 { | 843 { |
931 content::WindowedNotificationObserver forward_nav_load_observer( | 844 WindowedNotificationObserver forward_nav_load_observer( |
932 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 845 NOTIFICATION_NAV_ENTRY_COMMITTED, |
933 content::Source<content::NavigationController>( | 846 Source<NavigationController>(&contents->GetController())); |
934 &contents->GetController())); | 847 shell()->web_contents()->GetController().GoToIndex(4); |
935 contents->GetController().GoToIndex(4); | |
936 forward_nav_load_observer.Wait(); | 848 forward_nav_load_observer.Wait(); |
937 } | 849 } |
938 } | 850 } |
939 | 851 |
940 // Test for http://crbug.com/130016. | 852 // Test for http://crbug.com/130016. |
941 // Swapping out a render view should update its visiblity state. | 853 // Swapping out a render view should update its visiblity state. |
942 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 854 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
943 SwappedOutViewHasCorrectVisibilityState) { | 855 SwappedOutViewHasCorrectVisibilityState) { |
944 // Start two servers with different sites. | 856 // Start two servers with different sites. |
945 ASSERT_TRUE(test_server()->Start()); | 857 ASSERT_TRUE(test_server()->Start()); |
946 net::TestServer https_server( | 858 net::TestServer https_server( |
947 net::TestServer::TYPE_HTTPS, | 859 net::TestServer::TYPE_HTTPS, |
948 net::TestServer::kLocalhost, | 860 net::TestServer::kLocalhost, |
949 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 861 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
950 ASSERT_TRUE(https_server.Start()); | 862 ASSERT_TRUE(https_server.Start()); |
951 | 863 |
952 // Load a page with links that open in a new window. | 864 // Load a page with links that open in a new window. |
953 std::string replacement_path; | 865 std::string replacement_path; |
954 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 866 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
955 "files/click-noreferrer-links.html", | 867 "files/click-noreferrer-links.html", |
956 https_server.host_port_pair(), | 868 https_server.host_port_pair(), |
957 &replacement_path)); | 869 &replacement_path)); |
958 ui_test_utils::NavigateToURL(browser(), | 870 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
959 test_server()->GetURL(replacement_path)); | |
960 | 871 |
961 // Open a same-site link in a new tab. | 872 // Open a same-site link in a new widnow. |
962 ui_test_utils::WindowedTabAddedNotificationObserver new_tab_observer(( | 873 ShellAddedObserver new_shell_observer; |
963 content::Source<content::WebContentsDelegate>(browser()))); | |
964 bool success = false; | 874 bool success = false; |
965 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 875 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
966 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 876 shell()->web_contents()->GetRenderViewHost(), L"", |
967 L"window.domAutomationController.send(clickSameSiteTargetedLink());", | 877 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
968 &success)); | 878 &success)); |
969 EXPECT_TRUE(success); | 879 EXPECT_TRUE(success); |
970 new_tab_observer.Wait(); | 880 Shell* new_shell = new_shell_observer.GetShell(); |
971 | |
972 // Opens in new tab. | |
973 EXPECT_EQ(2, browser()->tab_count()); | |
974 EXPECT_EQ(1, browser()->active_index()); | |
975 | 881 |
976 // Wait for the navigation in the new tab to finish, if it hasn't. | 882 // Wait for the navigation in the new tab to finish, if it hasn't. |
977 content::WaitForLoadStop(chrome::GetActiveWebContents(browser())); | 883 WaitForLoadStop(new_shell->web_contents()); |
978 EXPECT_EQ("/files/navigate_opener.html", | 884 EXPECT_EQ("/files/navigate_opener.html", |
979 chrome::GetActiveWebContents(browser())->GetURL().path()); | 885 new_shell->web_contents()->GetURL().path()); |
980 EXPECT_EQ(1, browser()->active_index()); | |
981 | 886 |
982 RenderViewHost* rvh = | 887 RenderViewHost* rvh = new_shell->web_contents()->GetRenderViewHost(); |
983 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 888 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
984 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | |
985 rvh, L"", | 889 rvh, L"", |
986 L"window.domAutomationController.send(" | 890 L"window.domAutomationController.send(" |
987 L"document.webkitVisibilityState == 'visible');", | 891 L"document.webkitVisibilityState == 'visible');", |
988 &success)); | 892 &success)); |
989 EXPECT_TRUE(success); | 893 EXPECT_TRUE(success); |
990 | 894 |
991 // Now navigate the new tab to a different site. This should swap out the | 895 // Now navigate the new window to a different site. This should swap out the |
992 // tab's existing RenderView, causing it become hidden. | 896 // tab's existing RenderView, causing it become hidden. |
993 chrome::ActivateTabAt(browser(), 1, true); | 897 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
994 ui_test_utils::NavigateToURL(browser(), | |
995 https_server.GetURL("files/title1.html")); | |
996 | 898 |
997 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 899 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
998 rvh, L"", | 900 rvh, L"", |
999 L"window.domAutomationController.send(" | 901 L"window.domAutomationController.send(" |
1000 L"document.webkitVisibilityState == 'hidden');", | 902 L"document.webkitVisibilityState == 'hidden');", |
1001 &success)); | 903 &success)); |
1002 EXPECT_TRUE(success); | 904 EXPECT_TRUE(success); |
1003 | 905 |
1004 // Going back should make the previously swapped-out view to become visible | 906 // Going back should make the previously swapped-out view to become visible |
1005 // again. | 907 // again. |
1006 { | 908 { |
1007 content::WindowedNotificationObserver back_nav_load_observer( | 909 WindowedNotificationObserver back_nav_load_observer( |
1008 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 910 NOTIFICATION_NAV_ENTRY_COMMITTED, |
1009 content::Source<content::NavigationController>( | 911 Source<NavigationController>( |
1010 &chrome::GetActiveWebContents(browser())->GetController())); | 912 &new_shell->web_contents()->GetController())); |
1011 chrome::GoBack(browser(), CURRENT_TAB); | 913 new_shell->web_contents()->GetController().GoBack(); |
1012 back_nav_load_observer.Wait(); | 914 back_nav_load_observer.Wait(); |
1013 } | 915 } |
1014 | 916 |
1015 | 917 |
1016 EXPECT_EQ("/files/navigate_opener.html", | 918 EXPECT_EQ("/files/navigate_opener.html", |
1017 chrome::GetActiveWebContents(browser())->GetURL().path()); | 919 new_shell->web_contents()->GetURL().path()); |
1018 | 920 |
1019 EXPECT_EQ(rvh, chrome::GetActiveWebContents(browser())->GetRenderViewHost()); | 921 EXPECT_EQ(rvh, new_shell->web_contents()->GetRenderViewHost()); |
1020 | 922 |
1021 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 923 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1022 rvh, L"", | 924 rvh, L"", |
1023 L"window.domAutomationController.send(" | 925 L"window.domAutomationController.send(" |
1024 L"document.webkitVisibilityState == 'visible');", | 926 L"document.webkitVisibilityState == 'visible');", |
1025 &success)); | 927 &success)); |
1026 EXPECT_TRUE(success); | 928 EXPECT_TRUE(success); |
1027 } | 929 } |
1028 | 930 |
1029 // This class holds onto RenderViewHostObservers for as long as their observed | 931 // This class holds onto RenderViewHostObservers for as long as their observed |
1030 // RenderViewHosts are alive. This allows us to confirm that all hosts have | 932 // RenderViewHosts are alive. This allows us to confirm that all hosts have |
1031 // properly been shutdown. | 933 // properly been shutdown. |
1032 class RenderViewHostObserverArray { | 934 class RenderViewHostObserverArray { |
1033 public: | 935 public: |
1034 ~RenderViewHostObserverArray() { | 936 ~RenderViewHostObserverArray() { |
1035 // In case some would be left in there with a dead pointer to us. | 937 // In case some would be left in there with a dead pointer to us. |
1036 for (std::list<RVHObserver*>::iterator iter = observers_.begin(); | 938 for (std::list<RVHObserver*>::iterator iter = observers_.begin(); |
1037 iter != observers_.end(); ++iter) { | 939 iter != observers_.end(); ++iter) { |
1038 (*iter)->ClearParent(); | 940 (*iter)->ClearParent(); |
1039 } | 941 } |
1040 } | 942 } |
1041 void AddObserverToRVH(RenderViewHost* rvh) { | 943 void AddObserverToRVH(RenderViewHost* rvh) { |
1042 observers_.push_back(new RVHObserver(this, rvh)); | 944 observers_.push_back(new RVHObserver(this, rvh)); |
1043 } | 945 } |
1044 size_t GetNumObservers() const { | 946 size_t GetNumObservers() const { |
1045 return observers_.size(); | 947 return observers_.size(); |
1046 } | 948 } |
1047 private: | 949 private: |
1048 friend class RVHObserver; | 950 friend class RVHObserver; |
1049 class RVHObserver : public content::RenderViewHostObserver { | 951 class RVHObserver : public RenderViewHostObserver { |
1050 public: | 952 public: |
1051 RVHObserver(RenderViewHostObserverArray* parent, RenderViewHost* rvh) | 953 RVHObserver(RenderViewHostObserverArray* parent, RenderViewHost* rvh) |
1052 : content::RenderViewHostObserver(rvh), | 954 : RenderViewHostObserver(rvh), |
1053 parent_(parent) { | 955 parent_(parent) { |
1054 } | 956 } |
1055 virtual void RenderViewHostDestroyed(RenderViewHost* rvh) OVERRIDE { | 957 virtual void RenderViewHostDestroyed(RenderViewHost* rvh) OVERRIDE { |
1056 if (parent_) | 958 if (parent_) |
1057 parent_->RemoveObserver(this); | 959 parent_->RemoveObserver(this); |
1058 content::RenderViewHostObserver::RenderViewHostDestroyed(rvh); | 960 RenderViewHostObserver::RenderViewHostDestroyed(rvh); |
1059 }; | 961 }; |
1060 void ClearParent() { | 962 void ClearParent() { |
1061 parent_ = NULL; | 963 parent_ = NULL; |
1062 } | 964 } |
1063 private: | 965 private: |
1064 RenderViewHostObserverArray* parent_; | 966 RenderViewHostObserverArray* parent_; |
1065 }; | 967 }; |
1066 | 968 |
1067 void RemoveObserver(RVHObserver* observer) { | 969 void RemoveObserver(RVHObserver* observer) { |
1068 observers_.remove(observer); | 970 observers_.remove(observer); |
1069 } | 971 } |
1070 | 972 |
1071 std::list<RVHObserver*> observers_; | 973 std::list<RVHObserver*> observers_; |
1072 }; | 974 }; |
1073 | 975 |
1074 // Test for crbug.com/90867. Make sure we don't leak render view hosts since | 976 // Test for crbug.com/90867. Make sure we don't leak render view hosts since |
1075 // they may cause crashes or memory corruptions when trying to call dead | 977 // they may cause crashes or memory corruptions when trying to call dead |
1076 // delegate_. | 978 // delegate_. |
1077 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, LeakingRenderViewHosts) { | 979 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, LeakingRenderViewHosts) { |
1078 // Start two servers with different sites. | 980 // Start two servers with different sites. |
1079 ASSERT_TRUE(test_server()->Start()); | 981 ASSERT_TRUE(test_server()->Start()); |
1080 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | 982 net::TestServer https_server( |
1081 net::TestServer::kLocalhost, | 983 net::TestServer::TYPE_HTTPS, |
1082 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 984 net::TestServer::kLocalhost, |
985 FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
1083 ASSERT_TRUE(https_server.Start()); | 986 ASSERT_TRUE(https_server.Start()); |
1084 | 987 |
1085 // Create a new tab so that we can close the one we navigate and still have | |
1086 // a running browser. | |
1087 AddBlankTabAndShow(browser()); | |
Charlie Reis
2012/07/30 16:40:01
I guess this isn't needed?
jam
2012/07/30 17:03:50
right. this was needed for chrome (which quits if
| |
1088 | |
1089 // Load a random page and then navigate to view-source: of it. | 988 // Load a random page and then navigate to view-source: of it. |
1090 // This used to cause two RVH instances for the same SiteInstance, which | 989 // This used to cause two RVH instances for the same SiteInstance, which |
1091 // was a problem. This is no longer the case. | 990 // was a problem. This is no longer the case. |
1092 GURL navigated_url(test_server()->GetURL("files/title2.html")); | 991 GURL navigated_url(test_server()->GetURL("files/title2.html")); |
1093 ui_test_utils::NavigateToURL(browser(), navigated_url); | 992 NavigateToURL(shell(), navigated_url); |
1094 SiteInstance* site_instance1 = chrome::GetActiveWebContents(browser())-> | 993 SiteInstance* site_instance1 = shell()->web_contents()-> |
1095 GetRenderViewHost()->GetSiteInstance(); | 994 GetRenderViewHost()->GetSiteInstance(); |
1096 | 995 |
1097 // Observe the newly created render_view_host to make sure it will not leak. | 996 // Observe the newly created render_view_host to make sure it will not leak. |
1098 RenderViewHostObserverArray rvh_observers; | 997 RenderViewHostObserverArray rvh_observers; |
1099 rvh_observers.AddObserverToRVH(chrome::GetActiveWebContents(browser())-> | 998 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
1100 GetRenderViewHost()); | |
1101 | 999 |
1102 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + | 1000 GURL view_source_url(chrome::kViewSourceScheme + std::string(":") + |
1103 navigated_url.spec()); | 1001 navigated_url.spec()); |
1104 ui_test_utils::NavigateToURL(browser(), view_source_url); | 1002 NavigateToURL(shell(), view_source_url); |
1105 rvh_observers.AddObserverToRVH(chrome::GetActiveWebContents(browser())-> | 1003 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
1106 GetRenderViewHost()); | 1004 SiteInstance* site_instance2 = shell()->web_contents()-> |
1107 SiteInstance* site_instance2 = chrome::GetActiveWebContents(browser())-> | |
1108 GetRenderViewHost()->GetSiteInstance(); | 1005 GetRenderViewHost()->GetSiteInstance(); |
1109 | 1006 |
1110 // Ensure that view-source navigations force a new SiteInstance. | 1007 // Ensure that view-source navigations force a new SiteInstance. |
1111 EXPECT_NE(site_instance1, site_instance2); | 1008 EXPECT_NE(site_instance1, site_instance2); |
1112 | 1009 |
1113 // Now navigate to a different instance so that we swap out again. | 1010 // Now navigate to a different instance so that we swap out again. |
1114 ui_test_utils::NavigateToURL(browser(), | 1011 NavigateToURL(shell(), https_server.GetURL("files/title2.html")); |
1115 https_server.GetURL("files/title2.html")); | 1012 rvh_observers.AddObserverToRVH(shell()->web_contents()->GetRenderViewHost()); |
1116 rvh_observers.AddObserverToRVH(chrome::GetActiveWebContents(browser())-> | |
1117 GetRenderViewHost()); | |
1118 | 1013 |
1119 // This used to leak a render view host. | 1014 // This used to leak a render view host. |
1120 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser())); | 1015 shell()->Close(); |
1121 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 1016 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
1122 } | 1017 } |
1018 | |
1019 } // namespace content | |
OLD | NEW |