Chromium Code Reviews| 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 37820871831a87623cbd54b4d529e244b02fb1b3..e746b9f5d444bef76e0c4731f931ce9b0f6cff94 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 |
| @@ -20,7 +20,7 @@ |
| #include "ui/gfx/ios/uikit_util.h" |
| @interface TabHistoryPopupController (Testing) |
| -- (CGFloat)calculatePopupWidth:(NSArray*)entries; |
| ++ (CGFloat)popupWidthForItems:(const web::NavigationItemList)items; |
| @property(nonatomic, retain) |
| TabHistoryViewController* tabHistoryTableViewController; |
| @end |
| @@ -32,36 +32,26 @@ - (CGFloat)calculatePopupWidth:(NSArray*)entries; |
| 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_ |
| - entries:testEntriesArray()]); |
| - } |
| - 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]; |
| + items:web::CreateRawNavigationItemList(items_)]); |
| } |
| + |
| + web::ScopedNavigationItemList items_; |
| base::scoped_nsobject<UIView> parent_; |
| base::scoped_nsobject<TabHistoryPopupController> popup_; |
| }; |
| @@ -81,30 +71,6 @@ void TearDown() override { |
| } |
| 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()) { |
| @@ -117,19 +83,37 @@ void TearDown() override { |
| [UIApplication sharedApplication].keyWindow.frame.size.width * .85); |
| } |
| - CGFloat width = |
| - [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, nil]]; |
| + // 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]; |
| EXPECT_EQ(minWidth, width); |
| - width = |
| - [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, |
| - entryMedium, nil]]; |
| + // 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]; |
| EXPECT_GE(width, minWidth); |
| EXPECT_LE(width, maxWidth); |
| - width = [popup_ |
| - calculatePopupWidth:[NSArray arrayWithObjects:entryShort, entryLong, |
| - entryMedium, nil]]; |
| + // Add an item with a long URL and verify that the maximum width is returned. |
| + std::string longURL = |
|
Eugene But (OOO till 7-30)
2017/02/14 23:08:08
s/longURL/long_url
kkhorimoto
2017/02/14 23:23:51
Done.
|
| + "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(longURL)); |
| + items.back()->SetReferrer(referrer); |
| + raw_items.push_back(items.back().get()); |
| + width = [TabHistoryPopupController popupWidthForItems:raw_items]; |
| EXPECT_EQ(maxWidth, width); |
| } |