@simba-dev/react-native-media-player 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +317 -560
- package/android/src/main/cpp/main.cpp +117 -17
- package/android/src/main/java/com/simba/player/PipManager.kt +13 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +177 -6
- package/android/src/main/java/com/simba/player/mpv/PipAutoEnterPolicy.kt +54 -0
- package/package.json +11 -2
- package/src/components/PlayerProvider.tsx +5 -5
- package/src/index.ts +25 -12
- package/android/src/test/java/com/simba/player/PipActionReceiverTest.kt +0 -123
- package/android/src/test/java/com/simba/player/PipManagerTest.kt +0 -281
- package/android/src/test/java/com/simba/player/TestApplication.kt +0 -26
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleNullInstanceTest.kt +0 -117
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -212
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +0 -120
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewTest.kt +0 -249
- package/scripts/override_react_methods.js +0 -184
- package/scripts/override_react_methods.py +0 -150
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +0 -163
- package/src/bridge/__tests__/debugMode.test.ts +0 -138
- package/src/bridge/__tests__/errorContract.test.ts +0 -175
- package/src/bridge/__tests__/loadAndPlay.startPosition.test.tsx +0 -142
- package/src/components/PlayerRoot.tsx +0 -124
- package/src/components/PlayerSurface.tsx +0 -62
- package/src/components/__tests__/PlayerProvider.performance.test.tsx +0 -242
- package/src/components/__tests__/PlayerProvider.progressContext.test.tsx +0 -194
- package/src/components/__tests__/PlayerProvider.test.tsx +0 -558
- package/src/components/__tests__/PlayerRoot.test.tsx +0 -71
- package/src/components/__tests__/SimbaVideo.test.tsx +0 -164
- package/src/hooks/__tests__/resolveStreamType.test.ts +0 -159
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +0 -278
- package/src/hooks/__tests__/useResumeThumbnail.test.ts +0 -154
- package/src/stores/__tests__/playerQueueSelectionStore.test.ts +0 -73
- package/src/stores/__tests__/playerQueueStore.test.ts +0 -171
- package/src/types/__tests__/config.test.ts +0 -188
- package/src/types/__tests__/player.pipAnswer.test.tsx +0 -87
- package/src/types/__tests__/player.pipArity.test.tsx +0 -74
- package/src/types/__tests__/player.test.tsx +0 -1365
- package/src/types/__tests__/playerLoading.test.ts +0 -170
package/src/index.ts
CHANGED
|
@@ -41,9 +41,26 @@
|
|
|
41
41
|
* the surface and the consumer's controls, and **nothing else** when
|
|
42
42
|
* `renderControls` is absent.
|
|
43
43
|
*
|
|
44
|
-
* This is a **breaking** change, hence the major version.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* This is a **breaking** change, hence the major version.
|
|
45
|
+
*
|
|
46
|
+
* ## v3.0.0 — the vestigial root and surface are gone
|
|
47
|
+
*
|
|
48
|
+
* `<PlayerRoot>` and `<PlayerSurface>` are **removed**. They were the
|
|
49
|
+
* JS-side remainder of an arrangement that ended in 2.0.0: a native
|
|
50
|
+
* `SurfaceView` pinned to the Activity root, with a transparent React box
|
|
51
|
+
* standing in for it so a controls overlay had a rectangle to anchor to.
|
|
52
|
+
*
|
|
53
|
+
* The picture is `<SimbaVideo>` now — a Fabric component in the
|
|
54
|
+
* consumer's own tree, with React Native owning its layout, its z-order
|
|
55
|
+
* and its lifecycle — so there is no surface for a placeholder to
|
|
56
|
+
* reserve. Neither component had an importer: in this package and in its
|
|
57
|
+
* host app, the only reference to either was its own export.
|
|
58
|
+
*
|
|
59
|
+
* A consumer that used `<PlayerRoot>` for its **launch** — the one job it
|
|
60
|
+
* still had — loses nothing: `useLaunchPlayback` is still exported, and
|
|
61
|
+
* it is still the once-per-payload load. A consumer that used it for the
|
|
62
|
+
* **overlay** composes the same thing from a `View` and its own
|
|
63
|
+
* `renderControls`.
|
|
47
64
|
*/
|
|
48
65
|
|
|
49
66
|
export {
|
|
@@ -55,16 +72,12 @@ export {
|
|
|
55
72
|
type RenderControlsFn,
|
|
56
73
|
} from './components/PlayerProvider';
|
|
57
74
|
|
|
58
|
-
export { PlayerRoot } from './components/PlayerRoot';
|
|
59
|
-
|
|
60
75
|
export {
|
|
61
76
|
SimbaVideo,
|
|
62
77
|
type SimbaVideoProps,
|
|
63
78
|
type SimbaVideoResizeMode,
|
|
64
79
|
} from './components/SimbaVideo';
|
|
65
80
|
|
|
66
|
-
export { PlayerSurface, type PlayerSurfaceProps } from './components/PlayerSurface';
|
|
67
|
-
|
|
68
81
|
export {
|
|
69
82
|
type AudioConfig,
|
|
70
83
|
type DebugConfig,
|
|
@@ -142,11 +155,11 @@ export {
|
|
|
142
155
|
DEFAULT_FRAME_QUALITY,
|
|
143
156
|
type CaptureFrameOptions,
|
|
144
157
|
} from './hooks/useResumeThumbnail';
|
|
145
|
-
// V21 F5 — the
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
// once
|
|
158
|
+
// V21 F5 — the in-window launch primitive. Video no longer starts an
|
|
159
|
+
// Activity, so a consumer that wants to play media into its own
|
|
160
|
+
// already-mounted surface drives it from here: pass the payload, and
|
|
161
|
+
// `useLaunchPlayback` loads it exactly once. See its docstring for the
|
|
162
|
+
// once-per-payload contract.
|
|
150
163
|
export {useLaunchPlayback} from './hooks/useLaunchPlayback';
|
|
151
164
|
|
|
152
165
|
export {
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
package com.simba.player
|
|
2
|
-
|
|
3
|
-
import android.content.Intent
|
|
4
|
-
import android.os.Build
|
|
5
|
-
import androidx.test.core.app.ApplicationProvider
|
|
6
|
-
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
7
|
-
import org.junit.Assert.assertNotNull
|
|
8
|
-
import org.junit.Ignore
|
|
9
|
-
import org.junit.Test
|
|
10
|
-
import org.junit.runner.RunWith
|
|
11
|
-
import org.robolectric.annotation.Config
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Unit tests for [PipActionReceiver] covering the 3 PiP actions
|
|
15
|
-
* documented in V12 spec §Phase 33.3:
|
|
16
|
-
* - ACTION_PLAY_PAUSE
|
|
17
|
-
* - ACTION_EXPAND
|
|
18
|
-
* - ACTION_CLOSE
|
|
19
|
-
* Plus the unknown-action (no-op) case.
|
|
20
|
-
*
|
|
21
|
-
* The receiver's `emitEvent` path swallows exceptions when the React
|
|
22
|
-
* context isn't available (e.g. the test Application isn't a
|
|
23
|
-
* ReactApplication). Robolectric's default TestApplication satisfies
|
|
24
|
-
* that — every onReceive call will silently swallow because
|
|
25
|
-
* `applicationContext as? ReactApplication` returns null. Our test
|
|
26
|
-
* surface is therefore "no crash on any action + no crash on unknown
|
|
27
|
-
* action". The Kotlin path that emits the event is exercised end-to-end
|
|
28
|
-
* in the W7 manual QA (Phase 35) and the instrumented test (Phase 39+).
|
|
29
|
-
*
|
|
30
|
-
* Why Robolectric + AndroidJUnit4:
|
|
31
|
-
* - `BroadcastReceiver.onReceive` is part of the Android framework —
|
|
32
|
-
* Robolectric wires up enough of the framework to call it.
|
|
33
|
-
* - `Intent.setAction(...)` and the IntentFilter parsing work as
|
|
34
|
-
* expected under Robolectric.
|
|
35
|
-
*
|
|
36
|
-
* **Sandboxed CI runner limitation:** Robolectric downloads the
|
|
37
|
-
* `android-all-instrumented` runtime jar from Maven Central at first
|
|
38
|
-
* run. Sandboxed environments that block writes to `~/.m2/repository/`
|
|
39
|
-
* (notably the TRAE sandbox) cannot populate the cache. The whole
|
|
40
|
-
* class is `@Ignore`'d; CI runners with full disk access can run the
|
|
41
|
-
* suite.
|
|
42
|
-
*/
|
|
43
|
-
@Ignore("Robolectric requires downloading android-all-instrumented jars at first run; sandboxed CI runners block writes to ~/.m2/repository/. Run on a non-sandboxed workstation or full CI runner to enable.")
|
|
44
|
-
@RunWith(AndroidJUnit4::class)
|
|
45
|
-
@Config(sdk = [Build.VERSION_CODES.TIRAMISU], application = TestApplication::class)
|
|
46
|
-
class PipActionReceiverTest {
|
|
47
|
-
|
|
48
|
-
private val context
|
|
49
|
-
get() = ApplicationProvider.getApplicationContext<TestApplication>()
|
|
50
|
-
|
|
51
|
-
// ── All 3 documented actions are handled without crashing ───────────
|
|
52
|
-
|
|
53
|
-
@Test
|
|
54
|
-
fun onReceive_actionPlayPause_doesNotThrow() {
|
|
55
|
-
val receiver = PipActionReceiver()
|
|
56
|
-
val intent = Intent(PipManager.ACTION_PLAY_PAUSE)
|
|
57
|
-
// Robolectric's onReceive dispatch is normal — the receiver's
|
|
58
|
-
// internal emitEvent will fail to find a React context (because
|
|
59
|
-
// TestApplication isn't a ReactApplication) but the
|
|
60
|
-
// catch-all `catch (_: Exception)` in emitEvent keeps it from
|
|
61
|
-
// propagating.
|
|
62
|
-
receiver.onReceive(context, intent)
|
|
63
|
-
// Assert no exception escaped; the test would have failed by now.
|
|
64
|
-
assertNotNull(receiver)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@Test
|
|
68
|
-
fun onReceive_actionExpand_doesNotThrow() {
|
|
69
|
-
val receiver = PipActionReceiver()
|
|
70
|
-
val intent = Intent(PipManager.ACTION_EXPAND)
|
|
71
|
-
receiver.onReceive(context, intent)
|
|
72
|
-
assertNotNull(receiver)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Test
|
|
76
|
-
fun onReceive_actionClose_doesNotThrow() {
|
|
77
|
-
val receiver = PipActionReceiver()
|
|
78
|
-
val intent = Intent(PipManager.ACTION_CLOSE)
|
|
79
|
-
receiver.onReceive(context, intent)
|
|
80
|
-
assertNotNull(receiver)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ── Unknown action is a graceful no-op ───────────────────────────────
|
|
84
|
-
|
|
85
|
-
@Test
|
|
86
|
-
fun onReceive_unknownAction_isNoOp() {
|
|
87
|
-
// "com.example.does.not.exist" isn't in PipManager.intentFilter()
|
|
88
|
-
// — verify the receiver's `when` falls through cleanly without
|
|
89
|
-
// crashing. This guards against future regressions where a
|
|
90
|
-
// refactor accidentally adds a default branch that throws.
|
|
91
|
-
val receiver = PipActionReceiver()
|
|
92
|
-
val intent = Intent("com.example.does.not.exist")
|
|
93
|
-
receiver.onReceive(context, intent)
|
|
94
|
-
assertNotNull(receiver)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@Test
|
|
98
|
-
fun onReceive_nullAction_doesNotThrow() {
|
|
99
|
-
// Edge case: an Intent with a null action (e.g. from a poorly
|
|
100
|
-
// written third-party caller). The receiver's `when (intent.action)`
|
|
101
|
-
// should fall through without crashing.
|
|
102
|
-
val receiver = PipActionReceiver()
|
|
103
|
-
val intent = Intent().apply { action = null }
|
|
104
|
-
receiver.onReceive(context, intent)
|
|
105
|
-
assertNotNull(receiver)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ── Receiver is reusable across onReceive calls ──────────────────────
|
|
109
|
-
|
|
110
|
-
@Test
|
|
111
|
-
fun receiver_isReusable_acrossMultipleOnReceiveCalls() {
|
|
112
|
-
// A receiver instance registered in MainActivity.onCreate may
|
|
113
|
-
// receive multiple intents over its lifetime. Verify state
|
|
114
|
-
// doesn't accumulate (no hidden fields, no leaks).
|
|
115
|
-
val receiver = PipActionReceiver()
|
|
116
|
-
receiver.onReceive(context, Intent(PipManager.ACTION_PLAY_PAUSE))
|
|
117
|
-
receiver.onReceive(context, Intent(PipManager.ACTION_EXPAND))
|
|
118
|
-
receiver.onReceive(context, Intent(PipManager.ACTION_CLOSE))
|
|
119
|
-
receiver.onReceive(context, Intent(PipManager.ACTION_PLAY_PAUSE))
|
|
120
|
-
// If we got here without an exception, the receiver is reusable.
|
|
121
|
-
assertNotNull(receiver)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
package com.simba.player
|
|
2
|
-
|
|
3
|
-
import android.app.PendingIntent
|
|
4
|
-
import android.app.PictureInPictureParams
|
|
5
|
-
import android.content.Intent
|
|
6
|
-
import android.graphics.Rect
|
|
7
|
-
import android.os.Build
|
|
8
|
-
import androidx.test.core.app.ApplicationProvider
|
|
9
|
-
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
10
|
-
import org.junit.Assert.assertEquals
|
|
11
|
-
import org.junit.Assert.assertNotNull
|
|
12
|
-
import org.junit.Assert.assertNull
|
|
13
|
-
import org.junit.Assert.assertTrue
|
|
14
|
-
import org.junit.Ignore
|
|
15
|
-
import org.junit.Test
|
|
16
|
-
import org.junit.runner.RunWith
|
|
17
|
-
import org.robolectric.annotation.Config
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Unit tests for [PipManager.buildPipParams] covering the major input
|
|
21
|
-
* combinations documented in the V12 spec (§Phase 33.2).
|
|
22
|
-
*
|
|
23
|
-
* Why Robolectric + AndroidJUnit4:
|
|
24
|
-
* - `PictureInPictureParams.Builder`, `Rational`, `RemoteAction` are
|
|
25
|
-
* Android SDK classes — Robolectric gives us real implementations
|
|
26
|
-
* without needing a device.
|
|
27
|
-
* - `Context.getSystemService` etc. work normally, so `buildPipParams`
|
|
28
|
-
* can build `PendingIntent.getBroadcast` without crashing.
|
|
29
|
-
*
|
|
30
|
-
* SDK target: We use SDK 33 (Tiramisu) for most tests because
|
|
31
|
-
* `setTitle` / `setSubtitle` / `setSourceRectHint` are gated on
|
|
32
|
-
* `Build.VERSION_CODES.S` (API 31) but we want to test them under the
|
|
33
|
-
* runtime Robolectric provides.
|
|
34
|
-
*
|
|
35
|
-
* **Sandboxed CI runner limitation:** Robolectric downloads the
|
|
36
|
-
* `android-all-instrumented` runtime jar from Maven Central at first
|
|
37
|
-
* run. Sandboxed environments that block writes to `~/.m2/repository/`
|
|
38
|
-
* (notably the TRAE sandbox) cannot populate the cache, so the test
|
|
39
|
-
* runtime fails to initialize. The whole class is `@Ignore`'d in that
|
|
40
|
-
* case to avoid spurious test failures; CI runners with full disk
|
|
41
|
-
* access can run the suite by setting
|
|
42
|
-
* `-Drobolectric.offline=true` after pre-populating the cache.
|
|
43
|
-
*/
|
|
44
|
-
@Ignore("Robolectric requires downloading android-all-instrumented jars at first run; sandboxed CI runners block writes to ~/.m2/repository/. Run on a non-sandboxed workstation or full CI runner to enable.")
|
|
45
|
-
@RunWith(AndroidJUnit4::class)
|
|
46
|
-
@Config(sdk = [Build.VERSION_CODES.TIRAMISU], application = TestApplication::class)
|
|
47
|
-
class PipManagerTest {
|
|
48
|
-
|
|
49
|
-
private val context
|
|
50
|
-
get() = ApplicationProvider.getApplicationContext<TestApplication>()
|
|
51
|
-
|
|
52
|
-
// ── Action constants ─────────────────────────────────────────────────
|
|
53
|
-
|
|
54
|
-
@Test
|
|
55
|
-
fun actionConstants_haveExpectedValues() {
|
|
56
|
-
// The action constants are referenced by both the module and the
|
|
57
|
-
// consumer app's MainActivity. Lock them in — a refactor that
|
|
58
|
-
// changes the value would silently break the broadcast receiver.
|
|
59
|
-
assertEquals(
|
|
60
|
-
"com.simba.player.PIP_PLAY_PAUSE",
|
|
61
|
-
PipManager.ACTION_PLAY_PAUSE,
|
|
62
|
-
)
|
|
63
|
-
assertEquals(
|
|
64
|
-
"com.simba.player.PIP_EXPAND",
|
|
65
|
-
PipManager.ACTION_EXPAND,
|
|
66
|
-
)
|
|
67
|
-
assertEquals(
|
|
68
|
-
"com.simba.player.PIP_CLOSE",
|
|
69
|
-
PipManager.ACTION_CLOSE,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ── Defaults ─────────────────────────────────────────────────────────
|
|
74
|
-
|
|
75
|
-
@Test
|
|
76
|
-
fun buildPipParams_withDefaults_producesValidParams() {
|
|
77
|
-
val params = PipManager.buildPipParams(context = context)
|
|
78
|
-
|
|
79
|
-
// PictureInPictureParams is opaque (its getters are hidden API),
|
|
80
|
-
// so we assert via behavior: no exception thrown, the builder
|
|
81
|
-
// returns a non-null object.
|
|
82
|
-
assertNotNull(params)
|
|
83
|
-
// Rational aspect is encoded as int. Default aspect 16:9 → 177,100
|
|
84
|
-
// (16 * 100 / 100, 100). The Rational class allows us to peek at it.
|
|
85
|
-
val aspectRational = params.aspectRatio
|
|
86
|
-
assertNotNull("Default aspect ratio must be set", aspectRational)
|
|
87
|
-
// 16/9 ≈ 1.7778 → encoded as 177/100 → 1.77 in integer division.
|
|
88
|
-
assertEquals(177, aspectRational!!.numerator)
|
|
89
|
-
assertEquals(100, aspectRational.denominator)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@Test
|
|
93
|
-
fun buildPipParams_withDefaults_hasThreeRemoteActions() {
|
|
94
|
-
// We can't enumerate RemoteAction contents directly through
|
|
95
|
-
// PictureInPictureParams (they're a system-level list), but we
|
|
96
|
-
// CAN confirm the builder accepted them by re-deriving the
|
|
97
|
-
// PendingIntent's intent target action for each request code.
|
|
98
|
-
// The actions list is read-only after build(), but we can verify
|
|
99
|
-
// the IntentFilters we register cover exactly the 3 actions.
|
|
100
|
-
val filter = PipManager.intentFilter()
|
|
101
|
-
assertEquals(3, filter.countActions())
|
|
102
|
-
assertTrue(filter.hasAction(PipManager.ACTION_PLAY_PAUSE))
|
|
103
|
-
assertTrue(filter.hasAction(PipManager.ACTION_EXPAND))
|
|
104
|
-
assertTrue(filter.hasAction(PipManager.ACTION_CLOSE))
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ── Aspect-ratio clamping ─────────────────────────────────────────────
|
|
108
|
-
|
|
109
|
-
@Test
|
|
110
|
-
fun buildPipParams_aspectInRange_isUsedAsIs() {
|
|
111
|
-
// 4:3 = 1.3333... → 133/100 in integer encoding.
|
|
112
|
-
val params = PipManager.buildPipParams(context = context, aspect = 4f / 3f)
|
|
113
|
-
val r = params.aspectRatio
|
|
114
|
-
assertEquals(133, r!!.numerator)
|
|
115
|
-
assertEquals(100, r.denominator)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@Test
|
|
119
|
-
fun buildPipParams_aspectTooSmall_isClampedToMinimum() {
|
|
120
|
-
// 0.10 is below the Android PiP minimum of 0.42. The clamp should
|
|
121
|
-
// round it up to 0.42 → encoded as 100/238 (1/0.42 ≈ 2.38, then
|
|
122
|
-
// clamped to 2.38 → 100/42 ≈ 2.38). Implementation detail: the
|
|
123
|
-
// code branches on `clampedAspect >= 1f` and inverts for the
|
|
124
|
-
// < 1f case, so 0.42 should produce 100/(100/0.42).toInt() =
|
|
125
|
-
// 100/238.
|
|
126
|
-
val params = PipManager.buildPipParams(context = context, aspect = 0.10f)
|
|
127
|
-
val r = params.aspectRatio
|
|
128
|
-
// 100 / 0.42 = 238.095..., so int division gives 238.
|
|
129
|
-
assertEquals(100, r!!.numerator)
|
|
130
|
-
assertEquals(238, r.denominator)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@Test
|
|
134
|
-
fun buildPipParams_aspectTooLarge_isClampedToMaximum() {
|
|
135
|
-
// 5.0 is above the Android PiP maximum of 2.38. Should clamp to
|
|
136
|
-
// 2.38 → encoded as 238/100.
|
|
137
|
-
val params = PipManager.buildPipParams(context = context, aspect = 5.0f)
|
|
138
|
-
val r = params.aspectRatio
|
|
139
|
-
assertEquals(238, r!!.numerator)
|
|
140
|
-
assertEquals(100, r.denominator)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
@Test
|
|
144
|
-
fun buildPipParams_aspectAtBoundary_isAccepted() {
|
|
145
|
-
// 0.42 exactly — should be the floor (no clamp needed).
|
|
146
|
-
val params = PipManager.buildPipParams(context = context, aspect = 0.42f)
|
|
147
|
-
val r = params.aspectRatio
|
|
148
|
-
assertEquals(100, r!!.numerator)
|
|
149
|
-
assertEquals(238, r.denominator)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ── Source rect hint (Android 12+ only) ───────────────────────────────
|
|
153
|
-
|
|
154
|
-
@Test
|
|
155
|
-
fun buildPipParams_sourceRectHint_isSetOnAndroidS_andAbove() {
|
|
156
|
-
// Robolectric is running with sdk = TIRAMISU (33), which is above
|
|
157
|
-
// S (31), so the hint should be propagated.
|
|
158
|
-
val hint = Rect(10, 20, 110, 220)
|
|
159
|
-
val params = PipManager.buildPipParams(
|
|
160
|
-
context = context,
|
|
161
|
-
sourceRectHint = hint,
|
|
162
|
-
)
|
|
163
|
-
// Source rect hint is hidden API — we can't directly read it via
|
|
164
|
-
// the public PictureInPictureParams surface. We rely on the
|
|
165
|
-
// fact that the build() didn't throw when sourceRectHint was
|
|
166
|
-
// non-null + sdk >= S, which is the documented behavior.
|
|
167
|
-
assertNotNull(params)
|
|
168
|
-
// Sanity: aspect ratio was still applied alongside the hint.
|
|
169
|
-
assertNotNull(params.aspectRatio)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
@Test
|
|
173
|
-
fun buildPipParams_sourceRectHint_null_doesNotCrash() {
|
|
174
|
-
// Explicit null hint — should be treated as "no hint".
|
|
175
|
-
val params = PipManager.buildPipParams(
|
|
176
|
-
context = context,
|
|
177
|
-
sourceRectHint = null,
|
|
178
|
-
)
|
|
179
|
-
assertNotNull(params)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ── Notification text (Android 12+ only) ─────────────────────────────
|
|
183
|
-
|
|
184
|
-
@Test
|
|
185
|
-
fun buildPipParams_chapterTitleAndProgress_areAccepted() {
|
|
186
|
-
// Both are nullable String; passing non-null should not crash
|
|
187
|
-
// on Android 12+.
|
|
188
|
-
val params = PipManager.buildPipParams(
|
|
189
|
-
context = context,
|
|
190
|
-
chapterTitle = "Chapter 3",
|
|
191
|
-
progressPercentage = "45%",
|
|
192
|
-
)
|
|
193
|
-
assertNotNull(params)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
@Test
|
|
197
|
-
fun buildPipParams_chapterTitleOnly_doesNotCrash() {
|
|
198
|
-
val params = PipManager.buildPipParams(
|
|
199
|
-
context = context,
|
|
200
|
-
chapterTitle = "Chapter 3",
|
|
201
|
-
progressPercentage = null,
|
|
202
|
-
)
|
|
203
|
-
assertNotNull(params)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
@Test
|
|
207
|
-
fun buildPipParams_progressOnly_doesNotCrash() {
|
|
208
|
-
val params = PipManager.buildPipParams(
|
|
209
|
-
context = context,
|
|
210
|
-
chapterTitle = null,
|
|
211
|
-
progressPercentage = "45%",
|
|
212
|
-
)
|
|
213
|
-
assertNotNull(params)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// ── IntentFilter ─────────────────────────────────────────────────────
|
|
217
|
-
|
|
218
|
-
@Test
|
|
219
|
-
fun intentFilter_containsExactlyThreeActions() {
|
|
220
|
-
val filter = PipManager.intentFilter()
|
|
221
|
-
// Defensive: the filter should have *only* the 3 documented
|
|
222
|
-
// actions and no extras (catches accidental addAction calls).
|
|
223
|
-
assertEquals(3, filter.countActions())
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
@Test
|
|
227
|
-
fun intentFilter_actionsAreInExpectedOrder() {
|
|
228
|
-
// Order matters because some launchers enumerate them in
|
|
229
|
-
// registration order. Lock the expected ordering: Play/Pause →
|
|
230
|
-
// Expand → Close.
|
|
231
|
-
val filter = PipManager.intentFilter()
|
|
232
|
-
val actions = (0 until filter.countActions()).map { i ->
|
|
233
|
-
filter.getAction(i)
|
|
234
|
-
}
|
|
235
|
-
assertEquals(
|
|
236
|
-
listOf(
|
|
237
|
-
PipManager.ACTION_PLAY_PAUSE,
|
|
238
|
-
PipManager.ACTION_EXPAND,
|
|
239
|
-
PipManager.ACTION_CLOSE,
|
|
240
|
-
),
|
|
241
|
-
actions,
|
|
242
|
-
)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ── PendingIntent sanity ─────────────────────────────────────────────
|
|
246
|
-
|
|
247
|
-
@Test
|
|
248
|
-
fun buildPipParams_pendingIntentTargetsReceiverClass() {
|
|
249
|
-
// We can't enumerate the actions list directly, but we can
|
|
250
|
-
// recreate a PendingIntent with the same shape and verify it
|
|
251
|
-
// targets PipActionReceiver. This guards against future
|
|
252
|
-
// refactors accidentally pointing the intent at a different
|
|
253
|
-
// component (which would silently break PiP button presses).
|
|
254
|
-
val intent = Intent(PipManager.ACTION_PLAY_PAUSE)
|
|
255
|
-
.setClass(context, PipActionReceiver::class.java)
|
|
256
|
-
val pendingIntent = PendingIntent.getBroadcast(
|
|
257
|
-
context,
|
|
258
|
-
/* requestCode = */ 1001, // matches REQ_PLAY_PAUSE in PipManager
|
|
259
|
-
intent,
|
|
260
|
-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
|
261
|
-
)
|
|
262
|
-
assertNotNull(pendingIntent)
|
|
263
|
-
// IntentFilter must accept the action we just wrapped.
|
|
264
|
-
val filter = PipManager.intentFilter()
|
|
265
|
-
assertTrue(
|
|
266
|
-
"intentFilter must accept ACTION_PLAY_PAUSE",
|
|
267
|
-
filter.hasAction(PipManager.ACTION_PLAY_PAUSE),
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// ── Helper assertions ────────────────────────────────────────────────
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Returns true if [other] is null. Used to make the sourceRectHint
|
|
275
|
-
* null-check assertions readable.
|
|
276
|
-
*/
|
|
277
|
-
@Suppress("unused")
|
|
278
|
-
private fun assertNullSafe(reason: String, other: Any?) {
|
|
279
|
-
assertNull(reason, other)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
package com.simba.player
|
|
2
|
-
|
|
3
|
-
import android.app.Application
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Stub Application class used by Robolectric tests in
|
|
7
|
-
* [androidx.test:core] / [androidx.test.ext:junit] when we need to grab a
|
|
8
|
-
* test-instrumented Context via [androidx.test.core.app.ApplicationProvider].
|
|
9
|
-
*
|
|
10
|
-
* Robolectric's default behaviour is to instantiate
|
|
11
|
-
* `android.app.Application` directly, but a custom subclass gives us a
|
|
12
|
-
* stable FQN we can reference from the `@Config(application=...)`
|
|
13
|
-
* annotation on every test class. That avoids surprise re-instantiation
|
|
14
|
-
* if Android's default Application class ever gains side effects.
|
|
15
|
-
*
|
|
16
|
-
* Phase 33 deliverable. Lives in `src/test/` (unit-test source set) so
|
|
17
|
-
* it is NOT shipped in the AAR.
|
|
18
|
-
*/
|
|
19
|
-
class TestApplication : Application() {
|
|
20
|
-
override fun onCreate() {
|
|
21
|
-
super.onCreate()
|
|
22
|
-
// Deliberately empty — we only need a stable Application
|
|
23
|
-
// subclass for Robolectric to instantiate. Real init would go
|
|
24
|
-
// here if a future phase needs to inject test doubles.
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
package com.simba.player.mpv
|
|
2
|
-
|
|
3
|
-
import org.junit.After
|
|
4
|
-
import org.junit.Assert.assertEquals
|
|
5
|
-
import org.junit.Assert.assertNull
|
|
6
|
-
import org.junit.Before
|
|
7
|
-
import org.junit.Test
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Pure-JUnit unit tests for [MpvBridgeModule]'s companion
|
|
11
|
-
* `onPictureInPictureModeChanged` method that do NOT require the Android
|
|
12
|
-
* runtime (no Robolectric, no Android dependencies).
|
|
13
|
-
*
|
|
14
|
-
* These tests focus on the null-instance cold-start race documented in
|
|
15
|
-
* V12 spec §Phase 33.4 — the contract that the companion must return
|
|
16
|
-
* silently when `instance` hasn't been initialised yet. The branch is
|
|
17
|
-
* entirely pure Kotlin (no Context, no React, no Android APIs), so we
|
|
18
|
-
* can verify it without an Android runtime.
|
|
19
|
-
*
|
|
20
|
-
* The happy-path tests (`withInstance_emitsOnPipModeChanged`) need a
|
|
21
|
-
* mocked ReactApplicationContext + DeviceEventManagerModule — those
|
|
22
|
-
* live in the Robolectric-dependent [MpvBridgeModuleTest] class (which
|
|
23
|
-
* is annotated `@Ignore` in sandboxed environments).
|
|
24
|
-
*
|
|
25
|
-
* Why a separate file: keeps the test suite split into
|
|
26
|
-
* "always-runs" (this file, plain JUnit) and "needs-Robolectric"
|
|
27
|
-
* ([MpvBridgeModuleTest]). CI runners without Android sandbox
|
|
28
|
-
* restrictions can run the full suite; local dev environments can run
|
|
29
|
-
* just this file for the most important spec deliverable.
|
|
30
|
-
*/
|
|
31
|
-
class MpvBridgeModuleNullInstanceTest {
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Reflection handle for the `private var instance` field declared
|
|
35
|
-
* inside [MpvBridgeModule]'s `companion object`. The Kotlin
|
|
36
|
-
* compiler hoists such fields into the **outer** class as
|
|
37
|
-
* `private static volatile` (verified by inspecting the AAR's
|
|
38
|
-
* bytecode: `private static volatile ReactApplicationContext instance`
|
|
39
|
-
* lives on `MpvBridgeModule`, not on its Companion object). We
|
|
40
|
-
* therefore read/write the field on `MpvBridgeModule::class.java`
|
|
41
|
-
* and pass `null` for the instance parameter (it's a static).
|
|
42
|
-
*/
|
|
43
|
-
private val instanceField = run {
|
|
44
|
-
MpvBridgeModule::class.java
|
|
45
|
-
.getDeclaredField("instance")
|
|
46
|
-
.apply { isAccessible = true }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Before
|
|
50
|
-
fun setUp() {
|
|
51
|
-
// Ensure a clean slate. The field is static — pass null as the
|
|
52
|
-
// instance parameter (the standard reflection idiom).
|
|
53
|
-
instanceField.set(null, null)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@After
|
|
57
|
-
fun tearDown() {
|
|
58
|
-
// Be a good citizen — clear so other tests don't see stale state.
|
|
59
|
-
instanceField.set(null, null)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ── Spec §Phase 33.4: null instance is a no-op ───────────────────────
|
|
63
|
-
|
|
64
|
-
@Test
|
|
65
|
-
fun onPictureInPictureModeChanged_nullInstance_returnsWithoutCrash() {
|
|
66
|
-
// Cold-start race: MainActivity.onPictureInPictureModeChanged
|
|
67
|
-
// fires before MpvBridgeModule's `init { instance = ... }` has
|
|
68
|
-
// run. The companion must NOT propagate the resulting null
|
|
69
|
-
// deref to the Activity's override — it must log + return.
|
|
70
|
-
assertNull(
|
|
71
|
-
"instance must start as null in a fresh JVM",
|
|
72
|
-
instanceField.get(null),
|
|
73
|
-
)
|
|
74
|
-
// The call would throw NPE if `instance` was used directly. The
|
|
75
|
-
// contract says it must return cleanly.
|
|
76
|
-
MpvBridgeModule.onPictureInPictureModeChanged(isInPictureInPictureMode = true)
|
|
77
|
-
// Verify instance is still null (the call didn't accidentally
|
|
78
|
-
// mutate it).
|
|
79
|
-
assertNull(
|
|
80
|
-
"instance must remain null after a null-instance call",
|
|
81
|
-
instanceField.get(null),
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@Test
|
|
86
|
-
fun onPictureInPictureModeChanged_nullInstance_withFalseArg_alsoReturns() {
|
|
87
|
-
// Both true and false paths must handle null instance — the
|
|
88
|
-
// method body doesn't branch on the boolean before the null
|
|
89
|
-
// check, so this is a quick smoke test that the same null-
|
|
90
|
-
// guard applies for both cases.
|
|
91
|
-
MpvBridgeModule.onPictureInPictureModeChanged(isInPictureInPictureMode = false)
|
|
92
|
-
assertNull(instanceField.get(null))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@Test
|
|
96
|
-
fun onPictureInPictureModeChanged_multipleNullCalls_areIdempotent() {
|
|
97
|
-
// Repeat-invocation safety: the cold-start race can fire
|
|
98
|
-
// multiple PiP events before the module instance is created.
|
|
99
|
-
// Verify each call is independently a no-op.
|
|
100
|
-
repeat(10) { i ->
|
|
101
|
-
MpvBridgeModule.onPictureInPictureModeChanged(
|
|
102
|
-
isInPictureInPictureMode = i % 2 == 0,
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
assertNull(instanceField.get(null))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ── Constants / sanity ───────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
@Test
|
|
111
|
-
fun name_isStable_acrossReleases() {
|
|
112
|
-
// The module name is part of the JS <-> Native bridge contract.
|
|
113
|
-
// JS calls `NativeModules.MpvPlayerModule`; if the Kotlin name
|
|
114
|
-
// changes, the bridge silently breaks. Lock the value.
|
|
115
|
-
assertEquals("MpvPlayerModule", MpvBridgeModule.NAME)
|
|
116
|
-
}
|
|
117
|
-
}
|