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.
5 #include "components/omnibox/search_suggestion_parser.h"
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"
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
);
22 return scoped_ptr
<base::DictionaryValue
>(new base::DictionaryValue
);
27 TEST(SearchSuggestionParser
, GetAnswersImageURLsWithoutImagelines
) {
28 std::vector
<GURL
> urls
;
30 // No "l" entry in the dictionary.
31 SearchSuggestionParser::GetAnswersImageURLs(AsDictionary("").get(), &urls
);
32 EXPECT_TRUE(urls
.empty());
34 // Empty "l" entry in the dictionary.
35 SearchSuggestionParser::GetAnswersImageURLs(
36 AsDictionary("{ \"l\" : {} } ").get(), &urls
);
37 EXPECT_TRUE(urls
.empty());
40 TEST(SearchSuggestionParser
, GetAnswersImageURLsWithValidImage
) {
41 std::vector
<GURL
> urls
;
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(),
48 ASSERT_EQ(1U, urls
.size());
49 EXPECT_EQ("https://ssl.gstatic.com/foo.png", urls
[0].spec());