File: test_omnibox_client.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (150 lines) | stat: -rw-r--r-- 4,936 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/omnibox/browser/test_omnibox_client.h"

#include <memory>
#include <utility>
#include <vector>

#include "base/functional/callback.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_scheme_classifier.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/mock_unscoped_extension_provider_delegate.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"

TestOmniboxClient::TestOmniboxClient()
    : session_id_(SessionID::FromSerializedValue(1)),
      autocomplete_classifier_(
          std::make_unique<AutocompleteController>(
              CreateAutocompleteProviderClient(),
              AutocompleteClassifier::DefaultOmniboxProviders()),
          std::make_unique<TestSchemeClassifier>()),
      last_log_disposition_(WindowOpenDisposition::UNKNOWN) {}

TestOmniboxClient::~TestOmniboxClient() {
  autocomplete_classifier_.Shutdown();
}

std::unique_ptr<AutocompleteProviderClient>
TestOmniboxClient::CreateAutocompleteProviderClient() {
  auto provider_client = std::make_unique<MockAutocompleteProviderClient>();
  EXPECT_CALL(*provider_client, GetBuiltinURLs())
      .WillRepeatedly(testing::Return(std::vector<std::u16string>()));
  EXPECT_CALL(*provider_client, GetSchemeClassifier())
      .WillRepeatedly(testing::ReturnRef(scheme_classifier_));
  EXPECT_CALL(*provider_client, GetApplicationLocale())
      .WillRepeatedly(testing::Return("en-US"));

  provider_client->set_template_url_service(
      search_engines_test_environment_.template_url_service());

  // The `UnscopedExtensionProviderDelegate` should be set. It will be called
  // when `AutocompleteController::Stop()` is called on destruction.
  std::unique_ptr<MockUnscopedExtensionProviderDelegate> mock_delegate =
      std::make_unique<MockUnscopedExtensionProviderDelegate>();
  provider_client->set_unscoped_extension_provider_delegate(
      std::move(mock_delegate));
  return std::move(provider_client);
}

bool TestOmniboxClient::IsPasteAndGoEnabled() const {
  return true;
}

SessionID TestOmniboxClient::GetSessionID() const {
  return session_id_;
}

AutocompleteControllerEmitter*
TestOmniboxClient::GetAutocompleteControllerEmitter() {
  return nullptr;
}

TemplateURLService* TestOmniboxClient::GetTemplateURLService() {
  CHECK(search_engines_test_environment_.template_url_service());
  return search_engines_test_environment_.template_url_service();
}

const AutocompleteSchemeClassifier& TestOmniboxClient::GetSchemeClassifier()
    const {
  return scheme_classifier_;
}

AutocompleteClassifier* TestOmniboxClient::GetAutocompleteClassifier() {
  return &autocomplete_classifier_;
}

bool TestOmniboxClient::ShouldDefaultTypedNavigationsToHttps() const {
  return false;
}

int TestOmniboxClient::GetHttpsPortForTesting() const {
  return 0;
}

bool TestOmniboxClient::IsUsingFakeHttpsForHttpsUpgradeTesting() const {
  return false;
}

gfx::Image TestOmniboxClient::GetSizedIcon(const SkBitmap* bitmap) const {
  return gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(*bitmap));
}

gfx::Image TestOmniboxClient::GetSizedIcon(
    const gfx::VectorIcon& vector_icon_type,
    SkColor vector_icon_color) const {
  SkBitmap bitmap;
  bitmap.allocN32Pixels(16, 16);
  return gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
}

gfx::Image TestOmniboxClient::GetSizedIcon(const gfx::Image& icon) const {
  if (icon.IsEmpty()) {
    return gfx::Image();
  }
  return gfx::Image(*icon.ToImageSkia());
}

std::u16string TestOmniboxClient::GetFormattedFullURL() const {
  return location_bar_model_.GetFormattedFullURL();
}

std::u16string TestOmniboxClient::GetURLForDisplay() const {
  return location_bar_model_.GetURLForDisplay();
}

GURL TestOmniboxClient::GetNavigationEntryURL() const {
  return location_bar_model_.GetURL();
}

metrics::OmniboxEventProto::PageClassification
TestOmniboxClient::GetPageClassification(bool is_prefetch) const {
  return location_bar_model_.GetPageClassification(is_prefetch);
}

security_state::SecurityLevel TestOmniboxClient::GetSecurityLevel() const {
  return location_bar_model_.GetSecurityLevel();
}

net::CertStatus TestOmniboxClient::GetCertStatus() const {
  return location_bar_model_.GetCertStatus();
}

const gfx::VectorIcon& TestOmniboxClient::GetVectorIcon() const {
  return location_bar_model_.GetVectorIcon();
}

void TestOmniboxClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
  last_log_disposition_ = log->disposition;
}

base::WeakPtr<OmniboxClient> TestOmniboxClient::AsWeakPtr() {
  return weak_factory_.GetWeakPtr();
}