|
| 1 | +// Copyright (c) 2025 The Brave Authors. All rights reserved. |
| 2 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +// License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 | +// You can obtain one at https://mozilla.org/MPL/2.0/. |
| 5 | + |
| 6 | +#include "brave/components/omnibox/browser/brave_on_device_head_provider.h" |
| 7 | + |
| 8 | +#include <memory> |
| 9 | +#include <string_view> |
| 10 | + |
| 11 | +#include "base/memory/scoped_refptr.h" |
| 12 | +#include "base/strings/utf_string_conversions.h" |
| 13 | +#include "brave/components/omnibox/browser/brave_fake_autocomplete_provider_client.h" |
| 14 | +#include "brave/components/omnibox/browser/brave_omnibox_prefs.h" |
| 15 | +#include "components/omnibox/browser/autocomplete_input.h" |
| 16 | +#include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 17 | +#include "components/omnibox/browser/test_scheme_classifier.h" |
| 18 | +#include "components/prefs/pref_service.h" |
| 19 | +#include "content/public/test/browser_task_environment.h" |
| 20 | +#include "testing/gtest/include/gtest/gtest.h" |
| 21 | + |
| 22 | +class BraveOnDeviceHeadProviderTest : public testing::Test, |
| 23 | + public AutocompleteProviderListener { |
| 24 | + public: |
| 25 | + AutocompleteInput CreateAutocompleteInput(std::string_view text) { |
| 26 | + AutocompleteInput input(base::UTF8ToUTF16(text), |
| 27 | + metrics::OmniboxEventProto::OTHER, classifier_); |
| 28 | + return input; |
| 29 | + } |
| 30 | + |
| 31 | + void SetUp() override { |
| 32 | + provider_ = |
| 33 | + base::WrapRefCounted(BraveOnDeviceHeadProvider::Create(&client_, this)); |
| 34 | + } |
| 35 | + |
| 36 | + void OnProviderUpdate(bool updated_matches, |
| 37 | + const AutocompleteProvider* provider) override {} |
| 38 | + |
| 39 | + PrefService* prefs() { return client_.GetPrefs(); } |
| 40 | + |
| 41 | + protected: |
| 42 | + content::BrowserTaskEnvironment task_environment_; |
| 43 | + TestSchemeClassifier classifier_; |
| 44 | + BraveFakeAutocompleteProviderClient client_; |
| 45 | + scoped_refptr<BraveOnDeviceHeadProvider> provider_; |
| 46 | +}; |
| 47 | + |
| 48 | +TEST_F(BraveOnDeviceHeadProviderTest, SuggestionsDisabledNoResults) { |
| 49 | + prefs()->SetBoolean(omnibox::kTopSuggestionsEnabled, false); |
| 50 | + provider_->Start(CreateAutocompleteInput("Hello"), false); |
| 51 | + EXPECT_TRUE(provider_->done()); |
| 52 | + EXPECT_TRUE(provider_->matches().empty()); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_F(BraveOnDeviceHeadProviderTest, SuggestionsEnabledRunsProvider) { |
| 56 | + prefs()->SetBoolean(omnibox::kTopSuggestionsEnabled, true); |
| 57 | + provider_->Start(CreateAutocompleteInput("Hello"), false); |
| 58 | + EXPECT_FALSE(provider_->done()); |
| 59 | +} |
0 commit comments