Skip to content

Commit

Permalink
Video audio test (#218)
Browse files Browse the repository at this point in the history
* first test for incoming audio on a video.
* checks that audio is incoming while audio is enabled
  • Loading branch information
Kimblebee authored Jun 5, 2024
1 parent 00ff78d commit 171c27e
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_
import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_RATIO_1_1_BUTTON
import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_RATIO_BUTTON
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.runScenarioTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.TruthJUnit.assume
import com.google.jetpackcamera.feature.preview.R
import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_DROP_DOWN
import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_FLASH_BUTTON
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.feature.preview.ui.FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.feature.preview.ui.IMAGE_CAPTURE_SUCCESS_TAG
import com.google.jetpackcamera.feature.preview.ui.SCREEN_FLASH_OVERLAY
import com.google.jetpackcamera.settings.model.LensFacing
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.IMAGE_CAPTURE_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.assume
import com.google.jetpackcamera.utils.getCurrentLensFacing
import com.google.jetpackcamera.utils.onNodeWithContentDescription
import com.google.jetpackcamera.utils.runScenarioTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -76,7 +84,7 @@ internal class FlashDeviceTest {
composeTestRule.onNodeWithTag(QUICK_SETTINGS_FLASH_BUTTON)
.assertExists()
composeTestRule.onNodeWithContentDescription(
com.google.jetpackcamera.feature.preview.R.string.quick_settings_flash_on_description
R.string.quick_settings_flash_on_description
)
}

Expand All @@ -99,7 +107,7 @@ internal class FlashDeviceTest {
.performClick()

composeTestRule.onNodeWithContentDescription(
com.google.jetpackcamera.feature.preview.R.string.quick_settings_flash_auto_description
R.string.quick_settings_flash_auto_description
)
}

Expand All @@ -111,7 +119,7 @@ internal class FlashDeviceTest {
}

composeTestRule.onNodeWithContentDescription(
com.google.jetpackcamera.feature.preview.R.string.quick_settings_flash_off_description
R.string.quick_settings_flash_off_description
)

// Navigate to quick settings
Expand All @@ -127,7 +135,7 @@ internal class FlashDeviceTest {
.performClick()

composeTestRule.onNodeWithContentDescription(
com.google.jetpackcamera.feature.preview.R.string.quick_settings_flash_off_description
R.string.quick_settings_flash_off_description
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.test.uiautomator.Until
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.feature.preview.ui.IMAGE_CAPTURE_FAILURE_TAG
import com.google.jetpackcamera.feature.preview.ui.IMAGE_CAPTURE_SUCCESS_TAG
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import java.io.File
import java.net.URLConnection
import kotlinx.coroutines.test.runTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.feature.preview.ui.FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.feature.preview.ui.SETTINGS_BUTTON
import com.google.jetpackcamera.settings.R
import com.google.jetpackcamera.settings.ui.BACK_BUTTON
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.assume
import com.google.jetpackcamera.utils.onNodeWithText
import com.google.jetpackcamera.utils.runScenarioTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -72,7 +78,7 @@ class NavigationTest {

// Assert we do not see the settings screen based on the title
composeTestRule.onNodeWithText(
com.google.jetpackcamera.settings.R.string.settings_title
R.string.settings_title
).assertDoesNotExist()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_
import com.google.jetpackcamera.feature.preview.ui.FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.feature.preview.ui.PREVIEW_DISPLAY
import com.google.jetpackcamera.settings.model.LensFacing
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.assume
import com.google.jetpackcamera.utils.getCurrentLensFacing
import com.google.jetpackcamera.utils.runScenarioTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera

import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.longClick
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTouchInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.RequiresDevice
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.google.common.truth.Truth.assertThat
import com.google.jetpackcamera.feature.preview.ui.AMPLITUDE_HOT_TAG
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.runScenarioTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@RequiresDevice
class VideoAudioTest {
@get:Rule
val permissionsRule: GrantPermissionRule =
GrantPermissionRule.grant(*(APP_REQUIRED_PERMISSIONS).toTypedArray())

@get:Rule
val composeTestRule = createEmptyComposeRule()

private val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

@Before
fun setUp() {
assertThat(uiDevice.isScreenOn).isTrue()
}

@Test
fun audioIncomingWhenEnabled() {
runScenarioTest<MainActivity> {
// check audio visualizer composable for muted/unmuted icon.
// icon will only be unmuted if audio is nonzero
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}

// record video
composeTestRule.onNodeWithTag(CAPTURE_BUTTON)
.assertExists().performTouchInput { longClick(durationMillis = 5000) }

// assert hot amplitude tag visible
uiDevice.wait(
Until.findObject(By.res(AMPLITUDE_HOT_TAG)),
5000
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.feature.preview.ui.VIDEO_CAPTURE_EXTERNAL_UNSUPPORTED_TAG
import com.google.jetpackcamera.utils.APP_REQUIRED_PERMISSIONS
import java.io.File
import org.junit.Rule
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera
package com.google.jetpackcamera.utils

import android.os.Build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera
package com.google.jetpackcamera.utils

import android.content.Context
import androidx.annotation.StringRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera
package com.google.jetpackcamera.utils

import android.app.Activity
import androidx.compose.ui.semantics.SemanticsProperties
Expand All @@ -22,6 +22,7 @@ import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ActivityScenario
import com.google.jetpackcamera.MainActivity
import com.google.jetpackcamera.feature.preview.R
import com.google.jetpackcamera.feature.preview.quicksettings.ui.QUICK_SETTINGS_FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.settings.model.LensFacing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ fun AmplitudeVisualizer(
Icon(
modifier = Modifier
.align(Alignment.Center)
.size((0.5 * size).dp),
.size((0.5 * size).dp)
.apply {
if (audioAmplitude != 0.0) {
testTag(AMPLITUDE_HOT_TAG)
} else {
testTag(AMPLITUDE_NONE_TAG)
}
},
tint = Color.Black,
imageVector = if (audioAmplitude != 0.0) {
Icons.Filled.Mic
Expand Down Expand Up @@ -460,7 +467,9 @@ enum class ToggleState {
fun ToggleButton(
leftIcon: Painter,
rightIcon: Painter,
modifier: Modifier = Modifier.width(64.dp).height(32.dp),
modifier: Modifier = Modifier
.width(64.dp)
.height(32.dp),
initialState: ToggleState = ToggleState.Left,
onToggleStateChanged: (newState: ToggleState) -> Unit = {},
enabled: Boolean = true,
Expand Down Expand Up @@ -526,9 +535,11 @@ fun ToggleButton(
)
}
Row(
modifier = Modifier.matchParentSize().then(
if (enabled) Modifier else Modifier.alpha(0.38f)
),
modifier = Modifier
.matchParentSize()
.then(
if (enabled) Modifier else Modifier.alpha(0.38f)
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ const val VIDEO_CAPTURE_EXTERNAL_UNSUPPORTED_TAG = "ImageCaptureExternalUnsuppor
const val PREVIEW_DISPLAY = "PreviewDisplay"
const val SCREEN_FLASH_OVERLAY = "ScreenFlashOverlay"
const val SETTINGS_BUTTON = "SettingsButton"
const val AMPLITUDE_NONE_TAG = "AmplitudeNoneTag"
const val AMPLITUDE_HOT_TAG = "AmplitudeHotTag"

0 comments on commit 171c27e

Please sign in to comment.