-
Notifications
You must be signed in to change notification settings - Fork 37
[MUON-2017] Simplify BpkVideoPlayer by removing VideoHandler seam #2757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Henrik Sym (henrik-sky)
merged 4 commits into
main
from
muon-2017-simplify-bpkvideoplayer
Jul 27, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2541a80
[MUON-2017] Simplify BpkVideoPlayer by removing VideoHandler seam
antonicg 18e1979
Changes tests to given when then format
antonicg e4ca132
Adds tests for bpkVideoDefaultControls
antonicg 5db0de0
Address Copilot review comments on video player tests
antonicg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
220 changes: 220 additions & 0 deletions
220
...t/kotlin/net/skyscanner/backpack/compose/videoplayer/BpkVideoPlayerDefaultControlsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| /** | ||
| * Backpack for Android - Skyscanner's Design System | ||
| * | ||
| * Copyright 2018 - 2026 Skyscanner Ltd | ||
| * | ||
| * 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 net.skyscanner.backpack.compose.videoplayer | ||
|
|
||
| import android.os.ParcelFileDescriptor.AutoCloseInputStream | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithContentDescription | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import net.skyscanner.backpack.compose.theme.BpkTheme | ||
| import org.junit.After | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class BpkVideoPlayerDefaultControlsTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private var originalAnimationScales: Pair<String?, String?>? = null | ||
|
|
||
| private fun disableReducedMotionSignal() { | ||
| originalAnimationScales = | ||
| getGlobalSetting(ANIMATOR_DURATION_SCALE_KEY) to getGlobalSetting(TRANSITION_ANIMATION_SCALE_KEY) | ||
| putGlobalSetting(ANIMATOR_DURATION_SCALE_KEY, "1") | ||
| putGlobalSetting(TRANSITION_ANIMATION_SCALE_KEY, "1") | ||
| } | ||
|
|
||
| @After | ||
| fun restoreReducedMotionSignalIfChanged() { | ||
| originalAnimationScales?.let { (animator, transition) -> | ||
| putGlobalSetting(ANIMATOR_DURATION_SCALE_KEY, animator ?: "1") | ||
| putGlobalSetting(TRANSITION_ANIMATION_SCALE_KEY, transition ?: "1") | ||
| originalAnimationScales = null | ||
| } | ||
| } | ||
|
|
||
| private fun getGlobalSetting(key: String): String? = | ||
| runShellCommand("settings get global $key") | ||
| .trim() | ||
| .takeUnless { it == "null" || it.isEmpty() } | ||
|
|
||
| private fun putGlobalSetting(key: String, value: String) { | ||
| runShellCommand("settings put global $key $value") | ||
| } | ||
|
|
||
| private fun runShellCommand(command: String): String = | ||
| AutoCloseInputStream(InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(command)) | ||
| .use { it.readBytes().decodeToString() } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| private fun bundledVideoUrl(): String { | ||
| val targetPackage = InstrumentationRegistry.getInstrumentation().targetContext.packageName | ||
| return "android.resource://$targetPackage/raw/bpk_video_player_test" | ||
| } | ||
|
|
||
| private fun playableConfig(autoPlay: Boolean = true) = BpkVideoPlayerConfig( | ||
| videoUrl = BpkVideoUrl(bundledVideoUrl()), | ||
| startsMuted = true, | ||
| autoPlay = autoPlay, | ||
| loadTimeoutMs = 7_000L, | ||
| accessibilityLabel = "Test video", | ||
| ) | ||
|
|
||
| @Test | ||
| fun givenLoadingState_whenControlsRendered_thenPlayButtonIsNotShown() { | ||
| // When | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| val controller = rememberBpkVideoPlayerController( | ||
| BpkVideoPlayerConfig( | ||
| videoUrl = BpkVideoUrl("https://example.com/stub.mp4"), | ||
| accessibilityLabel = "Test video", | ||
| ), | ||
| ) | ||
| BpkVideoPlayerDefaultControls( | ||
| controller = controller, | ||
| playContentDescription = PLAY_LABEL, | ||
| pauseContentDescription = PAUSE_LABEL, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Then | ||
| composeTestRule.onNodeWithContentDescription(PLAY_LABEL).assertDoesNotExist() | ||
| composeTestRule.onNodeWithContentDescription(PAUSE_LABEL).assertDoesNotExist() | ||
| } | ||
|
|
||
| @Test | ||
| fun givenReadyToPlayState_whenControlsRendered_thenPlayButtonIsShown() { | ||
| // Given | ||
| disableReducedMotionSignal() | ||
| lateinit var controller: BpkVideoPlayerController | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| controller = rememberBpkVideoPlayerController(playableConfig(autoPlay = false)) | ||
| BpkVideoPlayerDefaultControls( | ||
| controller = controller, | ||
| playContentDescription = PLAY_LABEL, | ||
| pauseContentDescription = PAUSE_LABEL, | ||
| ) | ||
| } | ||
| } | ||
| composeTestRule.waitUntil(timeoutMillis = READY_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.ReadyToPlay | ||
| } | ||
|
|
||
| // Then | ||
| composeTestRule.onNodeWithContentDescription(PLAY_LABEL).assertIsDisplayed() | ||
| composeTestRule.onNodeWithContentDescription(PAUSE_LABEL).assertDoesNotExist() | ||
| } | ||
|
|
||
| @Test | ||
| fun givenPlayingState_whenControlsRendered_thenPauseButtonIsShown() { | ||
| // Given | ||
| disableReducedMotionSignal() | ||
| lateinit var controller: BpkVideoPlayerController | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| controller = rememberBpkVideoPlayerController(playableConfig(autoPlay = true)) | ||
| BpkVideoPlayerDefaultControls( | ||
| controller = controller, | ||
| playContentDescription = PLAY_LABEL, | ||
| pauseContentDescription = PAUSE_LABEL, | ||
| ) | ||
| } | ||
| } | ||
| composeTestRule.waitUntil(timeoutMillis = PLAYING_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.Playing | ||
| } | ||
|
|
||
| // Then | ||
| composeTestRule.onNodeWithContentDescription(PAUSE_LABEL).assertIsDisplayed() | ||
| composeTestRule.onNodeWithContentDescription(PLAY_LABEL).assertDoesNotExist() | ||
| } | ||
|
|
||
| @Test | ||
| fun givenReadyToPlayState_whenPlayButtonClicked_thenStateTransitionsToPlaying() { | ||
| // Given | ||
| disableReducedMotionSignal() | ||
| lateinit var controller: BpkVideoPlayerController | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| controller = rememberBpkVideoPlayerController(playableConfig(autoPlay = false)) | ||
| BpkVideoPlayerDefaultControls( | ||
| controller = controller, | ||
| playContentDescription = PLAY_LABEL, | ||
| pauseContentDescription = PAUSE_LABEL, | ||
| ) | ||
| } | ||
| } | ||
| composeTestRule.waitUntil(timeoutMillis = READY_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.ReadyToPlay | ||
| } | ||
|
|
||
| // When | ||
| composeTestRule.onNodeWithContentDescription(PLAY_LABEL).performClick() | ||
|
|
||
| // Then | ||
| composeTestRule.waitUntil(timeoutMillis = PLAYING_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.Playing | ||
| } | ||
| assertTrue(controller.playbackState.value is BpkVideoPlaybackState.Playing) | ||
| } | ||
|
|
||
| @Test | ||
| fun givenPlayingState_whenPauseButtonClicked_thenStateTransitionsToPaused() { | ||
| // Given | ||
| disableReducedMotionSignal() | ||
| lateinit var controller: BpkVideoPlayerController | ||
| composeTestRule.setContent { | ||
| BpkTheme { | ||
| controller = rememberBpkVideoPlayerController(playableConfig(autoPlay = true)) | ||
| BpkVideoPlayerDefaultControls( | ||
| controller = controller, | ||
| playContentDescription = PLAY_LABEL, | ||
| pauseContentDescription = PAUSE_LABEL, | ||
| ) | ||
| } | ||
| } | ||
| composeTestRule.waitUntil(timeoutMillis = PLAYING_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.Playing | ||
| } | ||
|
|
||
| // When | ||
| composeTestRule.onNodeWithContentDescription(PAUSE_LABEL).performClick() | ||
|
|
||
| // Then | ||
| composeTestRule.waitUntil(timeoutMillis = PLAYING_STATE_TIMEOUT_MS) { | ||
| controller.playbackState.value is BpkVideoPlaybackState.Paused | ||
| } | ||
| assertTrue(controller.playbackState.value is BpkVideoPlaybackState.Paused) | ||
| } | ||
|
|
||
| private companion object { | ||
| const val PLAY_LABEL = "Play" | ||
| const val PAUSE_LABEL = "Pause" | ||
| const val ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale" | ||
| const val TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale" | ||
| const val READY_STATE_TIMEOUT_MS = 7_000L | ||
| const val PLAYING_STATE_TIMEOUT_MS = 5_000L | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5db0de0