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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 2657323003: Convert HistoryTabHelper to use the new navigation callbacks. (Closed)
Patch Set: better fix to send this data from the renderer initially Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 3464 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 contents()->GetFrameTree()->root()->navigator(); 3475 contents()->GetFrameTree()->root()->navigator();
3476 3476
3477 const GURL url1("nonexistent:12121"); 3477 const GURL url1("nonexistent:12121");
3478 const GURL url1_fixed("http://nonexistent:12121/"); 3478 const GURL url1_fixed("http://nonexistent:12121/");
3479 const GURL url2("http://foo"); 3479 const GURL url2("http://foo");
3480 3480
3481 // We create pending entries for renderer-initiated navigations so that we 3481 // We create pending entries for renderer-initiated navigations so that we
3482 // can show them in new tabs when it is safe. 3482 // can show them in new tabs when it is safe.
3483 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false); 3483 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, false);
3484 main_test_rfh()->PrepareForCommit(); 3484 main_test_rfh()->PrepareForCommit();
3485 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, 3485 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, std::vector<GURL>(),
3486 base::TimeTicks::Now()); 3486 base::TimeTicks::Now());
3487 3487
3488 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing 3488 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing
3489 // the virtual URL to differ from the URL. 3489 // the virtual URL to differ from the URL.
3490 controller.GetPendingEntry()->SetURL(url1_fixed); 3490 controller.GetPendingEntry()->SetURL(url1_fixed);
3491 controller.GetPendingEntry()->SetVirtualURL(url1); 3491 controller.GetPendingEntry()->SetVirtualURL(url1);
3492 3492
3493 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); 3493 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL());
3494 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); 3494 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL());
3495 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3495 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
3496 3496
3497 // If the user clicks another link, we should replace the pending entry. 3497 // If the user clicks another link, we should replace the pending entry.
3498 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); 3498 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
3499 main_test_rfh()->PrepareForCommit(); 3499 main_test_rfh()->PrepareForCommit();
3500 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, 3500 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, std::vector<GURL>(),
3501 base::TimeTicks::Now()); 3501 base::TimeTicks::Now());
3502 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 3502 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
3503 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); 3503 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL());
3504 3504
3505 // Once it commits, the URL and virtual URL should reflect the actual page. 3505 // Once it commits, the URL and virtual URL should reflect the actual page.
3506 main_test_rfh()->SendNavigate(0, true, url2); 3506 main_test_rfh()->SendNavigate(0, true, url2);
3507 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3507 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
3508 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); 3508 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL());
3509 3509
3510 // We should not replace the pending entry for an error URL. 3510 // We should not replace the pending entry for an error URL.
3511 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, 3511 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, std::vector<GURL>(),
3512 base::TimeTicks::Now()); 3512 base::TimeTicks::Now());
3513 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3513 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3514 navigator->DidStartProvisionalLoad( 3514 navigator->DidStartProvisionalLoad(
3515 main_test_rfh(), GURL(kUnreachableWebDataURL), base::TimeTicks::Now()); 3515 main_test_rfh(), GURL(kUnreachableWebDataURL), std::vector<GURL>(),
3516 base::TimeTicks::Now());
3516 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3517 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3517 3518
3518 // We should remember if the pending entry will replace the current one. 3519 // We should remember if the pending entry will replace the current one.
3519 // http://crbug.com/308444. 3520 // http://crbug.com/308444.
3520 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, 3521 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, std::vector<GURL>(),
3521 base::TimeTicks::Now()); 3522 base::TimeTicks::Now());
3522 controller.GetPendingEntry()->set_should_replace_entry(true); 3523 controller.GetPendingEntry()->set_should_replace_entry(true);
3523 3524
3524 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); 3525 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false);
3525 main_test_rfh()->PrepareForCommit(); 3526 main_test_rfh()->PrepareForCommit();
3526 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, 3527 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, std::vector<GURL>(),
3527 base::TimeTicks::Now()); 3528 base::TimeTicks::Now());
3528 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); 3529 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry());
3529 main_test_rfh()->SendNavigateWithReplacement(0, false, url2); 3530 main_test_rfh()->SendNavigateWithReplacement(0, false, url2);
3530 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3531 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
3531 } 3532 }
3532 3533
3533 // Tests that the URLs for renderer-initiated navigations are not displayed to 3534 // Tests that the URLs for renderer-initiated navigations are not displayed to
3534 // the user until the navigation commits, to prevent URL spoof attacks. 3535 // the user until the navigation commits, to prevent URL spoof attacks.
3535 // See http://crbug.com/99016. 3536 // See http://crbug.com/99016.
3536 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 3537 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after
5279 main_test_rfh()->SimulateNavigationStart(url_1); 5280 main_test_rfh()->SimulateNavigationStart(url_1);
5280 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL()); 5281 EXPECT_EQ(url_1, controller.GetVisibleEntry()->GetURL());
5281 EXPECT_EQ(ReloadType::NONE, last_reload_type_); 5282 EXPECT_EQ(ReloadType::NONE, last_reload_type_);
5282 5283
5283 main_test_rfh()->SimulateNavigationCommit(url_2); 5284 main_test_rfh()->SimulateNavigationCommit(url_2);
5284 main_test_rfh()->SimulateNavigationCommit(url_1); 5285 main_test_rfh()->SimulateNavigationCommit(url_1);
5285 main_test_rfh()->SimulateNavigationCommit(url_1); 5286 main_test_rfh()->SimulateNavigationCommit(url_1);
5286 } 5287 }
5287 5288
5288 } // namespace content 5289 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698