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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 TEST_F(OmniboxPopupCellTest, AnswerStyle) { | 66 TEST_F(OmniboxPopupCellTest, AnswerStyle) { |
67 const char* weatherJson = | 67 const char* weatherJson = |
68 "{\"l\": [ {\"il\": {\"t\": [ {" | 68 "{\"l\": [ {\"il\": {\"t\": [ {" |
69 "\"t\": \"weather in pari<b>s</b>\", \"tt\": 8} ]}}, {" | 69 "\"t\": \"weather in pari<b>s</b>\", \"tt\": 8} ]}}, {" |
70 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, " | 70 "\"il\": {\"at\": {\"t\": \"Thu\",\"tt\": 12}, " |
71 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\"," | 71 "\"i\": {\"d\": \"//ssl.gstatic.com/onebox/weather/64/cloudy.png\"," |
72 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {" | 72 "\"t\": 3}, \"t\": [ {\"t\": \"46\",\"tt\": 1}, {" |
73 "\"t\": \"°F\",\"tt\": 3} ]}} ]}"; | 73 "\"t\": \"°F\",\"tt\": 3} ]}} ]}"; |
74 NSString* finalString = @"46°F Thu"; | 74 NSString* finalString = @"46°F Thu"; |
75 | 75 |
76 scoped_ptr<base::Value> root(base::JSONReader::Read(weatherJson)); | 76 std::unique_ptr<base::Value> root(base::JSONReader::Read(weatherJson)); |
77 ASSERT_NE(root, nullptr); | 77 ASSERT_NE(root, nullptr); |
78 base::DictionaryValue* dictionary; | 78 base::DictionaryValue* dictionary; |
79 root->GetAsDictionary(&dictionary); | 79 root->GetAsDictionary(&dictionary); |
80 ASSERT_NE(dictionary, nullptr); | 80 ASSERT_NE(dictionary, nullptr); |
81 AutocompleteMatch match; | 81 AutocompleteMatch match; |
82 match.answer = SuggestionAnswer::ParseAnswer(dictionary); | 82 match.answer = SuggestionAnswer::ParseAnswer(dictionary); |
83 EXPECT_TRUE(match.answer); | 83 EXPECT_TRUE(match.answer); |
84 cellData_.reset([[OmniboxPopupCellData alloc] initWithMatch:match | 84 cellData_.reset([[OmniboxPopupCellData alloc] initWithMatch:match |
85 contentsOffset:0 | 85 contentsOffset:0 |
86 image:nil | 86 image:nil |
87 answerImage:nil]); | 87 answerImage:nil]); |
88 EXPECT_NSEQ([[cellData_ description] string], finalString); | 88 EXPECT_NSEQ([[cellData_ description] string], finalString); |
89 size_t length = [[[cellData_ description] string] length]; | 89 size_t length = [[[cellData_ description] string] length]; |
90 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; | 90 const NSRange checkValues[] = {{0, 2}, {2, 2}, {4, 4}}; |
91 EXPECT_EQ(length, 8UL); | 91 EXPECT_EQ(length, 8UL); |
92 NSDictionary* lastAttributes = nil; | 92 NSDictionary* lastAttributes = nil; |
93 for (const NSRange& value : checkValues) { | 93 for (const NSRange& value : checkValues) { |
94 NSRange range; | 94 NSRange range; |
95 NSDictionary* currentAttributes = | 95 NSDictionary* currentAttributes = |
96 [[cellData_ description] attributesAtIndex:value.location | 96 [[cellData_ description] attributesAtIndex:value.location |
97 effectiveRange:&range]; | 97 effectiveRange:&range]; |
98 EXPECT_TRUE(NSEqualRanges(value, range)); | 98 EXPECT_TRUE(NSEqualRanges(value, range)); |
99 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); | 99 EXPECT_FALSE([currentAttributes isEqualToDictionary:lastAttributes]); |
100 lastAttributes = currentAttributes; | 100 lastAttributes = currentAttributes; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
OLD | NEW |