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

Side by Side Diff: ios/chrome/browser/ui/collection_view/cells/collection_view_text_item_unittest.mm

Issue 2856113002: CollectionViewTextItem should copy accessibilityLabel to the cell (Closed)
Patch Set: Created 3 years, 7 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/collection_view/cells/collection_view_text_item.mm ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/collection_view/cells/collection_view_text_item.h " 5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
6 6
7 #import <CoreGraphics/CoreGraphics.h> 7 #import <CoreGraphics/CoreGraphics.h>
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h " 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h "
11 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h" 11 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gtest_mac.h" 13 #include "testing/gtest_mac.h"
14 14
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 16 #error "This file requires ARC support."
17 #endif 17 #endif
18 18
19 namespace { 19 namespace {
20 20
21 // Test that accessory type is copied over to the cell from the item.
21 TEST(CollectionViewTextItemTest, ConfigureCellPortsAccessoryType) { 22 TEST(CollectionViewTextItemTest, ConfigureCellPortsAccessoryType) {
22 CollectionViewTextItem* item = 23 CollectionViewTextItem* item =
23 [[CollectionViewTextItem alloc] initWithType:0]; 24 [[CollectionViewTextItem alloc] initWithType:0];
24 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 25 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
25 CollectionViewTextCell* cell = [[[item cellClass] alloc] init]; 26 CollectionViewTextCell* cell = [[[item cellClass] alloc] init];
26 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]); 27 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]);
27 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, [cell accessoryType]); 28 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, [cell accessoryType]);
28 [item configureCell:cell]; 29 [item configureCell:cell];
29 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, [cell accessoryType]); 30 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, [cell accessoryType]);
30 } 31 }
31 32
33 // Test that text properties are copied over to the cell from the item.
32 TEST(CollectionViewTextItemTest, ConfigureCellPortsTextCellProperties) { 34 TEST(CollectionViewTextItemTest, ConfigureCellPortsTextCellProperties) {
33 CollectionViewTextItem* item = 35 CollectionViewTextItem* item =
34 [[CollectionViewTextItem alloc] initWithType:0]; 36 [[CollectionViewTextItem alloc] initWithType:0];
35 item.text = @"some text"; 37 item.text = @"some text";
36 item.detailText = @"some detail text"; 38 item.detailText = @"some detail text";
37 CollectionViewTextCell* cell = [[[item cellClass] alloc] init]; 39 CollectionViewTextCell* cell = [[[item cellClass] alloc] init];
38 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]); 40 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]);
39 EXPECT_FALSE([cell textLabel].text); 41 EXPECT_FALSE([cell textLabel].text);
40 EXPECT_FALSE([cell detailTextLabel].text); 42 EXPECT_FALSE([cell detailTextLabel].text);
41 [item configureCell:cell]; 43 [item configureCell:cell];
42 EXPECT_NSEQ(@"some text", [cell textLabel].text); 44 EXPECT_NSEQ(@"some text", [cell textLabel].text);
43 EXPECT_NSEQ(@"some detail text", [cell detailTextLabel].text); 45 EXPECT_NSEQ(@"some detail text", [cell detailTextLabel].text);
44 } 46 }
45 47
48 // Test that if the item has no accessibilityLabel, the cell gets one composed
49 // of the text and detailText.
50 TEST(CollectionViewTextItemTest, ConfigureCellDerivesAccessibilityLabel) {
51 CollectionViewTextItem* item =
52 [[CollectionViewTextItem alloc] initWithType:0];
53 item.text = @"some text";
54 item.detailText = @"some detail text";
55 CollectionViewTextCell* cell = [[[item cellClass] alloc] init];
56 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]);
57 EXPECT_FALSE([cell textLabel].accessibilityLabel);
58 [item configureCell:cell];
59 EXPECT_NSEQ(@"some text, some detail text", [cell accessibilityLabel]);
60 }
61
62 // Test that if the item has a non-empty accessibilityLabel, this is copied
63 // over to the cell.
64 TEST(CollectionViewTextItemTest, ConfigureCellPortsAccessibilityLabel) {
65 CollectionViewTextItem* item =
66 [[CollectionViewTextItem alloc] initWithType:0];
67 item.accessibilityLabel = @"completely different label";
68 // Also set text and detailText to verify that the derived
69 // accessibilityLabel is not composed of those.
70 item.text = @"some text";
71 item.detailText = @"some detail text";
72 CollectionViewTextCell* cell = [[[item cellClass] alloc] init];
73 EXPECT_TRUE([cell isMemberOfClass:[CollectionViewTextCell class]]);
74 EXPECT_FALSE([cell textLabel].accessibilityLabel);
75 [item configureCell:cell];
76 EXPECT_NSEQ(@"completely different label", [cell accessibilityLabel]);
77 }
78
46 } // namespace 79 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698