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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm

Issue 1099403005: [AiS] changing mac omnibox suggestions form NSMatrix to NSTableView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved description access to test code Created 5 years, 6 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
OLDNEW
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
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.
17 - (NSAttributedString*)description;
18
19 - (void)setImage:(NSImage*)image;
20 @end
21
14 namespace { 22 namespace {
15 23
16 class OmniboxPopupCellTest : public CocoaTest { 24 class OmniboxPopupCellTest : public CocoaTest {
17 public: 25 public:
18 OmniboxPopupCellTest() { 26 OmniboxPopupCellTest() {
19 } 27 }
20 28
21 void SetUp() override { 29 void SetUp() override {
22 CocoaTest::SetUp(); 30 CocoaTest::SetUp();
23 cell_.reset([[OmniboxPopupCell alloc] initTextCell:@""]); 31 cellData_.reset([[OmniboxPopupCellData alloc] init]);
24 button_.reset([[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]); 32 cell_.reset([[OmniboxPopupCell alloc] init]);
25 [button_ setCell:cell_]; 33 [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.
26 [[test_window() contentView] addSubview:button_]; 34 control_.reset([[NSControl alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]);
35 [control_ setCell:cell_];
36 [[test_window() contentView] addSubview:control_];
27 }; 37 };
28 38
29 protected: 39 protected:
40 base::scoped_nsobject<OmniboxPopupCellData> cellData_;
30 base::scoped_nsobject<OmniboxPopupCell> cell_; 41 base::scoped_nsobject<OmniboxPopupCell> cell_;
31 base::scoped_nsobject<NSButton> button_; 42 base::scoped_nsobject<NSControl> control_;
32 43
33 private: 44 private:
34 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupCellTest); 45 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupCellTest);
35 }; 46 };
36 47
37 TEST_VIEW(OmniboxPopupCellTest, button_); 48 TEST_VIEW(OmniboxPopupCellTest, control_);
38 49
39 TEST_F(OmniboxPopupCellTest, Image) { 50 TEST_F(OmniboxPopupCellTest, Image) {
40 [cell_ setImage:[NSImage imageNamed:NSImageNameInfo]]; 51 [cellData_ setImage:[NSImage imageNamed:NSImageNameInfo]];
41 [button_ display]; 52 [control_ display];
42 } 53 }
43 54
44 TEST_F(OmniboxPopupCellTest, Title) { 55 TEST_F(OmniboxPopupCellTest, Title) {
45 base::scoped_nsobject<NSAttributedString> text([[NSAttributedString alloc] 56 base::scoped_nsobject<NSAttributedString> text([[NSAttributedString alloc]
46 initWithString:@"The quick brown fox jumps over the lazy dog."]); 57 initWithString:@"The quick brown fox jumps over the lazy dog."]);
47 [cell_ setAttributedTitle:text]; 58 [cellData_ setContents:text];
48 [button_ display]; 59 [control_ display];
49 } 60 }
50 61
51 TEST_F(OmniboxPopupCellTest, AnswerStyle) { 62 TEST_F(OmniboxPopupCellTest, AnswerStyle) {
52 const char* weatherJson = 63 const char* weatherJson =
53 "{\"l\": [ {\"il\": {\"t\": [ {" 64 "{\"l\": [ {\"il\": {\"t\": [ {"
54 "\"t\": \"weather in pari&lt;b&gt;s&lt;/b&gt;\", \"tt\": 8} ]}}, {" 65 "\"t\": \"weather in pari&lt;b&gt;s&lt;/b&gt;\", \"tt\": 8} ]}}, {"
55 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, " 66 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, "
56 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\"," 67 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\","
57 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {" 68 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {"
58 "\"t\": \"°F\",\"tt\": 3} ]}} ]}"; 69 "\"t\": \"°F\",\"tt\": 3} ]}} ]}";
59 NSString* finalString = @"46°F Thu"; 70 NSString* finalString = @"46°F Thu";
60 71
61 scoped_ptr<base::Value> root(base::JSONReader::Read(weatherJson)); 72 scoped_ptr<base::Value> root(base::JSONReader::Read(weatherJson));
62 ASSERT_NE(root, nullptr); 73 ASSERT_NE(root, nullptr);
63 base::DictionaryValue* dictionary; 74 base::DictionaryValue* dictionary;
64 root->GetAsDictionary(&dictionary); 75 root->GetAsDictionary(&dictionary);
65 ASSERT_NE(dictionary, nullptr); 76 ASSERT_NE(dictionary, nullptr);
66 AutocompleteMatch match; 77 AutocompleteMatch match;
67 match.answer = SuggestionAnswer::ParseAnswer(dictionary); 78 match.answer = SuggestionAnswer::ParseAnswer(dictionary);
68 EXPECT_TRUE(match.answer); 79 EXPECT_TRUE(match.answer);
69 [cell_ setMatch:match]; 80 cellData_.reset([[OmniboxPopupCellData alloc] initWithMatch:match image:nil]);
70 EXPECT_NSEQ([[cell_ description] string], finalString); 81 EXPECT_NSEQ([[cellData_ description] string], finalString);
71 size_t length = [[cell_ description] length]; 82 size_t length = [[[cellData_ description] string] length];
72 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; 83 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}};
73 EXPECT_EQ(length, 8UL); 84 EXPECT_EQ(length, 8UL);
74 NSDictionary* lastAttributes = nil; 85 NSDictionary* lastAttributes = nil;
75 for (const NSRange& value : checkValues) { 86 for (const NSRange& value : checkValues) {
76 NSRange range; 87 NSRange range;
77 NSDictionary* currentAttributes = 88 NSDictionary* currentAttributes =
78 [[cell_ description] attributesAtIndex:value.location 89 [[cellData_ description] attributesAtIndex:value.location
79 effectiveRange:&range]; 90 effectiveRange:&range];
80 EXPECT_TRUE(NSEqualRanges(value, range)); 91 EXPECT_TRUE(NSEqualRanges(value, range));
81 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); 92 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]);
82 lastAttributes = currentAttributes; 93 lastAttributes = currentAttributes;
83 } 94 }
84 } 95 }
85 96
86 } // namespace 97 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698