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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.audiobrowser.util
|
|
2
2
|
|
|
3
3
|
import android.net.Uri
|
|
4
|
-
import androidx.core.net.toUri
|
|
5
4
|
import com.margelo.nitro.audiobrowser.NavigationErrorKind
|
|
6
5
|
import java.net.URLEncoder
|
|
7
6
|
|
|
@@ -11,6 +10,8 @@ import java.net.URLEncoder
|
|
|
11
10
|
* playable-only track while keeping its parent for queue restoration (docs/adr/0009).
|
|
12
11
|
*/
|
|
13
12
|
object BrowserPathHelper {
|
|
13
|
+
private val ABSOLUTE_URL = Regex("^([a-z][a-z0-9+.-]*:|//)", RegexOption.IGNORE_CASE)
|
|
14
|
+
|
|
14
15
|
const val ROOT_PATH = "/__root"
|
|
15
16
|
|
|
16
17
|
/** Full search paths are `/__search?q=<query>`; see [createSearchPath]. */
|
|
@@ -60,28 +61,19 @@ object BrowserPathHelper {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
|
-
* The parent path: [url] without `__trackId` and `__index`,
|
|
64
|
-
* Returns a non-contextual [url] unchanged.
|
|
64
|
+
* The parent path: [url] without `__trackId` and `__index`, every other character as written, so
|
|
65
|
+
* it equals the parent [build] was given. Returns a non-contextual [url] unchanged.
|
|
65
66
|
*/
|
|
66
67
|
fun stripTrackId(url: String): String {
|
|
67
68
|
if (!isContextual(url)) {
|
|
68
69
|
return url
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
val
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
builder.clearQuery()
|
|
75
|
-
|
|
76
|
-
uri.queryParameterNames.forEach { paramName ->
|
|
77
|
-
if (paramName != CONTEXTUAL_TRACK_PARAM && paramName != CONTEXTUAL_INDEX_PARAM) {
|
|
78
|
-
uri.getQueryParameters(paramName).forEach { value ->
|
|
79
|
-
builder.appendQueryParameter(paramName, value)
|
|
80
|
-
}
|
|
71
|
+
val (head, pairs) = splitQuery(url) ?: return url
|
|
72
|
+
val kept =
|
|
73
|
+
pairs.filterNot {
|
|
74
|
+
it.startsWith("$CONTEXTUAL_TRACK_PARAM=") || it.startsWith("$CONTEXTUAL_INDEX_PARAM=")
|
|
81
75
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return builder.build().toString()
|
|
76
|
+
return if (kept.isEmpty()) head else "$head?${kept.joinToString("&")}"
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
/**
|
|
@@ -97,35 +89,39 @@ object BrowserPathHelper {
|
|
|
97
89
|
}
|
|
98
90
|
|
|
99
91
|
/** The decoded `__trackId`, or null when [path] is not contextual. */
|
|
100
|
-
fun extractTrackId(path: String): String?
|
|
101
|
-
|
|
92
|
+
fun extractTrackId(path: String): String? = contextualValue(CONTEXTUAL_TRACK_PARAM, path)
|
|
93
|
+
|
|
94
|
+
/** The `__index`, or null when [path] is not contextual or its index is missing or negative. */
|
|
95
|
+
fun extractIndex(path: String): Int? =
|
|
96
|
+
contextualValue(CONTEXTUAL_INDEX_PARAM, path)?.toIntOrNull()?.takeIf { it >= 0 }
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* [path] cut at its first `?`: what precedes it, and the `name=value` pairs after it as written.
|
|
100
|
+
*/
|
|
101
|
+
private fun splitQuery(path: String): Pair<String, List<String>>? {
|
|
102
|
+
val mark = path.indexOf('?')
|
|
103
|
+
if (mark < 0) {
|
|
102
104
|
return null
|
|
103
105
|
}
|
|
104
|
-
|
|
105
|
-
val uri = Uri.parse(path)
|
|
106
|
-
return uri.getQueryParameter(CONTEXTUAL_TRACK_PARAM)
|
|
106
|
+
return path.substring(0, mark) to path.substring(mark + 1).split('&')
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/** The
|
|
110
|
-
fun
|
|
109
|
+
/** The percent-decoded value of [name] in a contextual [path]; null when there is none. */
|
|
110
|
+
private fun contextualValue(name: String, path: String): String? {
|
|
111
111
|
if (!isContextual(path)) {
|
|
112
112
|
return null
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
val
|
|
116
|
-
return
|
|
114
|
+
val prefix = "$name="
|
|
115
|
+
val pair = splitQuery(path)?.second?.firstOrNull { it.startsWith(prefix) } ?: return null
|
|
116
|
+
return Uri.decode(pair.substring(prefix.length))
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Joins [baseUrl] and [path] with exactly one slash. Returns [path] unchanged when it
|
|
121
|
-
*
|
|
120
|
+
* Joins [baseUrl] and [path] with exactly one slash. Returns [path] unchanged when it has a URI
|
|
121
|
+
* scheme (`content:`, `file:`, `HTTPS:`, …), starts with `//` or [baseUrl] is null.
|
|
122
122
|
*/
|
|
123
123
|
fun buildUrl(baseUrl: String?, path: String): String {
|
|
124
|
-
if (
|
|
125
|
-
return path
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (baseUrl == null) {
|
|
124
|
+
if (baseUrl == null || isAbsoluteUrl(path)) {
|
|
129
125
|
return path
|
|
130
126
|
}
|
|
131
127
|
|
|
@@ -133,4 +129,6 @@ object BrowserPathHelper {
|
|
|
133
129
|
val normalizedPath = path.trimStart('/')
|
|
134
130
|
return "$normalizedBase$normalizedPath"
|
|
135
131
|
}
|
|
132
|
+
|
|
133
|
+
private fun isAbsoluteUrl(url: String): Boolean = ABSOLUTE_URL.containsMatchIn(url)
|
|
136
134
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package com.audiobrowser.util
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import android.provider.MediaStore
|
|
5
|
+
import androidx.media3.common.MediaItem
|
|
6
|
+
import com.margelo.nitro.audiobrowser.MediaReference
|
|
7
|
+
import com.margelo.nitro.audiobrowser.SearchMode
|
|
8
|
+
import com.margelo.nitro.audiobrowser.SearchParams
|
|
9
|
+
|
|
10
|
+
object SearchParamsFactory {
|
|
11
|
+
/** A free-text search, as a car's search surface gives it. */
|
|
12
|
+
fun fromQuery(query: String): SearchParams =
|
|
13
|
+
SearchParams(
|
|
14
|
+
mode = null,
|
|
15
|
+
query = query,
|
|
16
|
+
genre = null,
|
|
17
|
+
artist = null,
|
|
18
|
+
album = null,
|
|
19
|
+
title = null,
|
|
20
|
+
playlist = null,
|
|
21
|
+
reference = MediaReference.UNKNOWN,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The search a play-from-search request asks for, from its query and the extras of
|
|
26
|
+
* https://developer.android.com/guide/components/intents-common#PlaySearch. The intent and the
|
|
27
|
+
* media session's legacy `playFromSearch` carry the same extras.
|
|
28
|
+
*/
|
|
29
|
+
fun fromPlayFromSearch(query: String, extras: Bundle?): SearchParams {
|
|
30
|
+
val mediaFocus = extras?.getString(MediaStore.EXTRA_MEDIA_FOCUS)
|
|
31
|
+
|
|
32
|
+
// The focus picks a vertical. Genre, artist and album focuses are filters, carried by the
|
|
33
|
+
// extras below, so they yield no mode. Android has no station or podcast focus: those
|
|
34
|
+
// verticals are iOS-only.
|
|
35
|
+
val mode =
|
|
36
|
+
when (mediaFocus) {
|
|
37
|
+
"vnd.android.cursor.item/*" -> if (query.isEmpty()) SearchMode.ANY else null
|
|
38
|
+
"vnd.android.cursor.item/audio" -> SearchMode.SONG
|
|
39
|
+
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE -> SearchMode.PLAYLIST
|
|
40
|
+
else -> null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return SearchParams(
|
|
44
|
+
mode = mode,
|
|
45
|
+
query = query,
|
|
46
|
+
genre = extras?.getString("android.intent.extra.genre"),
|
|
47
|
+
artist = extras?.getString(MediaStore.EXTRA_MEDIA_ARTIST),
|
|
48
|
+
album = extras?.getString(MediaStore.EXTRA_MEDIA_ALBUM),
|
|
49
|
+
title = extras?.getString(MediaStore.EXTRA_MEDIA_TITLE),
|
|
50
|
+
playlist = extras?.getString("android.intent.extra.playlist"),
|
|
51
|
+
reference = MediaReference.UNKNOWN,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The search [mediaItem] asks to play, or null when it names an item. Media3 gives the legacy
|
|
57
|
+
* `playFromSearch` and `prepareFromSearch` as one item with the query and no media id.
|
|
58
|
+
*/
|
|
59
|
+
fun voiceSearchOf(mediaItem: MediaItem): SearchParams? {
|
|
60
|
+
if (mediaItem.mediaId != MediaItem.DEFAULT_MEDIA_ID) return null
|
|
61
|
+
val request = mediaItem.requestMetadata
|
|
62
|
+
return request.searchQuery?.let { fromPlayFromSearch(it, request.extras) }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
package com.audiobrowser
|
|
2
|
+
|
|
3
|
+
import com.audiobrowser.TestFixtures.resolvedTrack
|
|
4
|
+
import com.audiobrowser.TestFixtures.staticRoute
|
|
5
|
+
import com.audiobrowser.browser.BrowserConfig
|
|
6
|
+
import com.audiobrowser.browser.BrowserManager
|
|
7
|
+
import com.audiobrowser.util.JsPromise
|
|
8
|
+
import com.margelo.nitro.audiobrowser.BrowseError
|
|
9
|
+
import com.margelo.nitro.audiobrowser.FormattedNavigationError
|
|
10
|
+
import com.margelo.nitro.audiobrowser.Func_std__shared_ptr_Promise_std__variant_ResolvedTrack__BrowseError__std__shared_ptr_Promise_std__variant_ResolvedTrack__BrowseError_______BrowserSourceCallbackParam
|
|
11
|
+
import com.margelo.nitro.audiobrowser.NativeBrowserConfiguration
|
|
12
|
+
import com.margelo.nitro.audiobrowser.NavigationError
|
|
13
|
+
import com.margelo.nitro.audiobrowser.NavigationErrorType
|
|
14
|
+
import com.margelo.nitro.audiobrowser.Variant_ResolvedTrack_BrowseError_Promise_BrowseResult_
|
|
15
|
+
import kotlin.time.Duration.Companion.seconds
|
|
16
|
+
import kotlinx.coroutines.CoroutineScope
|
|
17
|
+
import kotlinx.coroutines.test.StandardTestDispatcher
|
|
18
|
+
import kotlinx.coroutines.test.TestScope
|
|
19
|
+
import kotlinx.coroutines.test.runCurrent
|
|
20
|
+
import kotlinx.coroutines.test.runTest
|
|
21
|
+
import org.junit.Assert.assertEquals
|
|
22
|
+
import org.junit.Assert.assertNull
|
|
23
|
+
import org.junit.Test
|
|
24
|
+
import org.junit.runner.RunWith
|
|
25
|
+
import org.mockito.Mockito.CALLS_REAL_METHODS
|
|
26
|
+
import org.mockito.Mockito.mock
|
|
27
|
+
import org.robolectric.RobolectricTestRunner
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The navigation error across the reload behind `notifyContentChanged` and `invalidateAllContent`.
|
|
31
|
+
* Every page is served by a callback route whose answer the test settles, so a reload can load or
|
|
32
|
+
* fail on demand. Robolectric provides `android.net.Uri` and `android.util.LruCache`.
|
|
33
|
+
*/
|
|
34
|
+
@RunWith(RobolectricTestRunner::class)
|
|
35
|
+
class ContentRefreshNavigationErrorTest {
|
|
36
|
+
|
|
37
|
+
private class Request(val path: String) {
|
|
38
|
+
private val js = JsPromise<Variant_ResolvedTrack_BrowseError_Promise_BrowseResult_>()
|
|
39
|
+
val promise = js.promise
|
|
40
|
+
|
|
41
|
+
fun load(title: String = "Loaded") =
|
|
42
|
+
js.resolve(
|
|
43
|
+
Variant_ResolvedTrack_BrowseError_Promise_BrowseResult_.create(
|
|
44
|
+
resolvedTrack(path = path, title = title)
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
fun fail() =
|
|
49
|
+
js.resolve(
|
|
50
|
+
Variant_ResolvedTrack_BrowseError_Promise_BrowseResult_.create(BrowseError("Offline"))
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private val requests = mutableListOf<Request>()
|
|
55
|
+
private val errorEvents = mutableListOf<NavigationError?>()
|
|
56
|
+
private val formattedEvents = mutableListOf<FormattedNavigationError?>()
|
|
57
|
+
|
|
58
|
+
private fun callbackRoute(path: String) =
|
|
59
|
+
staticRoute(path, resolvedTrack(path = path))
|
|
60
|
+
.copy(
|
|
61
|
+
browseStatic = null,
|
|
62
|
+
browseCallback =
|
|
63
|
+
Func_std__shared_ptr_Promise_std__variant_ResolvedTrack__BrowseError__std__shared_ptr_Promise_std__variant_ResolvedTrack__BrowseError_______BrowserSourceCallbackParam {
|
|
64
|
+
Request(it.path).also { request -> requests += request }.promise
|
|
65
|
+
},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
// AudioBrowser's constructor needs JNI: a mock running its real methods, with the fields the
|
|
69
|
+
// navigation and reload paths read written in its place.
|
|
70
|
+
private fun TestScope.browser(): AudioBrowser {
|
|
71
|
+
val browser = mock(AudioBrowser::class.java, CALLS_REAL_METHODS)
|
|
72
|
+
val manager = BrowserManager()
|
|
73
|
+
manager.config = BrowserConfig(routes = arrayOf(callbackRoute("/a"), callbackRoute("/b")))
|
|
74
|
+
set(browser, "browserManager", manager)
|
|
75
|
+
set(browser, "mainScope", CoroutineScope(StandardTestDispatcher(testScheduler)))
|
|
76
|
+
set(
|
|
77
|
+
browser,
|
|
78
|
+
"_configuration",
|
|
79
|
+
NativeBrowserConfiguration(
|
|
80
|
+
path = null,
|
|
81
|
+
request = null,
|
|
82
|
+
requestResolver = null,
|
|
83
|
+
browse = null,
|
|
84
|
+
browseResolver = null,
|
|
85
|
+
media = null,
|
|
86
|
+
artwork = null,
|
|
87
|
+
nowPlayingArtwork = null,
|
|
88
|
+
routes = null,
|
|
89
|
+
singleTrack = null,
|
|
90
|
+
handleTrackLoad = null,
|
|
91
|
+
androidControllerOfflineError = null,
|
|
92
|
+
viewMoreTitle = null,
|
|
93
|
+
carPlayLoadingTitle = null,
|
|
94
|
+
resolveAlbumPath = null,
|
|
95
|
+
formatNavigationError = null,
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
browser.onNavigationError = { errorEvents += it.error }
|
|
99
|
+
browser.onFormattedNavigationError = { formattedEvents += it }
|
|
100
|
+
return browser
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private fun set(browser: AudioBrowser, field: String, value: Any) {
|
|
104
|
+
AudioBrowser::class
|
|
105
|
+
.java
|
|
106
|
+
.getDeclaredField(field)
|
|
107
|
+
.apply { isAccessible = true }
|
|
108
|
+
.set(browser, value)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Leaves [path] displayed with a navigation error, as a navigation that failed offline does. */
|
|
112
|
+
private fun TestScope.failNavigation(browser: AudioBrowser, path: String) {
|
|
113
|
+
browser.navigatePath(path)
|
|
114
|
+
runCurrent()
|
|
115
|
+
requests.removeAt(0).fail()
|
|
116
|
+
runCurrent()
|
|
117
|
+
assertEquals(NavigationErrorType.CALLBACK_ERROR, browser.getNavigationError()?.code)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Leaves [path] displayed with its page and no navigation error. */
|
|
121
|
+
private fun TestScope.loadNavigation(browser: AudioBrowser, path: String) {
|
|
122
|
+
browser.navigatePath(path)
|
|
123
|
+
runCurrent()
|
|
124
|
+
requests.removeAt(0).load(title = "First")
|
|
125
|
+
runCurrent()
|
|
126
|
+
assertEquals("First", browser.getContent()?.title)
|
|
127
|
+
assertNull(browser.getNavigationError())
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private fun TestScope.settleReload(settle: Request.() -> Unit) {
|
|
131
|
+
runCurrent()
|
|
132
|
+
requests.removeAt(0).settle()
|
|
133
|
+
runCurrent()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Test
|
|
137
|
+
fun `a notifyContentChanged reload that loads clears an earlier navigation error`() =
|
|
138
|
+
runTest(timeout = 5.seconds) {
|
|
139
|
+
val browser = browser()
|
|
140
|
+
failNavigation(browser, "/a")
|
|
141
|
+
|
|
142
|
+
browser.notifyContentChanged("/a")
|
|
143
|
+
settleReload { load() }
|
|
144
|
+
|
|
145
|
+
assertEquals("Loaded", browser.getContent()?.title)
|
|
146
|
+
assertNull(browser.getNavigationError())
|
|
147
|
+
assertNull(browser.getFormattedNavigationError())
|
|
148
|
+
assertNull(errorEvents.last())
|
|
149
|
+
assertNull(formattedEvents.last())
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Test
|
|
153
|
+
fun `an invalidateAllContent reload that loads clears an earlier navigation error`() =
|
|
154
|
+
runTest(timeout = 5.seconds) {
|
|
155
|
+
val browser = browser()
|
|
156
|
+
failNavigation(browser, "/a")
|
|
157
|
+
|
|
158
|
+
browser.invalidateAllContent()
|
|
159
|
+
settleReload { load() }
|
|
160
|
+
|
|
161
|
+
assertEquals("Loaded", browser.getContent()?.title)
|
|
162
|
+
assertNull(browser.getNavigationError())
|
|
163
|
+
assertNull(browser.getFormattedNavigationError())
|
|
164
|
+
assertNull(errorEvents.last())
|
|
165
|
+
assertNull(formattedEvents.last())
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@Test
|
|
169
|
+
fun `a notifyContentChanged reload that fails is reported as a navigation error`() =
|
|
170
|
+
runTest(timeout = 5.seconds) {
|
|
171
|
+
val browser = browser()
|
|
172
|
+
loadNavigation(browser, "/a")
|
|
173
|
+
|
|
174
|
+
browser.notifyContentChanged("/a")
|
|
175
|
+
settleReload { fail() }
|
|
176
|
+
|
|
177
|
+
assertEquals(NavigationErrorType.CALLBACK_ERROR, browser.getNavigationError()?.code)
|
|
178
|
+
assertEquals(browser.getNavigationError(), errorEvents.last())
|
|
179
|
+
assertEquals(browser.getFormattedNavigationError(), formattedEvents.last())
|
|
180
|
+
assertEquals("First", browser.getContent()?.title)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@Test
|
|
184
|
+
fun `an invalidateAllContent reload that fails is reported as a navigation error`() =
|
|
185
|
+
runTest(timeout = 5.seconds) {
|
|
186
|
+
val browser = browser()
|
|
187
|
+
loadNavigation(browser, "/a")
|
|
188
|
+
|
|
189
|
+
browser.invalidateAllContent()
|
|
190
|
+
settleReload { fail() }
|
|
191
|
+
|
|
192
|
+
assertEquals(NavigationErrorType.CALLBACK_ERROR, browser.getNavigationError()?.code)
|
|
193
|
+
assertEquals(browser.getNavigationError(), errorEvents.last())
|
|
194
|
+
assertEquals(browser.getFormattedNavigationError(), formattedEvents.last())
|
|
195
|
+
assertEquals("First", browser.getContent()?.title)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@Test
|
|
199
|
+
fun `a failed reload overtaken by a navigation reports nothing`() =
|
|
200
|
+
runTest(timeout = 5.seconds) {
|
|
201
|
+
val browser = browser()
|
|
202
|
+
loadNavigation(browser, "/a")
|
|
203
|
+
browser.notifyContentChanged("/a")
|
|
204
|
+
runCurrent()
|
|
205
|
+
browser.navigatePath("/b")
|
|
206
|
+
runCurrent()
|
|
207
|
+
|
|
208
|
+
requests.removeAt(0).fail()
|
|
209
|
+
runCurrent()
|
|
210
|
+
requests.removeAt(0).load()
|
|
211
|
+
runCurrent()
|
|
212
|
+
|
|
213
|
+
assertEquals("Loaded", browser.getContent()?.title)
|
|
214
|
+
assertNull(browser.getNavigationError())
|
|
215
|
+
assertEquals(emptyList<NavigationError?>(), errorEvents)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@Test
|
|
219
|
+
fun `a reload overtaken by a navigation that fails leaves its navigation error`() =
|
|
220
|
+
runTest(timeout = 5.seconds) {
|
|
221
|
+
val browser = browser()
|
|
222
|
+
loadNavigation(browser, "/a")
|
|
223
|
+
browser.notifyContentChanged("/a")
|
|
224
|
+
runCurrent()
|
|
225
|
+
browser.navigatePath("/b")
|
|
226
|
+
runCurrent()
|
|
227
|
+
|
|
228
|
+
requests.removeAt(1).fail()
|
|
229
|
+
runCurrent()
|
|
230
|
+
requests.removeAt(0).load()
|
|
231
|
+
runCurrent()
|
|
232
|
+
|
|
233
|
+
assertNull(browser.getContent())
|
|
234
|
+
assertEquals(NavigationErrorType.CALLBACK_ERROR, browser.getNavigationError()?.code)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
package com.audiobrowser
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import com.audiobrowser.TestFixtures.resolvedTrack
|
|
5
|
+
import com.audiobrowser.TestFixtures.staticRoute
|
|
6
|
+
import com.audiobrowser.browser.BrowserConfig
|
|
7
|
+
import com.audiobrowser.browser.BrowserManager
|
|
8
|
+
import com.audiobrowser.util.BrowserPathHelper
|
|
9
|
+
import com.margelo.nitro.audiobrowser.NativeBrowserConfiguration
|
|
10
|
+
import com.margelo.nitro.audiobrowser.Track
|
|
11
|
+
import java.time.Duration
|
|
12
|
+
import kotlinx.coroutines.MainScope
|
|
13
|
+
import org.junit.After
|
|
14
|
+
import org.junit.Assert.assertEquals
|
|
15
|
+
import org.junit.Assert.assertFalse
|
|
16
|
+
import org.junit.Assert.assertTrue
|
|
17
|
+
import org.junit.Rule
|
|
18
|
+
import org.junit.Test
|
|
19
|
+
import org.junit.rules.TemporaryFolder
|
|
20
|
+
import org.junit.runner.RunWith
|
|
21
|
+
import org.mockito.Mockito.CALLS_REAL_METHODS
|
|
22
|
+
import org.mockito.Mockito.mock
|
|
23
|
+
import org.robolectric.RobolectricTestRunner
|
|
24
|
+
import org.robolectric.Shadows.shadowOf
|
|
25
|
+
import org.robolectric.annotation.Config
|
|
26
|
+
|
|
27
|
+
/** Selecting a Playable track through `navigate(track)` plays it, whatever its path. */
|
|
28
|
+
@RunWith(RobolectricTestRunner::class)
|
|
29
|
+
@Config(sdk = [28])
|
|
30
|
+
class NavigateTrackTest {
|
|
31
|
+
|
|
32
|
+
@get:Rule val folder = TemporaryFolder()
|
|
33
|
+
|
|
34
|
+
private val service = buildService()
|
|
35
|
+
private val player = service.get().player
|
|
36
|
+
private val browserManager = BrowserManager()
|
|
37
|
+
|
|
38
|
+
@After
|
|
39
|
+
fun destroy() {
|
|
40
|
+
service.destroy()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// AudioBrowser's constructor needs JNI: a mock running its real methods, with the fields
|
|
44
|
+
// navigateTrack reads written as the constructor and the service connection write them.
|
|
45
|
+
private val browser =
|
|
46
|
+
mock(AudioBrowser::class.java, CALLS_REAL_METHODS).apply {
|
|
47
|
+
set("mainScope", MainScope())
|
|
48
|
+
set("connectedService", service.get())
|
|
49
|
+
set("browserManager", this@NavigateTrackTest.browserManager)
|
|
50
|
+
set(
|
|
51
|
+
"_configuration",
|
|
52
|
+
NativeBrowserConfiguration(
|
|
53
|
+
path = null,
|
|
54
|
+
request = null,
|
|
55
|
+
requestResolver = null,
|
|
56
|
+
browse = null,
|
|
57
|
+
browseResolver = null,
|
|
58
|
+
media = null,
|
|
59
|
+
artwork = null,
|
|
60
|
+
nowPlayingArtwork = null,
|
|
61
|
+
routes = null,
|
|
62
|
+
singleTrack = null,
|
|
63
|
+
handleTrackLoad = null,
|
|
64
|
+
androidControllerOfflineError = null,
|
|
65
|
+
viewMoreTitle = null,
|
|
66
|
+
carPlayLoadingTitle = null,
|
|
67
|
+
resolveAlbumPath = null,
|
|
68
|
+
formatNavigationError = null,
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private fun AudioBrowser.set(field: String, value: Any) {
|
|
74
|
+
AudioBrowser::class.java.getDeclaredField(field).apply { isAccessible = true }.set(this, value)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private fun navigate(track: Track) {
|
|
78
|
+
browser.navigateTrack(track)
|
|
79
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private fun silentTrack() =
|
|
83
|
+
TestFixtures.track(id = "a", src = folder.silentWavUri(Duration.ofMinutes(2)))
|
|
84
|
+
|
|
85
|
+
@Test
|
|
86
|
+
fun `a track with only a src plays`() {
|
|
87
|
+
val track = silentTrack()
|
|
88
|
+
assertFalse(player.playWhenReady)
|
|
89
|
+
|
|
90
|
+
navigate(track)
|
|
91
|
+
|
|
92
|
+
assertEquals(listOf(track.src), player.tracks.map { it.src })
|
|
93
|
+
assertTrue(player.playWhenReady)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Test
|
|
97
|
+
fun `a track whose contextual path does not expand plays alone`() {
|
|
98
|
+
// The page no longer lists the track, so the expansion returns nothing.
|
|
99
|
+
browserManager.config =
|
|
100
|
+
BrowserConfig(
|
|
101
|
+
routes =
|
|
102
|
+
arrayOf(
|
|
103
|
+
staticRoute(
|
|
104
|
+
"/stations",
|
|
105
|
+
resolvedTrack(path = "/stations", children = arrayOf(TestFixtures.track(id = "b"))),
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
val track = silentTrack().copy(path = BrowserPathHelper.build("/stations", "a"))
|
|
110
|
+
|
|
111
|
+
navigate(track)
|
|
112
|
+
|
|
113
|
+
assertEquals(listOf(track.src), player.tracks.map { it.src })
|
|
114
|
+
assertTrue(player.playWhenReady)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
package com.audiobrowser
|
|
2
2
|
|
|
3
|
+
import com.audiobrowser.util.JsPromise
|
|
3
4
|
import com.audiobrowser.util.artworkOf
|
|
4
5
|
import com.margelo.nitro.audiobrowser.ArtworkRendering
|
|
5
6
|
import com.margelo.nitro.audiobrowser.ArtworkRequestConfig
|
|
6
7
|
import com.margelo.nitro.audiobrowser.CardImage
|
|
8
|
+
import com.margelo.nitro.audiobrowser.Func_std__shared_ptr_Promise_RequestConfig___RequestConfig_std__optional_std__unordered_map_std__string__std__string__
|
|
9
|
+
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__
|
|
7
10
|
import com.margelo.nitro.audiobrowser.GridTile
|
|
8
11
|
import com.margelo.nitro.audiobrowser.ImageQueryParams
|
|
9
12
|
import com.margelo.nitro.audiobrowser.ImageShape
|
|
10
13
|
import com.margelo.nitro.audiobrowser.ImageSource
|
|
11
14
|
import com.margelo.nitro.audiobrowser.MediaRequestConfig
|
|
15
|
+
import com.margelo.nitro.audiobrowser.NativeBrowserConfiguration
|
|
12
16
|
import com.margelo.nitro.audiobrowser.NativeRouteEntry
|
|
13
17
|
import com.margelo.nitro.audiobrowser.RequestConfig
|
|
14
18
|
import com.margelo.nitro.audiobrowser.ResolvedTrack
|
|
@@ -86,6 +90,23 @@ object TestFixtures {
|
|
|
86
90
|
userAgent = null,
|
|
87
91
|
)
|
|
88
92
|
|
|
93
|
+
/** A layer `transform` whose JS promise rejects with [message]. */
|
|
94
|
+
fun throwingTransform(message: String) =
|
|
95
|
+
Func_std__shared_ptr_Promise_std__shared_ptr_Promise_RequestConfig_____RequestConfig_std__optional_std__unordered_map_std__string__std__string__ {
|
|
96
|
+
_,
|
|
97
|
+
_ ->
|
|
98
|
+
val js = JsPromise<RequestConfig>().apply { reject(Exception(message)) }
|
|
99
|
+
JsPromise<Promise<RequestConfig>>().apply { resolve(js.promise) }.promise
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A layer `transformSync` whose JS call throws: Nitro rejects with the JSError's `what()`. */
|
|
103
|
+
fun throwingTransformSync(what: String) =
|
|
104
|
+
Func_std__shared_ptr_Promise_RequestConfig___RequestConfig_std__optional_std__unordered_map_std__string__std__string__ {
|
|
105
|
+
_,
|
|
106
|
+
_ ->
|
|
107
|
+
JsPromise<RequestConfig>().apply { reject(Exception(what)) }.promise
|
|
108
|
+
}
|
|
109
|
+
|
|
89
110
|
fun mediaConfig(
|
|
90
111
|
baseUrl: String? = null,
|
|
91
112
|
path: String? = null,
|
|
@@ -169,6 +190,26 @@ object TestFixtures {
|
|
|
169
190
|
icyCharset = null,
|
|
170
191
|
)
|
|
171
192
|
|
|
193
|
+
fun browserConfiguration() =
|
|
194
|
+
NativeBrowserConfiguration(
|
|
195
|
+
path = null,
|
|
196
|
+
request = null,
|
|
197
|
+
requestResolver = null,
|
|
198
|
+
browse = null,
|
|
199
|
+
browseResolver = null,
|
|
200
|
+
media = null,
|
|
201
|
+
artwork = null,
|
|
202
|
+
nowPlayingArtwork = null,
|
|
203
|
+
routes = null,
|
|
204
|
+
singleTrack = null,
|
|
205
|
+
handleTrackLoad = null,
|
|
206
|
+
androidControllerOfflineError = null,
|
|
207
|
+
viewMoreTitle = null,
|
|
208
|
+
carPlayLoadingTitle = null,
|
|
209
|
+
resolveAlbumPath = null,
|
|
210
|
+
formatNavigationError = null,
|
|
211
|
+
)
|
|
212
|
+
|
|
172
213
|
/**
|
|
173
214
|
* A route serving [browseStatic] verbatim: the one browse arm that needs neither the JNI bridge
|
|
174
215
|
* nor HTTP.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package com.audiobrowser.browser
|
|
2
2
|
|
|
3
|
+
import com.audiobrowser.TestFixtures.throwingTransform
|
|
3
4
|
import com.audiobrowser.TestFixtures.transformableConfig
|
|
5
|
+
import com.audiobrowser.navigationErrorFor
|
|
6
|
+
import com.margelo.nitro.audiobrowser.NavigationErrorType
|
|
4
7
|
import kotlinx.coroutines.test.runTest
|
|
5
8
|
import org.junit.Assert.assertEquals
|
|
6
9
|
import org.junit.Assert.assertTrue
|
|
@@ -8,10 +11,6 @@ import org.junit.Assert.fail
|
|
|
8
11
|
import org.junit.Before
|
|
9
12
|
import org.junit.Test
|
|
10
13
|
|
|
11
|
-
/**
|
|
12
|
-
* Static layers only: Nitro Promises (transforms, resolvers) cannot be constructed on the JVM, so
|
|
13
|
-
* transforms are covered by RequestConfigBuilderTest and the Swift suite.
|
|
14
|
-
*/
|
|
15
14
|
class BrowserManagerBuildApiRequestTest {
|
|
16
15
|
|
|
17
16
|
private lateinit var bm: BrowserManager
|
|
@@ -105,4 +104,22 @@ class BrowserManagerBuildApiRequestTest {
|
|
|
105
104
|
assertEquals("/nowhere", e.path)
|
|
106
105
|
}
|
|
107
106
|
}
|
|
107
|
+
|
|
108
|
+
@Test
|
|
109
|
+
fun `a route transform that throws fails with callback-error`() = runTest {
|
|
110
|
+
bm.config = BrowserConfig(request = transformableConfig(baseUrl = "https://api.example.com"))
|
|
111
|
+
try {
|
|
112
|
+
bm.buildApiRequest(
|
|
113
|
+
kindConfig = null,
|
|
114
|
+
routeConfig = transformableConfig().copy(transform = throwingTransform("token expired")),
|
|
115
|
+
path = "/library",
|
|
116
|
+
params = emptyMap(),
|
|
117
|
+
)
|
|
118
|
+
fail("expected CallbackException")
|
|
119
|
+
} catch (e: CallbackException) {
|
|
120
|
+
val error = navigationErrorFor(e)
|
|
121
|
+
assertEquals(NavigationErrorType.CALLBACK_ERROR, error.code)
|
|
122
|
+
assertEquals("token expired", error.message)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
108
125
|
}
|