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

Unified Diff: ios/web/navigation/navigation_manager_impl_unittest.mm

Issue 2766453002: Implement Reload for ORIGINAL_REQUEST_URL in NavigationManagerImpl. (Closed)
Patch Set: addressed self review Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/navigation/navigation_manager_impl_unittest.mm
diff --git a/ios/web/navigation/navigation_manager_impl_unittest.mm b/ios/web/navigation/navigation_manager_impl_unittest.mm
index 5559662a8a7a958d9b6c251a91e6a766951a7c06..b376c7426abf2afffb10e5f366b044f698ac2f19 100644
--- a/ios/web/navigation/navigation_manager_impl_unittest.mm
+++ b/ios/web/navigation/navigation_manager_impl_unittest.mm
@@ -41,6 +41,14 @@ void OnNavigationItemCommitted(const LoadCommittedDetails&) override {}
CRWSessionController* session_controller() { return controller_.get(); }
NavigationManagerImpl* navigation_manager() { return manager_.get(); }
+ // Adds a redirect pending item with |url|.
+ // NOTE: use with discretion only when other fields don't matter.
+ void AddRedirectPendingItem(GURL url) {
+ manager_->AddPendingItem(url, Referrer(),
+ ui::PAGE_TRANSITION_IS_REDIRECT_MASK,
+ web::NavigationInitiationType::USER_INITIATED);
+ }
+
private:
TestBrowserState browser_state_;
TestNavigationManagerDelegate delegate_;
@@ -598,20 +606,154 @@ void OnNavigationItemCommitted(const LoadCommittedDetails&) override {}
EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType());
}
-// Tests that calling |Reload| on NavigationManager leaves the Url of the
-// visible item unchanged.
-TEST_F(NavigationManagerTest, ReloadWithNormalReloadType) {
+// Tests that calling |Reload| with web::ReloadType::NORMAL will not crash when
+// there is no item.
+TEST_F(NavigationManagerTest, ReloadEmptyWithNormal) {
+ ASSERT_FALSE(navigation_manager()->GetPendingItem());
+ ASSERT_EQ(0, navigation_manager()->GetItemCount());
+ navigation_manager()->Reload(web::ReloadType::NORMAL,
+ false /* check_for_repost */);
Eugene But (OOO till 7-30) 2017/03/23 00:08:20 Can we also verify that NavigationManagerDelegate:
liaoyuke 2017/03/27 16:22:43 Done.
+}
+
+// Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
+// the pending item unchanged when there is one.
+TEST_F(NavigationManagerTest, ReloadPendingItemWithNormal) {
navigation_manager()->AddPendingItem(
GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
web::NavigationInitiationType::USER_INITIATED);
- ASSERT_TRUE(navigation_manager()->GetVisibleItem());
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
- GURL url_before_reload = navigation_manager()->GetVisibleItem()->GetURL();
+ GURL url_before_reload = navigation_manager()->GetPendingItem()->GetURL();
navigation_manager()->Reload(web::ReloadType::NORMAL,
false /* check_for_repost */);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ EXPECT_EQ(url_before_reload,
+ navigation_manager()->GetPendingItem()->GetURL());
+}
+// Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
+// the last committed item unchanged when there is no pending item.
+TEST_F(NavigationManagerTest, ReloadLastCommittedItemWithNormal) {
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ [session_controller() commitPendingItem];
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
+
+ GURL url_before_reload =
+ navigation_manager()->GetLastCommittedItem()->GetURL();
+ navigation_manager()->Reload(web::ReloadType::NORMAL,
+ false /* check_for_repost */);
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
EXPECT_EQ(url_before_reload,
- navigation_manager()->GetVisibleItem()->GetURL());
+ navigation_manager()->GetLastCommittedItem()->GetURL());
+}
+
+// Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
+// changes the current item's url to its original request url when there is a
+// non-redirect pending item.
+TEST_F(NavigationManagerTest, ReloadNonRedirectPendingItemWithOriginal) {
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+
+ GURL expected_original_url = GURL("http://www.url.com/original");
+ navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
+ expected_original_url);
+ navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
+ false /* check_for_repost */);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ EXPECT_EQ(expected_original_url,
+ navigation_manager()->GetPendingItem()->GetURL());
+}
+
+// Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL skips
+// discards redirect pending items and sets the current item as the last
+// non-redirect item and changes its url to its original request url when there
+// is a redirect pending item.
+TEST_F(NavigationManagerTest, ReloadRedirectPendingItemWithOriginal) {
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ GURL expected_original_url = GURL("http://www.url.com/original");
+ navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
+ expected_original_url);
+ [session_controller() commitPendingItem];
+
+ AddRedirectPendingItem(GURL("http://www.url.com/pending"));
+
+ navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
+ false /* check_for_repost */);
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
+ EXPECT_FALSE(navigation_manager()->GetPendingItem());
+ EXPECT_EQ(1, navigation_manager()->GetItemCount());
+ EXPECT_EQ(expected_original_url,
+ navigation_manager()->GetLastCommittedItem()->GetURL());
+}
+
+// Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
+// skips redirect items and sets the current item as the last non-redirect item
+// and changes its url to its original request url when there are multiple
+// redirect items.
+TEST_F(NavigationManagerTest, ReloadMultipleRedirectItemsWithOriginal) {
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ GURL expected_original_url = GURL("http://www.url.com/original");
+ navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
+ expected_original_url);
+ [session_controller() commitPendingItem];
+
+ AddRedirectPendingItem(GURL("http://www.url.com/1"));
+ [session_controller() commitPendingItem];
+ AddRedirectPendingItem(GURL("http://www.url.com/2"));
+ [session_controller() commitPendingItem];
+ AddRedirectPendingItem(GURL("http://www.url.com/3"));
+
+ navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
+ false /* check_for_repost */);
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
+ EXPECT_FALSE(navigation_manager()->GetPendingItem());
+ EXPECT_EQ(1, navigation_manager()->GetItemCount());
+ EXPECT_EQ(expected_original_url,
+ navigation_manager()->GetLastCommittedItem()->GetURL());
+}
+
+// Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
+// skips redirect items and sets the current item as the last, instead of
+// earliest non-redirect item and changes its url to its original request url
+// when there are multiple non-redirect items.
+TEST_F(NavigationManagerTest, ReloadItemsWithOriginalNotEarlies) {
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com/1"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
+ GURL("http://www.url.com/1/original"));
+ [session_controller() commitPendingItem];
+
+ navigation_manager()->AddPendingItem(
+ GURL("http://www.url.com/2"), Referrer(), ui::PAGE_TRANSITION_TYPED,
+ web::NavigationInitiationType::USER_INITIATED);
+ ASSERT_TRUE(navigation_manager()->GetPendingItem());
+ GURL expected_original_url = GURL("http://www.url.com/original/2");
+ navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
+ expected_original_url);
+ [session_controller() commitPendingItem];
+
+ AddRedirectPendingItem(GURL("http://www.url.com/3"));
+
+ navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
+ false /* check_for_repost */);
+
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
+ EXPECT_FALSE(navigation_manager()->GetPendingItem());
+ EXPECT_EQ(2, navigation_manager()->GetItemCount());
+ EXPECT_EQ(expected_original_url,
+ navigation_manager()->GetLastCommittedItem()->GetURL());
}
Eugene But (OOO till 7-30) 2017/03/23 00:08:20 We should also test reloading with existing forwar
liaoyuke 2017/03/27 16:22:43 Do you mean redirect items exist before last non-r
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 I mean reloading item which is in the middle of th
} // namespace web

Powered by Google App Engine
This is Rietveld 408576698