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..b62a84636b5ff93e51dbc0d98c1c1a8312a7f624 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,10 @@ |
| #include "components/omnibox/suggestion_answer.h" |
| #import "testing/gtest_mac.h" |
| +@interface OmniboxPopupCellData () |
|
groby-ooo-7-16
2015/06/12 18:51:07
If we _must_ mutate, I'd prefer you define the set
dschuyler
2015/06/12 21:39:14
Done.
|
| +- (void)setContents:(NSAttributedString*)contents; |
| +@end |
| + |
| namespace { |
| class OmniboxPopupCellTest : public CocoaTest { |
| @@ -20,32 +24,38 @@ 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_]; |
| + 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]; |
| + AutocompleteMatch match; |
| + cellData_.reset([[OmniboxPopupCellData alloc] |
| + initWithMatch:match |
| + image:[NSImage imageNamed:NSImageNameInfo] |
| + answerImage:nil]); |
| + [cell_ setObjectValue:cellData_]; |
| + [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]; |
|
groby-ooo-7-16
2015/06/12 18:51:07
You don't have cellData_ set yet.
dschuyler
2015/06/12 21:39:14
Done.
|
| + [cell_ setObjectValue:cellData_]; |
| + [control_ display]; |
| } |
| TEST_F(OmniboxPopupCellTest, AnswerStyle) { |
| @@ -66,17 +76,19 @@ 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 |
| + answerImage: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 |
| - effectiveRange:&range]; |
| + [[cellData_ description] attributesAtIndex:value.location |
| + effectiveRange:&range]; |
| EXPECT_TRUE(NSEqualRanges(value, range)); |
| EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); |
| lastAttributes = currentAttributes; |