OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 } // namespace | 501 } // namespace |
502 | 502 |
503 // When loading a new page to replace an old page in the history list, make sure | 503 // When loading a new page to replace an old page in the history list, make sure |
504 // that the browser and renderer agree, and that both get it right. | 504 // that the browser and renderer agree, and that both get it right. |
505 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 505 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
506 CorrectLengthWithCurrentItemReplacement) { | 506 CorrectLengthWithCurrentItemReplacement) { |
507 NavigationController& controller = | 507 NavigationController& controller = |
508 shell()->web_contents()->GetController(); | 508 shell()->web_contents()->GetController(); |
509 | 509 |
510 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); | 510 EXPECT_TRUE(NavigateToURL( |
| 511 shell(), embedded_test_server()->GetURL("/simple_page.html"))); |
511 EXPECT_EQ(1, controller.GetEntryCount()); | 512 EXPECT_EQ(1, controller.GetEntryCount()); |
512 EXPECT_EQ(1, RendererHistoryLength(shell())); | 513 EXPECT_EQ(1, RendererHistoryLength(shell())); |
513 | 514 |
514 EXPECT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page1a"))); | 515 EXPECT_TRUE(RendererLocationReplace( |
| 516 shell(), embedded_test_server()->GetURL("/title1.html"))); |
515 EXPECT_EQ(1, controller.GetEntryCount()); | 517 EXPECT_EQ(1, controller.GetEntryCount()); |
516 EXPECT_EQ(1, RendererHistoryLength(shell())); | 518 EXPECT_EQ(1, RendererHistoryLength(shell())); |
517 | 519 |
518 // Now create two more entries and go back, to test replacing an entry without | 520 // Now create two more entries and go back, to test replacing an entry without |
519 // pruning the forward history. | 521 // pruning the forward history. |
520 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page2"))); | 522 EXPECT_TRUE( |
| 523 NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html"))); |
521 EXPECT_EQ(2, controller.GetEntryCount()); | 524 EXPECT_EQ(2, controller.GetEntryCount()); |
522 EXPECT_EQ(2, RendererHistoryLength(shell())); | 525 EXPECT_EQ(2, RendererHistoryLength(shell())); |
523 | 526 |
524 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page3"))); | 527 EXPECT_TRUE( |
| 528 NavigateToURL(shell(), embedded_test_server()->GetURL("/title3.html"))); |
525 EXPECT_EQ(3, controller.GetEntryCount()); | 529 EXPECT_EQ(3, controller.GetEntryCount()); |
526 EXPECT_EQ(3, RendererHistoryLength(shell())); | 530 EXPECT_EQ(3, RendererHistoryLength(shell())); |
527 | 531 |
528 controller.GoBack(); | 532 controller.GoBack(); |
529 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 533 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
530 controller.GoBack(); | 534 controller.GoBack(); |
531 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 535 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
532 EXPECT_TRUE(controller.CanGoForward()); | 536 EXPECT_TRUE(controller.CanGoForward()); |
533 | 537 |
534 EXPECT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page1b"))); | 538 EXPECT_TRUE(RendererLocationReplace( |
| 539 shell(), embedded_test_server()->GetURL("/simple_page.html?page1b"))); |
535 EXPECT_EQ(3, controller.GetEntryCount()); | 540 EXPECT_EQ(3, controller.GetEntryCount()); |
536 EXPECT_EQ(3, RendererHistoryLength(shell())); | 541 EXPECT_EQ(3, RendererHistoryLength(shell())); |
537 EXPECT_TRUE(controller.CanGoForward()); | 542 EXPECT_TRUE(controller.CanGoForward()); |
538 | 543 |
539 // Note that there's no way to access the renderer's notion of the history | 544 // Note that there's no way to access the renderer's notion of the history |
540 // offset via JavaScript. Checking just the history length, though, is enough; | 545 // offset via JavaScript. Checking just the history length, though, is enough; |
541 // if the replacement failed, there would be a new history entry and thus an | 546 // if the replacement failed, there would be a new history entry and thus an |
542 // incorrect length. | 547 // incorrect length. |
543 } | 548 } |
544 | 549 |
(...skipping 5726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6271 EXPECT_THAT(headers, | 6276 EXPECT_THAT(headers, |
6272 ::testing::ContainsRegex( | 6277 ::testing::ContainsRegex( |
6273 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); | 6278 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); |
6274 } | 6279 } |
6275 | 6280 |
6276 // Check that the favicon is not cleared for navigating in-page. | 6281 // Check that the favicon is not cleared for navigating in-page. |
6277 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 6282 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
6278 InPageNavigationDoesNotClearFavicon) { | 6283 InPageNavigationDoesNotClearFavicon) { |
6279 // Load a page and fake a favicon for it. | 6284 // Load a page and fake a favicon for it. |
6280 NavigationController& controller = shell()->web_contents()->GetController(); | 6285 NavigationController& controller = shell()->web_contents()->GetController(); |
6281 ASSERT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); | 6286 ASSERT_TRUE(NavigateToURL( |
| 6287 shell(), embedded_test_server()->GetURL("/simple_page.html"))); |
6282 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 6288 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
6283 ASSERT_TRUE(entry); | 6289 ASSERT_TRUE(entry); |
6284 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 6290 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
6285 favicon_status.valid = true; | 6291 favicon_status.valid = true; |
6286 | 6292 |
6287 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page1#"))); | 6293 ASSERT_TRUE(RendererLocationReplace( |
| 6294 shell(), embedded_test_server()->GetURL( |
| 6295 "/simple_page.html#same-document-navigation"))); |
6288 entry = controller.GetLastCommittedEntry(); | 6296 entry = controller.GetLastCommittedEntry(); |
6289 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); | 6297 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); |
6290 EXPECT_TRUE(favicon_status2.valid); | 6298 EXPECT_TRUE(favicon_status2.valid); |
6291 | 6299 |
6292 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page2"))); | 6300 ASSERT_TRUE(RendererLocationReplace( |
| 6301 shell(), |
| 6302 embedded_test_server()->GetURL("/simple_page.html?new-navigation"))); |
6293 entry = controller.GetLastCommittedEntry(); | 6303 entry = controller.GetLastCommittedEntry(); |
6294 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); | 6304 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); |
6295 EXPECT_FALSE(favicon_status3.valid); | 6305 EXPECT_FALSE(favicon_status3.valid); |
6296 } | 6306 } |
6297 | 6307 |
6298 namespace { | 6308 namespace { |
6299 | 6309 |
6300 // A BrowserMessageFilter that delays the FrameHostMsg_RunJavaScriptDialog IPC | 6310 // A BrowserMessageFilter that delays the FrameHostMsg_RunJavaScriptDialog IPC |
6301 // message until a commit happens on a given WebContents. This allows testing a | 6311 // message until a commit happens on a given WebContents. This allows testing a |
6302 // race condition. | 6312 // race condition. |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6809 // For non-PlzNavigate case, this happens asynchronously. | 6819 // For non-PlzNavigate case, this happens asynchronously. |
6810 if (!IsBrowserSideNavigationEnabled()) | 6820 if (!IsBrowserSideNavigationEnabled()) |
6811 same_tab_observer.Wait(); | 6821 same_tab_observer.Wait(); |
6812 | 6822 |
6813 const NavigationController& controller = | 6823 const NavigationController& controller = |
6814 shell()->web_contents()->GetController(); | 6824 shell()->web_contents()->GetController(); |
6815 ASSERT_EQ(controller.GetPendingEntry(), nullptr); | 6825 ASSERT_EQ(controller.GetPendingEntry(), nullptr); |
6816 } | 6826 } |
6817 | 6827 |
6818 } // namespace content | 6828 } // namespace content |
OLD | NEW |