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

Unified Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 669573005: Add a class to parse answer json. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed some unit test issues 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
« no previous file with comments | « no previous file | components/components_tests.gyp » ('j') | components/omnibox/base_search_provider.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/search_provider_unittest.cc
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index b77a6de014d66d446573e3b419318d1a993d6bde..a374774be6ee652f406c6e83624ceae14a34300e 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -39,6 +39,7 @@
#include "components/omnibox/autocomplete_provider_listener.h"
#include "components/omnibox/omnibox_field_trial.h"
#include "components/omnibox/omnibox_switches.h"
+#include "components/omnibox/suggestion_answer.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
@@ -3418,8 +3419,8 @@ TEST_F(SearchProviderTest, AnswersCache) {
base::string16 query = base::ASCIIToUTF16("weather los angeles");
SearchSuggestionParser::SuggestResult suggest_result(
query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(),
- base::string16(), base::string16(), base::string16(), std::string(),
- std::string(), false, 1200, false, false, query);
+ base::string16(), base::string16(), base::string16(), nullptr,
+ std::string(), std::string(), false, 1200, false, false, query);
QueryForInput(ASCIIToUTF16("weather l"), false, false);
provider_->transformed_default_history_results_.push_back(suggest_result);
answer = provider_->FindAnswersPrefetchData();
@@ -3428,12 +3429,28 @@ TEST_F(SearchProviderTest, AnswersCache) {
}
TEST_F(SearchProviderTest, RemoveExtraAnswers) {
+ std::string json =
+ "{ \"l\": ["
+ " { \"il\": { \"t\": [{ \"t\": \"text\", \"tt\": 8 }] } }, "
+ " { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 5 }] } } "
+ "] }";
+ scoped_ptr<SuggestionAnswer> answer1;
+ SuggestionAnswer::ParseAnswer(json, &answer1);
+ answer1->set_type(42);
+ scoped_ptr<SuggestionAnswer> answer2 = SuggestionAnswer::Copy(answer1.get());
+ answer2->set_type(1983);
+ scoped_ptr<SuggestionAnswer> answer3 = SuggestionAnswer::Copy(answer1.get());
+ answer3->set_type(423);
+
ACMatches matches;
AutocompleteMatch match1, match2, match3, match4, match5;
+ match1.answer = answer1.Pass();
match1.answer_contents = base::ASCIIToUTF16("the answer");
match1.answer_type = base::ASCIIToUTF16("42");
+ match3.answer = answer2.Pass();
match3.answer_contents = base::ASCIIToUTF16("not to play");
match3.answer_type = base::ASCIIToUTF16("1983");
+ match5.answer = answer3.Pass();
match5.answer_contents = base::ASCIIToUTF16("a man");
match5.answer_type = base::ASCIIToUTF16("423");
@@ -3448,10 +3465,14 @@ TEST_F(SearchProviderTest, RemoveExtraAnswers) {
EXPECT_EQ(base::ASCIIToUTF16("42"), matches[0].answer_type);
EXPECT_TRUE(matches[1].answer_contents.empty());
EXPECT_TRUE(matches[1].answer_type.empty());
+ EXPECT_FALSE(matches[1].answer.get());
Peter Kasting 2014/10/30 03:43:29 Nit: No get() on scoped_ptrs used as bools (4 plac
Justin Donnelly 2014/10/30 19:23:13 Nice. Rachel mentioned this earlier but it slippe
EXPECT_TRUE(matches[2].answer_contents.empty());
EXPECT_TRUE(matches[2].answer_type.empty());
+ EXPECT_FALSE(matches[2].answer.get());
EXPECT_TRUE(matches[3].answer_contents.empty());
EXPECT_TRUE(matches[3].answer_type.empty());
+ EXPECT_FALSE(matches[3].answer.get());
EXPECT_TRUE(matches[4].answer_contents.empty());
EXPECT_TRUE(matches[4].answer_type.empty());
+ EXPECT_FALSE(matches[4].answer.get());
}
« no previous file with comments | « no previous file | components/components_tests.gyp » ('j') | components/omnibox/base_search_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698