Chromium Code Reviews| Index: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm |
| index 0367a8494848f23f95d9900e1bfeaaead40bc29a..451cc22fe48ec5b89d9e5cb1380ea956b033d21a 100644 |
| --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm |
| @@ -11,6 +11,14 @@ |
| #include "components/omnibox/suggestion_answer.h" |
| #import "testing/gtest_mac.h" |
| +@interface OmniboxPopupCellData () |
| +- (void)setContents:(NSAttributedString*)contents; |
| + |
|
groby-ooo-7-16
2015/06/05 01:28:47
Kill a blank line, save a byte! ;)
dschuyler
2015/06/09 01:30:47
Done.
|
| +- (NSAttributedString*)description; |
| + |
| +- (void)setImage:(NSImage*)image; |
| +@end |
| + |
| namespace { |
| class OmniboxPopupCellTest : public CocoaTest { |
| @@ -20,32 +28,35 @@ class OmniboxPopupCellTest : public CocoaTest { |
| void SetUp() override { |
| CocoaTest::SetUp(); |
| - cell_.reset([[OmniboxPopupCell alloc] initTextCell:@""]); |
| - button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]); |
| - [button_ setCell:cell_]; |
| - [[test_window() contentView] addSubview:button_]; |
| + cellData_.reset([[OmniboxPopupCellData alloc] init]); |
| + cell_.reset([[OmniboxPopupCell alloc] init]); |
| + [cell_ setRepresentedObject:cellData_]; |
|
groby-ooo-7-16
2015/06/05 01:28:47
I thought you switched to objectValue?
dschuyler
2015/06/09 01:30:46
Thanks! I thought so too.
Done.
|
| + control_.reset([[NSControl alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]); |
| + [control_ setCell:cell_]; |
| + [[test_window() contentView] addSubview:control_]; |
| }; |
| protected: |
| + base::scoped_nsobject<OmniboxPopupCellData> cellData_; |
| base::scoped_nsobject<OmniboxPopupCell> cell_; |
| - base::scoped_nsobject<NSButton> button_; |
| + base::scoped_nsobject<NSControl> control_; |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OmniboxPopupCellTest); |
| }; |
| -TEST_VIEW(OmniboxPopupCellTest, button_); |
| +TEST_VIEW(OmniboxPopupCellTest, control_); |
| TEST_F(OmniboxPopupCellTest, Image) { |
| - [cell_ setImage:[NSImage imageNamed:NSImageNameInfo]]; |
| - [button_ display]; |
| + [cellData_ setImage:[NSImage imageNamed:NSImageNameInfo]]; |
| + [control_ display]; |
| } |
| TEST_F(OmniboxPopupCellTest, Title) { |
| base::scoped_nsobject<NSAttributedString> text([[NSAttributedString alloc] |
| initWithString:@"The quick brown fox jumps over the lazy dog."]); |
| - [cell_ setAttributedTitle:text]; |
| - [button_ display]; |
| + [cellData_ setContents:text]; |
| + [control_ display]; |
| } |
| TEST_F(OmniboxPopupCellTest, AnswerStyle) { |
| @@ -66,16 +77,16 @@ TEST_F(OmniboxPopupCellTest, AnswerStyle) { |
| AutocompleteMatch match; |
| match.answer = SuggestionAnswer::ParseAnswer(dictionary); |
| EXPECT_TRUE(match.answer); |
| - [cell_ setMatch:match]; |
| - EXPECT_NSEQ([[cell_ description] string], finalString); |
| - size_t length = [[cell_ description] length]; |
| + cellData_.reset([[OmniboxPopupCellData alloc] initWithMatch:match image:nil]); |
| + EXPECT_NSEQ([[cellData_ description] string], finalString); |
| + size_t length = [[[cellData_ description] string] length]; |
| const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; |
| EXPECT_EQ(length, 8UL); |
| NSDictionary* lastAttributes = nil; |
| for (const NSRange& value : checkValues) { |
| NSRange range; |
| NSDictionary* currentAttributes = |
| - [[cell_ description] attributesAtIndex:value.location |
| + [[cellData_ description] attributesAtIndex:value.location |
| effectiveRange:&range]; |
| EXPECT_TRUE(NSEqualRanges(value, range)); |
| EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); |