| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/omnibox/browser/suggestion_answer.h" | 5 #include "components/omnibox/browser/suggestion_answer.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 " { \"il\": { \"t\": [{ \"t\": \"text\", \"tt\": 8 }] } }, " | 192 " { \"il\": { \"t\": [{ \"t\": \"text\", \"tt\": 8 }] } }, " |
| 193 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 5 }], " | 193 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 5 }], " |
| 194 " \"i\": { \"d\": \"//example.com/foo.jpg\" } } } " | 194 " \"i\": { \"d\": \"//example.com/foo.jpg\" } } } " |
| 195 "] }"; | 195 "] }"; |
| 196 ASSERT_TRUE(ParseAnswer(json)); | 196 ASSERT_TRUE(ParseAnswer(json)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST(SuggestionAnswerTest, ValidPropertyValues) { | 199 TEST(SuggestionAnswerTest, ValidPropertyValues) { |
| 200 std::string json = | 200 std::string json = |
| 201 "{ \"l\": [" | 201 "{ \"l\": [" |
| 202 " { \"il\": { \"t\": [{ \"t\": \"text\", \"tt\": 8, \"ln\": 3 }, " | 202 " { \"il\": { \"t\": [{ \"t\": \"text\", \"tt\": 8 }, " |
| 203 " { \"t\": \"moar text\", \"tt\": 0 }], " | 203 " { \"t\": \"moar text\", \"tt\": 0 }], " |
| 204 " \"i\": { \"d\": \"//example.com/foo.jpg\" } } }, " | 204 " \"i\": { \"d\": \"//example.com/foo.jpg\" } } }, " |
| 205 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 5 }], " | 205 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 5, \"ln\": 3 }], " |
| 206 " \"at\": { \"t\": \"slatfatf\", \"tt\": 42 }, " | 206 " \"at\": { \"t\": \"slatfatf\", \"tt\": 42 }, " |
| 207 " \"st\": { \"t\": \"oh hi, Mark\", \"tt\": 729347 } } } " | 207 " \"st\": { \"t\": \"oh hi, Mark\", \"tt\": 729347 } } } " |
| 208 "] }"; | 208 "] }"; |
| 209 std::unique_ptr<SuggestionAnswer> answer = ParseAnswer(json); | 209 std::unique_ptr<SuggestionAnswer> answer = ParseAnswer(json); |
| 210 ASSERT_TRUE(answer); | 210 ASSERT_TRUE(answer); |
| 211 answer->set_type(420527); | 211 answer->set_type(420527); |
| 212 EXPECT_EQ(420527, answer->type()); | 212 EXPECT_EQ(420527, answer->type()); |
| 213 | 213 |
| 214 const SuggestionAnswer::ImageLine& first_line = answer->first_line(); | 214 const SuggestionAnswer::ImageLine& first_line = answer->first_line(); |
| 215 EXPECT_EQ(2U, first_line.text_fields().size()); | 215 EXPECT_EQ(2U, first_line.text_fields().size()); |
| 216 EXPECT_EQ(base::UTF8ToUTF16("text"), first_line.text_fields()[0].text()); | 216 EXPECT_EQ(base::UTF8ToUTF16("text"), first_line.text_fields()[0].text()); |
| 217 EXPECT_EQ(8, first_line.text_fields()[0].type()); | 217 EXPECT_EQ(8, first_line.text_fields()[0].type()); |
| 218 EXPECT_TRUE(first_line.text_fields()[0].has_num_lines()); | |
| 219 EXPECT_EQ(3, first_line.text_fields()[0].num_lines()); | |
| 220 EXPECT_EQ(base::UTF8ToUTF16("moar text"), first_line.text_fields()[1].text()); | 218 EXPECT_EQ(base::UTF8ToUTF16("moar text"), first_line.text_fields()[1].text()); |
| 221 EXPECT_EQ(0, first_line.text_fields()[1].type()); | 219 EXPECT_EQ(0, first_line.text_fields()[1].type()); |
| 222 EXPECT_FALSE(first_line.text_fields()[1].has_num_lines()); | 220 EXPECT_FALSE(first_line.text_fields()[1].has_num_lines()); |
| 221 EXPECT_EQ(1, first_line.TextNumLines()); |
| 223 | 222 |
| 224 EXPECT_FALSE(first_line.additional_text()); | 223 EXPECT_FALSE(first_line.additional_text()); |
| 225 EXPECT_FALSE(first_line.status_text()); | 224 EXPECT_FALSE(first_line.status_text()); |
| 226 | 225 |
| 227 EXPECT_TRUE(first_line.image_url().is_valid()); | 226 EXPECT_TRUE(first_line.image_url().is_valid()); |
| 228 EXPECT_EQ(GURL("https://example.com/foo.jpg"), first_line.image_url()); | 227 EXPECT_EQ(GURL("https://example.com/foo.jpg"), first_line.image_url()); |
| 229 | 228 |
| 230 const SuggestionAnswer::ImageLine& second_line = answer->second_line(); | 229 const SuggestionAnswer::ImageLine& second_line = answer->second_line(); |
| 231 EXPECT_EQ(1U, second_line.text_fields().size()); | 230 EXPECT_EQ(1U, second_line.text_fields().size()); |
| 232 EXPECT_EQ( | 231 EXPECT_EQ( |
| 233 base::UTF8ToUTF16("other text"), second_line.text_fields()[0].text()); | 232 base::UTF8ToUTF16("other text"), second_line.text_fields()[0].text()); |
| 234 EXPECT_EQ(5, second_line.text_fields()[0].type()); | 233 EXPECT_EQ(5, second_line.text_fields()[0].type()); |
| 234 EXPECT_TRUE(second_line.text_fields()[0].has_num_lines()); |
| 235 EXPECT_EQ(3, second_line.text_fields()[0].num_lines()); |
| 236 EXPECT_EQ(3, second_line.TextNumLines()); |
| 235 | 237 |
| 236 EXPECT_TRUE(second_line.additional_text()); | 238 EXPECT_TRUE(second_line.additional_text()); |
| 237 EXPECT_EQ( | 239 EXPECT_EQ( |
| 238 base::UTF8ToUTF16("slatfatf"), second_line.additional_text()->text()); | 240 base::UTF8ToUTF16("slatfatf"), second_line.additional_text()->text()); |
| 239 EXPECT_EQ(42, second_line.additional_text()->type()); | 241 EXPECT_EQ(42, second_line.additional_text()->type()); |
| 240 | 242 |
| 241 EXPECT_TRUE(second_line.status_text()); | 243 EXPECT_TRUE(second_line.status_text()); |
| 242 EXPECT_EQ( | 244 EXPECT_EQ( |
| 243 base::UTF8ToUTF16("oh hi, Mark"), second_line.status_text()->text()); | 245 base::UTF8ToUTF16("oh hi, Mark"), second_line.status_text()->text()); |
| 244 EXPECT_EQ(729347, second_line.status_text()->type()); | 246 EXPECT_EQ(729347, second_line.status_text()->type()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 274 " \"i\": { \"d\": \"//gstatic.com/foo.png\" } } }, " | 276 " \"i\": { \"d\": \"//gstatic.com/foo.png\" } } }, " |
| 275 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 8 }]," | 277 " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 8 }]," |
| 276 " \"i\": { \"d\": \"//gstatic.com/bar.jpg\", \"t\": 3 }}}]}"; | 278 " \"i\": { \"d\": \"//gstatic.com/bar.jpg\", \"t\": 3 }}}]}"; |
| 277 answer = ParseAnswer(json); | 279 answer = ParseAnswer(json); |
| 278 ASSERT_TRUE(answer); | 280 ASSERT_TRUE(answer); |
| 279 answer->AddImageURLsTo(&urls); | 281 answer->AddImageURLsTo(&urls); |
| 280 ASSERT_EQ(3U, urls.size()); | 282 ASSERT_EQ(3U, urls.size()); |
| 281 EXPECT_EQ(GURL("https://gstatic.com/foo.png"), urls[1]); | 283 EXPECT_EQ(GURL("https://gstatic.com/foo.png"), urls[1]); |
| 282 EXPECT_EQ(GURL("https://gstatic.com/bar.jpg"), urls[2]); | 284 EXPECT_EQ(GURL("https://gstatic.com/bar.jpg"), urls[2]); |
| 283 } | 285 } |
| OLD | NEW |