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

Side by Side Diff: ios/chrome/browser/ui/history/tab_history_popup_controller_unittest.mm

Issue 2693013005: Updated tab history classes to use NavigationItemLists. (Closed)
Patch Set: update DEPS, include url_formatter in BUILD.gn 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h" 5 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "components/sessions/core/session_types.h" 11 #include "components/sessions/core/session_types.h"
12 #import "ios/chrome/browser/ui/history/tab_history_view_controller.h" 12 #import "ios/chrome/browser/ui/history/tab_history_view_controller.h"
13 #include "ios/chrome/browser/ui/ui_util.h" 13 #include "ios/chrome/browser/ui/ui_util.h"
14 #import "ios/web/navigation/crw_session_entry.h"
15 #include "ios/web/public/navigation_item.h" 14 #include "ios/web/public/navigation_item.h"
16 #include "ios/web/public/referrer.h" 15 #include "ios/web/public/referrer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
19 #import "third_party/ocmock/OCMock/OCMock.h" 18 #import "third_party/ocmock/OCMock/OCMock.h"
20 #include "ui/gfx/ios/uikit_util.h" 19 #include "ui/gfx/ios/uikit_util.h"
21 20
22 @interface TabHistoryPopupController (Testing) 21 @interface TabHistoryPopupController (Testing)
23 - (CGFloat)calculatePopupWidth:(NSArray*)entries; 22 + (CGFloat)popupWidthForItems:(const web::NavigationItemList)items;
24 @property(nonatomic, retain) 23 @property(nonatomic, retain)
25 TabHistoryViewController* tabHistoryTableViewController; 24 TabHistoryViewController* tabHistoryTableViewController;
26 @end 25 @end
27 26
28 namespace { 27 namespace {
29 static const CGFloat kTabHistoryMinWidth = 250.0; 28 static const CGFloat kTabHistoryMinWidth = 250.0;
30 static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0; 29 static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0;
31 30
32 class TabHistoryPopupControllerTest : public PlatformTest { 31 class TabHistoryPopupControllerTest : public PlatformTest {
33 protected: 32 protected:
34 void SetUp() override { 33 void SetUp() override {
34 web::Referrer referrer(GURL("http://www.example.com"),
35 web::ReferrerPolicyDefault);
36 items_.push_back(web::NavigationItem::Create());
37 items_.back()->SetURL(GURL("http://www.example.com/0"));
38 items_.back()->SetReferrer(referrer);
39 items_.push_back(web::NavigationItem::Create());
40 items_.back()->SetURL(GURL("http://www.example.com/1"));
41 items_.back()->SetReferrer(referrer);
42 items_.push_back(web::NavigationItem::Create());
43 items_.back()->SetURL(GURL("http://www.example.com/0"));
44 items_.back()->SetReferrer(referrer);
45
35 parent_.reset([[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]); 46 parent_.reset([[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]);
36 popup_.reset([[TabHistoryPopupController alloc] 47 popup_.reset([[TabHistoryPopupController alloc]
37 initWithOrigin:CGPointZero 48 initWithOrigin:CGPointZero
38 parentView:parent_ 49 parentView:parent_
39 entries:testEntriesArray()]); 50 items:web::CreateRawNavigationItemList(items_)]);
40 } 51 }
41 void TearDown() override { 52
42 parent_.reset(); 53 web::ScopedNavigationItemList items_;
43 popup_.reset();
44 }
45 NSArray* testEntriesArray() {
46 web::Referrer referrer(GURL("http://www.example.com"),
47 web::ReferrerPolicyDefault);
48 std::unique_ptr<web::NavigationItem> item0 = web::NavigationItem::Create();
49 item0->SetURL(GURL("http://www.example.com/0"));
50 item0->SetReferrer(referrer);
51 CRWSessionEntry* entry0 =
52 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item0)];
53 std::unique_ptr<web::NavigationItem> item1 = web::NavigationItem::Create();
54 item1->SetURL(GURL("http://www.example.com/1"));
55 item1->SetReferrer(referrer);
56 CRWSessionEntry* entry1 =
57 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item1)];
58 std::unique_ptr<web::NavigationItem> item2 = web::NavigationItem::Create();
59 item2->SetURL(GURL("http://www.example.com/2"));
60 item2->SetReferrer(referrer);
61 CRWSessionEntry* entry2 =
62 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item2)];
63 return [NSArray arrayWithObjects:entry0, entry1, entry2, nil];
64 }
65 base::scoped_nsobject<UIView> parent_; 54 base::scoped_nsobject<UIView> parent_;
66 base::scoped_nsobject<TabHistoryPopupController> popup_; 55 base::scoped_nsobject<TabHistoryPopupController> popup_;
67 }; 56 };
68 57
69 TEST_F(TabHistoryPopupControllerTest, TestTableSize) { 58 TEST_F(TabHistoryPopupControllerTest, TestTableSize) {
70 NSInteger number_of_rows = 0; 59 NSInteger number_of_rows = 0;
71 60
72 UICollectionView* collectionView = 61 UICollectionView* collectionView =
73 [[popup_ tabHistoryTableViewController] collectionView]; 62 [[popup_ tabHistoryTableViewController] collectionView];
74 63
75 NSInteger number_of_sections = [collectionView numberOfSections]; 64 NSInteger number_of_sections = [collectionView numberOfSections];
76 for (NSInteger section = 0; section < number_of_sections; ++section) { 65 for (NSInteger section = 0; section < number_of_sections; ++section) {
77 number_of_rows += [collectionView numberOfItemsInSection:section]; 66 number_of_rows += [collectionView numberOfItemsInSection:section];
78 } 67 }
79 68
80 EXPECT_EQ(3, number_of_rows); 69 EXPECT_EQ(3, number_of_rows);
81 } 70 }
82 71
83 TEST_F(TabHistoryPopupControllerTest, TestCalculatePopupWidth) { 72 TEST_F(TabHistoryPopupControllerTest, TestCalculatePopupWidth) {
84 web::Referrer referrer(GURL("http://www.example.com"),
85 web::ReferrerPolicyDefault);
86 std::unique_ptr<web::NavigationItem> itemShort =
87 web::NavigationItem::Create();
88 itemShort->SetURL(GURL("http://foo.com/"));
89 itemShort->SetReferrer(referrer);
90 CRWSessionEntry* entryShort =
91 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemShort)];
92 std::unique_ptr<web::NavigationItem> itemMedium =
93 web::NavigationItem::Create();
94 itemMedium->SetURL(GURL("http://www.example.com/mediumurl"));
95 itemMedium->SetReferrer(referrer);
96 CRWSessionEntry* entryMedium =
97 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemMedium)];
98 std::string longURL =
99 "http://www.example.com/this/is/areally/long/url/that/"
100 "is/larger/than/the/maximum/table/width/so/its/text/will/get/cut/off/and/"
101 "the/max/width/is/used/";
102 std::unique_ptr<web::NavigationItem> itemLong = web::NavigationItem::Create();
103 itemLong->SetURL(GURL(longURL));
104 itemLong->SetReferrer(referrer);
105 CRWSessionEntry* entryLong =
106 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(itemLong)];
107
108 CGFloat minWidth = kTabHistoryMinWidth; 73 CGFloat minWidth = kTabHistoryMinWidth;
109 CGFloat maxWidth = kTabHistoryMinWidth; 74 CGFloat maxWidth = kTabHistoryMinWidth;
110 if (!IsIPadIdiom()) { 75 if (!IsIPadIdiom()) {
111 UIInterfaceOrientation orientation = 76 UIInterfaceOrientation orientation =
112 [[UIApplication sharedApplication] statusBarOrientation]; 77 [[UIApplication sharedApplication] statusBarOrientation];
113 if (!UIInterfaceOrientationIsPortrait(orientation)) 78 if (!UIInterfaceOrientationIsPortrait(orientation))
114 maxWidth = kTabHistoryMaxWidthLandscapePhone; 79 maxWidth = kTabHistoryMaxWidthLandscapePhone;
115 } else { 80 } else {
116 maxWidth = ui::AlignValueToUpperPixel( 81 maxWidth = ui::AlignValueToUpperPixel(
117 [UIApplication sharedApplication].keyWindow.frame.size.width * .85); 82 [UIApplication sharedApplication].keyWindow.frame.size.width * .85);
118 } 83 }
119 84
120 CGFloat width = 85 // Add an item with a short URL and verify that the minimum width is returned.
121 [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, nil]]; 86 web::ScopedNavigationItemList items;
87 web::Referrer referrer(GURL("http://www.example.com"),
88 web::ReferrerPolicyDefault);
89 items.push_back(web::NavigationItem::Create());
90 items.back()->SetURL(GURL("http://foo.com/"));
91 items.back()->SetReferrer(referrer);
92 web::NavigationItemList raw_items = web::CreateRawNavigationItemList(items);
93 CGFloat width = [TabHistoryPopupController popupWidthForItems:raw_items];
122 EXPECT_EQ(minWidth, width); 94 EXPECT_EQ(minWidth, width);
123 95
124 width = 96 // Add an item with a medium URL and verify that the returned width is between
125 [popup_ calculatePopupWidth:[NSArray arrayWithObjects:entryShort, 97 // the minimum and maximum.
126 entryMedium, nil]]; 98 items.push_back(web::NavigationItem::Create());
99 items.back()->SetURL(GURL("http://www.example.com/mediumurl"));
100 items.back()->SetReferrer(referrer);
101 raw_items.push_back(items.back().get());
102 width = [TabHistoryPopupController popupWidthForItems:raw_items];
127 EXPECT_GE(width, minWidth); 103 EXPECT_GE(width, minWidth);
128 EXPECT_LE(width, maxWidth); 104 EXPECT_LE(width, maxWidth);
129 105
130 width = [popup_ 106 // Add an item with a long URL and verify that the maximum width is returned.
131 calculatePopupWidth:[NSArray arrayWithObjects:entryShort, entryLong, 107 std::string long_url =
132 entryMedium, nil]]; 108 "http://www.example.com/this/is/areally/long/url/that/"
109 "is/larger/than/the/maximum/table/width/so/its/text/will/get/cut/off/and/"
110 "the/max/width/is/used/";
111 items.push_back(web::NavigationItem::Create());
112 items.back()->SetURL(GURL(long_url));
113 items.back()->SetReferrer(referrer);
114 raw_items.push_back(items.back().get());
115 width = [TabHistoryPopupController popupWidthForItems:raw_items];
133 EXPECT_EQ(maxWidth, width); 116 EXPECT_EQ(maxWidth, width);
134 } 117 }
135 118
136 } // namespace 119 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698