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
|
// 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/ash/system/system_tray_client_impl.h"
#include <memory>
#include "ash/constants/ash_features.h"
#include "ash/webui/settings/public/constants/routes.mojom-forward.h"
#include "base/check_deref.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/user_action_tester.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "url/gurl.h"
namespace {
constexpr const char kShowTouchpadSettingsPage[] = "ShowTouchpadSettingsPage";
constexpr const char kShowMouseSettingsPage[] = "ShowMouseSettingsPage";
constexpr const char kShowKeyboardSettingsPage[] = "ShowKeyboardSettingsPage";
constexpr const char kShowPointingStickSettingsPage[] =
"ShowPointingStickSettingsPage";
constexpr const char kShowGraphicsTabletSettingsPage[] =
"ShowGraphicsTabletSettingsPage";
constexpr const char kShowRemapKeysSettingsSubpage[] =
"ShowRemapKeysSettingsSubpage";
class TestSettingsWindowManager : public chrome::SettingsWindowManager {
public:
void ShowChromePageForProfile(Profile* profile,
const GURL& gurl,
int64_t display_id,
apps::LaunchCallback callback) override {
last_url_ = gurl;
if (callback) {
std::move(callback).Run(apps::LaunchResult(apps::State::kSuccess));
}
}
const GURL& last_url() { return last_url_; }
private:
GURL last_url_;
};
// Use BrowserWithTestWindowTest because it sets up ash::Shell, ash::SystemTray,
// ProfileManager, etc.
class SystemTrayClientImplTest : public BrowserWithTestWindowTest {
public:
void SetUp() override {
BrowserWithTestWindowTest::SetUp();
client_impl_ = std::make_unique<SystemTrayClientImpl>(
CHECK_DEREF(TestingBrowserProcess::GetGlobal()
->platform_part()
->GetSystemClock()),
CHECK_DEREF(TestingBrowserProcess::GetGlobal()
->platform_part()
->browser_policy_connector_ash()));
settings_window_manager_ = std::make_unique<TestSettingsWindowManager>();
chrome::SettingsWindowManager::SetInstanceForTesting(
settings_window_manager_.get());
}
void TearDown() override {
chrome::SettingsWindowManager::SetInstanceForTesting(nullptr);
settings_window_manager_.reset();
client_impl_.reset();
BrowserWithTestWindowTest::TearDown();
}
protected:
std::unique_ptr<SystemTrayClientImpl> client_impl_;
std::unique_ptr<TestSettingsWindowManager> settings_window_manager_;
};
TEST_F(SystemTrayClientImplTest, ShowAccountSettings) {
client_impl_->ShowAccountSettings();
EXPECT_EQ(
settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(chromeos::settings::mojom::kPeopleSectionPath));
}
TEST_F(SystemTrayClientImplTest, ShowTouchpadSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(ash::features::kInputDeviceSettingsSplit);
base::UserActionTester user_action_tester;
client_impl_->ShowTouchpadSettings();
EXPECT_EQ(settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kPerDeviceTouchpadSubpagePath));
EXPECT_EQ(1, user_action_tester.GetActionCount(kShowTouchpadSettingsPage));
}
TEST_F(SystemTrayClientImplTest, ShowMouseSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({ash::features::kInputDeviceSettingsSplit,
ash::features::kPeripheralCustomization},
{});
base::UserActionTester user_action_tester;
client_impl_->ShowMouseSettings();
EXPECT_EQ(settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kPerDeviceMouseSubpagePath));
EXPECT_EQ(1, user_action_tester.GetActionCount(kShowMouseSettingsPage));
}
TEST_F(SystemTrayClientImplTest, ShowGraphicsTabletSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({ash::features::kInputDeviceSettingsSplit,
ash::features::kPeripheralCustomization},
{});
base::UserActionTester user_action_tester;
client_impl_->ShowGraphicsTabletSettings();
EXPECT_EQ(settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kGraphicsTabletSubpagePath));
EXPECT_EQ(1,
user_action_tester.GetActionCount(kShowGraphicsTabletSettingsPage));
}
TEST_F(SystemTrayClientImplTest, ShowRemapKeysSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(ash::features::kInputDeviceSettingsSplit);
base::UserActionTester user_action_tester;
client_impl_->ShowRemapKeysSubpage(/*device_id=*/1);
EXPECT_EQ(settings_window_manager_->last_url(),
base::StrCat({chrome::GetOSSettingsUrl(
chromeos::settings::mojom::
kPerDeviceKeyboardRemapKeysSubpagePath)
.spec(),
"?keyboardId=1"}));
EXPECT_EQ(1,
user_action_tester.GetActionCount(kShowRemapKeysSettingsSubpage));
}
TEST_F(SystemTrayClientImplTest, ShowApnSubpage) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(ash::features::kApnRevamp);
client_impl_->ShowApnSubpage(/*network_id=*/"guid");
EXPECT_EQ(settings_window_manager_->last_url(),
base::StrCat({chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kApnSubpagePath)
.spec(),
"?guid=guid"}));
}
TEST_F(SystemTrayClientImplTest, ShowKeyboardSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({ash::features::kInputDeviceSettingsSplit,
ash::features::kPeripheralCustomization,
ash::features::kWelcomeExperience},
{});
base::UserActionTester user_action_tester;
client_impl_->ShowKeyboardSettings();
EXPECT_EQ(settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kPerDeviceKeyboardSubpagePath));
EXPECT_EQ(1, user_action_tester.GetActionCount(kShowKeyboardSettingsPage));
}
TEST_F(SystemTrayClientImplTest, ShowPointingStickSettings) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({ash::features::kInputDeviceSettingsSplit,
ash::features::kPeripheralCustomization,
ash::features::kWelcomeExperience},
{});
base::UserActionTester user_action_tester;
client_impl_->ShowPointingStickSettings();
EXPECT_EQ(settings_window_manager_->last_url(),
chrome::GetOSSettingsUrl(
chromeos::settings::mojom::kPerDevicePointingStickSubpagePath));
EXPECT_EQ(1,
user_action_tester.GetActionCount(kShowPointingStickSettingsPage));
}
} // namespace
|