From 08cffed994469a5328582eb5d22bbc154f16a462 Mon Sep 17 00:00:00 2001 From: Ashley Prasad Date: Fri, 16 Dec 2022 17:20:32 +0000 Subject: [PATCH] audio-settings: set input volume from slider - Add handler for input slider to update input gain volume. - Refactor simulateSliderClick from output test into suite for reuse in input test. - Test slider update triggers matching property update. Bug: b:260277007 Test: browser_test --gtest_filter=*OSSettings* Change-Id: Ifa71f987347611c8d10e123c182c3211aa7c3e24 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4082254 Reviewed-by: Michael Checo Auto-Submit: Ashley Prasad Commit-Queue: Ashley Prasad Cr-Commit-Position: refs/heads/main@{#1084376} --- .../settings/chromeos/device_page/audio.html | 3 +- .../settings/chromeos/device_page/audio.ts | 16 ++++ .../settings/chromeos/device_page_tests.js | 73 +++++++++++++++---- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/chrome/browser/resources/settings/chromeos/device_page/audio.html b/chrome/browser/resources/settings/chromeos/device_page/audio.html index 343e3d4c5748ca..3318dc742e3dc0 100644 --- a/chrome/browser/resources/settings/chromeos/device_page/audio.html +++ b/chrome/browser/resources/settings/chromeos/device_page/audio.html @@ -147,7 +147,8 @@

Input

on-click="onInputMuteClicked"> + value="[[audioSystemProperties_.inputVolumePercent]]" + on-cr-slider-value-changed="onInputVolumeSliderChanged"> diff --git a/chrome/browser/resources/settings/chromeos/device_page/audio.ts b/chrome/browser/resources/settings/chromeos/device_page/audio.ts index e8f07670d01de1..2bb3f34ba94e49 100644 --- a/chrome/browser/resources/settings/chromeos/device_page/audio.ts +++ b/chrome/browser/resources/settings/chromeos/device_page/audio.ts @@ -143,6 +143,22 @@ class SettingsAudioElement extends SettingsAudioElementBase { this.crosAudioConfig_.setActiveDevice(nextActiveDevice); } + /** + * Handles the event where the input volume slider is being changed. + */ + protected onInputVolumeSliderChanged(): void { + // TODO(b/260277007): Remove condition when setInputVolumePercent added to + // mojo definition. + if (!this.crosAudioConfig_.setInputVolumePercent) { + return; + } + + const sliderValue = this.shadowRoot! + .querySelector( + '#audioInputGainVolumeSlider')!.value; + this.crosAudioConfig_.setInputVolumePercent(sliderValue); + } + /** * Handles the event where the output volume slider is being changed. */ diff --git a/chrome/test/data/webui/settings/chromeos/device_page_tests.js b/chrome/test/data/webui/settings/chromeos/device_page_tests.js index b1ea1f5d2272bc..7515764ae063a1 100644 --- a/chrome/test/data/webui/settings/chromeos/device_page_tests.js +++ b/chrome/test/data/webui/settings/chromeos/device_page_tests.js @@ -726,6 +726,26 @@ suite('SettingsDevicePage', function() { ], }; + /** + * Simuates clicking at a given point on cr-slider element. + * @param {string} crSliderSelector + * @param {number} percent + * @return {Promise} + */ + async function simulateSliderClicked(crSliderSelector, percent) { + /** @type {!CrSliderElement} */ + const crSlider = audioPage.shadowRoot.querySelector(crSliderSelector); + assertTrue(isVisible(crSlider)); + const rect = crSlider.$.container.getBoundingClientRect(); + crSlider.dispatchEvent(new PointerEvent('pointerdown', { + buttons: 1, + pointerId: 1, + clientX: rect.left + ((percent / 100) * rect.width), + })); + return await flushTasks(); + } + + setup(async function() { loadTimeData.overrideValues({ enableAudioSettingsPage: true, @@ -770,21 +790,11 @@ suite('SettingsDevicePage', function() { }); test('simulate setting output volume slider mojo test', async function() { - async function simulateSliderClicked(value) { - const outputVolumeSlider = - audioPage.shadowRoot.querySelector('#outputVolumeSlider'); - const rect = outputVolumeSlider.$.container.getBoundingClientRect(); - outputVolumeSlider.dispatchEvent(new PointerEvent('pointerdown', { - buttons: 1, - pointerId: 1, - clientX: rect.left + (value * rect.width), - })); - return await flushTasks(); - } + const sliderSelector = '#outputVolumeSlider'; // Test clicking to min volume case. const minOutputVolumePercent = 0; - await simulateSliderClicked(minOutputVolumePercent / 100); + await simulateSliderClicked(sliderSelector, minOutputVolumePercent); assertEquals( minOutputVolumePercent, audioPage.audioSystemProperties_.outputVolumePercent, @@ -792,7 +802,7 @@ suite('SettingsDevicePage', function() { // Test clicking to max volume case. const maxOutputVolumePercent = 100; - await simulateSliderClicked(maxOutputVolumePercent / 100); + await simulateSliderClicked(sliderSelector, maxOutputVolumePercent); assertEquals( maxOutputVolumePercent, audioPage.audioSystemProperties_.outputVolumePercent, @@ -800,7 +810,7 @@ suite('SettingsDevicePage', function() { // Test clicking to non-boundary volume case. const nonBoundaryOutputVolumePercent = 50; - await simulateSliderClicked(50 / 100); + await simulateSliderClicked(sliderSelector, 50); assertEquals( nonBoundaryOutputVolumePercent, audioPage.audioSystemProperties_.outputVolumePercent, @@ -972,6 +982,41 @@ suite('SettingsDevicePage', function() { assertTrue(audioPage.getIsInputMutedForTest()); }); + + test('simulate setting input gain slider', async function() { + const sliderSelector = '#audioInputGainVolumeSlider'; + const inputSlider = audioPage.shadowRoot.querySelector(sliderSelector); + assertTrue(isVisible(inputSlider)); + assertEquals( + fakeCrosAudioConfig.defaultFakeAudioSystemProperties + .inputVolumePercent, + inputSlider.value); + + const minimumValue = 0; + await simulateSliderClicked(sliderSelector, minimumValue); + + assertEquals(minimumValue, inputSlider.value); + assertEquals( + fakeCrosAudioConfig.defaultFakeAudioSystemProperties + .inputVolumePercent, + inputSlider.value); + const maximumValue = 100; + await simulateSliderClicked(sliderSelector, maximumValue); + + assertEquals(maximumValue, inputSlider.value); + assertEquals( + fakeCrosAudioConfig.defaultFakeAudioSystemProperties + .inputVolumePercent, + inputSlider.value); + const middleValue = 50; + await simulateSliderClicked(sliderSelector, middleValue); + + assertEquals(middleValue, inputSlider.value); + assertEquals( + fakeCrosAudioConfig.defaultFakeAudioSystemProperties + .inputVolumePercent, + inputSlider.value); + }); }); suite(assert(TestNames.Pointers), function() {