react-native-audio-browser 1.0.0-next.2 → 1.0.0-next.4
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/android/src/cast/java/com/audiobrowser/cast/CastSupport.kt +37 -14
- package/android/src/main/java/com/audiobrowser/AudioBrowser.kt +38 -10
- package/android/src/main/java/com/audiobrowser/Service.kt +6 -41
- package/android/src/main/java/com/audiobrowser/browser/BrowserManager.kt +40 -34
- package/android/src/main/java/com/audiobrowser/browser/BrowserUrlResolution.kt +6 -5
- package/android/src/main/java/com/audiobrowser/browser/JsonModels.kt +12 -7
- package/android/src/main/java/com/audiobrowser/extension/QueueIndex.kt +19 -0
- package/android/src/main/java/com/audiobrowser/http/HttpClient.kt +2 -1
- package/android/src/main/java/com/audiobrowser/http/RequestConfigBuilder.kt +32 -18
- package/android/src/main/java/com/audiobrowser/model/PlayerSetupOptions.kt +2 -2
- package/android/src/main/java/com/audiobrowser/player/AutomaticBufferManager.kt +17 -16
- package/android/src/main/java/com/audiobrowser/player/InterceptingPlayer.kt +11 -0
- package/android/src/main/java/com/audiobrowser/player/MediaFactory.kt +5 -1
- package/android/src/main/java/com/audiobrowser/player/MediaSessionCallback.kt +28 -21
- package/android/src/main/java/com/audiobrowser/player/Player.kt +41 -31
- package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +4 -0
- package/android/src/main/java/com/audiobrowser/player/ResolvingOnReloadSource.kt +38 -0
- package/android/src/main/java/com/audiobrowser/player/TransformingDataSource.kt +34 -19
- package/android/src/main/java/com/audiobrowser/remote/RemotePlayback.kt +10 -1
- package/android/src/main/java/com/audiobrowser/remote/RemoteSwitchingPlayer.kt +48 -4
- package/android/src/main/java/com/audiobrowser/util/BrowserPathHelper.kt +32 -34
- package/android/src/main/java/com/audiobrowser/util/SearchParamsFactory.kt +64 -0
- package/android/src/test/java/com/audiobrowser/ContentRefreshNavigationErrorTest.kt +236 -0
- package/android/src/test/java/com/audiobrowser/NavigateTrackTest.kt +116 -0
- package/android/src/test/java/com/audiobrowser/TestFixtures.kt +41 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerBuildApiRequestTest.kt +21 -4
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerFavoritesTest.kt +49 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerPageShapeTest.kt +93 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerUnparsableResponseTest.kt +82 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserUrlResolutionTest.kt +27 -0
- package/android/src/test/java/com/audiobrowser/browser/JsonArtworkTest.kt +7 -1
- package/android/src/test/java/com/audiobrowser/browser/JsonFavoritedTest.kt +34 -0
- package/android/src/test/java/com/audiobrowser/browser/JsonStyleTest.kt +6 -6
- package/android/src/test/java/com/audiobrowser/extension/QueueIndexTest.kt +44 -0
- package/android/src/test/java/com/audiobrowser/http/HttpClientTest.kt +34 -0
- package/android/src/test/java/com/audiobrowser/http/RequestConfigBuilderTest.kt +90 -7
- package/android/src/test/java/com/audiobrowser/model/PlayerSetupOptionsTest.kt +19 -2
- package/android/src/test/java/com/audiobrowser/player/AutomaticBufferManagerTest.kt +17 -0
- package/android/src/test/java/com/audiobrowser/player/FavoriteCapabilityTest.kt +41 -0
- package/android/src/test/java/com/audiobrowser/player/MediaFactoryTest.kt +39 -0
- package/android/src/test/java/com/audiobrowser/player/MediaUrlReloadTest.kt +212 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerSeekSnapshotTest.kt +45 -0
- package/android/src/test/java/com/audiobrowser/player/SessionQueueShuffleOrderTest.kt +38 -0
- package/android/src/test/java/com/audiobrowser/player/SessionVoiceSearchTest.kt +173 -0
- package/android/src/test/java/com/audiobrowser/player/TransformingDataSourceTest.kt +127 -1
- package/android/src/test/java/com/audiobrowser/remote/FakeRemote.kt +28 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteSwitchingPlayerTest.kt +116 -0
- package/android/src/test/java/com/audiobrowser/util/BrowserPathHelperTest.kt +44 -0
- package/android/src/testCast/java/com/audiobrowser/cast/SdkCastRemoteTest.kt +188 -0
- package/ios/Browser/BrowserError.swift +8 -0
- package/ios/Browser/BrowserManager.swift +29 -28
- package/ios/Browser/BrowserPathHelper.swift +26 -24
- package/ios/Browser/FavoriteSet.swift +16 -8
- package/ios/Browser/Favorites.swift +66 -0
- package/ios/Browser/JsonModels.swift +27 -7
- package/ios/Browser/NavigationErrorState.swift +18 -1
- package/ios/Browser/PageResolver.swift +2 -2
- package/ios/Browser/RequestLayer.swift +11 -4
- package/ios/Browser/RequestPipeline.swift +8 -4
- package/ios/Browser/TabBarEntries.swift +7 -0
- package/ios/CarPlay/CarPlayImageLoader.swift +3 -7
- package/ios/CarPlay/CarPlaySession+Navigator.swift +3 -1
- package/ios/CarPlay/IntentHandlers.swift +1 -7
- package/ios/CarPlay/MediaIntentCriteria.swift +4 -4
- package/ios/Extension/CGSize+AspectFit.swift +11 -0
- package/ios/Extension/Dictionary+Headers.swift +8 -0
- package/ios/Extension/NavigationError+Conversion.swift +4 -3
- package/ios/Extension/ResolvedTrack+Copying.swift +15 -0
- package/ios/Http/HttpClient.swift +37 -11
- package/ios/HybridAudioBrowser+Browser.swift +9 -16
- package/ios/HybridAudioBrowser+Options.swift +1 -0
- package/ios/HybridAudioBrowser+Player.swift +24 -23
- package/ios/HybridAudioBrowser+PlayerCallbacks.swift +1 -2
- package/ios/Model/NitroTypeStubs.swift +39 -0
- package/ios/Model/TrackPlayerError.swift +21 -2
- package/ios/Player/AudioSessionController.swift +2 -2
- package/ios/Player/MediaLoader.swift +1 -1
- package/ios/Player/PlaybackStateMachine.swift +1 -2
- package/ios/Player/Player.swift +59 -20
- package/ios/Player/PlayerEngine.swift +5 -0
- package/ios/Player/QueueManager.swift +21 -4
- package/ios/Tests/BrowserErrorTests.swift +21 -0
- package/ios/Tests/BrowserPathHelperTests.swift +18 -0
- package/ios/Tests/CGSizeAspectFitTests.swift +36 -0
- package/ios/Tests/ClampedVolumeTests.swift +26 -0
- package/ios/Tests/FavoriteSetTests.swift +68 -3
- package/ios/Tests/FavoritesTests.swift +102 -0
- package/ios/Tests/HttpClientUserAgentTests.swift +45 -0
- package/ios/Tests/JsonModelsTests.swift +74 -6
- package/ios/Tests/MediaIntentCriteriaTests.swift +11 -1
- package/ios/Tests/MediaLoaderAssetOptionsTests.swift +7 -0
- package/ios/Tests/NavigationErrorStateTests.swift +73 -0
- package/ios/Tests/PlaybackStateMachineTests.swift +6 -4
- package/ios/Tests/PlayerPolicyTests.swift +38 -0
- package/ios/Tests/PlayerProgressTests.swift +109 -0
- package/ios/Tests/PlayerTests.swift +106 -0
- package/ios/Tests/QueueIndexTests.swift +43 -0
- package/ios/Tests/QueueManagerTests.swift +79 -15
- package/ios/Tests/RequestLayerTests.swift +22 -3
- package/ios/Tests/TabBarEntriesTests.swift +19 -0
- package/ios/Tests/TrackSelectorTests.swift +154 -0
- package/ios/Tests/UnparsableResponseTests.swift +91 -0
- package/ios/TrackSelector.swift +28 -8
- package/ios/Util/ArtworkImageFetcher.swift +9 -8
- package/ios/Util/SVGProcessor.swift +6 -17
- package/lib/commonjs/features/browser-config.js +6 -3
- package/lib/commonjs/features/browser-config.js.map +1 -1
- package/lib/commonjs/features/errors.js +12 -7
- package/lib/commonjs/features/errors.js.map +1 -1
- package/lib/commonjs/features/nowPlaying.js +9 -3
- package/lib/commonjs/features/nowPlaying.js.map +1 -1
- package/lib/commonjs/features/playback/controls.js +1 -2
- package/lib/commonjs/features/playback/controls.js.map +1 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js +2 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/commonjs/features/player/setup.js +2 -2
- package/lib/commonjs/features/queue/activeTrack.js +4 -2
- package/lib/commonjs/features/queue/activeTrack.js.map +1 -1
- package/lib/commonjs/features/sleepTimer.js +6 -5
- package/lib/commonjs/features/sleepTimer.js.map +1 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js +2 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js +2 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/commonjs/utils/callListener.js +23 -0
- package/lib/commonjs/utils/callListener.js.map +1 -0
- package/lib/module/features/browser-config.js +6 -3
- package/lib/module/features/browser-config.js.map +1 -1
- package/lib/module/features/errors.js +12 -7
- package/lib/module/features/errors.js.map +1 -1
- package/lib/module/features/nowPlaying.js +9 -3
- package/lib/module/features/nowPlaying.js.map +1 -1
- package/lib/module/features/playback/controls.js +1 -2
- package/lib/module/features/playback/controls.js.map +1 -1
- package/lib/module/features/playback/trackPlaybackTime.js +2 -1
- package/lib/module/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/module/features/player/setup.js +2 -2
- package/lib/module/features/queue/activeTrack.js +4 -2
- package/lib/module/features/queue/activeTrack.js.map +1 -1
- package/lib/module/features/sleepTimer.js +6 -5
- package/lib/module/features/sleepTimer.js.map +1 -1
- package/lib/module/utils/LazyNativeEmitter.js +2 -1
- package/lib/module/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/module/utils/NativeUpdatedValue.js +2 -1
- package/lib/module/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/module/utils/callListener.js +19 -0
- package/lib/module/utils/callListener.js.map +1 -0
- package/lib/typescript/src/features/browser-config.d.ts.map +1 -1
- package/lib/typescript/src/features/errors.d.ts +8 -6
- package/lib/typescript/src/features/errors.d.ts.map +1 -1
- package/lib/typescript/src/features/nowPlaying.d.ts +2 -1
- package/lib/typescript/src/features/nowPlaying.d.ts.map +1 -1
- package/lib/typescript/src/features/playback/controls.d.ts +1 -2
- package/lib/typescript/src/features/playback/controls.d.ts.map +1 -1
- package/lib/typescript/src/features/playback/trackPlaybackTime.d.ts.map +1 -1
- package/lib/typescript/src/features/player/setup.d.ts +2 -2
- package/lib/typescript/src/features/queue/activeTrack.d.ts +2 -1
- package/lib/typescript/src/features/queue/activeTrack.d.ts.map +1 -1
- package/lib/typescript/src/features/sleepTimer.d.ts +2 -1
- package/lib/typescript/src/features/sleepTimer.d.ts.map +1 -1
- package/lib/typescript/src/types/browser.d.ts +3 -2
- package/lib/typescript/src/types/browser.d.ts.map +1 -1
- package/lib/typescript/src/utils/LazyNativeEmitter.d.ts.map +1 -1
- package/lib/typescript/src/utils/NativeUpdatedValue.d.ts.map +1 -1
- package/lib/typescript/src/utils/callListener.d.ts +7 -0
- package/lib/typescript/src/utils/callListener.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/features/browser-config.test.ts +15 -0
- package/src/features/browser-config.ts +6 -3
- package/src/features/errors.test.ts +83 -0
- package/src/features/errors.ts +12 -7
- package/src/features/hook-wiring.test.ts +11 -10
- package/src/features/nowPlaying.ts +9 -3
- package/src/features/playback/controls.ts +1 -2
- package/src/features/playback/trackPlaybackTime.test.ts +24 -1
- package/src/features/playback/trackPlaybackTime.ts +2 -1
- package/src/features/player/setup.ts +2 -2
- package/src/features/queue/activeTrack.test.ts +32 -0
- package/src/features/queue/activeTrack.ts +8 -2
- package/src/features/sleepTimer.test.ts +24 -0
- package/src/features/sleepTimer.ts +6 -5
- package/src/types/browser.ts +3 -2
- package/src/utils/LazyNativeEmitter.test.ts +32 -0
- package/src/utils/LazyNativeEmitter.ts +3 -1
- package/src/utils/NativeUpdatedValue.test.ts +32 -0
- package/src/utils/NativeUpdatedValue.ts +3 -1
- package/src/utils/callListener.ts +17 -0
- package/website/guide/configuration.md +3 -3
- package/website/guide/errors.md +3 -1
- package/website/guide/live-streams.md +22 -20
|
@@ -3,7 +3,11 @@ package com.audiobrowser.browser
|
|
|
3
3
|
import com.audiobrowser.TestFixtures.resolvedTrack
|
|
4
4
|
import com.audiobrowser.TestFixtures.staticRoute
|
|
5
5
|
import com.audiobrowser.TestFixtures.track
|
|
6
|
+
import com.audiobrowser.TestFixtures.transformableConfig
|
|
7
|
+
import com.margelo.nitro.audiobrowser.NativeRouteEntry
|
|
6
8
|
import kotlinx.coroutines.runBlocking
|
|
9
|
+
import okhttp3.mockwebserver.MockResponse
|
|
10
|
+
import okhttp3.mockwebserver.MockWebServer
|
|
7
11
|
import org.junit.Assert.assertEquals
|
|
8
12
|
import org.junit.Before
|
|
9
13
|
import org.junit.Test
|
|
@@ -93,6 +97,51 @@ class BrowserManagerFavoritesTest {
|
|
|
93
97
|
assertEquals(mapOf("A" to false), favoritedByTitle(resolved.flattenedChildren?.toTypedArray()))
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
@Test
|
|
101
|
+
fun `favorited in an HTTP route's response wins over hydration`() = runBlocking {
|
|
102
|
+
val server = MockWebServer()
|
|
103
|
+
server.enqueue(
|
|
104
|
+
MockResponse()
|
|
105
|
+
.setBody(
|
|
106
|
+
"""{"path":"/home","title":"Home","children":[
|
|
107
|
+
{"title":"A","src":"https://s/a.mp3","favorited":true},
|
|
108
|
+
{"title":"B","src":"https://s/b.mp3","favorited":false}
|
|
109
|
+
]}"""
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
server.start()
|
|
113
|
+
try {
|
|
114
|
+
browserManager.config =
|
|
115
|
+
BrowserConfig(
|
|
116
|
+
request = transformableConfig(baseUrl = server.url("/").toString().trimEnd('/')),
|
|
117
|
+
routes =
|
|
118
|
+
arrayOf(
|
|
119
|
+
NativeRouteEntry(
|
|
120
|
+
path = "/home",
|
|
121
|
+
browseCallback = null,
|
|
122
|
+
browseConfig = transformableConfig(),
|
|
123
|
+
browseStatic = null,
|
|
124
|
+
searchCallback = null,
|
|
125
|
+
searchConfig = null,
|
|
126
|
+
media = null,
|
|
127
|
+
artwork = null,
|
|
128
|
+
)
|
|
129
|
+
),
|
|
130
|
+
)
|
|
131
|
+
browserManager.setFavoriteEnabled(true)
|
|
132
|
+
browserManager.setFavorites(listOf("https://s/b.mp3"))
|
|
133
|
+
|
|
134
|
+
val resolved = browserManager.resolve("/home")
|
|
135
|
+
|
|
136
|
+
assertEquals(
|
|
137
|
+
mapOf("A" to true, "B" to false),
|
|
138
|
+
favoritedByTitle(resolved.flattenedChildren?.toTypedArray()),
|
|
139
|
+
)
|
|
140
|
+
} finally {
|
|
141
|
+
server.shutdown()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
96
145
|
@Test
|
|
97
146
|
fun `disabled favoriting leaves tracks untouched`() = runBlocking {
|
|
98
147
|
servePage("/home", track(title = "A", id = "stable-a", src = "https://s/a.mp3"))
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
package com.audiobrowser.browser
|
|
2
|
+
|
|
3
|
+
import com.audiobrowser.TestFixtures.transformableConfig
|
|
4
|
+
import com.margelo.nitro.audiobrowser.NativeRouteEntry
|
|
5
|
+
import kotlinx.coroutines.runBlocking
|
|
6
|
+
import okhttp3.mockwebserver.MockResponse
|
|
7
|
+
import okhttp3.mockwebserver.MockWebServer
|
|
8
|
+
import org.junit.After
|
|
9
|
+
import org.junit.Assert.assertEquals
|
|
10
|
+
import org.junit.Assert.assertThrows
|
|
11
|
+
import org.junit.Before
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.RobolectricTestRunner
|
|
15
|
+
|
|
16
|
+
/** The page an endpoint answers: `BrowserSource` and `TabsSource` in `src/types/browser.ts`. */
|
|
17
|
+
@RunWith(RobolectricTestRunner::class)
|
|
18
|
+
class BrowserManagerPageShapeTest {
|
|
19
|
+
|
|
20
|
+
private lateinit var server: MockWebServer
|
|
21
|
+
private lateinit var browserManager: BrowserManager
|
|
22
|
+
|
|
23
|
+
@Before
|
|
24
|
+
fun setup() {
|
|
25
|
+
server = MockWebServer()
|
|
26
|
+
server.start()
|
|
27
|
+
browserManager = BrowserManager()
|
|
28
|
+
browserManager.config =
|
|
29
|
+
BrowserConfig(
|
|
30
|
+
request = transformableConfig(baseUrl = server.url("/").toString().trimEnd('/')),
|
|
31
|
+
routes =
|
|
32
|
+
arrayOf(
|
|
33
|
+
NativeRouteEntry(
|
|
34
|
+
path = BrowserManager.TABS_ROUTE_PATH,
|
|
35
|
+
browseCallback = null,
|
|
36
|
+
browseConfig = transformableConfig(),
|
|
37
|
+
browseStatic = null,
|
|
38
|
+
searchCallback = null,
|
|
39
|
+
searchConfig = null,
|
|
40
|
+
media = null,
|
|
41
|
+
artwork = null,
|
|
42
|
+
)
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@After
|
|
48
|
+
fun tearDown() {
|
|
49
|
+
server.shutdown()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun answer(body: String) {
|
|
53
|
+
server.enqueue(MockResponse().setBody(body))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Test
|
|
57
|
+
fun `a browse page without a path takes the requested path`() {
|
|
58
|
+
answer("""{"title":"Jazz","children":[{"title":"C","src":"https://s/c.mp3"}]}""")
|
|
59
|
+
|
|
60
|
+
val page = runBlocking { browserManager.resolve("/genres/jazz") }
|
|
61
|
+
|
|
62
|
+
assertEquals("/genres/jazz", page.path)
|
|
63
|
+
assertEquals("Jazz", page.title)
|
|
64
|
+
assertEquals(listOf("C"), page.flattenedChildren?.map { it.title })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun `a page's own path wins`() {
|
|
69
|
+
answer("""{"path":"/jazz","title":"Jazz"}""")
|
|
70
|
+
|
|
71
|
+
val page = runBlocking { browserManager.resolve("/genres/jazz") }
|
|
72
|
+
|
|
73
|
+
assertEquals("/jazz", page.path)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Test
|
|
77
|
+
fun `a tabs page needs neither title nor path`() {
|
|
78
|
+
answer("""{"children":[{"title":"Home","path":"/home"}]}""")
|
|
79
|
+
|
|
80
|
+
val tabs = runBlocking { browserManager.queryTabs() }
|
|
81
|
+
|
|
82
|
+
assertEquals(listOf("/home"), tabs.map { it.path })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Test
|
|
86
|
+
fun `a browse page without a title does not resolve`() {
|
|
87
|
+
answer("""{"path":"/genres/jazz","children":[]}""")
|
|
88
|
+
|
|
89
|
+
assertThrows(HttpStatusException::class.java) {
|
|
90
|
+
runBlocking { browserManager.resolve("/genres/jazz") }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
package/android/src/test/java/com/audiobrowser/browser/BrowserManagerUnparsableResponseTest.kt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package com.audiobrowser.browser
|
|
2
|
+
|
|
3
|
+
import com.audiobrowser.TestFixtures.transformableConfig
|
|
4
|
+
import com.audiobrowser.navigationErrorFor
|
|
5
|
+
import com.margelo.nitro.audiobrowser.NavigationError
|
|
6
|
+
import com.margelo.nitro.audiobrowser.NavigationErrorType
|
|
7
|
+
import kotlinx.coroutines.runBlocking
|
|
8
|
+
import okhttp3.mockwebserver.MockResponse
|
|
9
|
+
import okhttp3.mockwebserver.MockWebServer
|
|
10
|
+
import org.junit.After
|
|
11
|
+
import org.junit.Assert.assertEquals
|
|
12
|
+
import org.junit.Assert.fail
|
|
13
|
+
import org.junit.Before
|
|
14
|
+
import org.junit.Test
|
|
15
|
+
import org.junit.runner.RunWith
|
|
16
|
+
import org.robolectric.RobolectricTestRunner
|
|
17
|
+
|
|
18
|
+
/** A page fetch answered 2xx with a body that is not a page. */
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
class BrowserManagerUnparsableResponseTest {
|
|
21
|
+
|
|
22
|
+
private lateinit var server: MockWebServer
|
|
23
|
+
private lateinit var browserManager: BrowserManager
|
|
24
|
+
|
|
25
|
+
@Before
|
|
26
|
+
fun setup() {
|
|
27
|
+
server = MockWebServer()
|
|
28
|
+
server.start()
|
|
29
|
+
browserManager = BrowserManager()
|
|
30
|
+
browserManager.config =
|
|
31
|
+
BrowserConfig(
|
|
32
|
+
request = transformableConfig(baseUrl = server.url("/").toString().trimEnd('/'))
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@After
|
|
37
|
+
fun tearDown() {
|
|
38
|
+
server.shutdown()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private fun navigationErrorOfPage(response: MockResponse): NavigationError {
|
|
42
|
+
server.enqueue(response)
|
|
43
|
+
try {
|
|
44
|
+
runBlocking { browserManager.resolve("/page") }
|
|
45
|
+
} catch (e: Exception) {
|
|
46
|
+
return navigationErrorFor(e)
|
|
47
|
+
}
|
|
48
|
+
fail("resolve returned a page")
|
|
49
|
+
throw AssertionError()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun assertSuccessfulHttpError(statusCode: Int, error: NavigationError) {
|
|
53
|
+
assertEquals(NavigationErrorType.HTTP_ERROR, error.code)
|
|
54
|
+
assertEquals(statusCode.toDouble(), error.statusCode!!, 0.0)
|
|
55
|
+
assertEquals(true, error.statusCodeSuccess)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test
|
|
59
|
+
fun `a 2xx body that is not JSON is an http-error with a successful status`() {
|
|
60
|
+
val error = navigationErrorOfPage(MockResponse().setBody("<html>Sign in</html>"))
|
|
61
|
+
|
|
62
|
+
assertSuccessfulHttpError(200, error)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test
|
|
66
|
+
fun `a 2xx JSON body that is not a page is an http-error with a successful status`() {
|
|
67
|
+
val error =
|
|
68
|
+
navigationErrorOfPage(MockResponse().setResponseCode(203).setBody("""{"path":"/page"}"""))
|
|
69
|
+
|
|
70
|
+
assertSuccessfulHttpError(203, error)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
fun `a 2xx page with artwork of the wrong shape is an http-error with a successful status`() {
|
|
75
|
+
val error =
|
|
76
|
+
navigationErrorOfPage(
|
|
77
|
+
MockResponse().setBody("""{"path":"/page","title":"Page","artwork":{"light":"l.png"}}""")
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
assertSuccessfulHttpError(200, error)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -167,6 +167,21 @@ class BrowserUrlResolutionTest {
|
|
|
167
167
|
assertTrue(source.uri.contains("h=256"))
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
@Test
|
|
171
|
+
fun `resolveArtworkUrl adds image query params to an artwork url that has a query`() = runTest {
|
|
172
|
+
bm.config =
|
|
173
|
+
BrowserConfig(
|
|
174
|
+
artwork = artworkConfig(imageQueryParams = ImageQueryParams(width = "w", height = "h"))
|
|
175
|
+
)
|
|
176
|
+
val source =
|
|
177
|
+
bm.resolveArtworkUrl(
|
|
178
|
+
track(artwork = "https://img.example.com/a.jpg?v=2"),
|
|
179
|
+
perRouteConfig = null,
|
|
180
|
+
imageContext = ImageContext(256.0, 256.0),
|
|
181
|
+
)
|
|
182
|
+
assertEquals("https://img.example.com/a.jpg?v=2&w=256&h=256", source?.uri)
|
|
183
|
+
}
|
|
184
|
+
|
|
170
185
|
@Test
|
|
171
186
|
fun `displayArtworkSource re-resolves a registered uri with the display size`() = runTest {
|
|
172
187
|
bm.config =
|
|
@@ -225,6 +240,18 @@ class BrowserUrlResolutionTest {
|
|
|
225
240
|
assertEquals("1", source?.headers?.get("x-art"))
|
|
226
241
|
}
|
|
227
242
|
|
|
243
|
+
@Test
|
|
244
|
+
fun `a user-agent or content-type header in any case wins over the field`() = runTest {
|
|
245
|
+
bm.config =
|
|
246
|
+
BrowserConfig(
|
|
247
|
+
request =
|
|
248
|
+
transformableConfig(headers = mapOf("user-agent" to "mine", "CONTENT-TYPE" to "mine"))
|
|
249
|
+
.copy(userAgent = "UA", contentType = "image/png")
|
|
250
|
+
)
|
|
251
|
+
val source = bm.unattributedArtworkSource("https://img.example.com/a.png")
|
|
252
|
+
assertEquals(mapOf("user-agent" to "mine", "CONTENT-TYPE" to "mine"), source?.headers)
|
|
253
|
+
}
|
|
254
|
+
|
|
228
255
|
@Test
|
|
229
256
|
fun `unattributedArtworkSource returns null when there are no static headers`() = runTest {
|
|
230
257
|
bm.config = BrowserConfig()
|
|
@@ -39,7 +39,13 @@ class JsonArtworkTest {
|
|
|
39
39
|
)
|
|
40
40
|
assertEquals(
|
|
41
41
|
"https://e.example/d.png",
|
|
42
|
-
resolved
|
|
42
|
+
resolved
|
|
43
|
+
.toNitro(requestedPath = "/requested")
|
|
44
|
+
.children
|
|
45
|
+
?.first()
|
|
46
|
+
?.artwork
|
|
47
|
+
?.asSecondOrNull()
|
|
48
|
+
?.dark,
|
|
43
49
|
)
|
|
44
50
|
}
|
|
45
51
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.audiobrowser.browser
|
|
2
|
+
|
|
3
|
+
import kotlinx.serialization.json.Json
|
|
4
|
+
import org.junit.Assert.assertEquals
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
/** A `favorited` that a route's response carries on a track or a page. */
|
|
9
|
+
class JsonFavoritedTest {
|
|
10
|
+
private val json = Json { ignoreUnknownKeys = true }
|
|
11
|
+
|
|
12
|
+
private fun track(body: String) = json.decodeFromString<JsonTrack>(body).toNitro()
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `decodes the value the response carries`() {
|
|
16
|
+
assertEquals(true, track("""{"title":"X","src":"a","favorited":true}""").favorited)
|
|
17
|
+
assertEquals(false, track("""{"title":"X","src":"a","favorited":false}""").favorited)
|
|
18
|
+
assertNull(track("""{"title":"X","src":"a"}""").favorited)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun `decodes on a page and on its tracks`() {
|
|
23
|
+
val page =
|
|
24
|
+
json
|
|
25
|
+
.decodeFromString<JsonResolvedTrack>(
|
|
26
|
+
"""{"path":"/track/1","title":"Page","src":"p","favorited":true,"sections":[
|
|
27
|
+
{"children":[{"title":"A","src":"a","favorited":true},{"title":"B","src":"b"}]}
|
|
28
|
+
]}"""
|
|
29
|
+
)
|
|
30
|
+
.toNitro(requestedPath = "/requested")
|
|
31
|
+
assertEquals(true, page.favorited)
|
|
32
|
+
assertEquals(listOf(true, null), page.sections?.first()?.children?.map { it.favorited })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -35,7 +35,7 @@ class JsonStyleTest {
|
|
|
35
35
|
{"style":{"display":"grid","gridWrap":false},"children":[{"title":"C","src":"s"}]}
|
|
36
36
|
]}"""
|
|
37
37
|
)
|
|
38
|
-
val style = resolved.toNitro().sections?.first()?.style
|
|
38
|
+
val style = resolved.toNitro(requestedPath = "/requested").sections?.first()?.style
|
|
39
39
|
assertEquals(StyleDisplay.GRID, style?.display)
|
|
40
40
|
assertEquals(false, style?.gridWrap)
|
|
41
41
|
}
|
|
@@ -48,7 +48,7 @@ class JsonStyleTest {
|
|
|
48
48
|
{"title":"C","src":"s","style":"grid"}
|
|
49
49
|
]}"""
|
|
50
50
|
)
|
|
51
|
-
val nitro = resolved.toNitro()
|
|
51
|
+
val nitro = resolved.toNitro(requestedPath = "/requested")
|
|
52
52
|
assertNull(nitro.style)
|
|
53
53
|
assertNull(nitro.children?.first()?.style)
|
|
54
54
|
}
|
|
@@ -79,7 +79,7 @@ class JsonStyleTest {
|
|
|
79
79
|
{"style":{"display":"grid","gridWrap":"false"},"children":[{"title":"C","src":"s"}]}
|
|
80
80
|
]}"""
|
|
81
81
|
)
|
|
82
|
-
val style = resolved.toNitro().sections?.first()?.style
|
|
82
|
+
val style = resolved.toNitro(requestedPath = "/requested").sections?.first()?.style
|
|
83
83
|
assertEquals(StyleDisplay.GRID, style?.display)
|
|
84
84
|
assertNull(style?.gridWrap)
|
|
85
85
|
}
|
|
@@ -125,7 +125,7 @@ class JsonStyleTest {
|
|
|
125
125
|
"children":[{"title":"C","src":"s"}]}
|
|
126
126
|
]}"""
|
|
127
127
|
)
|
|
128
|
-
val style = resolved.toNitro().sections?.first()?.style
|
|
128
|
+
val style = resolved.toNitro(requestedPath = "/requested").sections?.first()?.style
|
|
129
129
|
assertEquals(GridTile.CARD, style?.gridTile)
|
|
130
130
|
assertEquals("#1e3a8a", style?.cardTint)
|
|
131
131
|
assertEquals(CardImage.BACKGROUND, style?.cardImage)
|
|
@@ -140,7 +140,7 @@ class JsonStyleTest {
|
|
|
140
140
|
"children":[{"title":"C","src":"s"}]}
|
|
141
141
|
]}"""
|
|
142
142
|
)
|
|
143
|
-
val style = resolved.toNitro().sections?.first()?.style
|
|
143
|
+
val style = resolved.toNitro(requestedPath = "/requested").sections?.first()?.style
|
|
144
144
|
assertEquals(GridTile.IMAGE, style?.gridTile)
|
|
145
145
|
assertEquals(ImageShape.CIRCULAR, style?.imageShape)
|
|
146
146
|
}
|
|
@@ -158,6 +158,6 @@ class JsonStyleTest {
|
|
|
158
158
|
{"style":{"gridTile":"hexagon"},"children":[{"title":"C","src":"s"}]}
|
|
159
159
|
]}"""
|
|
160
160
|
)
|
|
161
|
-
assertNull(resolved.toNitro().sections?.first()?.style)
|
|
161
|
+
assertNull(resolved.toNitro(requestedPath = "/requested").sections?.first()?.style)
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.audiobrowser.extension
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertThrows
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class QueueIndexTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun `a number no Int holds throws`() {
|
|
11
|
+
listOf(
|
|
12
|
+
Double.NaN,
|
|
13
|
+
Double.POSITIVE_INFINITY,
|
|
14
|
+
Double.NEGATIVE_INFINITY,
|
|
15
|
+
1e19,
|
|
16
|
+
-1e19,
|
|
17
|
+
Int.MAX_VALUE + 1.0,
|
|
18
|
+
Int.MIN_VALUE - 1.0,
|
|
19
|
+
)
|
|
20
|
+
.forEach { number ->
|
|
21
|
+
assertThrows("$number", IllegalArgumentException::class.java) { number.toQueueIndex() }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Test
|
|
26
|
+
fun `a number an Int holds drops its fraction`() {
|
|
27
|
+
assertEquals(0, 0.0.toQueueIndex())
|
|
28
|
+
assertEquals(2, 2.0.toQueueIndex())
|
|
29
|
+
assertEquals(1, 1.7.toQueueIndex())
|
|
30
|
+
assertEquals(0, (-0.5).toQueueIndex())
|
|
31
|
+
assertEquals(-1, (-1.0).toQueueIndex())
|
|
32
|
+
assertEquals(Int.MAX_VALUE, (Int.MAX_VALUE + 0.5).toQueueIndex())
|
|
33
|
+
assertEquals(Int.MIN_VALUE, (Int.MIN_VALUE - 0.5).toQueueIndex())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test
|
|
37
|
+
fun `the message names the number`() {
|
|
38
|
+
val error = assertThrows(IllegalArgumentException::class.java) { Double.NaN.toQueueIndex() }
|
|
39
|
+
assertEquals(
|
|
40
|
+
"Invalid track index: index must be a finite number within the range of Int, got NaN",
|
|
41
|
+
error.message,
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.audiobrowser.http
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.test.runTest
|
|
4
|
+
import okhttp3.mockwebserver.MockResponse
|
|
5
|
+
import okhttp3.mockwebserver.MockWebServer
|
|
6
|
+
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
|
|
9
|
+
class HttpClientTest {
|
|
10
|
+
|
|
11
|
+
/** Every User-Agent line a GET with [headers] and the default `userAgent` carries. */
|
|
12
|
+
private fun sentUserAgents(headers: Map<String, String>): List<String> =
|
|
13
|
+
MockWebServer().use { server ->
|
|
14
|
+
server.enqueue(MockResponse().setBody("{}"))
|
|
15
|
+
runTest {
|
|
16
|
+
HttpClient()
|
|
17
|
+
.request(HttpClient.HttpRequest(url = server.url("/").toString(), headers = headers))
|
|
18
|
+
.getOrThrow()
|
|
19
|
+
}
|
|
20
|
+
server.takeRequest().headers.values("User-Agent")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun `a user-agent header in any case is sent alone, in place of the default`() {
|
|
25
|
+
for (name in listOf("User-Agent", "user-agent", "USER-AGENT")) {
|
|
26
|
+
assertEquals(name, listOf("MyApp/1.0"), sentUserAgents(mapOf(name to "MyApp/1.0")))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Test
|
|
31
|
+
fun `without a user-agent header the default is sent`() {
|
|
32
|
+
assertEquals(listOf(HttpClient.DEFAULT_USER_AGENT), sentUserAgents(emptyMap()))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -2,7 +2,10 @@ package com.audiobrowser.http
|
|
|
2
2
|
|
|
3
3
|
import com.audiobrowser.TestFixtures
|
|
4
4
|
import com.audiobrowser.TestFixtures.mediaConfig
|
|
5
|
+
import com.audiobrowser.TestFixtures.throwingTransform
|
|
6
|
+
import com.audiobrowser.TestFixtures.throwingTransformSync
|
|
5
7
|
import com.audiobrowser.TestFixtures.transformableConfig
|
|
8
|
+
import com.audiobrowser.browser.CallbackException
|
|
6
9
|
import com.audiobrowser.util.JsPromise
|
|
7
10
|
import com.margelo.nitro.audiobrowser.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_RequestConfig_____RequestConfig_std__optional_std__unordered_map_std__string__std__string__
|
|
8
11
|
import com.margelo.nitro.audiobrowser.HttpMethod
|
|
@@ -245,6 +248,32 @@ class RequestConfigBuilderTest {
|
|
|
245
248
|
assertEquals("https://api.example.com/albums", result.url)
|
|
246
249
|
}
|
|
247
250
|
|
|
251
|
+
@Test
|
|
252
|
+
fun `buildUrl joins the query with an ampersand when the path already has one`() = runTest {
|
|
253
|
+
val relative =
|
|
254
|
+
RequestConfig(
|
|
255
|
+
method = null,
|
|
256
|
+
path = "/stations?genre=rock",
|
|
257
|
+
baseUrl = "https://api.example.com",
|
|
258
|
+
headers = null,
|
|
259
|
+
query = mapOf("locale" to "en"),
|
|
260
|
+
body = null,
|
|
261
|
+
contentType = null,
|
|
262
|
+
userAgent = null,
|
|
263
|
+
)
|
|
264
|
+
val absolute =
|
|
265
|
+
relative.copy(path = "https://img.example.com/a.jpg?v=2", query = mapOf("w" to "512"))
|
|
266
|
+
|
|
267
|
+
assertEquals(
|
|
268
|
+
"https://api.example.com/stations?genre=rock&locale=en",
|
|
269
|
+
RequestConfigBuilder.buildHttpRequest(relative).url,
|
|
270
|
+
)
|
|
271
|
+
assertEquals(
|
|
272
|
+
"https://img.example.com/a.jpg?v=2&w=512",
|
|
273
|
+
RequestConfigBuilder.buildHttpRequest(absolute).url,
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
248
277
|
@Test
|
|
249
278
|
fun `composeResolved merges async then sync with sync winning`() {
|
|
250
279
|
val async =
|
|
@@ -267,7 +296,7 @@ class RequestConfigBuilderTest {
|
|
|
267
296
|
}
|
|
268
297
|
|
|
269
298
|
@Test
|
|
270
|
-
fun `
|
|
299
|
+
fun `mergeConfigOrBase MediaRequestConfig static fields merge over base and preserve callbacks`() =
|
|
271
300
|
runTest {
|
|
272
301
|
val base =
|
|
273
302
|
RequestConfig(
|
|
@@ -281,7 +310,7 @@ class RequestConfigBuilderTest {
|
|
|
281
310
|
userAgent = "base-ua",
|
|
282
311
|
)
|
|
283
312
|
val override = mediaConfig(headers = mapOf("x-media" to "2"), query = mapOf("token" to "abc"))
|
|
284
|
-
val merged = RequestConfigBuilder.
|
|
313
|
+
val merged = RequestConfigBuilder.mergeConfigOrBase(base, override)
|
|
285
314
|
assertEquals("/stream.mp3", merged.path)
|
|
286
315
|
assertEquals("https://media.example.com", merged.baseUrl)
|
|
287
316
|
assertEquals("1", merged.headers?.get("x-base"))
|
|
@@ -301,12 +330,66 @@ class RequestConfigBuilderTest {
|
|
|
301
330
|
}
|
|
302
331
|
|
|
303
332
|
@Test
|
|
304
|
-
fun `
|
|
333
|
+
fun `mergeConfigOrBase MediaRequestConfig carries the base path over a static media path`() =
|
|
334
|
+
runTest {
|
|
335
|
+
val base =
|
|
336
|
+
RequestConfig(null, "/stream/123", "https://api.example.com", null, null, null, null, null)
|
|
337
|
+
val media = mediaConfig(path = "/static-media-path")
|
|
338
|
+
val merged = RequestConfigBuilder.mergeConfigOrBase(base, media)
|
|
339
|
+
assertEquals("/stream/123", merged.path)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@Test
|
|
343
|
+
fun `mergeConfig TransformableRequestConfig throws a CallbackException when a transform throws`() =
|
|
344
|
+
runTest {
|
|
345
|
+
val base =
|
|
346
|
+
RequestConfig(null, "/library", "https://api.example.com", null, null, null, null, null)
|
|
347
|
+
val layer = transformableConfig().copy(transform = throwingTransform("token expired"))
|
|
348
|
+
try {
|
|
349
|
+
RequestConfigBuilder.mergeConfig(base, layer, emptyMap())
|
|
350
|
+
fail("expected CallbackException")
|
|
351
|
+
} catch (e: CallbackException) {
|
|
352
|
+
assertEquals("token expired", e.message)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@Test
|
|
357
|
+
fun `a throwing transformSync's CallbackException carries its message without the JS stack`() =
|
|
358
|
+
runTest {
|
|
359
|
+
val base =
|
|
360
|
+
RequestConfig(null, "/library", "https://api.example.com", null, null, null, null, null)
|
|
361
|
+
val layer =
|
|
362
|
+
transformableConfig()
|
|
363
|
+
.copy(
|
|
364
|
+
transformSync =
|
|
365
|
+
throwingTransformSync(
|
|
366
|
+
"token expired\n\nError: token expired\n at transformSync (:11:92)"
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
try {
|
|
370
|
+
RequestConfigBuilder.mergeConfig(base, layer, emptyMap())
|
|
371
|
+
fail("expected CallbackException")
|
|
372
|
+
} catch (e: CallbackException) {
|
|
373
|
+
assertEquals("token expired", e.message)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@Test
|
|
378
|
+
fun `mergeConfigOrBase skips a layer whose transform throws`() = runTest {
|
|
379
|
+
val base =
|
|
380
|
+
RequestConfig(null, "/stream.mp3", "https://media.example.com", null, null, null, null, null)
|
|
381
|
+
val layer = transformableConfig().copy(transform = throwingTransform("token expired"))
|
|
382
|
+
assertEquals(base, RequestConfigBuilder.mergeConfigOrBase(base, layer))
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
@Test
|
|
386
|
+
fun `mergeConfigOrBase MediaRequestConfig skips a layer whose transform throws`() = runTest {
|
|
305
387
|
val base =
|
|
306
|
-
RequestConfig(null, "/stream
|
|
307
|
-
val media = mediaConfig(
|
|
308
|
-
val merged = RequestConfigBuilder.
|
|
309
|
-
assertEquals("
|
|
388
|
+
RequestConfig(null, "/stream.mp3", "https://media.example.com", null, null, null, null, null)
|
|
389
|
+
val media = mediaConfig().copy(transform = throwingTransform("token expired"))
|
|
390
|
+
val merged = RequestConfigBuilder.mergeConfigOrBase(base, media)
|
|
391
|
+
assertEquals("https://media.example.com", merged.baseUrl)
|
|
392
|
+
assertEquals("/stream.mp3", merged.path)
|
|
310
393
|
}
|
|
311
394
|
|
|
312
395
|
@Test
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
package com.audiobrowser.model
|
|
2
2
|
|
|
3
|
+
import com.margelo.nitro.audiobrowser.Func_std__shared_ptr_Promise_std__optional_NowPlayingUpdate____FormatNowPlayingParams as NowPlayingFormatter
|
|
3
4
|
import com.margelo.nitro.audiobrowser.NativeSetupPlayerOptions
|
|
4
5
|
import com.margelo.nitro.audiobrowser.RemoteOutputsOptions
|
|
5
6
|
import org.junit.Assert.assertEquals
|
|
6
7
|
import org.junit.Assert.assertNull
|
|
8
|
+
import org.junit.Assert.assertSame
|
|
7
9
|
import org.junit.Test
|
|
8
10
|
|
|
9
11
|
class PlayerSetupOptionsTest {
|
|
10
|
-
private fun setup(
|
|
12
|
+
private fun setup(
|
|
13
|
+
remoteOutputs: RemoteOutputsOptions? = null,
|
|
14
|
+
nowPlayingMetadataFormatter: NowPlayingFormatter? = null,
|
|
15
|
+
) =
|
|
11
16
|
NativeSetupPlayerOptions(
|
|
12
17
|
android = null,
|
|
13
18
|
ios = null,
|
|
14
19
|
options = null,
|
|
15
20
|
autoUpdateNowPlayingMetadata = null,
|
|
16
|
-
nowPlayingMetadataFormatter =
|
|
21
|
+
nowPlayingMetadataFormatter = nowPlayingMetadataFormatter,
|
|
17
22
|
playWhenReady = null,
|
|
18
23
|
repeatMode = null,
|
|
19
24
|
retry = null,
|
|
@@ -32,4 +37,16 @@ class PlayerSetupOptionsTest {
|
|
|
32
37
|
options.update(setup(null))
|
|
33
38
|
assertNull(options.remoteOutputs)
|
|
34
39
|
}
|
|
40
|
+
|
|
41
|
+
@Test
|
|
42
|
+
fun `a setup without a formatter removes the earlier one`() {
|
|
43
|
+
val options = PlayerSetupOptions()
|
|
44
|
+
val formatter = NowPlayingFormatter { error("not called") }
|
|
45
|
+
|
|
46
|
+
options.update(setup(nowPlayingMetadataFormatter = formatter))
|
|
47
|
+
assertSame(formatter, options.nowPlayingMetadataFormatter)
|
|
48
|
+
|
|
49
|
+
options.update(setup())
|
|
50
|
+
assertNull(options.nowPlayingMetadataFormatter)
|
|
51
|
+
}
|
|
35
52
|
}
|
|
@@ -74,6 +74,23 @@ class AutomaticBufferManagerTest {
|
|
|
74
74
|
assertEquals(6_000, threshold)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
@Test
|
|
78
|
+
fun `an underrun keeps a threshold set above the automatic maximum`() {
|
|
79
|
+
val slowStart =
|
|
80
|
+
BufferConfig(bufferForPlaybackMs = 10_000, bufferForPlaybackAfterRebufferMs = 10_000)
|
|
81
|
+
val loadControl = DynamicLoadControl(slowStart)
|
|
82
|
+
val manager =
|
|
83
|
+
AutomaticBufferManager(loadControl, slowStart, clock = { nowMs }).also { it.attach(engine) }
|
|
84
|
+
|
|
85
|
+
manager.onPlaybackStateChanged(MediaPlayer.STATE_BUFFERING)
|
|
86
|
+
`when`(engine.totalBufferedDuration).thenReturn(10_000)
|
|
87
|
+
manager.onPlaybackStateChanged(MediaPlayer.STATE_READY)
|
|
88
|
+
nowMs += 20_000
|
|
89
|
+
manager.onPlaybackStateChanged(MediaPlayer.STATE_BUFFERING)
|
|
90
|
+
|
|
91
|
+
assertEquals(10_000, loadControl.getBufferConfig().bufferForPlaybackAfterRebufferMs)
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
@Test
|
|
78
95
|
fun `a reconnect's first buffering is not a rebuffer`() {
|
|
79
96
|
play()
|