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

Unified 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: Tweaked API and finished unit tests Created 6 years, 2 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
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
index 0e193f4f27bd0e6f8ba33cb542a4fe75cc7b7092..8b8e697df314d111d706194270658b06ece0e5b0 100644
--- a/components/omnibox/search_suggestion_parser_unittest.cc
+++ b/components/omnibox/search_suggestion_parser_unittest.cc
@@ -7,6 +7,7 @@
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
+#include "components/omnibox/suggestion_answer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -28,12 +29,14 @@ TEST(SearchSuggestionParser, GetAnswersImageURLsWithoutImagelines) {
std::vector<GURL> urls;
// No "l" entry in the dictionary.
- SearchSuggestionParser::GetAnswersImageURLs(AsDictionary("").get(), &urls);
+ SuggestionAnswer answer;
+ SuggestionAnswer::ParseAnswer(AsDictionary("").get(), &answer);
+ SearchSuggestionParser::GetAnswersImageURLs(answer, &urls);
EXPECT_TRUE(urls.empty());
// Empty "l" entry in the dictionary.
- SearchSuggestionParser::GetAnswersImageURLs(
- AsDictionary("{ \"l\" : {} } ").get(), &urls);
+ SuggestionAnswer::ParseAnswer(AsDictionary("{ \"l\" : {} } ").get(), &answer);
+ SearchSuggestionParser::GetAnswersImageURLs(answer, &urls);
EXPECT_TRUE(urls.empty());
}
@@ -41,10 +44,14 @@ 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);
+ "{ \"l\" : ["
+ "{\"il\": { \"t\": [{\"t\": \"some text\", \"tt\": 5}]}},"
+ "{\"il\": { \"t\": [{\"t\": \"other text\", \"tt\": 8}],"
+ " \"i\": {\"d\": \"//ssl.gstatic.com/foo.png\", \"t\": 3}}}]}";
+ SuggestionAnswer answer;
+ answer.SetType("532");
+ SuggestionAnswer::ParseAnswer(AsDictionary(answer_json).get(), &answer);
+ SearchSuggestionParser::GetAnswersImageURLs(answer, &urls);
ASSERT_EQ(1U, urls.size());
EXPECT_EQ("https://ssl.gstatic.com/foo.png", urls[0].spec());
}

Powered by Google App Engine
This is Rietveld 408576698