Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / autocomplete / search_provider_unittest.cc
index 13e0818..459eb38 100644 (file)
@@ -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"
@@ -75,10 +76,10 @@ class SearchProviderForTest : public SearchProvider {
   bool is_success() { return is_success_; };
 
  protected:
-  virtual ~SearchProviderForTest();
+  ~SearchProviderForTest() override;
 
  private:
-  virtual void RecordDeletionResult(bool success) OVERRIDE;
+  void RecordDeletionResult(bool success) override;
   bool is_success_;
   DISALLOW_COPY_AND_ASSIGN(SearchProviderForTest);
 };
@@ -157,8 +158,8 @@ class SearchProviderTest : public testing::Test,
   }
 
   // See description above class for what this registers.
-  virtual void SetUp() OVERRIDE;
-  virtual void TearDown() OVERRIDE;
+  void SetUp() override;
+  void TearDown() override;
 
   void RunTest(TestData* cases, int num_cases, bool prefer_keyword);
 
@@ -185,7 +186,7 @@ class SearchProviderTest : public testing::Test,
 
   // AutocompleteProviderListener:
   // If we're waiting for the provider to finish, this exits the message loop.
-  virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
+  void OnProviderUpdate(bool updated_matches) override;
 
   // Runs a nested message loop until provider_ is done. The message loop is
   // exited by way of OnProviderUpdate.
@@ -322,7 +323,7 @@ void SearchProviderTest::SetUp() {
       &profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
 
   provider_ = new SearchProviderForTest(this, turl_model, &profile_);
-  provider_->kMinimumTimeBetweenSuggestQueriesMs = 0;
+  OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0;
 }
 
 void SearchProviderTest::TearDown() {
@@ -338,7 +339,7 @@ void SearchProviderTest::RunTest(TestData* cases,
   ACMatches matches;
   for (int i = 0; i < num_cases; ++i) {
     AutocompleteInput input(cases[i].input, base::string16::npos,
-                            base::string16(), GURL(),
+                            std::string(), GURL(),
                             metrics::OmniboxEventProto::INVALID_SPEC, false,
                             prefer_keyword, true, true,
                             ChromeAutocompleteSchemeClassifier(&profile_));
@@ -383,7 +384,7 @@ void SearchProviderTest::QueryForInput(const base::string16& text,
                                        bool prevent_inline_autocomplete,
                                        bool prefer_keyword) {
   // Start a query.
-  AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(),
+  AutocompleteInput input(text, base::string16::npos, std::string(), GURL(),
                           metrics::OmniboxEventProto::INVALID_SPEC,
                           prevent_inline_autocomplete, prefer_keyword, true,
                           true, ChromeAutocompleteSchemeClassifier(&profile_));
@@ -797,7 +798,7 @@ TEST_F(SearchProviderTest, DontGiveNavsuggestionsInForcedQueryMode) {
       { "a2", "a", kEmptyMatch } },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     ForcedQueryTestHelper("a", cases[i].json, cases[i].matches_in_default_mode,
                            "regular input with json=" + cases[i].json);
     ForcedQueryTestHelper("?a", cases[i].json,
@@ -1001,7 +1002,7 @@ TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
       TemplateURLServiceFactory::GetForProfile(&profile_),
       NULL, AutocompleteProvider::TYPE_SEARCH);
   controller.Start(AutocompleteInput(
-      ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(),
+      ASCIIToUTF16("k t"), base::string16::npos, std::string(), GURL(),
       metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true,
       ChromeAutocompleteSchemeClassifier(&profile_)));
   const AutocompleteResult& result = controller.result();
@@ -1247,7 +1248,7 @@ TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) {
       { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } }
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // Send the query twice in order to have a synchronous pass after the first
     // response is received.  This is necessary because SearchProvider doesn't
     // allow an asynchronous response to change the default match.
@@ -1262,13 +1263,13 @@ TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) {
         cases[i].default_provider_json + " and keyword_provider_json=" +
         cases[i].keyword_provider_json);
     const ACMatches& matches = provider_->matches();
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
     size_t j = 0;
     // Ensure that the returned matches equal the expectations.
     for (; j < matches.size(); ++j)
       EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents);
     // Ensure that no expected matches are missing.
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
+    for (; j < arraysize(cases[i].matches); ++j)
       EXPECT_EQ(std::string(), cases[i].matches[j]);
   }
 }
@@ -1492,7 +1493,7 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
       std::string() },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // Send the query twice in order to have a synchronous pass after the first
     // response is received.  This is necessary because SearchProvider doesn't
     // allow an asynchronous response to change the default match.
@@ -1502,8 +1503,8 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
     }
 
     const std::string description = "for input with json=" + cases[i].json;
-    CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].matches),
-                 cases[i].matches, provider_->matches());
+    CheckMatches(description, arraysize(cases[i].matches), cases[i].matches,
+                 provider_->matches());
   }
 }
 
