OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/omnibox/search_suggestion_parser.h" |
| 6 |
| 7 #include "base/json/json_reader.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 scoped_ptr<base::DictionaryValue> AsDictionary(const std::string& json) { |
| 16 base::Value* value = base::JSONReader::Read(json); |
| 17 base::DictionaryValue* dict; |
| 18 if (value && value->GetAsDictionary(&dict)) |
| 19 return scoped_ptr<base::DictionaryValue>(dict); |
| 20 |
| 21 delete value; |
| 22 return scoped_ptr<base::DictionaryValue>(new base::DictionaryValue); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 TEST(SearchSuggestionParser, GetAnswersImageURLsWithoutImagelines) { |
| 28 std::vector<GURL> urls; |
| 29 |
| 30 // No "l" entry in the dictionary. |
| 31 SearchSuggestionParser::GetAnswersImageURLs(AsDictionary("").get(), &urls); |
| 32 EXPECT_TRUE(urls.empty()); |
| 33 |
| 34 // Empty "l" entry in the dictionary. |
| 35 SearchSuggestionParser::GetAnswersImageURLs( |
| 36 AsDictionary("{ \"l\" : {} } ").get(), &urls); |
| 37 EXPECT_TRUE(urls.empty()); |
| 38 } |
| 39 |
| 40 TEST(SearchSuggestionParser, GetAnswersImageURLsWithValidImage) { |
| 41 std::vector<GURL> urls; |
| 42 |
| 43 const char answer_json[] = |
| 44 "{ \"l\" : [{\"il\": { \"i\": {\"d\": " |
| 45 "\"//ssl.gstatic.com/foo.png\",\"t\": 3}}}]}"; |
| 46 SearchSuggestionParser::GetAnswersImageURLs(AsDictionary(answer_json).get(), |
| 47 &urls); |
| 48 ASSERT_EQ(1U, urls.size()); |
| 49 EXPECT_EQ("https://ssl.gstatic.com/foo.png", urls[0].spec()); |
| 50 } |
OLD | NEW |