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 "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 #include "content/public/browser/navigation_entry.h" | 8 #include "content/public/browser/navigation_entry.h" |
9 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 9 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
10 #include "content/public/browser/resource_throttle.h" | 10 #include "content/public/browser/resource_throttle.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 #endif | 244 #endif |
245 // Tests that the |should_replace_current_entry| flag persists correctly across | 245 // Tests that the |should_replace_current_entry| flag persists correctly across |
246 // request transfers that began with a cross-process navigation. | 246 // request transfers that began with a cross-process navigation. |
247 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, | 247 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, |
248 MAYBE_ReplaceEntryCrossProcessThenTransfer) { | 248 MAYBE_ReplaceEntryCrossProcessThenTransfer) { |
249 const NavigationController& controller = | 249 const NavigationController& controller = |
250 shell()->web_contents()->GetController(); | 250 shell()->web_contents()->GetController(); |
251 host_resolver()->AddRule("*", "127.0.0.1"); | 251 host_resolver()->AddRule("*", "127.0.0.1"); |
252 ASSERT_TRUE(test_server()->Start()); | 252 ASSERT_TRUE(test_server()->Start()); |
253 | 253 |
254 // These must all stay in scope with replace_host. | |
255 GURL::Replacements replace_host; | |
256 std::string a_com("A.com"); | |
257 std::string b_com("B.com"); | |
258 | |
259 // Navigate to a starting URL, so there is a history entry to replace. | 254 // Navigate to a starting URL, so there is a history entry to replace. |
260 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); | 255 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); |
261 NavigateToURL(shell(), url1); | 256 NavigateToURL(shell(), url1); |
262 | 257 |
263 // Force all future navigations to transfer. Note that this includes same-site | 258 // Force all future navigations to transfer. Note that this includes same-site |
264 // navigiations which may cause double process swaps (via OpenURL and then via | 259 // navigiations which may cause double process swaps (via OpenURL and then via |
265 // transfer). This test intentionally exercises that case. | 260 // transfer). This test intentionally exercises that case. |
266 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 261 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
267 | 262 |
268 // Navigate to a page on A.com with entry replacement. This navigation is | 263 // Navigate to a page on A.com with entry replacement. This navigation is |
269 // cross-site, so the renderer will send it to the browser via OpenURL to give | 264 // cross-site, so the renderer will send it to the browser via OpenURL to give |
270 // to a new process. It will then be transferred into yet another process due | 265 // to a new process. It will then be transferred into yet another process due |
271 // to the call above. | 266 // to the call above. |
| 267 GURL::Replacements replace_host; |
272 GURL url2 = test_server()->GetURL("files/site_isolation/blank.html?2"); | 268 GURL url2 = test_server()->GetURL("files/site_isolation/blank.html?2"); |
273 replace_host.SetHostStr(a_com); | 269 replace_host.SetHostStr("A.com"); |
274 url2 = url2.ReplaceComponents(replace_host); | 270 url2 = url2.ReplaceComponents(replace_host); |
275 // Used to make sure the request for url2 succeeds, and there was only one of | 271 // Used to make sure the request for url2 succeeds, and there was only one of |
276 // them. | 272 // them. |
277 tracking_delegate().SetTrackedURL(url2); | 273 tracking_delegate().SetTrackedURL(url2); |
278 NavigateToURLContentInitiated(shell(), url2, true, true); | 274 NavigateToURLContentInitiated(shell(), url2, true, true); |
279 | 275 |
280 // There should be one history entry. url2 should have replaced url1. | 276 // There should be one history entry. url2 should have replaced url1. |
281 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 277 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
282 EXPECT_EQ(1, controller.GetEntryCount()); | 278 EXPECT_EQ(1, controller.GetEntryCount()); |
283 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 279 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
284 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 280 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
285 // Make sure the request succeeded. | 281 // Make sure the request succeeded. |
286 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 282 EXPECT_TRUE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
287 | 283 |
288 // Now navigate as before to a page on B.com, but normally (without | 284 // Now navigate as before to a page on B.com, but normally (without |
289 // replacement). This will still perform a double process-swap as above, via | 285 // replacement). This will still perform a double process-swap as above, via |
290 // OpenURL and then transfer. | 286 // OpenURL and then transfer. |
291 GURL url3 = test_server()->GetURL("files/site_isolation/blank.html?3"); | 287 GURL url3 = test_server()->GetURL("files/site_isolation/blank.html?3"); |
292 replace_host.SetHostStr(b_com); | 288 replace_host.SetHostStr("B.com"); |
293 url3 = url3.ReplaceComponents(replace_host); | 289 url3 = url3.ReplaceComponents(replace_host); |
294 // Used to make sure the request for url3 succeeds, and there was only one of | 290 // Used to make sure the request for url3 succeeds, and there was only one of |
295 // them. | 291 // them. |
296 tracking_delegate().SetTrackedURL(url3); | 292 tracking_delegate().SetTrackedURL(url3); |
297 NavigateToURLContentInitiated(shell(), url3, false, true); | 293 NavigateToURLContentInitiated(shell(), url3, false, true); |
298 | 294 |
299 // There should be two history entries. url2 should have replaced url1. url2 | 295 // There should be two history entries. url2 should have replaced url1. url2 |
300 // should not have replaced url3. | 296 // should not have replaced url3. |
301 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 297 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
302 EXPECT_EQ(2, controller.GetEntryCount()); | 298 EXPECT_EQ(2, controller.GetEntryCount()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 350 |
355 // Tests that the |should_replace_current_entry| flag persists correctly across | 351 // Tests that the |should_replace_current_entry| flag persists correctly across |
356 // request transfers that cross processes twice from renderer policy. | 352 // request transfers that cross processes twice from renderer policy. |
357 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, | 353 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, |
358 MAYBE_ReplaceEntryCrossProcessTwice) { | 354 MAYBE_ReplaceEntryCrossProcessTwice) { |
359 const NavigationController& controller = | 355 const NavigationController& controller = |
360 shell()->web_contents()->GetController(); | 356 shell()->web_contents()->GetController(); |
361 host_resolver()->AddRule("*", "127.0.0.1"); | 357 host_resolver()->AddRule("*", "127.0.0.1"); |
362 ASSERT_TRUE(test_server()->Start()); | 358 ASSERT_TRUE(test_server()->Start()); |
363 | 359 |
364 // These must all stay in scope with replace_host. | |
365 GURL::Replacements replace_host; | |
366 std::string a_com("A.com"); | |
367 std::string b_com("B.com"); | |
368 | |
369 // Navigate to a starting URL, so there is a history entry to replace. | 360 // Navigate to a starting URL, so there is a history entry to replace. |
370 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); | 361 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); |
371 NavigateToURL(shell(), url1); | 362 NavigateToURL(shell(), url1); |
372 | 363 |
373 // Navigate to a page on A.com which redirects to B.com with entry | 364 // Navigate to a page on A.com which redirects to B.com with entry |
374 // replacement. This will switch processes via OpenURL twice. First to A.com, | 365 // replacement. This will switch processes via OpenURL twice. First to A.com, |
375 // and second in response to the server redirect to B.com. The second swap is | 366 // and second in response to the server redirect to B.com. The second swap is |
376 // also renderer-initiated via OpenURL because decidePolicyForNavigation is | 367 // also renderer-initiated via OpenURL because decidePolicyForNavigation is |
377 // currently applied on redirects. | 368 // currently applied on redirects. |
| 369 GURL::Replacements replace_host; |
378 GURL url2b = test_server()->GetURL("files/site_isolation/blank.html?2"); | 370 GURL url2b = test_server()->GetURL("files/site_isolation/blank.html?2"); |
379 replace_host.SetHostStr(b_com); | 371 replace_host.SetHostStr("B.com"); |
380 url2b = url2b.ReplaceComponents(replace_host); | 372 url2b = url2b.ReplaceComponents(replace_host); |
381 GURL url2a = test_server()->GetURL( | 373 GURL url2a = test_server()->GetURL( |
382 "server-redirect?" + net::EscapeQueryParamValue(url2b.spec(), false)); | 374 "server-redirect?" + net::EscapeQueryParamValue(url2b.spec(), false)); |
383 replace_host.SetHostStr(a_com); | 375 replace_host.SetHostStr("A.com"); |
384 url2a = url2a.ReplaceComponents(replace_host); | 376 url2a = url2a.ReplaceComponents(replace_host); |
385 NavigateToURLContentInitiated(shell(), url2a, true, true); | 377 NavigateToURLContentInitiated(shell(), url2a, true, true); |
386 | 378 |
387 // There should be one history entry. url2b should have replaced url1. | 379 // There should be one history entry. url2b should have replaced url1. |
388 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 380 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
389 EXPECT_EQ(1, controller.GetEntryCount()); | 381 EXPECT_EQ(1, controller.GetEntryCount()); |
390 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 382 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
391 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 383 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
392 | 384 |
393 // Now repeat without replacement. | 385 // Now repeat without replacement. |
394 GURL url3b = test_server()->GetURL("files/site_isolation/blank.html?3"); | 386 GURL url3b = test_server()->GetURL("files/site_isolation/blank.html?3"); |
395 replace_host.SetHostStr(b_com); | 387 replace_host.SetHostStr("B.com"); |
396 url3b = url3b.ReplaceComponents(replace_host); | 388 url3b = url3b.ReplaceComponents(replace_host); |
397 GURL url3a = test_server()->GetURL( | 389 GURL url3a = test_server()->GetURL( |
398 "server-redirect?" + net::EscapeQueryParamValue(url3b.spec(), false)); | 390 "server-redirect?" + net::EscapeQueryParamValue(url3b.spec(), false)); |
399 replace_host.SetHostStr(a_com); | 391 replace_host.SetHostStr("A.com"); |
400 url3a = url3a.ReplaceComponents(replace_host); | 392 url3a = url3a.ReplaceComponents(replace_host); |
401 NavigateToURLContentInitiated(shell(), url3a, false, true); | 393 NavigateToURLContentInitiated(shell(), url3a, false, true); |
402 | 394 |
403 // There should be two history entries. url2b should have replaced url1. url2b | 395 // There should be two history entries. url2b should have replaced url1. url2b |
404 // should not have replaced url3b. | 396 // should not have replaced url3b. |
405 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 397 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
406 EXPECT_EQ(2, controller.GetEntryCount()); | 398 EXPECT_EQ(2, controller.GetEntryCount()); |
407 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 399 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
408 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 400 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
409 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 401 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
410 } | 402 } |
411 | 403 |
412 // Tests that the request is destroyed when a cross process navigation is | 404 // Tests that the request is destroyed when a cross process navigation is |
413 // cancelled. | 405 // cancelled. |
414 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, NoLeakOnCrossSiteCancel) { | 406 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, NoLeakOnCrossSiteCancel) { |
415 const NavigationController& controller = | 407 const NavigationController& controller = |
416 shell()->web_contents()->GetController(); | 408 shell()->web_contents()->GetController(); |
417 host_resolver()->AddRule("*", "127.0.0.1"); | 409 host_resolver()->AddRule("*", "127.0.0.1"); |
418 ASSERT_TRUE(test_server()->Start()); | 410 ASSERT_TRUE(test_server()->Start()); |
419 | 411 |
420 // These must all stay in scope with replace_host. | |
421 GURL::Replacements replace_host; | |
422 std::string a_com("A.com"); | |
423 std::string b_com("B.com"); | |
424 | |
425 // Navigate to a starting URL, so there is a history entry to replace. | 412 // Navigate to a starting URL, so there is a history entry to replace. |
426 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); | 413 GURL url1 = test_server()->GetURL("files/site_isolation/blank.html?1"); |
427 NavigateToURL(shell(), url1); | 414 NavigateToURL(shell(), url1); |
428 | 415 |
429 // Force all future navigations to transfer. | 416 // Force all future navigations to transfer. |
430 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 417 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
431 | 418 |
432 NoTransferRequestDelegate no_transfer_request_delegate; | 419 NoTransferRequestDelegate no_transfer_request_delegate; |
433 WebContentsDelegate* old_delegate = shell()->web_contents()->GetDelegate(); | 420 WebContentsDelegate* old_delegate = shell()->web_contents()->GetDelegate(); |
434 shell()->web_contents()->SetDelegate(&no_transfer_request_delegate); | 421 shell()->web_contents()->SetDelegate(&no_transfer_request_delegate); |
435 | 422 |
436 // Navigate to a page on A.com with entry replacement. This navigation is | 423 // Navigate to a page on A.com with entry replacement. This navigation is |
437 // cross-site, so the renderer will send it to the browser via OpenURL to give | 424 // cross-site, so the renderer will send it to the browser via OpenURL to give |
438 // to a new process. It will then be transferred into yet another process due | 425 // to a new process. It will then be transferred into yet another process due |
439 // to the call above. | 426 // to the call above. |
| 427 GURL::Replacements replace_host; |
440 GURL url2 = test_server()->GetURL("files/site_isolation/blank.html?2"); | 428 GURL url2 = test_server()->GetURL("files/site_isolation/blank.html?2"); |
441 replace_host.SetHostStr(a_com); | 429 replace_host.SetHostStr("A.com"); |
442 url2 = url2.ReplaceComponents(replace_host); | 430 url2 = url2.ReplaceComponents(replace_host); |
443 // Used to make sure the second request is cancelled, and there is only one | 431 // Used to make sure the second request is cancelled, and there is only one |
444 // request for url2. | 432 // request for url2. |
445 tracking_delegate().SetTrackedURL(url2); | 433 tracking_delegate().SetTrackedURL(url2); |
446 | 434 |
447 // Don't wait for the navigation to complete, since that never happens in | 435 // Don't wait for the navigation to complete, since that never happens in |
448 // this case. | 436 // this case. |
449 NavigateToURLContentInitiated(shell(), url2, false, false); | 437 NavigateToURLContentInitiated(shell(), url2, false, false); |
450 | 438 |
451 // There should be one history entry, with url1. | 439 // There should be one history entry, with url1. |
452 EXPECT_EQ(1, controller.GetEntryCount()); | 440 EXPECT_EQ(1, controller.GetEntryCount()); |
453 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 441 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
454 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); | 442 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
455 | 443 |
456 // Make sure the request for url2 did not complete. | 444 // Make sure the request for url2 did not complete. |
457 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 445 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
458 | 446 |
459 shell()->web_contents()->SetDelegate(old_delegate); | 447 shell()->web_contents()->SetDelegate(old_delegate); |
460 } | 448 } |
461 | 449 |
462 } // namespace content | 450 } // namespace content |
OLD | NEW |