@@ -1924,7 +1925,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
       "3" },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // Send the query twice in order to have a synchronous pass after the first
     // response is received.  This is necessary because SearchProvider doesn't
     // allow an asynchronous response to change the default match.
@@ -1962,7 +1963,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
     EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
               it->inline_autocompletion);
 
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
     size_t j = 0;
     // Ensure that the returned matches equal the expectations.
     for (; j < matches.size(); ++j) {
@@ -1974,7 +1975,7 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
                 matches[j].allowed_to_be_default_match);
     }
     // Ensure that no expected matches are missing.
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+    for (; j < arraysize(cases[i].matches); ++j) {
       SCOPED_TRACE(" Case # " + base::IntToString(i));
       EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents);
     }
@@ -2162,7 +2163,7 @@ TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
         kEmptyExpectedMatch } },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // First, send the query "a" and receive the JSON response |first_json|.
     ClearAllResults();
     QueryForInputAndWaitForFetcherResponses(
@@ -2171,14 +2172,14 @@ TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
     // Verify that the matches after the asynchronous results are as expected.
     std::string description = "first asynchronous response for input with "
         "first_json=" + cases[i].first_json;
-    CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].first_async_matches),
+    CheckMatches(description, arraysize(cases[i].first_async_matches),
                  cases[i].first_async_matches, provider_->matches());
 
     // Then, send the query "ab" and check the synchronous matches.
     description = "synchronous response after the first keystroke after input "
         "with first_json=" + cases[i].first_json;
     QueryForInput(ASCIIToUTF16("ab"), false, false);
-    CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].sync_matches),
+    CheckMatches(description, arraysize(cases[i].sync_matches),
                  cases[i].sync_matches, provider_->matches());
 
     // Finally, get the provided JSON response, |second_json|, and verify the
@@ -2193,7 +2194,7 @@ TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) {
     second_fetcher->SetResponseString(cases[i].second_json);
     second_fetcher->delegate()->OnURLFetchComplete(second_fetcher);
     RunTillProviderDone();
-    CheckMatches(description, ARRAYSIZE_UNSAFE(cases[i].second_async_matches),
+    CheckMatches(description, arraysize(cases[i].second_async_matches),
                  cases[i].second_async_matches, provider_->matches());
   }
 }
@@ -2258,7 +2259,7 @@ TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
       { "term", "a1", "a2", "term2", "a3", "a4" } }
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     QueryForInputAndWaitForFetcherResponses(
         cases[i].input, false, cases[i].json, std::string());
 
@@ -2266,7 +2267,7 @@ TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
     const ACMatches& matches = provider_->matches();
 
     // Ensure no extra matches are present.
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
 
     size_t j = 0;
     // Ensure that the returned matches equal the expectations.
@@ -2274,7 +2275,7 @@ TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
       EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]),
                 matches[j].contents) << description;
     // Ensure that no expected matches are missing.
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j)
+    for (; j < arraysize(cases[i].matches); ++j)
       EXPECT_EQ(kNotApplicable, cases[i].matches[j]) <<
           "Case # " << i << " " << description;
   }
@@ -2370,7 +2371,7 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
         kEmptyMatch, kEmptyMatch } },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // Send the query twice in order to have a synchronous pass after the first
     // response is received.  This is necessary because SearchProvider doesn't
     // allow an asynchronous response to change the default match.
@@ -2382,7 +2383,7 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
     SCOPED_TRACE("input=" + cases[i].input + " json=" + cases[i].json);
     size_t j = 0;
     const ACMatches& matches = provider_->matches();
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output));
+    ASSERT_LE(matches.size(), arraysize(cases[i].output));
     // Ensure that the returned matches equal the expectations.
     for (; j < matches.size(); ++j) {
       EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents),
@@ -2392,7 +2393,7 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
                 matches[j].allowed_to_be_default_match);
     }
     // Ensure that no expected matches are missing.
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) {
+    for (; j < arraysize(cases[i].output); ++j) {
       EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents);
       EXPECT_EQ(AutocompleteMatchType::NUM_TYPES,
                 cases[i].output[j].match_type);
@@ -2594,7 +2595,7 @@ TEST_F(SearchProviderTest, NavigationInline) {
                                "?www.abc.com", std::string(), true, true },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     // First test regular mode.
     QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
     SearchSuggestionParser::NavigationResult result(
@@ -2730,7 +2731,7 @@ TEST_F(SearchProviderTest, ParseEntitySuggestion) {
       },
     },
   };
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     QueryForInputAndWaitForFetcherResponses(
         ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json,
         std::string());
