Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 11 #include "components/omnibox/suggestion_answer.h" | 11 #include "components/omnibox/suggestion_answer.h" |
| 12 #import "testing/gtest_mac.h" | 12 #import "testing/gtest_mac.h" |
| 13 | 13 |
| 14 @interface OmniboxPopupCellData () | |
| 15 - (void)setContents:(NSAttributedString*)contents; | |
| 16 - (NSAttributedString*)description; | |
|
groby-ooo-7-16
2015/06/11 01:22:17
That's already defined in an anonymous category in
Scott Hess - ex-Googler
2015/06/11 21:52:02
Any concerns about this overriding NSObject protoc
dschuyler
2015/06/11 22:34:22
Done.
dschuyler
2015/06/11 22:34:22
While I'm ok with it being description, I can also
| |
| 17 - (void)setImage:(NSImage*)image; | |
|
groby-ooo-7-16
2015/06/11 01:22:17
Instead of having setters on what's otherwise an i
Scott Hess - ex-Googler
2015/06/11 21:52:02
I agree, for a data object you should either aim f
dschuyler
2015/06/11 22:34:22
I used the existing initWithMatch, with the hope t
dschuyler
2015/06/11 22:34:22
I think we're going in the fully-immutable directi
| |
| 18 @end | |
| 19 | |
| 14 namespace { | 20 namespace { |
| 15 | 21 |
| 16 class OmniboxPopupCellTest : public CocoaTest { | 22 class OmniboxPopupCellTest : public CocoaTest { |
| 17 public: | 23 public: |
| 18 OmniboxPopupCellTest() { | 24 OmniboxPopupCellTest() { |
| 19 } | 25 } |
| 20 | 26 |
| 21 void SetUp() override { | 27 void SetUp() override { |
| 22 CocoaTest::SetUp(); | 28 CocoaTest::SetUp(); |
| 23 cell_.reset([[OmniboxPopupCell alloc] initTextCell:@""]); | 29 cellData_.reset([[OmniboxPopupCellData alloc] init]); |
| 24 button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]); | 30 cell_.reset([[OmniboxPopupCell alloc] init]); |
| 25 [button_ setCell:cell_]; | 31 [cell_ setObjectValue:cellData_]; |
| 26 [[test_window() contentView] addSubview:button_]; | 32 control_.reset([[NSControl alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]); |
| 33 [control_ setCell:cell_]; | |
| 34 [[test_window() contentView] addSubview:control_]; | |
| 27 }; | 35 }; |
| 28 | 36 |
| 29 protected: | 37 protected: |
| 38 base::scoped_nsobject<OmniboxPopupCellData> cellData_; | |
| 30 base::scoped_nsobject<OmniboxPopupCell> cell_; | 39 base::scoped_nsobject<OmniboxPopupCell> cell_; |
| 31 base::scoped_nsobject<NSButton> button_; | 40 base::scoped_nsobject<NSControl> control_; |
| 32 | 41 |
| 33 private: | 42 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupCellTest); | 43 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupCellTest); |
| 35 }; | 44 }; |
| 36 | 45 |
| 37 TEST_VIEW(OmniboxPopupCellTest, button_); | 46 TEST_VIEW(OmniboxPopupCellTest, control_); |
| 38 | 47 |
| 39 TEST_F(OmniboxPopupCellTest, Image) { | 48 TEST_F(OmniboxPopupCellTest, Image) { |
| 40 [cell_ setImage:[NSImage imageNamed:NSImageNameInfo]]; | 49 [cellData_ setImage:[NSImage imageNamed:NSImageNameInfo]]; |
|
groby-ooo-7-16
2015/06/11 01:22:17
This doesn't what you expect it to do - you alread
dschuyler
2015/06/11 22:34:22
Done.
| |
| 41 [button_ display]; | 50 [control_ display]; |
| 42 } | 51 } |
| 43 | 52 |
| 44 TEST_F(OmniboxPopupCellTest, Title) { | 53 TEST_F(OmniboxPopupCellTest, Title) { |
| 45 base::scoped_nsobject<NSAttributedString> text([[NSAttributedString alloc] | 54 base::scoped_nsobject<NSAttributedString> text([[NSAttributedString alloc] |
| 46 initWithString:@"The quick brown fox jumps over the lazy dog."]); | 55 initWithString:@"The quick brown fox jumps over the lazy dog."]); |
| 47 [cell_ setAttributedTitle:text]; | 56 [cellData_ setContents:text]; |
| 48 [button_ display]; | 57 [control_ display]; |
| 49 } | 58 } |
| 50 | 59 |
| 51 TEST_F(OmniboxPopupCellTest, AnswerStyle) { | 60 TEST_F(OmniboxPopupCellTest, AnswerStyle) { |
| 52 const char* weatherJson = | 61 const char* weatherJson = |
| 53 "{\"l\": [ {\"il\": {\"t\": [ {" | 62 "{\"l\": [ {\"il\": {\"t\": [ {" |
| 54 "\"t\": \"weather in pari<b>s</b>\", \"tt\": 8} ]}}, {" | 63 "\"t\": \"weather in pari<b>s</b>\", \"tt\": 8} ]}}, {" |
| 55 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, " | 64 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, " |
| 56 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\"," | 65 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\"," |
| 57 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {" | 66 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {" |
| 58 "\"t\": \"°F\",\"tt\": 3} ]}} ]}"; | 67 "\"t\": \"°F\",\"tt\": 3} ]}} ]}"; |
| 59 NSString* finalString = @"46°F Thu"; | 68 NSString* finalString = @"46°F Thu"; |
| 60 | 69 |
| 61 scoped_ptr<base::Value> root(base::JSONReader::Read(weatherJson)); | 70 scoped_ptr<base::Value> root(base::JSONReader::Read(weatherJson)); |
| 62 ASSERT_NE(root, nullptr); | 71 ASSERT_NE(root, nullptr); |
| 63 base::DictionaryValue* dictionary; | 72 base::DictionaryValue* dictionary; |
| 64 root->GetAsDictionary(&dictionary); | 73 root->GetAsDictionary(&dictionary); |
| 65 ASSERT_NE(dictionary, nullptr); | 74 ASSERT_NE(dictionary, nullptr); |
| 66 AutocompleteMatch match; | 75 AutocompleteMatch match; |
| 67 match.answer = SuggestionAnswer::ParseAnswer(dictionary); | 76 match.answer = SuggestionAnswer::ParseAnswer(dictionary); |
| 68 EXPECT_TRUE(match.answer); | 77 EXPECT_TRUE(match.answer); |
| 69 [cell_ setMatch:match]; | 78 cellData_.reset([[OmniboxPopupCellData alloc] initWithMatch:match image:nil]); |
| 70 EXPECT_NSEQ([[cell_ description] string], finalString); | 79 EXPECT_NSEQ([[cellData_ description] string], finalString); |
| 71 size_t length = [[cell_ description] length]; | 80 size_t length = [[[cellData_ description] string] length]; |
| 72 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; | 81 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; |
| 73 EXPECT_EQ(length, 8UL); | 82 EXPECT_EQ(length, 8UL); |
| 74 NSDictionary* lastAttributes = nil; | 83 NSDictionary* lastAttributes = nil; |
| 75 for (const NSRange& value : checkValues) { | 84 for (const NSRange& value : checkValues) { |
| 76 NSRange range; | 85 NSRange range; |
| 77 NSDictionary* currentAttributes = | 86 NSDictionary* currentAttributes = |
| 78 [[cell_ description] attributesAtIndex:value.location | 87 [[cellData_ description] attributesAtIndex:value.location |
| 79 effectiveRange:&range]; | 88 effectiveRange:&range]; |
| 80 EXPECT_TRUE(NSEqualRanges(value, range)); | 89 EXPECT_TRUE(NSEqualRanges(value, range)); |
| 81 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); | 90 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); |
| 82 lastAttributes = currentAttributes; | 91 lastAttributes = currentAttributes; |
| 83 } | 92 } |
| 84 } | 93 } |
| 85 | 94 |
| 86 } // namespace | 95 } // namespace |
| OLD | NEW |