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
ash / system / audio / audio_detailed_view_pixeltest.cc [blame]
// 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 <vector>
#include "ash/system/tray/tray_detailed_view.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test/pixel/ash_pixel_test_init_params.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/ash/components/audio/audio_devices_pref_handler.h"
#include "chromeos/ash/components/audio/audio_devices_pref_handler_stub.h"
#include "chromeos/ash/components/audio/cras_audio_handler.h"
#include "chromeos/ash/components/dbus/audio/audio_node.h"
#include "chromeos/ash/components/dbus/audio/fake_cras_audio_client.h"
#include "third_party/cros_system_api/dbus/audio/dbus-constants.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/view.h"
namespace ash {
constexpr uint64_t kInternalMicId = 10003;
// Pixel tests for the quick settings audio detailed view.
class AudioDetailedViewPixelTest : public AshTestBase,
public testing::WithParamInterface<bool> {
public:
AudioDetailedViewPixelTest() {
scoped_features_.InitWithFeatureState(features::kOnDeviceSpeechRecognition,
IsCaptionEnabled());
}
bool IsCaptionEnabled() { return GetParam(); }
// AshTestBase:
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
private:
base::test::ScopedFeatureList scoped_features_;
};
INSTANTIATE_TEST_SUITE_P(All,
AudioDetailedViewPixelTest,
/*IsCaptionEnabled()=*/testing::Bool());
TEST_P(AudioDetailedViewPixelTest, Basics) {
// Pin input and output devices to ensure consistent behavior.
auto* audio_handler = CrasAudioHandler::Get();
AudioDevice output_device(FakeCrasAudioClient::Get()->node_list()[1]);
AudioDevice input_device(FakeCrasAudioClient::Get()->node_list()[5]);
audio_handler->SwitchToDevice(output_device, true,
DeviceActivateType::kActivateByUser);
audio_handler->SwitchToDevice(input_device, true,
DeviceActivateType::kActivateByUser);
UnifiedSystemTray* system_tray = GetPrimaryUnifiedSystemTray();
system_tray->ShowBubble();
ASSERT_TRUE(system_tray->bubble());
system_tray->bubble()
->unified_system_tray_controller()
->ShowAudioDetailedView();
TrayDetailedView* detailed_view =
system_tray->bubble()
->quick_settings_view()
->GetDetailedViewForTest<TrayDetailedView>();
ASSERT_TRUE(detailed_view);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"qs_audio_detailed_view",
/*revision_number=*/16, detailed_view));
}
TEST_P(AudioDetailedViewPixelTest, ShowNoiseCancellationButton) {
// Setup for showing noise cancellation button.
auto* client = FakeCrasAudioClient::Get();
auto* audio_handler = CrasAudioHandler::Get();
auto internal_mic_node =
AudioNode(true, kInternalMicId, false, kInternalMicId, 0, "Fake Mic",
"INTERNAL_MIC", "Internal Mic", false /* is_active*/,
0 /* pluged_time */, 1, cras::EFFECT_TYPE_NONE, 0);
client->SetVoiceIsolationUIAppearance(
VoiceIsolationUIAppearance(cras::EFFECT_TYPE_NOISE_CANCELLATION,
cras::EFFECT_TYPE_NOISE_CANCELLATION, false));
AudioNodeList node_list;
node_list.push_back(internal_mic_node);
client->SetAudioNodesAndNotifyObserversForTesting(node_list);
client->SetNoiseCancellationSupported(true);
scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_ =
base::MakeRefCounted<AudioDevicesPrefHandlerStub>();
audio_pref_handler_->SetVoiceIsolationState(true);
audio_handler->SetPrefHandlerForTesting(audio_pref_handler_);
audio_handler->RequestNoiseCancellationSupported(base::DoNothing());
audio_handler->RequestVoiceIsolationUIAppearance();
audio_handler->SwitchToDevice(AudioDevice(internal_mic_node), true,
DeviceActivateType::kActivateByUser);
UnifiedSystemTray* system_tray = GetPrimaryUnifiedSystemTray();
system_tray->ShowBubble();
ASSERT_TRUE(system_tray->bubble());
system_tray->bubble()
->unified_system_tray_controller()
->ShowAudioDetailedView();
TrayDetailedView* detailed_view =
system_tray->bubble()
->quick_settings_view()
->GetDetailedViewForTest<TrayDetailedView>();
ASSERT_TRUE(detailed_view);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"qs_audio_detailed_view",
/*revision_number=*/8, detailed_view));
}
} // namespace ash