| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 seen_ = true; | 154 seen_ = true; |
| 155 if (!running_) | 155 if (!running_) |
| 156 return; | 156 return; |
| 157 | 157 |
| 158 message_loop_runner_->Quit(); | 158 message_loop_runner_->Quit(); |
| 159 running_ = false; | 159 running_ = false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 class SitePerProcessBrowserTest : public ContentBrowserTest { | 162 class SitePerProcessBrowserTest : public ContentBrowserTest { |
| 163 protected: | 163 protected: |
| 164 // Start at a data URL so each extra navigation creates a navigation entry. |
| 165 // (The first navigation will silently be classified as AUTO_SUBFRAME.) |
| 166 // TODO(creis): This won't be necessary when we can wait for LOAD_STOP. |
| 167 void StartFrameAtDataURL() { |
| 168 std::string data_url_script = |
| 169 "var iframes = document.getElementById('test');iframes.src=" |
| 170 "'data:text/html,dataurl';"; |
| 171 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); |
| 172 } |
| 173 |
| 164 bool NavigateIframeToURL(Shell* window, | 174 bool NavigateIframeToURL(Shell* window, |
| 165 const GURL& url, | 175 const GURL& url, |
| 166 std::string iframe_id) { | 176 std::string iframe_id) { |
| 177 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
| 178 // navigations generate extra DidStartLoading and DidStopLoading messages. |
| 179 // Until we replace swappedout:// with frame proxies, we need to listen for |
| 180 // something else. For now, we trigger NEW_SUBFRAME navigations and listen |
| 181 // for commit. |
| 167 std::string script = base::StringPrintf( | 182 std::string script = base::StringPrintf( |
| 168 "var iframes = document.getElementById('%s');iframes.src='%s';", | 183 "setTimeout(\"" |
| 184 "var iframes = document.getElementById('%s');iframes.src='%s';" |
| 185 "\",0)", |
| 169 iframe_id.c_str(), url.spec().c_str()); | 186 iframe_id.c_str(), url.spec().c_str()); |
| 170 WindowedNotificationObserver load_observer( | 187 WindowedNotificationObserver load_observer( |
| 171 NOTIFICATION_LOAD_STOP, | 188 NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 172 Source<NavigationController>( | 189 Source<NavigationController>( |
| 173 &shell()->web_contents()->GetController())); | 190 &window->web_contents()->GetController())); |
| 174 bool result = ExecuteScript(window->web_contents(), script); | 191 bool result = ExecuteScript(window->web_contents(), script); |
| 175 load_observer.Wait(); | 192 load_observer.Wait(); |
| 176 return result; | 193 return result; |
| 177 } | 194 } |
| 178 | 195 |
| 179 void NavigateToURLContentInitiated(Shell* window, | 196 void NavigateToURLContentInitiated(Shell* window, |
| 180 const GURL& url, | 197 const GURL& url, |
| 181 bool should_replace_current_entry) { | 198 bool should_replace_current_entry) { |
| 182 std::string script; | 199 std::string script; |
| 183 if (should_replace_current_entry) | 200 if (should_replace_current_entry) |
| 184 script = base::StringPrintf("location.replace('%s')", url.spec().c_str()); | 201 script = base::StringPrintf("location.replace('%s')", url.spec().c_str()); |
| 185 else | 202 else |
| 186 script = base::StringPrintf("location.href = '%s'", url.spec().c_str()); | 203 script = base::StringPrintf("location.href = '%s'", url.spec().c_str()); |
| 187 TestNavigationObserver load_observer(shell()->web_contents(), 1); | 204 TestNavigationObserver load_observer(shell()->web_contents(), 1); |
| 188 bool result = ExecuteScript(window->web_contents(), script); | 205 bool result = ExecuteScript(window->web_contents(), script); |
| 189 EXPECT_TRUE(result); | 206 EXPECT_TRUE(result); |
| 190 load_observer.Wait(); | 207 load_observer.Wait(); |
| 191 } | 208 } |
| 192 | 209 |
| 193 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 210 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 194 command_line->AppendSwitch(switches::kSitePerProcess); | 211 command_line->AppendSwitch(switches::kSitePerProcess); |
| 212 |
| 213 // TODO(creis): Remove this when GTK is no longer a supported platform. |
| 214 command_line->AppendSwitch(switches::kForceCompositingMode); |
| 195 } | 215 } |
| 196 }; | 216 }; |
| 197 | 217 |
| 198 // Ensure that we can complete a cross-process subframe navigation. | 218 // Ensure that we can complete a cross-process subframe navigation. |
| 199 // TODO(nasko): Disable this test for now, since enabling swapping out of | 219 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
| 200 // RenderFrameHosts causes this to break. Fix this test once | 220 host_resolver()->AddRule("*", "127.0.0.1"); |
| 201 // didFailProvisionalLoad is moved from RenderView to RenderFrame. | |
| 202 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { | |
| 203 ASSERT_TRUE(test_server()->Start()); | 221 ASSERT_TRUE(test_server()->Start()); |
| 204 net::SpawnedTestServer https_server( | |
| 205 net::SpawnedTestServer::TYPE_HTTPS, | |
| 206 net::SpawnedTestServer::kLocalhost, | |
| 207 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
| 208 ASSERT_TRUE(https_server.Start()); | |
| 209 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 222 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 223 NavigateToURL(shell(), main_url); |
| 210 | 224 |
| 211 NavigateToURL(shell(), main_url); | 225 StartFrameAtDataURL(); |
| 212 | 226 |
| 213 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 227 SitePerProcessWebContentsObserver observer(shell()->web_contents()); |
| 214 | 228 |
| 215 // Load same-site page into iframe. | 229 // Load same-site page into iframe. |
| 216 GURL http_url(test_server()->GetURL("files/title1.html")); | 230 GURL http_url(test_server()->GetURL("files/title1.html")); |
| 217 EXPECT_TRUE(NavigateIframeToURL(shell(), http_url, "test")); | 231 EXPECT_TRUE(NavigateIframeToURL(shell(), http_url, "test")); |
| 218 EXPECT_EQ(observer.navigation_url(), http_url); | 232 EXPECT_EQ(http_url, observer.navigation_url()); |
| 219 EXPECT_TRUE(observer.navigation_succeeded()); | 233 EXPECT_TRUE(observer.navigation_succeeded()); |
| 220 | 234 |
| 235 // These must stay in scope with replace_host. |
| 236 GURL::Replacements replace_host; |
| 237 std::string foo_com("foo.com"); |
| 238 |
| 221 // Load cross-site page into iframe. | 239 // Load cross-site page into iframe. |
| 222 GURL https_url(https_server.GetURL("files/title1.html")); | 240 GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| 223 EXPECT_TRUE(NavigateIframeToURL(shell(), https_url, "test")); | 241 replace_host.SetHostStr(foo_com); |
| 224 EXPECT_EQ(observer.navigation_url(), https_url); | 242 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 243 EXPECT_TRUE(NavigateIframeToURL(shell(), cross_site_url, "test")); |
| 244 EXPECT_EQ(cross_site_url, observer.navigation_url()); |
| 225 EXPECT_TRUE(observer.navigation_succeeded()); | 245 EXPECT_TRUE(observer.navigation_succeeded()); |
| 226 | 246 |
| 227 // Ensure that we have created a new process for the subframe. | 247 // Ensure that we have created a new process for the subframe. |
| 228 FrameTreeNode* root = | 248 FrameTreeNode* root = |
| 229 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 249 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 230 GetFrameTree()->root(); | 250 GetFrameTree()->root(); |
| 231 ASSERT_EQ(1U, root->child_count()); | 251 ASSERT_EQ(1U, root->child_count()); |
| 232 FrameTreeNode* child = root->child_at(0); | 252 FrameTreeNode* child = root->child_at(0); |
| 233 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), | 253 EXPECT_NE(shell()->web_contents()->GetRenderViewHost(), |
| 234 child->current_frame_host()->render_view_host()); | 254 child->current_frame_host()->render_view_host()); |
| 235 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 255 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 236 child->current_frame_host()->render_view_host()->GetSiteInstance()); | 256 child->current_frame_host()->render_view_host()->GetSiteInstance()); |
| 237 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), | 257 EXPECT_NE(shell()->web_contents()->GetRenderProcessHost(), |
| 238 child->current_frame_host()->GetProcess()); | 258 child->current_frame_host()->GetProcess()); |
| 239 } | 259 } |
| 240 | 260 |
| 241 // TODO(nasko): Disable this test until out-of-process iframes is ready and the | 261 // TODO(nasko): Disable this test until out-of-process iframes is ready and the |
| 242 // security checks are back in place. | 262 // security checks are back in place. |
| 263 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run |
| 264 // on Android (http://crbug.com/187570). |
| 243 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 265 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 244 DISABLED_CrossSiteIframeRedirectOnce) { | 266 DISABLED_CrossSiteIframeRedirectOnce) { |
| 245 ASSERT_TRUE(test_server()->Start()); | 267 ASSERT_TRUE(test_server()->Start()); |
| 246 net::SpawnedTestServer https_server( | 268 net::SpawnedTestServer https_server( |
| 247 net::SpawnedTestServer::TYPE_HTTPS, | 269 net::SpawnedTestServer::TYPE_HTTPS, |
| 248 net::SpawnedTestServer::kLocalhost, | 270 net::SpawnedTestServer::kLocalhost, |
| 249 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 271 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 250 ASSERT_TRUE(https_server.Start()); | 272 ASSERT_TRUE(https_server.Start()); |
| 251 | 273 |
| 252 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 274 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 379 |
| 358 // Redirecting to Same-site Page should be loaded successfully. | 380 // Redirecting to Same-site Page should be loaded successfully. |
| 359 load_observer2.Wait(); | 381 load_observer2.Wait(); |
| 360 EXPECT_EQ(observer.navigation_url(), http_url); | 382 EXPECT_EQ(observer.navigation_url(), http_url); |
| 361 EXPECT_TRUE(observer.navigation_succeeded()); | 383 EXPECT_TRUE(observer.navigation_succeeded()); |
| 362 } | 384 } |
| 363 } | 385 } |
| 364 | 386 |
| 365 // TODO(nasko): Disable this test until out-of-process iframes is ready and the | 387 // TODO(nasko): Disable this test until out-of-process iframes is ready and the |
| 366 // security checks are back in place. | 388 // security checks are back in place. |
| 389 // TODO(creis): Replace SpawnedTestServer with host_resolver to get test to run |
| 390 // on Android (http://crbug.com/187570). |
| 367 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 391 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 368 DISABLED_CrossSiteIframeRedirectTwice) { | 392 DISABLED_CrossSiteIframeRedirectTwice) { |
| 369 ASSERT_TRUE(test_server()->Start()); | 393 ASSERT_TRUE(test_server()->Start()); |
| 370 net::SpawnedTestServer https_server( | 394 net::SpawnedTestServer https_server( |
| 371 net::SpawnedTestServer::TYPE_HTTPS, | 395 net::SpawnedTestServer::TYPE_HTTPS, |
| 372 net::SpawnedTestServer::kLocalhost, | 396 net::SpawnedTestServer::kLocalhost, |
| 373 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | 397 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 374 ASSERT_TRUE(https_server.Start()); | 398 ASSERT_TRUE(https_server.Start()); |
| 375 | 399 |
| 376 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 400 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 464 |
| 441 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 465 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 442 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 466 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
| 443 EXPECT_FALSE(observer.navigation_succeeded()); | 467 EXPECT_FALSE(observer.navigation_succeeded()); |
| 444 } | 468 } |
| 445 } | 469 } |
| 446 | 470 |
| 447 // Tests that the |should_replace_current_entry| flag persists correctly across | 471 // Tests that the |should_replace_current_entry| flag persists correctly across |
| 448 // request transfers that began with a cross-process navigation. | 472 // request transfers that began with a cross-process navigation. |
| 449 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 473 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 450 ReplaceEntryCrossProcessThenTranfers) { | 474 ReplaceEntryCrossProcessThenTransfer) { |
| 451 const NavigationController& controller = | 475 const NavigationController& controller = |
| 452 shell()->web_contents()->GetController(); | 476 shell()->web_contents()->GetController(); |
| 453 host_resolver()->AddRule("*", "127.0.0.1"); | 477 host_resolver()->AddRule("*", "127.0.0.1"); |
| 454 ASSERT_TRUE(test_server()->Start()); | 478 ASSERT_TRUE(test_server()->Start()); |
| 455 | 479 |
| 456 // These must all stay in scope with replace_host. | 480 // These must all stay in scope with replace_host. |
| 457 GURL::Replacements replace_host; | 481 GURL::Replacements replace_host; |
| 458 std::string a_com("A.com"); | 482 std::string a_com("A.com"); |
| 459 std::string b_com("B.com"); | 483 std::string b_com("B.com"); |
| 460 | 484 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 // There should be two history entries. url2b should have replaced url1. url2b | 618 // There should be two history entries. url2b should have replaced url1. url2b |
| 595 // should not have replaced url3b. | 619 // should not have replaced url3b. |
| 596 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 620 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 597 EXPECT_EQ(2, controller.GetEntryCount()); | 621 EXPECT_EQ(2, controller.GetEntryCount()); |
| 598 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 622 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| 599 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 623 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
| 600 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 624 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
| 601 } | 625 } |
| 602 | 626 |
| 603 } // namespace content | 627 } // namespace content |
| OLD | NEW |