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

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

Issue 2766453002: Implement Reload for ORIGINAL_REQUEST_URL in NavigationManagerImpl. (Closed)
Patch Set: 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..127e91da0c2f342ff17bbf168a3e580cf8af2983 100644
--- a/ios/web/navigation/navigation_manager_impl_unittest.mm
+++ b/ios/web/navigation/navigation_manager_impl_unittest.mm
@@ -41,6 +41,16 @@ void OnNavigationItemCommitted(const LoadCommittedDetails&) override {}
CRWSessionController* session_controller() { return controller_.get(); }
NavigationManagerImpl* navigation_manager() { return manager_.get(); }
+ // Adds a pending item by calling:
+ // AddPendingItem(url, Referrer(), ui::PAGE_TRANSITION_IS_REDIRECT_MASK,
+ // web::NavigationInitiationType::USER_INITIATED);
+ // 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 +608,158 @@ 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_EQ(0, navigation_manager()->GetItemCount());
+ navigation_manager()->Reload(web::ReloadType::NORMAL,
+ false /* check_for_repost */);
+}
+
+// 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()->GetPendingItem());
+
+ 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);
- ASSERT_TRUE(navigation_manager()->GetVisibleItem());
+ [session_controller() commitPendingItem];
+ ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
- GURL url_before_reload = navigation_manager()->GetVisibleItem()->GetURL();
+ 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, ReloadMultiRedirectItemsWithOriginal) {
+ 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 (not earlies)
+// 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/original/1"));
+ [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());
}
} // namespace web

Powered by Google App Engine
This is Rietveld 408576698