Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / omnibox / search_suggestion_parser_unittest.cc
blob0e193f4f27bd0e6f8ba33cb542a4fe75cc7b7092
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"
11 #include "url/gurl.h"
13 namespace {
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);
21 delete value;
22 return scoped_ptr<base::DictionaryValue>(new base::DictionaryValue);
25 } // namespace
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(),
47 &urls);
48 ASSERT_EQ(1U, urls.size());
49 EXPECT_EQ("https://ssl.gstatic.com/foo.png", urls[0].spec());