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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
// Copyright 2023 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/device_section.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ash/input_method/input_method_configuration.h"
#include "chrome/browser/ash/printing/fake_cups_printers_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ash/settings/os_settings_identifier.h"
#include "chrome/browser/ui/webui/ash/settings/search/search_tag_registry.h"
#include "chrome/grit/generated_resources.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 "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/spellcheck/browser/pref_names.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/ash/mock_input_method_manager_impl.h"
namespace ash::settings {
namespace mojom {
using ::chromeos::settings::mojom::Setting;
using ::chromeos::settings::mojom::Subpage;
} // namespace mojom
namespace {
constexpr OsSettingsIdentifier kAudioPageOsSettingsId = {
.subpage = mojom::Subpage::kAudio};
constexpr OsSettingsIdentifier kKeyboardOsSettingsId = {
.subpage = mojom::Subpage::kKeyboard};
constexpr OsSettingsIdentifier kPerDeviceKeyboardOsSettingsId = {
.subpage = mojom::Subpage::kPerDeviceKeyboard};
constexpr OsSettingsIdentifier kKeyboardBlockMetaFkeyRewritesOsSettingsId = {
.setting = mojom::Setting::kKeyboardBlockMetaFkeyRewrites};
constexpr OsSettingsIdentifier kAddPrinterId = {
.setting = mojom::Setting::kAddPrinter};
constexpr OsSettingsIdentifier kPrintingDetailsId = {
.subpage = mojom::Subpage::kPrintingDetails};
constexpr OsSettingsIdentifier kPrintJobsId = {.setting =
mojom::Setting::kPrintJobs};
constexpr OsSettingsIdentifier kScanningAppId = {
.setting = mojom::Setting::kScanningApp};
// Provides a correctly formatted result_id based on `SearchConcept`
// configuration in `device_section.cc`. Based on private static function in
// `SearchTagRegistry`.
std::string GetSubpageSearchResultId(OsSettingsIdentifier id, int message_id) {
std::stringstream ss;
ss << id.subpage << "," << message_id;
return ss.str();
}
std::string GetSettingsSearchResultId(OsSettingsIdentifier id, int message_id) {
std::stringstream ss;
ss << id.setting << "," << message_id;
return ss.str();
}
} // namespace
// Test for the device settings page.
class DeviceSectionTest : public testing::Test {
public:
DeviceSectionTest()
: local_search_service_proxy_(
std::make_unique<
ash::local_search_service::LocalSearchServiceProxy>(
/*for_testing=*/true)),
search_tag_registry_(local_search_service_proxy_.get()) {}
~DeviceSectionTest() override = default;
protected:
void SetUp() override {
profile_manager_ = std::make_unique<TestingProfileManager>(
TestingBrowserProcess::GetGlobal());
ASSERT_TRUE(profile_manager_->SetUp());
profile_ = profile_manager_->CreateTestingProfile("name");
// Mock Input method manager and register prefs for Inputs settings
input_method::InitializeForTesting(
new input_method::MockInputMethodManagerImpl());
pref_service_.registry()->RegisterBooleanPref(
prefs::kEmojiSuggestionEnterpriseAllowed, true);
pref_service_.registry()->RegisterBooleanPref(
spellcheck::prefs::kSpellCheckEnable, true);
}
void TearDown() override {
// Ensure `device_section_` is destroyed before `pref_service_`.
device_section_.reset();
profile_ = nullptr;
profile_manager_->DeleteTestingProfile("name");
}
TestingProfile* profile() { return profile_; }
TestingPrefServiceSimple* pref_service() { return &pref_service_; }
ash::settings::SearchTagRegistry* search_tag_registry() {
return &search_tag_registry_;
}
FakeCupsPrintersManager* printers_manager() { return &printers_manager_; }
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<DeviceSection> device_section_;
private:
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<ash::local_search_service::LocalSearchServiceProxy>
local_search_service_proxy_;
ash::settings::SearchTagRegistry search_tag_registry_;
TestingPrefServiceSimple pref_service_;
std::unique_ptr<TestingProfileManager> profile_manager_;
raw_ptr<TestingProfile> profile_;
FakeCupsPrintersManager printers_manager_;
};
// Verify registry updated with Audio search tags.
TEST_F(DeviceSectionTest, SearchResultIncludeAudio) {
feature_list_.Reset();
device_section_ = std::make_unique<DeviceSection>(
profile(), search_tag_registry(), printers_manager(), pref_service());
std::string result_id = GetSubpageSearchResultId(
kAudioPageOsSettingsId, IDS_OS_SETTINGS_TAG_AUDIO_SETTINGS);
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(result_id));
}
// Verify registry updated with Printing search tags.
TEST_F(DeviceSectionTest, SearchResultIncludePrinting) {
device_section_ = std::make_unique<DeviceSection>(
profile(), search_tag_registry(), printers_manager(), pref_service());
std::string add_printer_result_id = GetSettingsSearchResultId(
kAddPrinterId, IDS_OS_SETTINGS_TAG_PRINTING_ADD_PRINTER);
std::string printing_details_result_id = GetSubpageSearchResultId(
kPrintingDetailsId, IDS_OS_SETTINGS_TAG_PRINTING);
std::string print_jobs_result_id = GetSettingsSearchResultId(
kPrintJobsId, IDS_OS_SETTINGS_TAG_PRINT_MANAGEMENT);
std::string scanning_app_result_id = GetSettingsSearchResultId(
kScanningAppId, IDS_OS_SETTINGS_TAG_SCANNING_APP);
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(add_printer_result_id));
EXPECT_TRUE(
search_tag_registry()->GetTagMetadata(printing_details_result_id));
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(print_jobs_result_id));
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(scanning_app_result_id));
}
// Verify registry updated with per device settings search tags when flag is
// enabled.
TEST_F(DeviceSectionTest, SearchResultChangeToSettingsSplitWithFlag) {
feature_list_.InitAndEnableFeature(ash::features::kInputDeviceSettingsSplit);
device_section_ = std::make_unique<DeviceSection>(
profile(), search_tag_registry(), printers_manager(), pref_service());
std::string result_id = GetSubpageSearchResultId(
kPerDeviceKeyboardOsSettingsId, IDS_OS_SETTINGS_TAG_KEYBOARD);
std::string switch_top_row_key_id = GetSettingsSearchResultId(
kKeyboardBlockMetaFkeyRewritesOsSettingsId,
IDS_OS_SETTINGS_TAG_KEYBOARD_BLOCK_META_FKEY_COMBO_REWRITES);
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(result_id));
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(switch_top_row_key_id));
}
// Verify registry updated with regular settings search tags when flag is
// disabled.
TEST_F(DeviceSectionTest, SearchResultChangeBackWithoutFlag) {
feature_list_.InitAndDisableFeature(features::kInputDeviceSettingsSplit);
device_section_ = std::make_unique<DeviceSection>(
profile(), search_tag_registry(), printers_manager(), pref_service());
std::string result_id = GetSubpageSearchResultId(
kKeyboardOsSettingsId, IDS_OS_SETTINGS_TAG_KEYBOARD);
std::string switch_top_row_key_id = GetSettingsSearchResultId(
kKeyboardBlockMetaFkeyRewritesOsSettingsId,
IDS_OS_SETTINGS_TAG_KEYBOARD_BLOCK_META_FKEY_COMBO_REWRITES);
EXPECT_TRUE(search_tag_registry()->GetTagMetadata(result_id));
EXPECT_FALSE(search_tag_registry()->GetTagMetadata(switch_top_row_key_id));
}
} // namespace ash::settings
|