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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // The number of times ShowRepostFormWarningDialog() was called. | 291 // The number of times ShowRepostFormWarningDialog() was called. |
292 int repost_form_warning_count_; | 292 int repost_form_warning_count_; |
293 }; | 293 }; |
294 | 294 |
295 // ----------------------------------------------------------------------------- | 295 // ----------------------------------------------------------------------------- |
296 | 296 |
297 TEST_F(NavigationControllerTest, Defaults) { | 297 TEST_F(NavigationControllerTest, Defaults) { |
298 NavigationControllerImpl& controller = controller_impl(); | 298 NavigationControllerImpl& controller = controller_impl(); |
299 | 299 |
300 EXPECT_FALSE(controller.GetPendingEntry()); | 300 EXPECT_FALSE(controller.GetPendingEntry()); |
301 EXPECT_FALSE(controller.GetVisibleEntry()); | 301 EXPECT_TRUE(controller.IsInitialNavigation()); |
302 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 302 EXPECT_TRUE(controller.GetVisibleEntry()); |
| 303 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 304 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 305 EXPECT_EQ(controller.GetEntryCount(), 1); |
303 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 306 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
304 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | |
305 EXPECT_EQ(controller.GetEntryCount(), 0); | |
306 EXPECT_FALSE(controller.CanGoBack()); | 307 EXPECT_FALSE(controller.CanGoBack()); |
307 EXPECT_FALSE(controller.CanGoForward()); | 308 EXPECT_FALSE(controller.CanGoForward()); |
308 } | 309 } |
309 | 310 |
310 TEST_F(NavigationControllerTest, GoToOffset) { | 311 TEST_F(NavigationControllerTest, GoToOffset) { |
311 NavigationControllerImpl& controller = controller_impl(); | 312 NavigationControllerImpl& controller = controller_impl(); |
312 TestNotificationTracker notifications; | 313 TestNotificationTracker notifications; |
313 RegisterForAllNavNotifications(¬ifications, &controller); | 314 RegisterForAllNavNotifications(¬ifications, &controller); |
314 | 315 |
315 const int kNumUrls = 5; | 316 const int kNumUrls = 5; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 382 } |
382 | 383 |
383 TEST_F(NavigationControllerTest, LoadURL) { | 384 TEST_F(NavigationControllerTest, LoadURL) { |
384 NavigationControllerImpl& controller = controller_impl(); | 385 NavigationControllerImpl& controller = controller_impl(); |
385 TestNotificationTracker notifications; | 386 TestNotificationTracker notifications; |
386 RegisterForAllNavNotifications(¬ifications, &controller); | 387 RegisterForAllNavNotifications(¬ifications, &controller); |
387 | 388 |
388 const GURL url1("http://foo1"); | 389 const GURL url1("http://foo1"); |
389 const GURL url2("http://foo2"); | 390 const GURL url2("http://foo2"); |
390 | 391 |
| 392 // We start with an entry for the initial blank page. |
| 393 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 394 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 395 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 396 |
391 controller.LoadURL( | 397 controller.LoadURL( |
392 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 398 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
393 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | 399 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
394 // Creating a pending notification should not have issued any of the | 400 // Creating a pending notification should not have issued any of the |
395 // notifications we're listening for. | 401 // notifications we're listening for. |
396 EXPECT_EQ(0U, notifications.size()); | 402 EXPECT_EQ(0U, notifications.size()); |
397 | 403 |
398 // The load should now be pending. | 404 // The load should now be pending. |
399 EXPECT_EQ(controller.GetEntryCount(), 0); | |
400 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | |
401 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 405 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
402 EXPECT_FALSE(controller.GetLastCommittedEntry()); | |
403 ASSERT_TRUE(controller.GetPendingEntry()); | 406 ASSERT_TRUE(controller.GetPendingEntry()); |
404 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 407 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
405 EXPECT_FALSE(controller.CanGoBack()); | 408 EXPECT_FALSE(controller.CanGoBack()); |
406 EXPECT_FALSE(controller.CanGoForward()); | 409 EXPECT_FALSE(controller.CanGoForward()); |
407 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 410 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
408 | 411 |
409 // Neither the timestamp nor the status code should have been set yet. | 412 // Neither the timestamp nor the status code should have been set yet. |
410 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 413 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
411 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 414 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
412 | 415 |
413 // We should have gotten no notifications from the preceeding checks. | 416 // We should have gotten no notifications from the preceeding checks. |
414 EXPECT_EQ(0U, notifications.size()); | 417 EXPECT_EQ(0U, notifications.size()); |
415 | 418 |
416 main_test_rfh()->PrepareForCommit(); | 419 main_test_rfh()->PrepareForCommit(); |
417 main_test_rfh()->SendNavigate(0, entry_id, true, url1); | 420 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
418 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 421 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
419 navigation_entry_committed_counter_ = 0; | 422 navigation_entry_committed_counter_ = 0; |
420 | 423 |
421 // The load should now be committed. | 424 // The load should now be committed, replacing the initial entry. |
422 EXPECT_EQ(controller.GetEntryCount(), 1); | 425 EXPECT_EQ(controller.GetEntryCount(), 1); |
423 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 426 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
424 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 427 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
425 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 428 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
426 EXPECT_FALSE(controller.GetPendingEntry()); | 429 EXPECT_FALSE(controller.GetPendingEntry()); |
427 ASSERT_TRUE(controller.GetVisibleEntry()); | 430 ASSERT_TRUE(controller.GetVisibleEntry()); |
428 EXPECT_FALSE(controller.CanGoBack()); | 431 EXPECT_FALSE(controller.CanGoBack()); |
429 EXPECT_FALSE(controller.CanGoForward()); | 432 EXPECT_FALSE(controller.CanGoForward()); |
430 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 433 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
431 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 434 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 // Without any navigations, the renderer starts at about:blank. | 1004 // Without any navigations, the renderer starts at about:blank. |
1002 const GURL kExistingURL(url::kAboutBlankURL); | 1005 const GURL kExistingURL(url::kAboutBlankURL); |
1003 | 1006 |
1004 // Now make a pending new navigation. | 1007 // Now make a pending new navigation. |
1005 const GURL kNewURL("http://eh"); | 1008 const GURL kNewURL("http://eh"); |
1006 controller.LoadURL( | 1009 controller.LoadURL( |
1007 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1010 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1008 EXPECT_EQ(0U, notifications.size()); | 1011 EXPECT_EQ(0U, notifications.size()); |
1009 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1012 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1010 EXPECT_TRUE(controller.GetPendingEntry()); | 1013 EXPECT_TRUE(controller.GetPendingEntry()); |
1011 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1014 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1015 EXPECT_TRUE(controller.IsInitialNavigation()); |
1012 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1016 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
1013 | 1017 |
1014 // Before that commits, a document.write and location.reload can cause the | 1018 // Before that commits, a document.write and location.reload can cause the |
1015 // renderer to send a FrameNavigate with page_id -1 and nav_entry_id 0. | 1019 // renderer to send a FrameNavigate with page_id -1 and nav_entry_id 0. |
1016 // PlzNavigate: this will stop the old navigation and start a new one. | 1020 // PlzNavigate: this will stop the old navigation and start a new one. |
1017 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); | 1021 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); |
1018 main_test_rfh()->SendNavigate(-1, 0, false, kExistingURL); | 1022 main_test_rfh()->SendNavigate(-1, 0, false, kExistingURL); |
1019 | 1023 |
1020 // This should clear the pending entry and notify of a navigation state | 1024 // This should clear the pending entry and notify of a navigation state |
1021 // change, so that we do not keep displaying kNewURL. | 1025 // change, so that we do not keep displaying kNewURL. |
1022 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1026 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1023 EXPECT_FALSE(controller.GetPendingEntry()); | 1027 EXPECT_FALSE(controller.GetPendingEntry()); |
1024 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1028 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1029 EXPECT_TRUE(controller.IsInitialNavigation()); |
1025 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1030 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1026 switches::kEnableBrowserSideNavigation)) | 1031 switches::kEnableBrowserSideNavigation)) |
1027 EXPECT_EQ(4, delegate->navigation_state_change_count()); | 1032 EXPECT_EQ(4, delegate->navigation_state_change_count()); |
1028 else | 1033 else |
1029 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 1034 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
1030 | 1035 |
1031 contents()->SetDelegate(NULL); | 1036 contents()->SetDelegate(NULL); |
1032 } | 1037 } |
1033 | 1038 |
1034 // Tests that the pending entry state is correct after an abort. | 1039 // Tests that the pending entry state is correct after an abort. |
(...skipping 10 matching lines...) Expand all Loading... |
1045 contents()->SetDelegate(delegate.get()); | 1050 contents()->SetDelegate(delegate.get()); |
1046 | 1051 |
1047 // Start with a pending new navigation. | 1052 // Start with a pending new navigation. |
1048 const GURL kNewURL("http://eh"); | 1053 const GURL kNewURL("http://eh"); |
1049 controller.LoadURL( | 1054 controller.LoadURL( |
1050 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1055 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1051 main_test_rfh()->PrepareForCommit(); | 1056 main_test_rfh()->PrepareForCommit(); |
1052 EXPECT_EQ(0U, notifications.size()); | 1057 EXPECT_EQ(0U, notifications.size()); |
1053 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1058 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1054 EXPECT_TRUE(controller.GetPendingEntry()); | 1059 EXPECT_TRUE(controller.GetPendingEntry()); |
1055 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1060 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1061 EXPECT_TRUE(controller.IsInitialNavigation()); |
1056 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1062 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
1057 | 1063 |
1058 // It may abort before committing, if it's a download or due to a stop or | 1064 // It may abort before committing, if it's a download or due to a stop or |
1059 // a new navigation from the user. | 1065 // a new navigation from the user. |
1060 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; | 1066 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; |
1061 params.error_code = net::ERR_ABORTED; | 1067 params.error_code = net::ERR_ABORTED; |
1062 params.error_description = base::string16(); | 1068 params.error_description = base::string16(); |
1063 params.url = kNewURL; | 1069 params.url = kNewURL; |
1064 params.showing_repost_interstitial = false; | 1070 params.showing_repost_interstitial = false; |
1065 main_test_rfh()->OnMessageReceived( | 1071 main_test_rfh()->OnMessageReceived( |
1066 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 1072 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
1067 params)); | 1073 params)); |
1068 | 1074 |
1069 // This should not clear the pending entry or notify of a navigation state | 1075 // This should not clear the pending entry or notify of a navigation state |
1070 // change, so that we keep displaying kNewURL (until the user clears it). | 1076 // change, so that we keep displaying kNewURL (until the user clears it). |
1071 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1077 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1072 EXPECT_TRUE(controller.GetPendingEntry()); | 1078 EXPECT_TRUE(controller.GetPendingEntry()); |
1073 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1079 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1080 EXPECT_TRUE(controller.IsInitialNavigation()); |
1074 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1081 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
1075 NavigationEntry* pending_entry = controller.GetPendingEntry(); | 1082 NavigationEntry* pending_entry = controller.GetPendingEntry(); |
1076 | 1083 |
1077 // Ensure that a reload keeps the same pending entry. | 1084 // Ensure that a reload keeps the same pending entry. |
1078 controller.Reload(true); | 1085 controller.Reload(true); |
1079 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1086 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1080 EXPECT_TRUE(controller.GetPendingEntry()); | 1087 EXPECT_TRUE(controller.GetPendingEntry()); |
1081 EXPECT_EQ(pending_entry, controller.GetPendingEntry()); | 1088 EXPECT_EQ(pending_entry, controller.GetPendingEntry()); |
1082 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1089 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 1090 EXPECT_TRUE(controller.IsInitialNavigation()); |
1083 | 1091 |
1084 contents()->SetDelegate(NULL); | 1092 contents()->SetDelegate(NULL); |
1085 } | 1093 } |
1086 | 1094 |
1087 // Tests that the pending URL is not visible during a renderer-initiated | 1095 // Tests that the pending URL is not visible during a renderer-initiated |
1088 // redirect and abort. See http://crbug.com/83031. | 1096 // redirect and abort. See http://crbug.com/83031. |
1089 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { | 1097 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { |
1090 NavigationControllerImpl& controller = controller_impl(); | 1098 NavigationControllerImpl& controller = controller_impl(); |
1091 TestNotificationTracker notifications; | 1099 TestNotificationTracker notifications; |
1092 RegisterForAllNavNotifications(¬ifications, &controller); | 1100 RegisterForAllNavNotifications(¬ifications, &controller); |
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2639 controller.GoBack(); | 2647 controller.GoBack(); |
2640 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | 2648 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2641 main_test_rfh()->PrepareForCommit(); | 2649 main_test_rfh()->PrepareForCommit(); |
2642 main_test_rfh()->SendNavigate(1, entry_id, false, url); | 2650 main_test_rfh()->SendNavigate(1, entry_id, false, url); |
2643 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2651 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2644 navigation_entry_committed_counter_ = 0; | 2652 navigation_entry_committed_counter_ = 0; |
2645 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2653 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
2646 } | 2654 } |
2647 } | 2655 } |
2648 | 2656 |
2649 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) | 2657 TEST_F(NavigationControllerTest, PushStateWithoutCommittedEntry) |
2650 { | 2658 { |
2651 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); | 2659 ASSERT_TRUE(controller_impl().IsInitialNavigation()); |
2652 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2660 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2653 GURL url("http://foo"); | 2661 GURL url("http://foo"); |
2654 params.page_id = 1; | 2662 params.page_id = 1; |
2655 params.nav_entry_id = 0; | 2663 params.nav_entry_id = 0; |
2656 params.did_create_new_entry = true; | 2664 params.did_create_new_entry = true; |
2657 params.url = url; | 2665 params.url = url; |
2658 params.page_state = PageState::CreateFromURL(url); | 2666 params.page_state = PageState::CreateFromURL(url); |
2659 params.was_within_same_page = true; | 2667 params.was_within_same_page = true; |
2660 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 2668 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
2661 main_test_rfh()->PrepareForCommit(); | 2669 main_test_rfh()->PrepareForCommit(); |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3389 EXPECT_TRUE(controller.IsInitialNavigation()); | 3397 EXPECT_TRUE(controller.IsInitialNavigation()); |
3390 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3398 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3391 | 3399 |
3392 // There should be no title yet. | 3400 // There should be no title yet. |
3393 EXPECT_TRUE(contents()->GetTitle().empty()); | 3401 EXPECT_TRUE(contents()->GetTitle().empty()); |
3394 | 3402 |
3395 // If something else modifies the contents of the about:blank page, then | 3403 // If something else modifies the contents of the about:blank page, then |
3396 // we must revert to showing about:blank to avoid a URL spoof. | 3404 // we must revert to showing about:blank to avoid a URL spoof. |
3397 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); | 3405 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
3398 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); | 3406 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
3399 EXPECT_FALSE(controller.GetVisibleEntry()); | 3407 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 3408 EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry()); |
| 3409 EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 3410 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL()); |
3400 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3411 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
3401 | 3412 |
3402 notifications.Reset(); | 3413 notifications.Reset(); |
3403 } | 3414 } |
3404 | 3415 |
3405 // Tests that the URLs for browser-initiated navigations in new tabs are | 3416 // Tests that the URLs for browser-initiated navigations in new tabs are |
3406 // displayed to the user even after they fail, as long as the initial | 3417 // displayed to the user even after they fail, as long as the initial |
3407 // about:blank page has not been modified. If so, we must revert to showing | 3418 // about:blank page has not been modified. If so, we must revert to showing |
3408 // about:blank. See http://crbug.com/355537. | 3419 // about:blank. See http://crbug.com/355537. |
3409 TEST_F(NavigationControllerTest, ShowBrowserURLAfterFailUntilModified) { | 3420 TEST_F(NavigationControllerTest, ShowBrowserURLAfterFailUntilModified) { |
(...skipping 29 matching lines...) Expand all Loading... |
3439 params.showing_repost_interstitial = false; | 3450 params.showing_repost_interstitial = false; |
3440 main_test_rfh()->OnMessageReceived( | 3451 main_test_rfh()->OnMessageReceived( |
3441 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); | 3452 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); |
3442 contents()->SetIsLoading(false, true, NULL); | 3453 contents()->SetIsLoading(false, true, NULL); |
3443 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 3454 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
3444 | 3455 |
3445 // If something else later modifies the contents of the about:blank page, then | 3456 // If something else later modifies the contents of the about:blank page, then |
3446 // we must revert to showing about:blank to avoid a URL spoof. | 3457 // we must revert to showing about:blank to avoid a URL spoof. |
3447 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); | 3458 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
3448 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); | 3459 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
3449 EXPECT_FALSE(controller.GetVisibleEntry()); | 3460 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 3461 EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry()); |
| 3462 EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 3463 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL()); |
3450 EXPECT_FALSE(controller.GetPendingEntry()); | 3464 EXPECT_FALSE(controller.GetPendingEntry()); |
3451 | 3465 |
3452 notifications.Reset(); | 3466 notifications.Reset(); |
3453 } | 3467 } |
3454 | 3468 |
3455 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3469 // Tests that the URLs for renderer-initiated navigations in new tabs are |
3456 // displayed to the user even after they fail, as long as the initial | 3470 // displayed to the user even after they fail, as long as the initial |
3457 // about:blank page has not been modified. If so, we must revert to showing | 3471 // about:blank page has not been modified. If so, we must revert to showing |
3458 // about:blank. See http://crbug.com/355537. | 3472 // about:blank. See http://crbug.com/355537. |
3459 TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) { | 3473 TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) { |
(...skipping 27 matching lines...) Expand all Loading... |
3487 params.url = url; | 3501 params.url = url; |
3488 params.showing_repost_interstitial = false; | 3502 params.showing_repost_interstitial = false; |
3489 main_test_rfh()->OnMessageReceived( | 3503 main_test_rfh()->OnMessageReceived( |
3490 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); | 3504 FrameHostMsg_DidFailProvisionalLoadWithError(0, params)); |
3491 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 3505 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
3492 | 3506 |
3493 // If something else later modifies the contents of the about:blank page, then | 3507 // If something else later modifies the contents of the about:blank page, then |
3494 // we must revert to showing about:blank to avoid a URL spoof. | 3508 // we must revert to showing about:blank to avoid a URL spoof. |
3495 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); | 3509 main_test_rfh()->OnMessageReceived(FrameHostMsg_DidAccessInitialDocument(0)); |
3496 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); | 3510 EXPECT_TRUE(contents()->HasAccessedInitialDocument()); |
3497 EXPECT_FALSE(controller.GetVisibleEntry()); | 3511 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 3512 EXPECT_EQ(controller.GetLastCommittedEntry(), controller.GetVisibleEntry()); |
| 3513 EXPECT_NE(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
| 3514 EXPECT_EQ(GURL(url::kAboutBlankURL), controller.GetVisibleEntry()->GetURL()); |
3498 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); | 3515 EXPECT_EQ(url, controller.GetPendingEntry()->GetURL()); |
3499 | 3516 |
3500 notifications.Reset(); | 3517 notifications.Reset(); |
3501 } | 3518 } |
3502 | 3519 |
3503 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { | 3520 TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { |
3504 NavigationControllerImpl& controller = controller_impl(); | 3521 NavigationControllerImpl& controller = controller_impl(); |
3505 TestNotificationTracker notifications; | 3522 TestNotificationTracker notifications; |
3506 RegisterForAllNavNotifications(¬ifications, &controller); | 3523 RegisterForAllNavNotifications(¬ifications, &controller); |
3507 | 3524 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 | 3774 |
3758 // Set the controller as active, triggering the requested reload. | 3775 // Set the controller as active, triggering the requested reload. |
3759 controller.SetActive(true); | 3776 controller.SetActive(true); |
3760 ASSERT_FALSE(controller.NeedsReload()); | 3777 ASSERT_FALSE(controller.NeedsReload()); |
3761 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, | 3778 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, |
3762 controller.GetPendingEntry()->GetTransitionType()); | 3779 controller.GetPendingEntry()->GetTransitionType()); |
3763 } | 3780 } |
3764 | 3781 |
3765 // Test requesting and triggering a lazy reload without any committed entry nor | 3782 // Test requesting and triggering a lazy reload without any committed entry nor |
3766 // pending entry. | 3783 // pending entry. |
| 3784 // TODO(creis): Does this test make sense anymore? |
3767 TEST_F(NavigationControllerTest, LazyReloadWithoutCommittedEntry) { | 3785 TEST_F(NavigationControllerTest, LazyReloadWithoutCommittedEntry) { |
3768 NavigationControllerImpl& controller = controller_impl(); | 3786 NavigationControllerImpl& controller = controller_impl(); |
3769 ASSERT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 3787 ASSERT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 3788 ASSERT_TRUE(controller.IsInitialNavigation()); |
3770 EXPECT_FALSE(controller.NeedsReload()); | 3789 EXPECT_FALSE(controller.NeedsReload()); |
3771 controller.SetNeedsReload(); | 3790 controller.SetNeedsReload(); |
3772 EXPECT_TRUE(controller.NeedsReload()); | 3791 EXPECT_TRUE(controller.NeedsReload()); |
3773 | 3792 |
3774 // Doing a "load if necessary" shouldn't DCHECK. | 3793 // Doing a "load if necessary" shouldn't DCHECK. |
3775 controller.LoadIfNecessary(); | 3794 controller.LoadIfNecessary(); |
3776 ASSERT_FALSE(controller.NeedsReload()); | 3795 ASSERT_FALSE(controller.NeedsReload()); |
3777 } | 3796 } |
3778 | 3797 |
3779 // Test requesting and triggering a lazy reload without any committed entry and | 3798 // Test requesting and triggering a lazy reload without any committed entry and |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4554 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4573 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4555 } | 4574 } |
4556 | 4575 |
4557 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 4576 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
4558 NavigationControllerImpl& controller = controller_impl(); | 4577 NavigationControllerImpl& controller = controller_impl(); |
4559 TestNotificationTracker notifications; | 4578 TestNotificationTracker notifications; |
4560 RegisterForAllNavNotifications(¬ifications, &controller); | 4579 RegisterForAllNavNotifications(¬ifications, &controller); |
4561 | 4580 |
4562 // Initial state. | 4581 // Initial state. |
4563 EXPECT_TRUE(controller.IsInitialNavigation()); | 4582 EXPECT_TRUE(controller.IsInitialNavigation()); |
| 4583 EXPECT_TRUE(controller.IsInitialBlankNavigation()); |
4564 | 4584 |
4565 // After commit, it stays false. | 4585 // After commit, it stays false. |
4566 const GURL url1("http://foo1"); | 4586 const GURL url1("http://foo1"); |
4567 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 4587 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
4568 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4588 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4569 navigation_entry_committed_counter_ = 0; | 4589 navigation_entry_committed_counter_ = 0; |
4570 EXPECT_FALSE(controller.IsInitialNavigation()); | 4590 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 4591 EXPECT_FALSE(controller.IsInitialBlankNavigation()); |
4571 | 4592 |
4572 // After starting a new navigation, it stays false. | 4593 // After starting a new navigation, it stays false. |
4573 const GURL url2("http://foo2"); | 4594 const GURL url2("http://foo2"); |
4574 controller.LoadURL( | 4595 controller.LoadURL( |
4575 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4596 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4597 EXPECT_FALSE(controller.IsInitialNavigation()); |
| 4598 EXPECT_FALSE(controller.IsInitialBlankNavigation()); |
| 4599 |
| 4600 // For cloned tabs, IsInitialNavigationShould be true but |
| 4601 // IsInitialBlankNavigation should be false. |
| 4602 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
| 4603 EXPECT_TRUE(clone->GetController().IsInitialNavigation()); |
| 4604 EXPECT_FALSE(clone->GetController().IsInitialBlankNavigation()); |
4576 } | 4605 } |
4577 | 4606 |
4578 // Check that the favicon is not reused across a client redirect. | 4607 // Check that the favicon is not reused across a client redirect. |
4579 // (crbug.com/28515) | 4608 // (crbug.com/28515) |
4580 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 4609 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
4581 const GURL kPageWithFavicon("http://withfavicon.html"); | 4610 const GURL kPageWithFavicon("http://withfavicon.html"); |
4582 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 4611 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
4583 const GURL kIconURL("http://withfavicon.ico"); | 4612 const GURL kIconURL("http://withfavicon.ico"); |
4584 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 4613 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
4585 | 4614 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5039 EXPECT_EQ(default_ssl_status.connection_status, | 5068 EXPECT_EQ(default_ssl_status.connection_status, |
5040 details.ssl_status.connection_status); | 5069 details.ssl_status.connection_status); |
5041 EXPECT_EQ(default_ssl_status.content_status, | 5070 EXPECT_EQ(default_ssl_status.content_status, |
5042 details.ssl_status.content_status); | 5071 details.ssl_status.content_status); |
5043 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size()); | 5072 EXPECT_EQ(0u, details.ssl_status.signed_certificate_timestamp_ids.size()); |
5044 | 5073 |
5045 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); | 5074 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); |
5046 } | 5075 } |
5047 | 5076 |
5048 } // namespace content | 5077 } // namespace content |
OLD | NEW |