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

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

Issue 2672953005: Updated ownership of NavigationItems within CRWSessionController. (Closed)
Patch Set: fix unittests 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
« no previous file with comments | « no previous file | ios/web/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0ee4a53cca1f1fee57f9fb2adcf83bcd9b15c7c3 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
@@ -13,6 +13,7 @@
#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/navigation_item_list.h"
#include "ios/web/public/referrer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -31,37 +32,38 @@ - (CGFloat)calculatePopupWidth:(NSArray*)entries;
class TabHistoryPopupControllerTest : public PlatformTest {
protected:
- void SetUp() override {
+ TabHistoryPopupControllerTest() : PlatformTest() {
parent_.reset([[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]);
+ // Create test items and populate |items_|.
+ 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/2"));
+ items_.back()->SetReferrer(referrer);
+ // Create the popup controller using CRWSessionEntries created from the
+ // NavigationItems in |items_|.
popup_.reset([[TabHistoryPopupController alloc]
initWithOrigin:CGPointZero
parentView:parent_
- entries:testEntriesArray()]);
- }
- void TearDown() override {
- parent_.reset();
- popup_.reset();
+ entries:EntriesListForItems(items_)]);
}
- 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];
+
+ NSArray* EntriesListForItems(const web::ScopedNavigationItemList& items) {
+ NSMutableArray* entries = [NSMutableArray array];
+ for (size_t index = 0; index < items.size(); ++index) {
+ base::scoped_nsobject<CRWSessionEntry> entry(
+ [[CRWSessionEntry alloc] initWithNavigationItem:items[index].get()]);
+ [entries addObject:entry];
+ }
+ return entries;
}
+ web::ScopedNavigationItemList items_;
base::scoped_nsobject<UIView> parent_;
base::scoped_nsobject<TabHistoryPopupController> popup_;
};
@@ -81,30 +83,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()) {
@@ -116,20 +94,28 @@ void TearDown() override {
maxWidth = ui::AlignValueToUpperPixel(
[UIApplication sharedApplication].keyWindow.frame.size.width * .85);
}
-
- CGFloat width =
- [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, nil]];
+ web::Referrer referrer(GURL("http://www.example.com"),
+ web::ReferrerPolicyDefault);
+ web::ScopedNavigationItemList items;
+ items.push_back(web::NavigationItem::Create());
+ items.back()->SetURL(GURL("http://foo.com/"));
+ items.back()->SetReferrer(referrer);
+ CGFloat width = [popup_ calculatePopupWidth:EntriesListForItems(items)];
EXPECT_EQ(minWidth, width);
-
- width =
- [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort,
- entryMedium, nil]];
+ items.push_back(web::NavigationItem::Create());
+ items.back()->SetURL(GURL("http://www.example.com/mediumurl"));
+ items.back()->SetReferrer(referrer);
+ width = [popup_ calculatePopupWidth:EntriesListForItems(items)];
EXPECT_GE(width, minWidth);
EXPECT_LE(width, maxWidth);
-
- width = [popup_
- calculatePopupWidth:[NSArray arrayWithObjects:entryShort, entryLong,
- entryMedium, nil]];
+ 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);
+ width = [popup_ calculatePopupWidth:EntriesListForItems(items)];
EXPECT_EQ(maxWidth, width);
}
« no previous file with comments | « no previous file | ios/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698