APM: add field trial to disable `TransientSuppressor`

Regardless of the APM config, the transient suppressor (TS) submodule
won't be created if the `WebRTC-ApmTransientSuppressorKillSwitch`
field trial, disabled by default, is enabled.

Bug: webrtc:13663
Change-Id: Ic1ef9aa57c728296d671d4ef253630c581a86610
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286382
Reviewed-by: Hanna Silen <silen@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38839}
diff --git a/modules/audio_processing/audio_processing_impl_unittest.cc b/modules/audio_processing/audio_processing_impl_unittest.cc
index ea61dae..346b5f5 100644
--- a/modules/audio_processing/audio_processing_impl_unittest.cc
+++ b/modules/audio_processing/audio_processing_impl_unittest.cc
@@ -960,6 +960,55 @@
   }
 }
 
+TEST(AudioProcessingImplTest, CanDisableTransientSuppressor) {
+  // Do not explicitly disable "WebRTC-ApmTransientSuppressorKillSwitch" since
+  // to check that, by default, it is disabled.
+  auto apm = AudioProcessingBuilder()
+                 .SetConfig({.transient_suppression = {.enabled = false}})
+                 .Create();
+  EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled);
+}
+
+TEST(AudioProcessingImplTest, CanEnableTransientSuppressor) {
+  // Do not explicitly disable "WebRTC-ApmTransientSuppressorKillSwitch" since
+  // to check that, by default, it is disabled.
+  auto apm = AudioProcessingBuilder()
+                 .SetConfig({.transient_suppression = {.enabled = true}})
+                 .Create();
+  EXPECT_TRUE(apm->GetConfig().transient_suppression.enabled);
+}
+
+TEST(AudioProcessingImplTest, CanDisableTransientSuppressorIfUsageAllowed) {
+  // Disable the field trial that disallows to enable transient suppression.
+  test::ScopedFieldTrials field_trials(
+      "WebRTC-ApmTransientSuppressorKillSwitch/Disabled/");
+  auto apm = AudioProcessingBuilder()
+                 .SetConfig({.transient_suppression = {.enabled = false}})
+                 .Create();
+  EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled);
+}
+
+TEST(AudioProcessingImplTest, CanEnableTransientSuppressorIfUsageAllowed) {
+  // Disable the field trial that disallows to enable transient suppression.
+  test::ScopedFieldTrials field_trials(
+      "WebRTC-ApmTransientSuppressorKillSwitch/Disabled/");
+  auto apm = AudioProcessingBuilder()
+                 .SetConfig({.transient_suppression = {.enabled = true}})
+                 .Create();
+  EXPECT_TRUE(apm->GetConfig().transient_suppression.enabled);
+}
+
+TEST(AudioProcessingImplTest,
+     CannotEnableTransientSuppressorIfUsageDisallowed) {
+  // Enable the field trial that disallows to enable transient suppression.
+  test::ScopedFieldTrials field_trials(
+      "WebRTC-ApmTransientSuppressorKillSwitch/Enabled/");
+  auto apm = AudioProcessingBuilder()
+                 .SetConfig({.transient_suppression = {.enabled = true}})
+                 .Create();
+  EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled);
+}
+
 // Tests that the minimum startup volume is applied at the startup.
 TEST_P(InputVolumeStartupParameterizedTest,
        VerifyStartupMinVolumeAppliedAtStartup) {