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 "content/browser/site_per_process_browsertest.h" | |
6 | |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
7 #include "content/browser/frame_host/cross_process_frame_connector.h" | 9 #include "content/browser/frame_host/cross_process_frame_connector.h" |
8 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
9 #include "content/browser/frame_host/render_frame_proxy_host.h" | 11 #include "content/browser/frame_host/render_frame_proxy_host.h" |
10 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 12 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
18 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
19 #include "content/public/test/content_browser_test.h" | |
20 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
23 #include "content/test/content_browser_test_utils_internal.h" | 24 #include "content/test/content_browser_test_utils_internal.h" |
24 #include "net/dns/mock_host_resolver.h" | 25 #include "net/dns/mock_host_resolver.h" |
25 #include "url/gurl.h" | |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 class SitePerProcessWebContentsObserver: public WebContentsObserver { | 29 class SitePerProcessWebContentsObserver: public WebContentsObserver { |
30 public: | 30 public: |
31 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | 31 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
32 : WebContentsObserver(web_contents), | 32 : WebContentsObserver(web_contents), |
33 navigation_succeeded_(false) {} | 33 navigation_succeeded_(false) {} |
34 virtual ~SitePerProcessWebContentsObserver() {} | 34 virtual ~SitePerProcessWebContentsObserver() {} |
35 | 35 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 details_ = details; | 142 details_ = details; |
143 seen_twice_ = seen_; | 143 seen_twice_ = seen_; |
144 seen_ = true; | 144 seen_ = true; |
145 if (!running_) | 145 if (!running_) |
146 return; | 146 return; |
147 | 147 |
148 message_loop_runner_->Quit(); | 148 message_loop_runner_->Quit(); |
149 running_ = false; | 149 running_ = false; |
150 } | 150 } |
151 | 151 |
152 class SitePerProcessBrowserTest : public ContentBrowserTest { | 152 // |
153 public: | 153 // SitePerProcessBrowserTest |
154 SitePerProcessBrowserTest() {} | 154 // |
155 | 155 |
156 protected: | 156 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
157 // Start at a data URL so each extra navigation creates a navigation entry. | 157 }; |
158 // (The first navigation will silently be classified as AUTO_SUBFRAME.) | 158 |
159 // TODO(creis): This won't be necessary when we can wait for LOAD_STOP. | 159 void SitePerProcessBrowserTest::StartFrameAtDataURL() { |
160 void StartFrameAtDataURL() { | 160 std::string data_url_script = |
161 std::string data_url_script = | |
162 "var iframes = document.getElementById('test');iframes.src=" | 161 "var iframes = document.getElementById('test');iframes.src=" |
163 "'data:text/html,dataurl';"; | 162 "'data:text/html,dataurl';"; |
164 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); | 163 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); |
165 } | 164 } |
166 | 165 |
167 bool NavigateIframeToURL(Shell* window, | 166 bool SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window, |
168 const GURL& url, | 167 const GURL& url, |
169 std::string iframe_id) { | 168 std::string iframe_id) { |
170 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe | 169 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
171 // navigations generate extra DidStartLoading and DidStopLoading messages. | 170 // navigations generate extra DidStartLoading and DidStopLoading messages. |
172 // Until we replace swappedout:// with frame proxies, we need to listen for | 171 // Until we replace swappedout:// with frame proxies, we need to listen for |
173 // something else. For now, we trigger NEW_SUBFRAME navigations and listen | 172 // something else. For now, we trigger NEW_SUBFRAME navigations and listen |
174 // for commit. | 173 // for commit. |
175 std::string script = base::StringPrintf( | 174 std::string script = base::StringPrintf( |
176 "setTimeout(\"" | 175 "setTimeout(\"" |
177 "var iframes = document.getElementById('%s');iframes.src='%s';" | 176 "var iframes = document.getElementById('%s');iframes.src='%s';" |
178 "\",0)", | 177 "\",0)", |
179 iframe_id.c_str(), url.spec().c_str()); | 178 iframe_id.c_str(), url.spec().c_str()); |
180 WindowedNotificationObserver load_observer( | 179 WindowedNotificationObserver load_observer( |
181 NOTIFICATION_NAV_ENTRY_COMMITTED, | 180 NOTIFICATION_NAV_ENTRY_COMMITTED, |
182 Source<NavigationController>( | 181 Source<NavigationController>( |
183 &window->web_contents()->GetController())); | 182 &window->web_contents()->GetController())); |
184 bool result = ExecuteScript(window->web_contents(), script); | 183 bool result = ExecuteScript(window->web_contents(), script); |
185 load_observer.Wait(); | 184 load_observer.Wait(); |
186 return result; | 185 return result; |
187 } | 186 } |
188 | 187 |
189 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 188 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
190 command_line->AppendSwitch(switches::kSitePerProcess); | 189 command_line->AppendSwitch(switches::kSitePerProcess); |
191 } | |
192 }; | 190 }; |
193 | 191 |
194 // Ensure that we can complete a cross-process subframe navigation. | 192 // Ensure that we can complete a cross-process subframe navigation. |
195 // Crashes ChromeOS bot, but the bug is probably present on other platforms | 193 // Crashes ChromeOS bot, but the bug is probably present on other platforms |
196 // also. http://crbug.com/399775 | 194 // also. http://crbug.com/399775 |
197 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { | 195 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
Charlie Reis
2014/08/25 20:58:44
Ah, you might need to rebase past Nasko's CL at so
dmazzoni
2014/08/26 23:31:03
Yes, it works again now.
| |
198 host_resolver()->AddRule("*", "127.0.0.1"); | 196 host_resolver()->AddRule("*", "127.0.0.1"); |
199 ASSERT_TRUE(test_server()->Start()); | 197 ASSERT_TRUE(test_server()->Start()); |
200 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 198 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
201 NavigateToURL(shell(), main_url); | 199 NavigateToURL(shell(), main_url); |
202 | 200 |
203 // It is safe to obtain the root frame tree node here, as it doesn't change. | 201 // It is safe to obtain the root frame tree node here, as it doesn't change. |
204 FrameTreeNode* root = | 202 FrameTreeNode* root = |
205 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 203 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
206 GetFrameTree()->root(); | 204 GetFrameTree()->root(); |
207 | 205 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector()); | 292 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector()); |
295 EXPECT_EQ( | 293 EXPECT_EQ( |
296 child->current_frame_host()->render_view_host()->GetView(), | 294 child->current_frame_host()->render_view_host()->GetView(), |
297 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); | 295 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); |
298 } | 296 } |
299 | 297 |
300 // Crash a subframe and ensures its children are cleared from the FrameTree. | 298 // Crash a subframe and ensures its children are cleared from the FrameTree. |
301 // See http://crbug.com/338508. | 299 // See http://crbug.com/338508. |
302 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. | 300 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. |
303 // TODO(creis): Enable this on Android when we can kill the process there. | 301 // TODO(creis): Enable this on Android when we can kill the process there. |
304 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { | 302 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrashSubframe) { |
305 host_resolver()->AddRule("*", "127.0.0.1"); | 303 host_resolver()->AddRule("*", "127.0.0.1"); |
306 ASSERT_TRUE(test_server()->Start()); | 304 ASSERT_TRUE(test_server()->Start()); |
307 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 305 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
308 NavigateToURL(shell(), main_url); | 306 NavigateToURL(shell(), main_url); |
309 | 307 |
310 StartFrameAtDataURL(); | 308 StartFrameAtDataURL(); |
311 | 309 |
312 // These must stay in scope with replace_host. | 310 // These must stay in scope with replace_host. |
313 GURL::Replacements replace_host; | 311 GURL::Replacements replace_host; |
314 std::string foo_com("foo.com"); | 312 std::string foo_com("foo.com"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 } | 352 } |
355 EXPECT_EQ(0U, root->child_count()); | 353 EXPECT_EQ(0U, root->child_count()); |
356 EXPECT_EQ(GURL(), root->current_url()); | 354 EXPECT_EQ(GURL(), root->current_url()); |
357 } | 355 } |
358 | 356 |
359 // TODO(nasko): Disable this test until out-of-process iframes is ready and the | 357 // TODO(nasko): Disable this test until out-of-process iframes is ready and the |
360 // security checks are back in place. | 358 // security checks are back in place. |
361 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run | 359 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run |
362 // on Android (http://crbug.com/187570). | 360 // on Android (http://crbug.com/187570). |
363 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 361 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
364 DISABLED_CrossSiteIframeRedirectOnce) { | 362 CrossSiteIframeRedirectOnce) { |
Charlie Reis
2014/08/25 20:58:43
These probably shouldn't be re-enabled.
dmazzoni
2014/08/26 23:31:03
Oops, forgot I left these in.
| |
365 ASSERT_TRUE(test_server()->Start()); | 363 ASSERT_TRUE(test_server()->Start()); |
366 net::SpawnedTestServer https_server( | 364 net::SpawnedTestServer https_server( |
367 net::SpawnedTestServer::TYPE_HTTPS, | 365 net::SpawnedTestServer::TYPE_HTTPS, |
368 net::SpawnedTestServer::kLocalhost, | 366 net::SpawnedTestServer::kLocalhost, |
369 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 367 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
370 ASSERT_TRUE(https_server.Start()); | 368 ASSERT_TRUE(https_server.Start()); |
371 | 369 |
372 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 370 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
373 GURL http_url(test_server()->GetURL("files/title1.html")); | 371 GURL http_url(test_server()->GetURL("files/title1.html")); |
374 GURL https_url(https_server.GetURL("files/title1.html")); | 372 GURL https_url(https_server.GetURL("files/title1.html")); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 EXPECT_EQ(observer.navigation_url(), http_url); | 478 EXPECT_EQ(observer.navigation_url(), http_url); |
481 EXPECT_TRUE(observer.navigation_succeeded()); | 479 EXPECT_TRUE(observer.navigation_succeeded()); |
482 } | 480 } |
483 } | 481 } |
484 | 482 |
485 // TODO(nasko): Disable this test until out-of-process iframes is ready and the | 483 // TODO(nasko): Disable this test until out-of-process iframes is ready and the |
486 // security checks are back in place. | 484 // security checks are back in place. |
487 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run | 485 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run |
488 // on Android (http://crbug.com/187570). | 486 // on Android (http://crbug.com/187570). |
489 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 487 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
490 DISABLED_CrossSiteIframeRedirectTwice) { | 488 CrossSiteIframeRedirectTwice) { |
491 ASSERT_TRUE(test_server()->Start()); | 489 ASSERT_TRUE(test_server()->Start()); |
492 net::SpawnedTestServer https_server( | 490 net::SpawnedTestServer https_server( |
493 net::SpawnedTestServer::TYPE_HTTPS, | 491 net::SpawnedTestServer::TYPE_HTTPS, |
494 net::SpawnedTestServer::kLocalhost, | 492 net::SpawnedTestServer::kLocalhost, |
495 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 493 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
496 ASSERT_TRUE(https_server.Start()); | 494 ASSERT_TRUE(https_server.Start()); |
497 | 495 |
498 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 496 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
499 GURL http_url(test_server()->GetURL("files/title1.html")); | 497 GURL http_url(test_server()->GetURL("files/title1.html")); |
500 GURL https_url(https_server.GetURL("files/title1.html")); | 498 GURL https_url(https_server.GetURL("files/title1.html")); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 "server-redirect?" + client_redirect_http_url.spec())); | 558 "server-redirect?" + client_redirect_http_url.spec())); |
561 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 559 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
562 | 560 |
563 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 561 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
564 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 562 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
565 EXPECT_FALSE(observer.navigation_succeeded()); | 563 EXPECT_FALSE(observer.navigation_succeeded()); |
566 } | 564 } |
567 } | 565 } |
568 | 566 |
569 } // namespace content | 567 } // namespace content |
OLD | NEW |