Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: components/omnibox/search_suggestion_parser_unittest.cc

Issue 669573005: Add a class to parse answer json. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix case on "copyright" Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/omnibox/search_suggestion_parser.cc ('k') | components/omnibox/suggestion_answer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « components/omnibox/search_suggestion_parser.cc ('k') | components/omnibox/suggestion_answer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698