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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/ash/settings/pages/device/inputs_section.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ash/input_method/editor_geolocation_mock_provider.h"
#include "chrome/browser/ash/input_method/editor_geolocation_provider.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ash/settings/search/search_tag_registry.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/chrome_ash_test_base.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/components/magic_boost/test/fake_magic_boost_state.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/prefs/testing_pref_service.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_ui_data_source.h"
namespace ash::settings {
namespace {
constexpr OsSettingsIdentifier kShowOrcaSettingsId = {
.setting = chromeos::settings::mojom::Setting::kShowOrca};
std::string GetSettingsSearchResultId(OsSettingsIdentifier id, int message_id) {
std::stringstream ss;
ss << id.setting << "," << message_id;
return ss.str();
}
} // namespace
// Test for the inputs settings page.
class InputsSectionTest : public ChromeAshTestBase {
public:
InputsSectionTest()
: local_search_service_proxy_(
std::make_unique<
ash::local_search_service::LocalSearchServiceProxy>(
/*for_testing=*/true)),
search_tag_registry_(local_search_service_proxy_.get()) {}
~InputsSectionTest() override = default;
TestingProfile* profile() { return &profile_; }
TestingPrefServiceSimple* pref_service() { return &pref_service_; }
ash::settings::SearchTagRegistry* search_tag_registry() {
return &search_tag_registry_;
}
std::unique_ptr<InputsSection> inputs_section_;
protected:
void SetUp() override {
pref_service()->registry()->RegisterBooleanPref(
prefs::kEmojiSuggestionEnterpriseAllowed, true);
pref_service()->registry()->RegisterBooleanPref(
spellcheck::prefs::kSpellCheckEnable, true);
ChromeAshTestBase::SetUp();
}
void TearDown() override {
inputs_section_.reset();
ChromeAshTestBase::TearDown();
}
private:
std::unique_ptr<ash::local_search_service::LocalSearchServiceProxy>
local_search_service_proxy_;
ash::settings::SearchTagRegistry search_tag_registry_;
TestingPrefServiceSimple pref_service_;
TestingProfile profile_;
};
TEST_F(InputsSectionTest,
InputsSectionShouldIncludeHelpMeWriteSettingsWhenMagicBoostIsDisabled) {
base::test::ScopedFeatureList feature_list;
// Note that `kMahi` is associated with the Magic Boost feature.
feature_list.InitWithFeatures(
/*enabled_features=*/
{
chromeos::features::kFeatureManagementOrca,
},
/*disabled_features=*/{ash::features::kOrcaUseAccountCapabilities,
chromeos::features::kFeatureManagementMahi,
chromeos::features::kMahi});
auto mock_geolocation_provider =
std::make_unique<input_method::EditorGeolocationMockProvider>("us");
input_method::EditorMediator editor_mediator(
profile(), std::move(mock_geolocation_provider));
inputs_section_ = std::make_unique<InputsSection>(
profile(), search_tag_registry(), pref_service(), &editor_mediator);
std::unique_ptr<content::TestWebUIDataSource> html_source =
content::TestWebUIDataSource::Create("test-inputs-section");
inputs_section_->AddLoadTimeData(html_source->GetWebUIDataSource());
EXPECT_TRUE(
html_source->GetLocalizedStrings()->FindBool("allowOrca").value());
}
TEST_F(InputsSectionTest,
InputsSectionShouldNotHaveHelpMeWriteSettingsWhenMagicBoostIsEnabled) {
base::test::ScopedFeatureList feature_list;
// Note that `kMahi` is associated with the Magic Boost feature.
feature_list.InitWithFeatures(
/*enabled_features=*/{chromeos::features::kFeatureManagementOrca,
chromeos::features::kFeatureManagementMahi,
chromeos::features::kMahi},
/*disabled_features=*/{
ash::features::kOrcaUseAccountCapabilities,
});
chromeos::test::FakeMagicBoostState magic_boost_state;
magic_boost_state.SetAvailability(true);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kMahiRestrictionsOverride);
auto mock_geolocation_provider =
std::make_unique<input_method::EditorGeolocationMockProvider>("us");
input_method::EditorMediator editor_mediator(
profile(), std::move(mock_geolocation_provider));
inputs_section_ = std::make_unique<InputsSection>(
profile(), search_tag_registry(), pref_service(), &editor_mediator);
std::unique_ptr<content::TestWebUIDataSource> html_source =
content::TestWebUIDataSource::Create("test-inputs-section");
inputs_section_->AddLoadTimeData(html_source->GetWebUIDataSource());
EXPECT_FALSE(
html_source->GetLocalizedStrings()->FindBool("allowOrca").value());
}
TEST_F(InputsSectionTest, SearchResultShouldIncludeHelpMeWrite) {
base::test::ScopedFeatureList feature_list;
// Note that `kMahi` is associated with the Magic Boost feature.
feature_list.InitWithFeatures(
/*enabled_features=*/
{
chromeos::features::kFeatureManagementOrca,
},
/*disabled_features=*/{ash::features::kOrcaUseAccountCapabilities,
chromeos::features::kFeatureManagementMahi,
chromeos::features::kMahi});
auto mock_geolocation_provider =
std::make_unique<input_method::EditorGeolocationMockProvider>("us");
input_method::EditorMediator editor_mediator(
profile(), std::move(mock_geolocation_provider));
inputs_section_ = std::make_unique<InputsSection>(
profile(), search_tag_registry(), pref_service(), &editor_mediator);
std::string result_id = GetSettingsSearchResultId(
kShowOrcaSettingsId,
IDS_OS_SETTINGS_TAG_LANGUAGES_HELP_ME_WRITE_SUGGESTIONS);
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(result_id));
}
} // namespace ash::settings
|