-
Notifications
You must be signed in to change notification settings - Fork 941
/
Copy pathtopsites_provider_unittest.cc
60 lines (48 loc) · 2.13 KB
/
topsites_provider_unittest.cc
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
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/components/omnibox/browser/topsites_provider.h"
#include <string_view>
#include "base/strings/utf_string_conversions.h"
#include "brave/components/omnibox/browser/brave_fake_autocomplete_provider_client.h"
#include "brave/components/omnibox/browser/brave_omnibox_prefs.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/test_scheme_classifier.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
class TopSitesProviderTest : public testing::Test {
public:
TopSitesProviderTest() : provider_(new TopSitesProvider(&client_)) {
}
AutocompleteInput CreateAutocompleteInput(std::string_view text) {
AutocompleteInput input(base::UTF8ToUTF16(text),
metrics::OmniboxEventProto::OTHER,
classifier_);
return input;
}
PrefService* prefs() {
return client_.GetPrefs();
}
protected:
TestSchemeClassifier classifier_;
BraveFakeAutocompleteProviderClient client_;
scoped_refptr<TopSitesProvider> provider_;
};
// Checks that the top sites list is not empty and that non-ASCII inputs do not
// blow the matcher.
TEST_F(TopSitesProviderTest, SmokeTest) {
provider_->Start(CreateAutocompleteInput(""), false);
EXPECT_TRUE(provider_->matches().empty());
provider_->Start(CreateAutocompleteInput("dex"), false);
EXPECT_FALSE(provider_->matches().empty());
provider_->Start(CreateAutocompleteInput("тест"), false);
EXPECT_TRUE(provider_->matches().empty());
provider_->Start(CreateAutocompleteInput("테스트"), false);
EXPECT_TRUE(provider_->matches().empty());
}
TEST_F(TopSitesProviderTest, NoMatchingWhenPrefIsOff) {
prefs()->SetBoolean(omnibox::kTopSuggestionsEnabled, false);
provider_->Start(CreateAutocompleteInput("dex"), false);
EXPECT_TRUE(provider_->matches().empty());
}