Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.google.jetpackcamera

import android.os.Build
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
Expand All @@ -28,7 +27,6 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.TruthJUnit.assume
import com.google.jetpackcamera.ui.components.capture.CAPTURE_BUTTON
import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_DROP_DOWN
import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_RATIO_1_1_BUTTON
Expand All @@ -37,6 +35,7 @@ import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_STREAM_CONF
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.TEST_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.runMainActivityScenarioTest
import com.google.jetpackcamera.utils.waitForCaptureButton
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -74,19 +73,15 @@ class BackgroundDeviceTest {
@Test
fun background_foreground() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

backgroundThenForegroundApp()
}

@Test
fun flipCamera_then_background_foreground() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// Navigate to quick settings
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN)
Expand All @@ -109,9 +104,7 @@ class BackgroundDeviceTest {
@Test
fun setAspectRatio_then_background_foreground() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// Navigate to quick settings
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN)
Expand Down Expand Up @@ -147,9 +140,7 @@ class BackgroundDeviceTest {
assumeSupportsSingleStream()

// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// Navigate to quick settings
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.google.jetpackcamera.ui.components.capture.CAPTURE_BUTTON
import com.google.jetpackcamera.ui.components.capture.IMAGE_CAPTURE_FAILURE_TAG
import com.google.jetpackcamera.ui.components.capture.IMAGE_CAPTURE_SUCCESS_TAG
import com.google.jetpackcamera.ui.components.capture.VIDEO_CAPTURE_EXTERNAL_UNSUPPORTED_TAG
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.FILE_PREFIX
import com.google.jetpackcamera.utils.IMAGE_CAPTURE_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.IMAGE_PREFIX
Expand All @@ -53,6 +52,7 @@ import com.google.jetpackcamera.utils.getTestUri
import com.google.jetpackcamera.utils.longClickForVideoRecording
import com.google.jetpackcamera.utils.runMainActivityMediaStoreAutoDeleteScenarioTest
import com.google.jetpackcamera.utils.runMainActivityScenarioTestForResult
import com.google.jetpackcamera.utils.waitForCaptureButton
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -77,9 +77,7 @@ internal class ImageCaptureDeviceTest {
filePrefix = FILE_PREFIX
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

composeTestRule.onNodeWithTag(CAPTURE_BUTTON)
.assertExists()
Expand All @@ -95,9 +93,7 @@ internal class ImageCaptureDeviceTest {
filePrefix = FILE_PREFIX
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

uiDevice.pressKeyCode(KeyEvent.KEYCODE_VOLUME_UP)

Expand All @@ -112,9 +108,7 @@ internal class ImageCaptureDeviceTest {
filePrefix = FILE_PREFIX
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
uiDevice.pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN)

composeTestRule.waitUntil(timeoutMillis = IMAGE_CAPTURE_TIMEOUT_MILLIS) {
Expand All @@ -131,9 +125,7 @@ internal class ImageCaptureDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_IMAGE_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

composeTestRule.onNodeWithTag(CAPTURE_BUTTON)
.assertExists()
Expand All @@ -156,9 +148,7 @@ internal class ImageCaptureDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_IMAGE_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

composeTestRule.onNodeWithTag(CAPTURE_BUTTON)
.assertExists()
Expand All @@ -182,9 +172,7 @@ internal class ImageCaptureDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_IMAGE_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

composeTestRule.longClickForVideoRecording()

Expand Down Expand Up @@ -215,9 +203,7 @@ internal class ImageCaptureDeviceTest {
)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
repeat(2) {
clickCaptureAndWaitUntilMessageDisappears(
IMAGE_CAPTURE_TIMEOUT_MILLIS,
Expand All @@ -243,9 +229,7 @@ internal class ImageCaptureDeviceTest {
getMultipleImageCaptureIntent(null, MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
repeat(2) {
clickCaptureAndWaitUntilMessageDisappears(
IMAGE_CAPTURE_TIMEOUT_MILLIS,
Expand All @@ -267,9 +251,7 @@ internal class ImageCaptureDeviceTest {
getMultipleImageCaptureIntent(null, MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
uiDevice.pressBack()
}
Truth.assertThat(result.resultCode).isEqualTo(Activity.RESULT_CANCELED)
Expand All @@ -289,9 +271,7 @@ internal class ImageCaptureDeviceTest {
)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
clickCaptureAndWaitUntilMessageDisappears(
IMAGE_CAPTURE_TIMEOUT_MILLIS,
IMAGE_CAPTURE_FAILURE_TAG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_DROP_DOWN
import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_RATIO_1_1_BUTTON
import com.google.jetpackcamera.ui.components.capture.QUICK_SETTINGS_RATIO_BUTTON
import com.google.jetpackcamera.ui.components.capture.SETTINGS_BUTTON
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.DEFAULT_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.TEST_REQUIRED_PERMISSIONS
import com.google.jetpackcamera.utils.assume
import com.google.jetpackcamera.utils.onNodeWithText
import com.google.jetpackcamera.utils.runMainActivityScenarioTest
import com.google.jetpackcamera.utils.searchForQuickSetting
import com.google.jetpackcamera.utils.waitForCaptureButton
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -60,9 +60,7 @@ class NavigationTest {
@Test
fun backAfterReturnFromSettings_doesNotReturnToSettings() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// open quick settings
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN).assertExists().performClick()
Expand Down Expand Up @@ -96,9 +94,7 @@ class NavigationTest {
@Test
fun returnFromSettings_afterFlipCamera_returnsToPreview() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// If flipping the camera is available, flip it. Otherwise skip test.
composeTestRule.onNodeWithTag(FLIP_CAMERA_BUTTON)
Expand Down Expand Up @@ -131,9 +127,7 @@ class NavigationTest {
@Test
fun backFromQuickSettings_returnToPreview() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// Navigate to the quick settings screen
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN)
Expand All @@ -155,9 +149,7 @@ class NavigationTest {
@Test
fun backFromQuickSettingsExpended_returnToQuickSettings() = runMainActivityScenarioTest {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()

// Navigate to the quick settings screen
composeTestRule.onNodeWithTag(QUICK_SETTINGS_DROP_DOWN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ class PermissionsTest {
@Test
fun allPermissions_alreadyGranted_screenNotShown() {
runMainActivityScenarioTest {
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.google.common.truth.Truth
import com.google.jetpackcamera.ui.components.capture.CAPTURE_BUTTON
import com.google.jetpackcamera.ui.components.capture.VIDEO_CAPTURE_FAILURE_TAG
import com.google.jetpackcamera.ui.components.capture.VIDEO_CAPTURE_SUCCESS_TAG
import com.google.jetpackcamera.utils.APP_START_TIMEOUT_MILLIS
import com.google.jetpackcamera.utils.IMAGE_PREFIX
import com.google.jetpackcamera.utils.MOVIES_DIR_PATH
import com.google.jetpackcamera.utils.TEST_REQUIRED_PERMISSIONS
Expand All @@ -46,6 +45,7 @@ import com.google.jetpackcamera.utils.pressAndDragToLockVideoRecording
import com.google.jetpackcamera.utils.runMainActivityMediaStoreAutoDeleteScenarioTest
import com.google.jetpackcamera.utils.runScenarioTestForResult
import com.google.jetpackcamera.utils.tapStartLockedVideoRecording
import com.google.jetpackcamera.utils.waitForCaptureButton
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -68,9 +68,7 @@ internal class VideoRecordingDeviceTest {
) {
val timeStamp = System.currentTimeMillis()
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
composeTestRule.longClickForVideoRecordingCheckingElapsedTime()
composeTestRule.waitUntil(timeoutMillis = VIDEO_CAPTURE_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(VIDEO_CAPTURE_SUCCESS_TAG).isDisplayed()
Expand All @@ -85,13 +83,11 @@ internal class VideoRecordingDeviceTest {
) {
val timeStamp = System.currentTimeMillis()
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
composeTestRule.pressAndDragToLockVideoRecording()

// stop recording
// fixme: this shouldnt need two clicks
// fixme: this shouldn't need two clicks
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).assertExists().performClick()
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).assertExists().performClick()

Expand All @@ -111,9 +107,7 @@ internal class VideoRecordingDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_VIDEO_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
composeTestRule.longClickForVideoRecordingCheckingElapsedTime()
}
Truth.assertThat(result.resultCode).isEqualTo(Activity.RESULT_OK)
Expand All @@ -130,9 +124,7 @@ internal class VideoRecordingDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_VIDEO_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
// start recording
composeTestRule.tapStartLockedVideoRecording()

Expand All @@ -153,9 +145,7 @@ internal class VideoRecordingDeviceTest {
getSingleImageCaptureIntent(uri, MediaStore.ACTION_VIDEO_CAPTURE)
) {
// Wait for the capture button to be displayed
composeTestRule.waitUntil(timeoutMillis = APP_START_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}
composeTestRule.waitForCaptureButton()
composeTestRule.longClickForVideoRecording()
composeTestRule.waitUntil(timeoutMillis = VIDEO_CAPTURE_TIMEOUT_MILLIS) {
composeTestRule.onNodeWithTag(VIDEO_CAPTURE_FAILURE_TAG).isDisplayed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ fun ComposeTestRule.wait(timeoutMillis: Long) {
}
}
fun ComposeTestRule.waitForCaptureButton(timeoutMillis: Long = APP_START_TIMEOUT_MILLIS) {
// Wait for the capture button to be displayed
// Wait for the capture button to be displayed and enabled
waitUntil(timeoutMillis = timeoutMillis) {
onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
onNode(hasTestTag(CAPTURE_BUTTON) and isEnabled()).isDisplayed()
}
}

Expand Down
Loading
Loading