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

Side by Side Diff: ios/chrome/browser/ui/infobars/infobar_view_unittest.mm

Issue 2826083003: [ObjC ARC] Converts ios/chrome/browser/ui/infobars:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « ios/chrome/browser/ui/infobars/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/infobars/infobar_view.h" 5 #import "ios/chrome/browser/ui/infobars/infobar_view.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/gtest_mac.h" 8 #include "testing/gtest_mac.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
11 @interface InfoBarView (Testing) 15 @interface InfoBarView (Testing)
12 - (CGFloat)buttonsHeight; 16 - (CGFloat)buttonsHeight;
13 - (CGFloat)buttonMargin; 17 - (CGFloat)buttonMargin;
14 - (CGFloat)computeRequiredHeightAndLayoutSubviews:(BOOL)layout; 18 - (CGFloat)computeRequiredHeightAndLayoutSubviews:(BOOL)layout;
15 - (CGFloat)heightThatFitsButtonsUnderOtherWidgets:(CGFloat)heightOfFirstLine 19 - (CGFloat)heightThatFitsButtonsUnderOtherWidgets:(CGFloat)heightOfFirstLine
16 layout:(BOOL)layout; 20 layout:(BOOL)layout;
17 - (CGFloat)minimumInfobarHeight; 21 - (CGFloat)minimumInfobarHeight;
18 - (NSString*)stripMarkersFromString:(NSString*)string; 22 - (NSString*)stripMarkersFromString:(NSString*)string;
19 - (const std::vector<std::pair<NSUInteger, NSRange>>&)linkRanges; 23 - (const std::vector<std::pair<NSUInteger, NSRange>>&)linkRanges;
20 @end 24 @end
21 25
22 namespace { 26 namespace {
23 27
24 const int kShortStringLength = 4; 28 const int kShortStringLength = 4;
25 const int kLongStringLength = 1000; 29 const int kLongStringLength = 1000;
26 30
27 class InfoBarViewTest : public PlatformTest { 31 class InfoBarViewTest : public PlatformTest {
28 protected: 32 protected:
29 void SetUp() override { 33 void SetUp() override {
30 PlatformTest::SetUp(); 34 PlatformTest::SetUp();
31 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 35 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
32 infobarView_.reset([[InfoBarView alloc] 36 infobarView_ =
33 initWithFrame:CGRectMake(0, 0, screenWidth, 0) 37 [[InfoBarView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 0)
34 delegate:NULL]); 38 delegate:NULL];
35 [infobarView_ addCloseButtonWithTag:0 target:nil action:nil]; 39 [infobarView_ addCloseButtonWithTag:0 target:nil action:nil];
36 } 40 }
37 41
38 NSString* RandomString(int numberOfCharacters) { 42 NSString* RandomString(int numberOfCharacters) {
39 NSMutableString* string = [NSMutableString string]; 43 NSMutableString* string = [NSMutableString string];
40 NSString* letters = @"abcde "; 44 NSString* letters = @"abcde ";
41 for (int i = 0; i < numberOfCharacters; i++) { 45 for (int i = 0; i < numberOfCharacters; i++) {
42 [string 46 [string
43 appendFormat:@"%C", [letters characterAtIndex:arc4random_uniform( 47 appendFormat:@"%C", [letters characterAtIndex:arc4random_uniform(
44 [letters length])]]; 48 [letters length])]];
(...skipping 23 matching lines...) Expand all
68 EXPECT_NSEQ(expectedOutput, output); 72 EXPECT_NSEQ(expectedOutput, output);
69 const std::vector<std::pair<NSUInteger, NSRange>>& ranges = 73 const std::vector<std::pair<NSUInteger, NSRange>>& ranges =
70 [infobarView_ linkRanges]; 74 [infobarView_ linkRanges];
71 EXPECT_EQ(expectedRanges.size(), ranges.size()); 75 EXPECT_EQ(expectedRanges.size(), ranges.size());
72 for (unsigned int i = 0; i < expectedRanges.size(); ++i) { 76 for (unsigned int i = 0; i < expectedRanges.size(); ++i) {
73 EXPECT_EQ(expectedRanges[i].first, ranges[i].first); 77 EXPECT_EQ(expectedRanges[i].first, ranges[i].first);
74 EXPECT_TRUE(NSEqualRanges(expectedRanges[i].second, ranges[i].second)); 78 EXPECT_TRUE(NSEqualRanges(expectedRanges[i].second, ranges[i].second));
75 } 79 }
76 } 80 }
77 81
78 base::scoped_nsobject<InfoBarView> infobarView_; 82 InfoBarView* infobarView_;
79 }; 83 };
80 84
81 TEST_F(InfoBarViewTest, TestLayoutWithNoLabel) { 85 TEST_F(InfoBarViewTest, TestLayoutWithNoLabel) {
82 // Do not call -addLabel: to test the case when there is no label. 86 // Do not call -addLabel: to test the case when there is no label.
83 EXPECT_EQ(MinimumInfobarHeight(), InfobarHeight()); 87 EXPECT_EQ(MinimumInfobarHeight(), InfobarHeight());
84 } 88 }
85 89
86 TEST_F(InfoBarViewTest, TestLayoutWithShortLabel) { 90 TEST_F(InfoBarViewTest, TestLayoutWithShortLabel) {
87 [infobarView_ addLabel:ShortRandomString()]; 91 [infobarView_ addLabel:ShortRandomString()];
88 EXPECT_EQ(MinimumInfobarHeight(), InfobarHeight()); 92 EXPECT_EQ(MinimumInfobarHeight(), InfobarHeight());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Multiple links and text. 175 // Multiple links and text.
172 NSString* link3 = 176 NSString* link3 =
173 [NSString stringWithFormat:@"baz%@qux%@tot", linkFoo, linkBar]; 177 [NSString stringWithFormat:@"baz%@qux%@tot", linkFoo, linkBar];
174 ranges.clear(); 178 ranges.clear();
175 ranges.push_back(std::make_pair(1, NSMakeRange(3, 3))); 179 ranges.push_back(std::make_pair(1, NSMakeRange(3, 3)));
176 ranges.push_back(std::make_pair(2, NSMakeRange(9, 3))); 180 ranges.push_back(std::make_pair(2, NSMakeRange(9, 3)));
177 TestLinkDetectionHelper(link3, @"bazfooquxbartot", ranges); 181 TestLinkDetectionHelper(link3, @"bazfooquxbartot", ranges);
178 } 182 }
179 183
180 } // namespace 184 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/infobars/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698