Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 | 1222 |
| 1223 // This should not clear the pending entry or notify of a navigation state | 1223 // This should not clear the pending entry or notify of a navigation state |
| 1224 // change, so that we keep displaying kNewURL (until the user clears it). | 1224 // change, so that we keep displaying kNewURL (until the user clears it). |
| 1225 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1225 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1226 EXPECT_TRUE(controller.GetPendingEntry()); | 1226 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1227 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1227 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 1228 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1228 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
| 1229 NavigationEntry* pending_entry = controller.GetPendingEntry(); | 1229 NavigationEntry* pending_entry = controller.GetPendingEntry(); |
| 1230 | 1230 |
| 1231 // Ensure that a reload keeps the same pending entry. | 1231 // Ensure that a reload keeps the same pending entry. |
| 1232 controller.Reload(true); | 1232 controller.Reload(ReloadType::NORMAL, true); |
| 1233 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1233 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
| 1234 EXPECT_TRUE(controller.GetPendingEntry()); | 1234 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1235 EXPECT_EQ(pending_entry, controller.GetPendingEntry()); | 1235 EXPECT_EQ(pending_entry, controller.GetPendingEntry()); |
| 1236 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1236 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
| 1237 | 1237 |
| 1238 contents()->SetDelegate(NULL); | 1238 contents()->SetDelegate(NULL); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 // Tests that the pending URL is not visible during a renderer-initiated | 1241 // Tests that the pending URL is not visible during a renderer-initiated |
| 1242 // redirect and abort. See http://crbug.com/83031. | 1242 // redirect and abort. See http://crbug.com/83031. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1369 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | 1369 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1370 EXPECT_EQ(0U, notifications.size()); | 1370 EXPECT_EQ(0U, notifications.size()); |
| 1371 main_test_rfh()->PrepareForCommit(); | 1371 main_test_rfh()->PrepareForCommit(); |
| 1372 main_test_rfh()->SendNavigate(entry_id, true, url1); | 1372 main_test_rfh()->SendNavigate(entry_id, true, url1); |
| 1373 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1373 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1374 navigation_entry_committed_counter_ = 0; | 1374 navigation_entry_committed_counter_ = 0; |
| 1375 ASSERT_TRUE(controller.GetVisibleEntry()); | 1375 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1376 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1376 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1377 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); | 1377 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1378 | 1378 |
| 1379 controller.Reload(true); | 1379 controller.Reload(ReloadType::NORMAL, true); |
| 1380 EXPECT_EQ(0U, notifications.size()); | 1380 EXPECT_EQ(0U, notifications.size()); |
| 1381 | 1381 |
| 1382 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1382 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
| 1383 EXPECT_FALSE(timestamp.is_null()); | 1383 EXPECT_FALSE(timestamp.is_null()); |
| 1384 | 1384 |
| 1385 // The reload is pending. | 1385 // The reload is pending. |
| 1386 EXPECT_EQ(controller.GetEntryCount(), 1); | 1386 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1387 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1387 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1388 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1388 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1389 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1389 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1425 | 1425 |
| 1426 controller.LoadURL( | 1426 controller.LoadURL( |
| 1427 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1427 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1428 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | 1428 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1429 main_test_rfh()->PrepareForCommit(); | 1429 main_test_rfh()->PrepareForCommit(); |
| 1430 main_test_rfh()->SendNavigate(entry_id, true, url1); | 1430 main_test_rfh()->SendNavigate(entry_id, true, url1); |
| 1431 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1431 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1432 navigation_entry_committed_counter_ = 0; | 1432 navigation_entry_committed_counter_ = 0; |
| 1433 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); | 1433 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1434 | 1434 |
| 1435 controller.Reload(true); | 1435 controller.Reload(ReloadType::NORMAL, true); |
| 1436 EXPECT_EQ(0U, notifications.size()); | 1436 EXPECT_EQ(0U, notifications.size()); |
| 1437 | 1437 |
| 1438 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); | 1438 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
| 1439 main_test_rfh()->SendNavigate(entry_id, true, url2); | 1439 main_test_rfh()->SendNavigate(entry_id, true, url2); |
| 1440 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1440 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1441 navigation_entry_committed_counter_ = 0; | 1441 navigation_entry_committed_counter_ = 0; |
| 1442 | 1442 |
| 1443 // Now the reload is committed. | 1443 // Now the reload is committed. |
| 1444 EXPECT_EQ(controller.GetEntryCount(), 2); | 1444 EXPECT_EQ(controller.GetEntryCount(), 2); |
| 1445 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1445 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1463 main_test_rfh()->PrepareForCommit(); | 1463 main_test_rfh()->PrepareForCommit(); |
| 1464 main_test_rfh()->SendNavigate(entry_id, true, url1); | 1464 main_test_rfh()->SendNavigate(entry_id, true, url1); |
| 1465 ASSERT_TRUE(controller.GetVisibleEntry()); | 1465 ASSERT_TRUE(controller.GetVisibleEntry()); |
| 1466 | 1466 |
| 1467 // Make the entry believe its RenderProcessHost is a guest. | 1467 // Make the entry believe its RenderProcessHost is a guest. |
| 1468 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); | 1468 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); |
| 1469 reinterpret_cast<MockRenderProcessHost*>( | 1469 reinterpret_cast<MockRenderProcessHost*>( |
| 1470 entry1->site_instance()->GetProcess())->set_is_for_guests_only(true); | 1470 entry1->site_instance()->GetProcess())->set_is_for_guests_only(true); |
| 1471 | 1471 |
| 1472 // And reload. | 1472 // And reload. |
| 1473 controller.Reload(true); | 1473 controller.Reload(ReloadType::NORMAL, true); |
| 1474 | 1474 |
| 1475 // The reload is pending. Check that the NavigationEntry didn't get replaced | 1475 // The reload is pending. Check that the NavigationEntry didn't get replaced |
| 1476 // because of having the wrong process. | 1476 // because of having the wrong process. |
| 1477 EXPECT_EQ(controller.GetEntryCount(), 1); | 1477 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1478 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1478 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1479 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1479 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1480 | 1480 |
| 1481 NavigationEntryImpl* entry2 = controller.GetPendingEntry(); | 1481 NavigationEntryImpl* entry2 = controller.GetPendingEntry(); |
| 1482 EXPECT_EQ(entry1, entry2); | 1482 EXPECT_EQ(entry1, entry2); |
| 1483 } | 1483 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1512 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); | 1512 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1513 | 1513 |
| 1514 // The NavigationEntry should save both the original URL and the final | 1514 // The NavigationEntry should save both the original URL and the final |
| 1515 // redirected URL. | 1515 // redirected URL. |
| 1516 EXPECT_EQ( | 1516 EXPECT_EQ( |
| 1517 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1517 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
| 1518 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1518 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
| 1519 | 1519 |
| 1520 // Reload using the original URL. | 1520 // Reload using the original URL. |
| 1521 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1521 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1522 controller.ReloadOriginalRequestURL(false); | 1522 controller.Reload(ReloadType::ORIGINAL_REQUEST_URL, false); |
|
Takashi Toyoshima
2016/12/15 06:21:52
testing
| |
| 1523 EXPECT_EQ(0U, notifications.size()); | 1523 EXPECT_EQ(0U, notifications.size()); |
| 1524 | 1524 |
| 1525 // The reload is pending. The request should point to the original URL. | 1525 // The reload is pending. The request should point to the original URL. |
| 1526 EXPECT_EQ(original_url, navigated_url()); | 1526 EXPECT_EQ(original_url, navigated_url()); |
| 1527 EXPECT_EQ(controller.GetEntryCount(), 1); | 1527 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 1528 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1528 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 1529 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1529 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 1530 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1530 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 1531 EXPECT_TRUE(controller.GetPendingEntry()); | 1531 EXPECT_TRUE(controller.GetPendingEntry()); |
| 1532 EXPECT_FALSE(controller.CanGoBack()); | 1532 EXPECT_FALSE(controller.CanGoBack()); |
| (...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3451 // A transient entry is added, interrupting the navigation. | 3451 // A transient entry is added, interrupting the navigation. |
| 3452 std::unique_ptr<NavigationEntry> transient_entry(new NavigationEntryImpl); | 3452 std::unique_ptr<NavigationEntry> transient_entry(new NavigationEntryImpl); |
| 3453 transient_entry->SetURL(transient_url); | 3453 transient_entry->SetURL(transient_url); |
| 3454 controller.SetTransientEntry(std::move(transient_entry)); | 3454 controller.SetTransientEntry(std::move(transient_entry)); |
| 3455 EXPECT_TRUE(controller.GetTransientEntry()); | 3455 EXPECT_TRUE(controller.GetTransientEntry()); |
| 3456 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3456 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 3457 | 3457 |
| 3458 // The page is reloaded, which should remove the pending entry for |url1| and | 3458 // The page is reloaded, which should remove the pending entry for |url1| and |
| 3459 // the transient entry for |transient_url|, and start a navigation to | 3459 // the transient entry for |transient_url|, and start a navigation to |
| 3460 // |transient_url|. | 3460 // |transient_url|. |
| 3461 controller.Reload(true); | 3461 controller.Reload(ReloadType::NORMAL, true); |
| 3462 entry_id = controller.GetPendingEntry()->GetUniqueID(); | 3462 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 3463 EXPECT_FALSE(controller.GetTransientEntry()); | 3463 EXPECT_FALSE(controller.GetTransientEntry()); |
| 3464 EXPECT_TRUE(controller.GetPendingEntry()); | 3464 EXPECT_TRUE(controller.GetPendingEntry()); |
| 3465 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3465 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
| 3466 ASSERT_EQ(controller.GetEntryCount(), 1); | 3466 ASSERT_EQ(controller.GetEntryCount(), 1); |
| 3467 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3467 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
| 3468 | 3468 |
| 3469 // Load of |transient_url| completes. | 3469 // Load of |transient_url| completes. |
| 3470 main_test_rfh()->PrepareForCommit(); | 3470 main_test_rfh()->PrepareForCommit(); |
| 3471 main_test_rfh()->SendNavigate(entry_id, true, transient_url); | 3471 main_test_rfh()->SendNavigate(entry_id, true, transient_url); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3974 NavigateAndCommit(url1); | 3974 NavigateAndCommit(url1); |
| 3975 controller.GetVisibleEntry()->SetTitle(title); | 3975 controller.GetVisibleEntry()->SetTitle(title); |
| 3976 NavigateAndCommit(url2); | 3976 NavigateAndCommit(url2); |
| 3977 | 3977 |
| 3978 std::unique_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 3978 std::unique_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
| 3979 clone->GetController().LoadIfNecessary(); | 3979 clone->GetController().LoadIfNecessary(); |
| 3980 | 3980 |
| 3981 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 3981 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
| 3982 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); | 3982 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); |
| 3983 | 3983 |
| 3984 clone->GetController().Reload(true); | 3984 clone->GetController().Reload(ReloadType::NORMAL, true); |
| 3985 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); | 3985 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); |
| 3986 } | 3986 } |
| 3987 | 3987 |
| 3988 // Make sure that cloning a WebContentsImpl doesn't copy interstitials. | 3988 // Make sure that cloning a WebContentsImpl doesn't copy interstitials. |
| 3989 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { | 3989 TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { |
| 3990 NavigationControllerImpl& controller = controller_impl(); | 3990 NavigationControllerImpl& controller = controller_impl(); |
| 3991 const GURL url1("http://foo1"); | 3991 const GURL url1("http://foo1"); |
| 3992 const GURL url2("http://foo2"); | 3992 const GURL url2("http://foo2"); |
| 3993 | 3993 |
| 3994 NavigateAndCommit(url1); | 3994 NavigateAndCommit(url1); |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5069 params.page_state = PageState::CreateFromURL(replace_url); | 5069 params.page_state = PageState::CreateFromURL(replace_url); |
| 5070 params.was_within_same_page = true; | 5070 params.was_within_same_page = true; |
| 5071 params.method = "GET"; | 5071 params.method = "GET"; |
| 5072 params.post_id = -1; | 5072 params.post_id = -1; |
| 5073 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); | 5073 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); |
| 5074 main_test_rfh()->PrepareForCommit(); | 5074 main_test_rfh()->PrepareForCommit(); |
| 5075 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 5075 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
| 5076 | 5076 |
| 5077 // Now reload. replaceState overrides the POST, so we should not show a | 5077 // Now reload. replaceState overrides the POST, so we should not show a |
| 5078 // repost warning dialog. | 5078 // repost warning dialog. |
| 5079 controller_impl().Reload(true); | 5079 controller_impl().Reload(ReloadType::NORMAL, true); |
| 5080 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 5080 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
| 5081 } | 5081 } |
| 5082 | 5082 |
| 5083 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { | 5083 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| 5084 GURL url("http://foo"); | 5084 GURL url("http://foo"); |
| 5085 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, | 5085 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 5086 std::string()); | 5086 std::string()); |
| 5087 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 5087 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 5088 params.nav_entry_id = 0; | 5088 params.nav_entry_id = 0; |
| 5089 params.did_create_new_entry = true; | 5089 params.did_create_new_entry = true; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5205 // means that occasionally a navigation conflict will end up with one entry | 5205 // means that occasionally a navigation conflict will end up with one entry |
| 5206 // bubbling to the end of the entry list, but that's the least-bad option. | 5206 // bubbling to the end of the entry list, but that's the least-bad option. |
| 5207 EXPECT_EQ(3, controller.GetEntryCount()); | 5207 EXPECT_EQ(3, controller.GetEntryCount()); |
| 5208 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 5208 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 5209 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); | 5209 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); |
| 5210 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); | 5210 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); |
| 5211 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); | 5211 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); |
| 5212 } | 5212 } |
| 5213 | 5213 |
| 5214 } // namespace content | 5214 } // namespace content |
| OLD | NEW |