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

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

Issue 489353004: Componentize SearchProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
Index: chrome/browser/autocomplete/answers_cache_unittest.cc
diff --git a/chrome/browser/autocomplete/answers_cache_unittest.cc b/chrome/browser/autocomplete/answers_cache_unittest.cc
deleted file mode 100644
index 0ee7ef57c85c6db39459719d3ef9fe5f8232bb03..0000000000000000000000000000000000000000
--- a/chrome/browser/autocomplete/answers_cache_unittest.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// 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 "chrome/browser/autocomplete/answers_cache.h"
-
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(AnswersCacheTest, CacheStartsEmpty) {
- AnswersCache cache(1);
- EXPECT_TRUE(cache.empty());
-}
-
-TEST(AnswersCacheTest, UpdatePopulatesCache) {
- AnswersCache cache(1);
- cache.UpdateRecentAnswers(base::ASCIIToUTF16("weather los angeles"),
- base::ASCIIToUTF16("2334"));
- EXPECT_FALSE(cache.empty());
-}
-
-TEST(AnswersCacheTest, GetWillRetrieveMatchingInfo) {
- AnswersCache cache(1);
-
- base::string16 full_query_text = base::ASCIIToUTF16("weather los angeles");
- base::string16 query_type = base::ASCIIToUTF16("2334");
- cache.UpdateRecentAnswers(full_query_text, query_type);
-
- // Partial prefixes retrieve info.
- AnswersQueryData data = cache.GetTopAnswerEntry(full_query_text.substr(0, 8));
- EXPECT_EQ(full_query_text, data.full_query_text);
- EXPECT_EQ(query_type, data.query_type);
-
- // Mismatched prefix retrieves empty data.
- data = cache.GetTopAnswerEntry(full_query_text.substr(1, 8));
- EXPECT_TRUE(data.full_query_text.empty() && data.query_type.empty());
-
- // Full match retrieves info.
- data = cache.GetTopAnswerEntry(full_query_text);
- EXPECT_EQ(full_query_text, data.full_query_text);
- EXPECT_EQ(query_type, data.query_type);
-}
-
-TEST(AnswersCacheTest, MatchMostRecent) {
- AnswersCache cache(2);
-
- base::string16 query_weather_la = base::ASCIIToUTF16("weather los angeles");
- base::string16 query_weather_lv = base::ASCIIToUTF16("weather las vegas");
- base::string16 query_type = base::ASCIIToUTF16("2334");
-
- cache.UpdateRecentAnswers(query_weather_lv, query_type);
- cache.UpdateRecentAnswers(query_weather_la, query_type);
-
- // "weather los angeles" is most recent match to "weather l".
- AnswersQueryData data =
- cache.GetTopAnswerEntry(base::ASCIIToUTF16("weather l"));
- EXPECT_EQ(query_weather_la, data.full_query_text);
-
- // Update recency for "weather las vegas".
- cache.GetTopAnswerEntry(query_weather_lv);
-
- // "weather las vegas" should now be the most recent match to "weather l".
- data = cache.GetTopAnswerEntry(base::ASCIIToUTF16("weather l"));
- EXPECT_EQ(query_weather_lv, data.full_query_text);
-}
-
-TEST(AnswersCacheTest, LeastRecentItemIsEvicted) {
- AnswersCache cache(2);
-
- base::string16 query_weather_la = base::ASCIIToUTF16("weather los angeles");
- base::string16 query_weather_lv = base::ASCIIToUTF16("weather las vegas");
- base::string16 query_weather_lb = base::ASCIIToUTF16("weather long beach");
- base::string16 query_type = base::ASCIIToUTF16("2334");
-
- cache.UpdateRecentAnswers(query_weather_lb, query_type);
- cache.UpdateRecentAnswers(query_weather_lv, query_type);
- EXPECT_FALSE(
- cache.GetTopAnswerEntry(query_weather_lb).full_query_text.empty());
- EXPECT_FALSE(
- cache.GetTopAnswerEntry(query_weather_lv).full_query_text.empty());
- EXPECT_TRUE(
- cache.GetTopAnswerEntry(query_weather_la).full_query_text.empty());
-
- cache.UpdateRecentAnswers(query_weather_la, query_type);
- EXPECT_TRUE(
- cache.GetTopAnswerEntry(query_weather_lb).full_query_text.empty());
- EXPECT_FALSE(
- cache.GetTopAnswerEntry(query_weather_lv).full_query_text.empty());
- EXPECT_FALSE(
- cache.GetTopAnswerEntry(query_weather_la).full_query_text.empty());
-}
-
-TEST(AnswersCacheTest, DuplicateEntries) {
- AnswersCache cache(2);
-
- base::string16 query_weather_lv = base::ASCIIToUTF16("weather las vegas");
- base::string16 query_weather_lb = base::ASCIIToUTF16("weather long beach");
- base::string16 query_weather_l = base::ASCIIToUTF16("weather l");
- base::string16 query_type = base::ASCIIToUTF16("2334");
-
- cache.UpdateRecentAnswers(query_weather_lb, query_type);
- cache.UpdateRecentAnswers(query_weather_lv, query_type);
-
- // Test that duplicate entries update recency.
- cache.UpdateRecentAnswers(query_weather_lb, query_type);
- EXPECT_EQ(query_weather_lb,
- cache.GetTopAnswerEntry(query_weather_l).full_query_text);
-
- // Test duplicate do not evict other entries. LV should still be in cache.
- cache.UpdateRecentAnswers(query_weather_lb, query_type);
- EXPECT_FALSE(
- cache.GetTopAnswerEntry(query_weather_lv).full_query_text.empty());
-}
« no previous file with comments | « chrome/browser/autocomplete/answers_cache.cc ('k') | chrome/browser/autocomplete/autocomplete_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698