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

Unified Diff: ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm

Issue 2706403009: Revert of Updated tab history classes to use NavigationItemLists. (Closed)
Patch Set: Created 3 years, 10 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/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm
diff --git a/ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm b/ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm
index 6f1e9e77e87b5912eb244edf347a7f0a35cf33fd..37820871831a87623cbd54b4d529e244b02fb1b3 100644
--- a/ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm
+++ b/ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm
@@ -11,6 +11,7 @@
#include "components/sessions/core/session_types.h"
#import "ios/chrome/browser/ui/history/tab_history_view_controller.h"
#include "ios/chrome/browser/ui/ui_util.h"
+#import "ios/web/navigation/crw_session_entry.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/referrer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,7 +20,7 @@
#include "ui/gfx/ios/uikit_util.h"
@interface TabHistoryPopupController (Testing)
-+ (CGFloat)popupWidthForItems:(const web::NavigationItemList)items;
+- (CGFloat)calculatePopupWidth:(NSArray*)entries;
@property(nonatomic, retain)
TabHistoryViewController* tabHistoryTableViewController;
@end
@@ -31,26 +32,36 @@
class TabHistoryPopupControllerTest : public PlatformTest {
protected:
void SetUp() override {
- web::Referrer referrer(GURL("http://www.example.com"),
- web::ReferrerPolicyDefault);
- items_.push_back(web::NavigationItem::Create());
- items_.back()->SetURL(GURL("http://www.example.com/0"));
- items_.back()->SetReferrer(referrer);
- items_.push_back(web::NavigationItem::Create());
- items_.back()->SetURL(GURL("http://www.example.com/1"));
- items_.back()->SetReferrer(referrer);
- items_.push_back(web::NavigationItem::Create());
- items_.back()->SetURL(GURL("http://www.example.com/0"));
- items_.back()->SetReferrer(referrer);
-
parent_.reset([[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]);
popup_.reset([[TabHistoryPopupController alloc]
initWithOrigin:CGPointZero
parentView:parent_
- items:web::CreateRawNavigationItemList(items_)]);
+ entries:testEntriesArray()]);
}
-
- web::ScopedNavigationItemList items_;
+ void TearDown() override {
+ parent_.reset();
+ popup_.reset();
+ }
+ NSArray* testEntriesArray() {
+ web::Referrer referrer(GURL("http://www.example.com"),
+ web::ReferrerPolicyDefault);
+ std::unique_ptr<web::NavigationItem> item0 = web::NavigationItem::Create();
+ item0->SetURL(GURL("http://www.example.com/0"));
+ item0->SetReferrer(referrer);
+ CRWSessionEntry* entry0 =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item0)];
+ std::unique_ptr<web::NavigationItem> item1 = web::NavigationItem::Create();
+ item1->SetURL(GURL("http://www.example.com/1"));
+ item1->SetReferrer(referrer);
+ CRWSessionEntry* entry1 =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item1)];
+ std::unique_ptr<web::NavigationItem> item2 = web::NavigationItem::Create();
+ item2->SetURL(GURL("http://www.example.com/2"));
+ item2->SetReferrer(referrer);
+ CRWSessionEntry* entry2 =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item2)];
+ return [NSArray arrayWithObjects:entry0, entry1, entry2, nil];
+ }
base::scoped_nsobject<UIView> parent_;
base::scoped_nsobject<TabHistoryPopupController> popup_;
};
@@ -70,6 +81,30 @@
}
TEST_F(TabHistoryPopupControllerTest, TestCalculatePopupWidth) {
+ web::Referrer referrer(GURL("http://www.example.com"),
+ web::ReferrerPolicyDefault);
+ std::unique_ptr<web::NavigationItem> itemShort =
+ web::NavigationItem::Create();
+ itemShort->SetURL(GURL("http://foo.com/"));
+ itemShort->SetReferrer(referrer);
+ CRWSessionEntry* entryShort =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemShort)];
+ std::unique_ptr<web::NavigationItem> itemMedium =
+ web::NavigationItem::Create();
+ itemMedium->SetURL(GURL("http://www.example.com/mediumurl"));
+ itemMedium->SetReferrer(referrer);
+ CRWSessionEntry* entryMedium =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemMedium)];
+ std::string longURL =
+ "http://www.example.com/this/is/areally/long/url/that/"
+ "is/larger/than/the/maximum/table/width/so/its/text/will/get/cut/off/and/"
+ "the/max/width/is/used/";
+ std::unique_ptr<web::NavigationItem> itemLong = web::NavigationItem::Create();
+ itemLong->SetURL(GURL(longURL));
+ itemLong->SetReferrer(referrer);
+ CRWSessionEntry* entryLong =
+ [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemLong)];
+
CGFloat minWidth = kTabHistoryMinWidth;
CGFloat maxWidth = kTabHistoryMinWidth;
if (!IsIPadIdiom()) {
@@ -82,37 +117,19 @@
[UIApplication sharedApplication].keyWindow.frame.size.width * .85);
}
- // Add an item with a short URL and verify that the minimum width is returned.
- web::ScopedNavigationItemList items;
- web::Referrer referrer(GURL("http://www.example.com"),
- web::ReferrerPolicyDefault);
- items.push_back(web::NavigationItem::Create());
- items.back()->SetURL(GURL("http://foo.com/"));
- items.back()->SetReferrer(referrer);
- web::NavigationItemList raw_items = web::CreateRawNavigationItemList(items);
- CGFloat width = [TabHistoryPopupController popupWidthForItems:raw_items];
+ CGFloat width =
+ [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, nil]];
EXPECT_EQ(minWidth, width);
- // Add an item with a medium URL and verify that the returned width is between
- // the minimum and maximum.
- items.push_back(web::NavigationItem::Create());
- items.back()->SetURL(GURL("http://www.example.com/mediumurl"));
- items.back()->SetReferrer(referrer);
- raw_items.push_back(items.back().get());
- width = [TabHistoryPopupController popupWidthForItems:raw_items];
+ width =
+ [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort,
+ entryMedium, nil]];
EXPECT_GE(width, minWidth);
EXPECT_LE(width, maxWidth);
- // Add an item with a long URL and verify that the maximum width is returned.
- std::string long_url =
- "http://www.example.com/this/is/areally/long/url/that/"
- "is/larger/than/the/maximum/table/width/so/its/text/will/get/cut/off/and/"
- "the/max/width/is/used/";
- items.push_back(web::NavigationItem::Create());
- items.back()->SetURL(GURL(long_url));
- items.back()->SetReferrer(referrer);
- raw_items.push_back(items.back().get());
- width = [TabHistoryPopupController popupWidthForItems:raw_items];
+ width = [popup_
+ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, entryLong,
+ entryMedium, nil]];
EXPECT_EQ(maxWidth, width);
}

Powered by Google App Engine
This is Rietveld 408576698