Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 248963007: Perform navigation policy check on UI thread for --site-per-process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/loader/cross_site_resource_handler.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "content/browser/frame_host/frame_tree.h" 7 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/notification_observer.h" 10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
18 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
19 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
20 #include "content/test/content_browser_test_utils_internal.h"
20 #include "net/dns/mock_host_resolver.h" 21 #include "net/dns/mock_host_resolver.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 class SitePerProcessWebContentsObserver: public WebContentsObserver { 26 class SitePerProcessWebContentsObserver: public WebContentsObserver {
26 public: 27 public:
27 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) 28 explicit SitePerProcessWebContentsObserver(WebContents* web_contents)
28 : WebContentsObserver(web_contents), 29 : WebContentsObserver(web_contents),
29 navigation_succeeded_(false) {} 30 navigation_succeeded_(false) {}
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 197 }
197 }; 198 };
198 199
199 // Ensure that we can complete a cross-process subframe navigation. 200 // Ensure that we can complete a cross-process subframe navigation.
200 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { 201 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) {
201 host_resolver()->AddRule("*", "127.0.0.1"); 202 host_resolver()->AddRule("*", "127.0.0.1");
202 ASSERT_TRUE(test_server()->Start()); 203 ASSERT_TRUE(test_server()->Start());
203 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); 204 GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
204 NavigateToURL(shell(), main_url); 205 NavigateToURL(shell(), main_url);
205 206
206 StartFrameAtDataURL(); 207 // It is safe to obtain the root frame tree node here, as it doesn't change.
208 FrameTreeNode* root =
209 static_cast<WebContentsImpl*>(shell()->web_contents())->
210 GetFrameTree()->root();
207 211
208 SitePerProcessWebContentsObserver observer(shell()->web_contents()); 212 SitePerProcessWebContentsObserver observer(shell()->web_contents());
209 213
210 // Load same-site page into iframe. 214 // Load same-site page into iframe.
211 GURL http_url(test_server()->GetURL("files/title1.html")); 215 GURL http_url(test_server()->GetURL("files/title1.html"));
212 EXPECT_TRUE(NavigateIframeToURL(shell(), http_url, "test")); 216 NavigateFrameToURL(root->child_at(0), http_url);
213 EXPECT_EQ(http_url, observer.navigation_url()); 217 EXPECT_EQ(http_url, observer.navigation_url());
214 EXPECT_TRUE(observer.navigation_succeeded()); 218 EXPECT_TRUE(observer.navigation_succeeded());
215 219
216 // These must stay in scope with replace_host. 220 // These must stay in scope with replace_host.
217 GURL::Replacements replace_host; 221 GURL::Replacements replace_host;
218 std::string foo_com("foo.com"); 222 std::string foo_com("foo.com");
219 223
220 // Load cross-site page into iframe. 224 // Load cross-site page into iframe.
221 GURL cross_site_url(test_server()->GetURL("files/title2.html")); 225 GURL cross_site_url(test_server()->GetURL("files/title2.html"));
222 replace_host.SetHostStr(foo_com); 226 replace_host.SetHostStr(foo_com);
223 cross_site_url = cross_site_url.ReplaceComponents(replace_host); 227 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
224 EXPECT_TRUE(NavigateIframeToURL(shell(), cross_site_url, "test")); 228 NavigateFrameToURL(root->child_at(0), cross_site_url);
225 EXPECT_EQ(cross_site_url, observer.navigation_url()); 229 EXPECT_EQ(cross_site_url, observer.navigation_url());
226 EXPECT_TRUE(observer.navigation_succeeded()); 230 EXPECT_TRUE(observer.navigation_succeeded());
227 231
228 // Ensure that we have created a new process for the subframe. 232 // Ensure that we have created a new process for the subframe.
229 FrameTreeNode* root =
230 static_cast<WebContentsImpl*>(shell()->web_contents())->
231 GetFrameTree()->root();
232 ASSERT_EQ(1U, root->child_count()); 233 ASSERT_EQ(1U, root->child_count());
233 FrameTreeNode* child = root->child_at(0); 234 FrameTreeNode* child = root->child_at(0);
235 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance();
236 RenderViewHost* rvh = child->current_frame_host()->render_view_host();
237 RenderProcessHost* rph = child->current_frame_host()->GetProcess();
238 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), rvh);
239 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance);
240 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), rph);
241
242 // Load another cross-site page into the same iframe.
243 cross_site_url = test_server()->GetURL("files/title3.html");
244 std::string bar_com("bar.com");
245 replace_host.SetHostStr(bar_com);
246 cross_site_url = cross_site_url.ReplaceComponents(replace_host);
247 NavigateFrameToURL(root->child_at(0), cross_site_url);
248 EXPECT_EQ(cross_site_url, observer.navigation_url());
249 EXPECT_TRUE(observer.navigation_succeeded());
250
251 // Check again that a new process is created and is different from the
252 // top level one and the previous one.
253 ASSERT_EQ(1U, root->child_count());
254 child = root->child_at(0);
234 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), 255 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(),
235 child->current_frame_host()->render_view_host()); 256 child->current_frame_host()->render_view_host());
257 EXPECT_NE(rvh, child->current_frame_host()->render_view_host());
236 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), 258 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
237 child->current_frame_host()->render_view_host()->GetSiteInstance()); 259 child->current_frame_host()->GetSiteInstance());
260 EXPECT_NE(site_instance,
261 child->current_frame_host()->GetSiteInstance());
238 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), 262 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(),
239 child->current_frame_host()->GetProcess()); 263 child->current_frame_host()->GetProcess());
264 EXPECT_NE(rph, child->current_frame_host()->GetProcess());
240 } 265 }
241 266
242 // Crash a subframe and ensures its children are cleared from the FrameTree. 267 // Crash a subframe and ensures its children are cleared from the FrameTree.
243 // See http://crbug.com/338508. 268 // See http://crbug.com/338508.
244 // TODO(creis): Enable this on Android when we can kill the process there. 269 // TODO(creis): Enable this on Android when we can kill the process there.
245 #if defined(OS_ANDROID) 270 #if defined(OS_ANDROID)
246 #define MAYBE_CrashSubframe DISABLED_CrashSubframe 271 #define MAYBE_CrashSubframe DISABLED_CrashSubframe
247 #else 272 #else
248 #define MAYBE_CrashSubframe CrashSubframe 273 #define MAYBE_CrashSubframe CrashSubframe
249 #endif 274 #endif
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 "server-redirect?" + client_redirect_http_url.spec())); 531 "server-redirect?" + client_redirect_http_url.spec()));
507 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); 532 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test"));
508 533
509 // DidFailProvisionalLoad when navigating to client_redirect_http_url. 534 // DidFailProvisionalLoad when navigating to client_redirect_http_url.
510 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); 535 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url);
511 EXPECT_FALSE(observer.navigation_succeeded()); 536 EXPECT_FALSE(observer.navigation_succeeded());
512 } 537 }
513 } 538 }
514 539
515 } // namespace content 540 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/cross_site_resource_handler.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698