| Index: chrome/browser/omnibox_performance_browsertest.cc
|
| diff --git a/chrome/browser/omnibox_performance_browsertest.cc b/chrome/browser/omnibox_performance_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2af8de92255b5ad28e3da8d65113d3503c012670
|
| --- /dev/null
|
| +++ b/chrome/browser/omnibox_performance_browsertest.cc
|
| @@ -0,0 +1,163 @@
|
| +// Copyright (c) 2016 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 <string>
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/history/history_service_factory.h"
|
| +#include "chrome/browser/search_engines/template_url_service_factory.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_window.h"
|
| +#include "chrome/browser/ui/location_bar/location_bar.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "chrome/test/base/interactive_test_utils.h"
|
| +#include "chrome/test/base/search_test_utils.h"
|
| +#include "components/history/core/browser/history_service.h"
|
| +#include "components/omnibox/browser/omnibox_popup_model.h"
|
| +#include "components/omnibox/browser/omnibox_view.h"
|
| +#include "components/search_engines/template_url_service.h"
|
| +#include "testing/perf/scoped_histogram_result_printer.h"
|
| +
|
| +using base::Time;
|
| +using base::TimeDelta;
|
| +using history::HistoryService;
|
| +
|
| +namespace {
|
| +
|
| +constexpr char kPopularUrl[] = "http://long.popular_url_with.many_variations/";
|
| +
|
| +struct TestHistoryEntry {
|
| + std::string url;
|
| + std::string title;
|
| + int visit_count;
|
| + int typed_count;
|
| +};
|
| +
|
| +void AddControllerHistograms(perf_test::ScopedHistogramResultPrinter* printer) {
|
| + DCHECK(printer);
|
| + std::string histogram_prefix("Omnibox.ProviderTime2.");
|
| + std::string measurement_prefix("ProviderTime2.");
|
| +
|
| + printer->AddHistogramStrict(histogram_prefix + "HistoryURL",
|
| + measurement_prefix + "HistoryURL");
|
| + printer->AddHistogramStrict(histogram_prefix + "HistoryQuick",
|
| + measurement_prefix + "HistoryQuick");
|
| + printer->AddHistogramStrict("Omnibox.StartSearchToFirstResultsTime",
|
| + "StartSearchToFirstResultsTime");
|
| + printer->AddHistogramStrict("Omnibox.HistoryIDSetFromWords",
|
| + "HistoryIDSetFromWords");
|
| +}
|
| +
|
| +std::string GenerateSymbolsToChooseFrom() {
|
| + std::string res;
|
| + auto append_chars = [&res](char from, char to) {
|
| + for (char ch = from; ch <= to; ++ch)
|
| + res += ch;
|
| + };
|
| + append_chars('a', 'z');
|
| + append_chars('A', 'Z');
|
| + append_chars('0', '9');
|
| + res += ",/=+?#";
|
| + return res;
|
| +}
|
| +
|
| +std::string GenerateWeiredShortString(int seed) {
|
| + CR_DEFINE_STATIC_LOCAL(std::string, syms, (GenerateSymbolsToChooseFrom()));
|
| + std::string res;
|
| + // Much like translating to another calculation system.
|
| + for (auto i = std::hash<int>()(seed); i; i /= syms.size()) {
|
| + res += syms[i % syms.size()];
|
| + }
|
| + return res;
|
| +}
|
| +
|
| +std::string GeneratePopularUrlVariation() {
|
| + static long iteration = 0;
|
| + std::string res = kPopularUrl;
|
| +
|
| + constexpr int kShortStringsCount = 5;
|
| + for (int i = iteration; i < iteration + kShortStringsCount; ++i)
|
| + res += GenerateWeiredShortString(i);
|
| +
|
| + ++iteration;
|
| + return res;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class OmniboxPerformanceTest : public InProcessBrowserTest {
|
| + protected:
|
| + void SetUpOnMainThread() override;
|
| + void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time);
|
| +
|
| + OmniboxView* omnibox_view_ = nullptr;
|
| + AutocompleteController* ac_controller_ = nullptr;
|
| + HistoryService* history_service_ = nullptr;
|
| +};
|
| +
|
| +void OmniboxPerformanceTest::SetUpOnMainThread() {
|
| + omnibox_view_ = browser()->window()->GetLocationBar()->GetOmniboxView();
|
| + ASSERT_TRUE(omnibox_view_);
|
| +
|
| + ac_controller_ =
|
| + omnibox_view_->model()->popup_model()->autocomplete_controller();
|
| + ASSERT_TRUE(ac_controller_);
|
| +
|
| + // History
|
| + {
|
| + Profile* profile = browser()->profile();
|
| +
|
| + search_test_utils::WaitForTemplateURLServiceToLoad(
|
| + TemplateURLServiceFactory::GetForProfile(profile));
|
| +
|
| + history_service_ = HistoryServiceFactory::GetForProfile(
|
| + profile, ServiceAccessType::EXPLICIT_ACCESS);
|
| + ASSERT_TRUE(history_service_);
|
| +
|
| + ui_test_utils::WaitForHistoryToLoad(history_service_);
|
| + ASSERT_TRUE(history_service_->BackendLoaded());
|
| + }
|
| +}
|
| +
|
| +void OmniboxPerformanceTest::AddHistoryEntry(const TestHistoryEntry& entry,
|
| + const Time& time) {
|
| + history_service_->AddPageWithDetails(
|
| + GURL(entry.url), base::UTF8ToUTF16(entry.title), entry.visit_count,
|
| + entry.typed_count, time, false, history::SOURCE_BROWSED);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(OmniboxPerformanceTest, DeletingPopularUrl) {
|
| + // Preparing histogram printer.
|
| + perf_test::ScopedHistogramResultPrinter scoped_printer(
|
| + perf_test::TestBasedPerfTestPrinter(::testing::UnitTest::GetInstance(),
|
| + "ms"));
|
| + AddControllerHistograms(&scoped_printer);
|
| +
|
| + // Generating urls.
|
| + {
|
| + constexpr std::size_t kNumberOfUrls = 10000;
|
| + for (std::size_t i = 0; i < kNumberOfUrls; ++i) {
|
| + constexpr int kVisitCount = 1;
|
| + constexpr int kTypedCount = 1;
|
| + auto new_entry = GeneratePopularUrlVariation();
|
| + AddHistoryEntry(
|
| + {
|
| + new_entry, "Page: " + std::to_string(i), kVisitCount, kTypedCount,
|
| + },
|
| + base::Time::Now() - base::TimeDelta::FromHours(i));
|
| + }
|
| + }
|
| +
|
| + const std::string test_url = GeneratePopularUrlVariation();
|
| +
|
| + omnibox_view_->SetFocus();
|
| + omnibox_view_->SelectAll(true);
|
| + omnibox_view_->SetUserText(base::UTF8ToUTF16(test_url));
|
| + ui_test_utils::WaitForAutocompleteController(*ac_controller_);
|
| +
|
| + for (size_t i = test_url.length(); i != 0; --i)
|
| + EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK, false,
|
| + false, false, false));
|
| +}
|
|
|