@@ -2740,7 +2741,7 @@ TEST_F(SearchProviderTest, ParseEntitySuggestion) {
 
     SCOPED_TRACE("for input with json = " + cases[i].response_json);
 
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
     size_t j = 0;
     // Ensure that the returned matches equal the expectations.
     for (; j < matches.size(); ++j) {
@@ -2757,7 +2758,7 @@ TEST_F(SearchProviderTest, ParseEntitySuggestion) {
       EXPECT_EQ(match.type, matches[j].type);
     }
     // Ensure that no expected matches are missing.
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+    for (; j < arraysize(cases[i].matches); ++j) {
       SCOPED_TRACE(" and match index: " + base::IntToString(j));
       EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable);
       EXPECT_EQ(cases[i].matches[j].description, kNotApplicable);
@@ -2856,7 +2857,7 @@ TEST_F(SearchProviderTest, PrefetchMetadataParsing) {
     }
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     QueryForInputAndWaitForFetcherResponses(
         ASCIIToUTF16(cases[i].input_text),
         cases[i].prefer_keyword_provider_results,
@@ -2871,7 +2872,7 @@ TEST_F(SearchProviderTest, PrefetchMetadataParsing) {
     ASSERT_FALSE(matches.empty());
     EXPECT_GE(matches[0].relevance, 1300);
 
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
     // Ensure that the returned matches equal the expectations.
     for (size_t j = 0; j < matches.size(); ++j) {
       SCOPED_TRACE(description);
@@ -2954,7 +2955,7 @@ TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) {
     },
   };
 
-  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+  for (size_t i = 0; i < arraysize(cases); ++i) {
     ClearAllResults();
     QueryForInputAndWaitForFetcherResponses(
         ASCIIToUTF16(cases[i].input_text), false,
@@ -2966,7 +2967,7 @@ TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) {
     EXPECT_GE(matches[0].relevance, 1300);
 
     SCOPED_TRACE("for case: " + base::IntToString(i));
-    ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
+    ASSERT_LE(matches.size(), arraysize(cases[i].matches));
     size_t j = 0;
     // Ensure that the returned matches equal the expectations.
     for (; j < matches.size(); ++j) {
@@ -2975,7 +2976,7 @@ TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) {
                 base::UTF16ToUTF8(matches[j].contents));
       EXPECT_EQ(cases[i].matches[j].type, matches[j].type);
     }
-    for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) {
+    for (; j < arraysize(cases[i].matches); ++j) {
       SCOPED_TRACE("and match: " + base::IntToString(j));
       EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable);
       EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES);
@@ -3061,7 +3062,7 @@ TEST_F(SearchProviderTest, ParseDeletionUrl) {
        },
      };
 
-     for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+     for (size_t i = 0; i < arraysize(cases); ++i) {
        QueryForInputAndWaitForFetcherResponses(
            ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json,
            std::string());
@@ -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,22 @@ TEST_F(SearchProviderTest, AnswersCache) {
 }
 
 TEST_F(SearchProviderTest, RemoveExtraAnswers) {
+  SuggestionAnswer answer1;
+  answer1.set_type(42);
+  SuggestionAnswer answer2;
+  answer2.set_type(1983);
+  SuggestionAnswer answer3;
+  answer3.set_type(423);
+
   ACMatches matches;
   AutocompleteMatch match1, match2, match3, match4, match5;
+  match1.answer = SuggestionAnswer::copy(&answer1);
   match1.answer_contents = base::ASCIIToUTF16("the answer");
   match1.answer_type = base::ASCIIToUTF16("42");
+  match3.answer = SuggestionAnswer::copy(&answer2);
   match3.answer_contents = base::ASCIIToUTF16("not to play");
   match3.answer_type = base::ASCIIToUTF16("1983");
+  match5.answer = SuggestionAnswer::copy(&answer3);
   match5.answer_contents = base::ASCIIToUTF16("a man");
   match5.answer_type = base::ASCIIToUTF16("423");
 
@@ -3446,12 +3457,17 @@ TEST_F(SearchProviderTest, RemoveExtraAnswers) {
   SearchProvider::RemoveExtraAnswers(&matches);
   EXPECT_EQ(base::ASCIIToUTF16("the answer"), matches[0].answer_contents);
   EXPECT_EQ(base::ASCIIToUTF16("42"), matches[0].answer_type);
+  EXPECT_TRUE(answer1.Equals(*matches[0].answer));
   EXPECT_TRUE(matches[1].answer_contents.empty());
   EXPECT_TRUE(matches[1].answer_type.empty());
+  EXPECT_FALSE(matches[1].answer);
   EXPECT_TRUE(matches[2].answer_contents.empty());
   EXPECT_TRUE(matches[2].answer_type.empty());
+  EXPECT_FALSE(matches[2].answer);
   EXPECT_TRUE(matches[3].answer_contents.empty());
   EXPECT_TRUE(matches[3].answer_type.empty());
+  EXPECT_FALSE(matches[3].answer);
   EXPECT_TRUE(matches[4].answer_contents.empty());
   EXPECT_TRUE(matches[4].answer_type.empty());
+  EXPECT_FALSE(matches[4].answer);
 }