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

Unified Diff: components/omnibox/search_suggestion_parser_unittest.cc

Issue 470403003: [AiS] Fix parsing for Answers Images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to HEAD Created 6 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/omnibox/search_suggestion_parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/omnibox/search_suggestion_parser_unittest.cc
diff --git a/components/omnibox/search_suggestion_parser_unittest.cc b/components/omnibox/search_suggestion_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0e193f4f27bd0e6f8ba33cb542a4fe75cc7b7092
--- /dev/null
+++ b/components/omnibox/search_suggestion_parser_unittest.cc
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/omnibox/search_suggestion_parser.h"
+
+#include "base/json/json_reader.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace {
+
+scoped_ptr<base::DictionaryValue> AsDictionary(const std::string& json) {
+ base::Value* value = base::JSONReader::Read(json);
+ base::DictionaryValue* dict;
+ if (value && value->GetAsDictionary(&dict))
+ return scoped_ptr<base::DictionaryValue>(dict);
+
+ delete value;
+ return scoped_ptr<base::DictionaryValue>(new base::DictionaryValue);
+}
+
+} // namespace
+
+TEST(SearchSuggestionParser, GetAnswersImageURLsWithoutImagelines) {
+ std::vector<GURL> urls;
+
+ // No "l" entry in the dictionary.
+ SearchSuggestionParser::GetAnswersImageURLs(AsDictionary("").get(), &urls);
+ EXPECT_TRUE(urls.empty());
+
+ // Empty "l" entry in the dictionary.
+ SearchSuggestionParser::GetAnswersImageURLs(
+ AsDictionary("{ \"l\" : {} } ").get(), &urls);
+ EXPECT_TRUE(urls.empty());
+}
+
+TEST(SearchSuggestionParser, GetAnswersImageURLsWithValidImage) {
+ std::vector<GURL> urls;
+
+ const char answer_json[] =
+ "{ \"l\" : [{\"il\": { \"i\": {\"d\": "
+ "\"//ssl.gstatic.com/foo.png\",\"t\": 3}}}]}";
+ SearchSuggestionParser::GetAnswersImageURLs(AsDictionary(answer_json).get(),
+ &urls);
+ ASSERT_EQ(1U, urls.size());
+ EXPECT_EQ("https://ssl.gstatic.com/foo.png", urls[0].spec());
+}
« no previous file with comments | « components/omnibox/search_suggestion_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698