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

Unified Diff: components/omnibox/browser/history_quick_provider_unittest.cc

Issue 2300323003: Adding performance tests for HQP that represent importance of optimising HistoryItemsForTerms method (Closed)
Patch Set: Rebasing on prepared components perftests. Created 4 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/browser/history_quick_provider_unittest.cc
diff --git a/components/omnibox/browser/history_quick_provider_unittest.cc b/components/omnibox/browser/history_quick_provider_unittest.cc
index 0a556fd5c6cb5d644e061cc8132c4b76c4cdfe84..67cc807d7b14fc3a43609c64e6a7b0cd93dd8177 100644
--- a/components/omnibox/browser/history_quick_provider_unittest.cc
+++ b/components/omnibox/browser/history_quick_provider_unittest.cc
@@ -13,14 +13,12 @@
#include <string>
#include <vector>
-#include "base/files/scoped_temp_dir.h"
#include "base/format_macros.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/sequenced_worker_pool_owner.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/bookmarks/test/test_bookmark_client.h"
@@ -30,15 +28,12 @@
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/url_database.h"
#include "components/history/core/test/history_service_test_util.h"
-#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_result.h"
+#include "components/omnibox/browser/fake_autocomplete_provider_client.h"
+#include "components/omnibox/browser/history_test_util.h"
#include "components/omnibox/browser/history_url_provider.h"
-#include "components/omnibox/browser/in_memory_url_index.h"
#include "components/omnibox/browser/in_memory_url_index_test_util.h"
-#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
-#include "components/omnibox/browser/test_scheme_classifier.h"
-#include "components/omnibox/browser/url_index_private_data.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_terms_data.h"
#include "sql/transaction.h"
@@ -178,57 +173,6 @@ class GetURLTask : public history::HistoryDBTask {
DISALLOW_COPY_AND_ASSIGN(GetURLTask);
};
-class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient {
- public:
- FakeAutocompleteProviderClient() : pool_owner_(3, "Background Pool") {
- bookmark_model_ = bookmarks::TestBookmarkClient::CreateModel();
- if (history_dir_.CreateUniqueTempDir()) {
- history_service_ =
- history::CreateHistoryService(history_dir_.GetPath(), true);
- }
-
- in_memory_url_index_.reset(new InMemoryURLIndex(
- bookmark_model_.get(), history_service_.get(), nullptr,
- pool_owner_.pool().get(), history_dir_.GetPath(), SchemeSet()));
- in_memory_url_index_->Init();
- }
-
- const AutocompleteSchemeClassifier& GetSchemeClassifier() const override {
- return scheme_classifier_;
- }
-
- const SearchTermsData& GetSearchTermsData() const override {
- return search_terms_data_;
- }
-
- history::HistoryService* GetHistoryService() override {
- return history_service_.get();
- }
-
- bookmarks::BookmarkModel* GetBookmarkModel() override {
- return bookmark_model_.get();
- }
-
- InMemoryURLIndex* GetInMemoryURLIndex() override {
- return in_memory_url_index_.get();
- }
-
- void set_in_memory_url_index(std::unique_ptr<InMemoryURLIndex> index) {
- in_memory_url_index_ = std::move(index);
- }
-
- private:
- base::SequencedWorkerPoolOwner pool_owner_;
- base::ScopedTempDir history_dir_;
- std::unique_ptr<bookmarks::BookmarkModel> bookmark_model_;
- TestSchemeClassifier scheme_classifier_;
- SearchTermsData search_terms_data_;
- std::unique_ptr<InMemoryURLIndex> in_memory_url_index_;
- std::unique_ptr<history::HistoryService> history_service_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient);
-};
-
} // namespace
class HistoryQuickProviderTest : public testing::Test {
@@ -347,36 +291,24 @@ void HistoryQuickProviderTest::FillData() {
for (size_t i = 0; i < data_count; ++i) {
const TestURLInfo& cur(test_data[i]);
Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now);
- sql::Transaction transaction(&db);
-
- // Add URL.
- transaction.Begin();
- std::string sql_cmd_line = base::StringPrintf(
- "INSERT INTO \"urls\" VALUES(%" PRIuS ", \'%s\', \'%s\', %d, %d, %"
- PRId64 ", 0, 0)",
- i + 1, cur.url.c_str(), cur.title.c_str(), cur.visit_count,
- cur.typed_count, visit_time.ToInternalValue());
- sql::Statement sql_stmt(db.GetUniqueStatement(sql_cmd_line.c_str()));
- EXPECT_TRUE(sql_stmt.Run());
- transaction.Commit();
-
- // Add visits.
- for (int j = 0; j < cur.visit_count; ++j) {
+
+ history::AddURLToDBForTests(&db, i + 1, cur.url, cur.title, cur.visit_count,
+ cur.typed_count, visit_time);
+
+ auto add_visit = [&db, &visit_id, &visit_time,
+ &i](ui::PageTransition transtition) mutable {
Peter Kasting 2016/10/24 22:28:29 Nit: Can just use [&]
dyaroshev 2016/10/26 22:29:13 I thought it wasn't allowed. Done.
// Assume earlier visits are at one-day intervals.
visit_time -= TimeDelta::FromDays(1);
- transaction.Begin();
- // Mark the most recent |cur.typed_count| visits as typed.
- std::string sql_cmd_line = base::StringPrintf(
- "INSERT INTO \"visits\" VALUES(%" PRIuS ", %" PRIuS ", %" PRId64
- ", 0, %d, 0, 1)",
- visit_id++, i + 1, visit_time.ToInternalValue(),
- (j < cur.typed_count) ? ui::PAGE_TRANSITION_TYPED :
- ui::PAGE_TRANSITION_LINK);
-
- sql::Statement sql_stmt(db.GetUniqueStatement(sql_cmd_line.c_str()));
- EXPECT_TRUE(sql_stmt.Run());
- transaction.Commit();
- }
+ history::AddVisitToDBForTests(&db, visit_id++, i + 1, visit_time,
+ transtition);
+ };
+
+ // Mark the most recent |cur.typed_count| visits as typed.
+ for (int j = 0; j < cur.typed_count; ++j)
+ add_visit(ui::PAGE_TRANSITION_TYPED);
+
+ for (int j = cur.typed_count; j < cur.visit_count; ++j)
+ add_visit(ui::PAGE_TRANSITION_LINK);
}
}

Powered by Google App Engine
This is Rietveld 408576698