Chromium Code Reviews| Index: content/browser/frame_host/navigation_controller_impl_unittest.cc |
| diff --git a/content/browser/frame_host/navigation_controller_impl_unittest.cc b/content/browser/frame_host/navigation_controller_impl_unittest.cc |
| index 0abf6409dbb892e83d1b68974fccbfb08b13c793..12183ebbbc301768e0ba4fa78b9633d7f13f9e39 100644 |
| --- a/content/browser/frame_host/navigation_controller_impl_unittest.cc |
| +++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc |
| @@ -23,6 +23,7 @@ |
| #include "content/browser/frame_host/frame_navigation_entry.h" |
| #include "content/browser/frame_host/navigation_entry_impl.h" |
| #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| +#include "content/browser/frame_host/navigation_handle_impl.h" |
| #include "content/browser/frame_host/navigation_request.h" |
| #include "content/browser/frame_host/navigator.h" |
| #include "content/browser/frame_host/navigator_impl.h" |
| @@ -32,7 +33,6 @@ |
| #include "content/common/frame_owner_properties.h" |
| #include "content/common/site_isolation_policy.h" |
| #include "content/common/view_messages.h" |
| -#include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_view_host.h" |
| @@ -311,18 +311,36 @@ class LoadCommittedDetailsObserver : public WebContentsObserver { |
| public: |
| // Observes navigation for the specified |web_contents|. |
| explicit LoadCommittedDetailsObserver(WebContents* web_contents) |
| - : WebContentsObserver(web_contents) {} |
| - |
| - const LoadCommittedDetails& details() { return details_; } |
| + : WebContentsObserver(web_contents), |
| + type_(NAVIGATION_TYPE_UNKNOWN), |
| + is_in_page_(false), |
| + is_main_frame_(false), |
| + did_replace_entry_(false) {} |
| + |
| + NavigationType type() { return type_; } |
| + const GURL& previous_url() { return previous_url_; } |
| + bool is_in_page() { return is_in_page_; } |
| + bool is_main_frame() { return is_main_frame_; } |
| + bool did_replace_entry() { return did_replace_entry_; } |
| private: |
| - void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, |
| - const LoadCommittedDetails& details, |
| - const FrameNavigateParams& params) override { |
| - details_ = details; |
| + void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| + if (!navigation_handle->HasCommitted()) |
| + return; |
| + |
| + type_ = static_cast<NavigationHandleImpl*>(navigation_handle)-> |
| + navigation_type(); |
| + previous_url_ = navigation_handle->GetPreviousURL(); |
| + is_in_page_ = navigation_handle->IsSamePage(); |
| + is_main_frame_ = navigation_handle->IsInMainFrame(); |
| + did_replace_entry_ = navigation_handle->DidReplaceEntry(); |
| } |
| - LoadCommittedDetails details_; |
| + NavigationType type_; |
|
nasko
2017/02/09 00:29:11
nit: navigation_type_
jam
2017/02/09 01:15:03
Done.
|
| + GURL previous_url_; |
| + bool is_in_page_; |
| + bool is_main_frame_; |
| + bool did_replace_entry_; |
| }; |
| // PlzNavigate |
| @@ -2018,7 +2036,7 @@ TEST_F(NavigationControllerTest, Redirect) { |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type()); |
| EXPECT_EQ(controller.GetEntryCount(), 1); |
| EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| @@ -2086,7 +2104,7 @@ TEST_F(NavigationControllerTest, PostThenRedirect) { |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type()); |
| EXPECT_EQ(controller.GetEntryCount(), 1); |
| EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| @@ -2137,7 +2155,7 @@ TEST_F(NavigationControllerTest, ImmediateRedirect) { |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.type()); |
| EXPECT_EQ(controller.GetEntryCount(), 1); |
| EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| @@ -2197,7 +2215,7 @@ TEST_F(NavigationControllerTest, |
| main_test_rfh()->PrepareForCommit(); |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| - EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.type()); |
| } |
| // Tests navigation via link click within a subframe. A new navigation entry |
| @@ -2262,14 +2280,13 @@ TEST_F(NavigationControllerTest, NewSubframe) { |
| subframe->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_EQ(url1, observer.details().previous_url); |
| - EXPECT_FALSE(observer.details().is_in_page); |
| - EXPECT_FALSE(observer.details().is_main_frame); |
| + EXPECT_EQ(url1, observer.previous_url()); |
| + EXPECT_FALSE(observer.is_in_page()); |
| + EXPECT_FALSE(observer.is_main_frame()); |
| // The new entry should be appended. |
| NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| EXPECT_EQ(2, controller.GetEntryCount()); |
| - EXPECT_EQ(entry, observer.details().entry); |
| // New entry should refer to the new page, but the old URL (entries only |
| // reflect the toplevel URL). |
| @@ -2641,8 +2658,8 @@ TEST_F(NavigationControllerTest, InPage) { |
| NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| - EXPECT_TRUE(observer.details().did_replace_entry); |
| + EXPECT_TRUE(observer.is_in_page()); |
| + EXPECT_TRUE(observer.did_replace_entry()); |
| EXPECT_EQ(1, controller.GetEntryCount()); |
| // Fragment navigation to a new page. |
| @@ -2665,8 +2682,8 @@ TEST_F(NavigationControllerTest, InPage) { |
| NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| - EXPECT_FALSE(observer.details().did_replace_entry); |
| + EXPECT_TRUE(observer.is_in_page()); |
| + EXPECT_FALSE(observer.did_replace_entry()); |
| EXPECT_EQ(2, controller.GetEntryCount()); |
| // Go back one. |
| @@ -2679,7 +2696,7 @@ TEST_F(NavigationControllerTest, InPage) { |
| main_test_rfh()->SendNavigateWithParams(&back_params); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| + EXPECT_TRUE(observer.is_in_page()); |
| EXPECT_EQ(2, controller.GetEntryCount()); |
| EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
| @@ -2694,7 +2711,7 @@ TEST_F(NavigationControllerTest, InPage) { |
| main_test_rfh()->SendNavigateWithParams(&forward_params); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| + EXPECT_TRUE(observer.is_in_page()); |
| EXPECT_EQ(2, controller.GetEntryCount()); |
| EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
| EXPECT_EQ(forward_params.url, |
| @@ -2718,13 +2735,14 @@ TEST_F(NavigationControllerTest, InPage) { |
| params.nav_entry_id = 0; |
| params.did_create_new_entry = true; |
| params.url = url3; |
| + params.was_within_same_page = false; |
| navigation_entry_committed_counter_ = 0; |
| main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); |
| main_test_rfh()->PrepareForCommit(); |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_FALSE(observer.details().is_in_page); |
| + EXPECT_FALSE(observer.is_in_page()); |
| EXPECT_EQ(3, controller.GetEntryCount()); |
| EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| } |
| @@ -2760,8 +2778,8 @@ TEST_F(NavigationControllerTest, InPage_Replace) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| - EXPECT_TRUE(observer.details().did_replace_entry); |
| + EXPECT_TRUE(observer.is_in_page()); |
| + EXPECT_TRUE(observer.did_replace_entry()); |
| EXPECT_EQ(1, controller.GetEntryCount()); |
| } |
| @@ -2814,8 +2832,8 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_TRUE(observer.details().is_in_page); |
| - EXPECT_TRUE(observer.details().did_replace_entry); |
| + EXPECT_TRUE(observer.is_in_page()); |
| + EXPECT_TRUE(observer.did_replace_entry()); |
| EXPECT_EQ(2, controller.GetEntryCount()); |
| } |
| @@ -2841,7 +2859,7 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| navigation_entry_committed_counter_ = 0; |
| - EXPECT_FALSE(observer.details().is_in_page); |
| + EXPECT_FALSE(observer.is_in_page()); |
| EXPECT_EQ(3, controller.GetEntryCount()); |
| } |
| @@ -5096,7 +5114,7 @@ TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(PAGE_TYPE_ERROR, |
| controller_impl().GetLastCommittedEntry()->GetPageType()); |
| - EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, observer.type()); |
| } |
| // Navigate to existing page. |
| @@ -5108,7 +5126,7 @@ TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(PAGE_TYPE_ERROR, |
| controller_impl().GetLastCommittedEntry()->GetPageType()); |
| - EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, observer.type()); |
| } |
| // Navigate to same page. |
| @@ -5124,7 +5142,7 @@ TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(PAGE_TYPE_ERROR, |
| controller_impl().GetLastCommittedEntry()->GetPageType()); |
| - EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.details().type); |
| + EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, observer.type()); |
| } |
| // Navigate in page. |
| @@ -5138,7 +5156,7 @@ TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
| main_test_rfh()->SendNavigateWithParams(¶ms); |
| EXPECT_EQ(PAGE_TYPE_ERROR, |
| controller_impl().GetLastCommittedEntry()->GetPageType()); |
| - EXPECT_TRUE(observer.details().is_in_page); |
| + EXPECT_TRUE(observer.is_in_page()); |
| } |
| } |