react-native-audio-browser 0.2.0-next.32 → 0.2.0-next.34
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/ios/AVPlayerEngine.swift +60 -24
- package/ios/AVPlayerEngineCallbacks.swift +0 -1
- package/ios/Browser/BrowserConfig.swift +0 -5
- package/ios/Browser/BrowserError.swift +16 -0
- package/ios/Browser/BrowserManager.swift +36 -141
- package/ios/Browser/BrowserPathHelper.swift +25 -12
- package/ios/Browser/FavoriteSet.swift +46 -0
- package/ios/Browser/JsonModels.swift +79 -199
- package/ios/Browser/PageResolver.swift +16 -96
- package/ios/Browser/RequestLayer.swift +97 -2
- package/ios/Browser/RequestPipeline.swift +78 -227
- package/ios/Browser/SectionScope.swift +25 -0
- package/ios/Browser/SimpleRouter.swift +73 -144
- package/ios/CarPlay/CarPlayNowPlayingManager.swift +4 -4
- package/ios/CarPlay/CarPlaySession.swift +3 -3
- package/ios/CarPlay/MediaIntentPlayback.swift +1 -1
- package/ios/Extension/Capability+RemoteCommand.swift +22 -69
- package/ios/Extension/SearchParams+Query.swift +28 -0
- package/ios/Extension/Track+AVPlayer.swift +0 -16
- package/ios/Extension/Track+Copying.swift +3 -1
- package/ios/Extension/Track+Identity.swift +7 -0
- package/ios/Http/HttpClient.swift +12 -30
- package/ios/HybridAudioBrowser+Browser.swift +21 -38
- package/ios/HybridAudioBrowser+Options.swift +27 -66
- package/ios/HybridAudioBrowser+Player.swift +4 -60
- package/ios/HybridAudioBrowser+PlayerCallbacks.swift +6 -38
- package/ios/HybridAudioBrowser.swift +36 -99
- package/ios/Model/NitroTypeStubs.swift +80 -0
- package/ios/Model/PlayerUpdateOptions.swift +2 -0
- package/ios/Model/RemoteCommand.swift +6 -78
- package/ios/Player/NowPlayingUpdater.swift +13 -7
- package/ios/Player/Player.swift +26 -10
- package/ios/Player/PlayerCallbacks.swift +1 -4
- package/ios/Player/PlayerEngine.swift +17 -0
- package/ios/Player/RetryLoop.swift +5 -1
- package/ios/RemoteCommand/RemoteCommandCallbacks.swift +0 -3
- package/ios/RemoteCommand/RemoteCommandController.swift +23 -12
- package/ios/Tests/BrowserPathHelperTests.swift +33 -0
- package/ios/Tests/CapabilityRemoteCommandTests.swift +35 -0
- package/ios/Tests/EmitterTests.swift +3 -48
- package/ios/Tests/FavoriteSetTests.swift +60 -0
- package/ios/Tests/PlayerPolicyTests.swift +27 -3
- package/ios/Tests/PlayerTests.swift +95 -17
- package/ios/Tests/RemoteCommandControllerTests.swift +44 -15
- package/ios/Tests/RequestLayerTests.swift +116 -0
- package/ios/Tests/SearchParamsQueryTests.swift +48 -0
- package/ios/Tests/SectionScopeTests.swift +53 -0
- package/ios/Tests/SimpleRouterTests.swift +38 -3
- package/ios/Tests/Support/TestTypes.swift +44 -3
- package/ios/TrackSelector.swift +34 -52
- package/ios/Util/Emitter.swift +0 -14
- package/ios/Util/NetworkMonitor.swift +8 -25
- package/ios/Util/OutputPicker.swift +48 -0
- package/package.json +1 -1
- package/ios/Model/SourceType.swift +0 -6
- package/ios/Tests/RemoteCommandTests.swift +0 -65
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import Testing
|
|
2
|
+
|
|
3
|
+
@testable import AudioBrowserTestable
|
|
4
|
+
|
|
5
|
+
struct FavoriteSetTests {
|
|
6
|
+
private func favorites(_ identities: [String], enabled: Bool = true) -> FavoriteSet {
|
|
7
|
+
var set = FavoriteSet()
|
|
8
|
+
set.enabled = enabled
|
|
9
|
+
_ = set.replace(with: identities)
|
|
10
|
+
return set
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Test func replaceReportsWhetherTheIdentitiesChanged() {
|
|
14
|
+
var set = FavoriteSet()
|
|
15
|
+
let changes = [["a", "b"], ["b", "a"], ["a", "b", "a"], []].map { set.replace(with: $0) }
|
|
16
|
+
#expect(changes == [true, false, false, true])
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Test func hydratesTrueOrFalseByIdentity() {
|
|
20
|
+
let set = favorites(["a", "stable"])
|
|
21
|
+
#expect(set.hydrate(Track(src: "a")).favorited == true)
|
|
22
|
+
#expect(set.hydrate(Track(src: "b")).favorited == false)
|
|
23
|
+
#expect(set.hydrate(Track(id: "stable", src: "x")).favorited == true)
|
|
24
|
+
#expect(set.hydrate(Track(id: "other", src: "a")).favorited == false)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test func leavesATrackAloneWhenDisabled() {
|
|
28
|
+
#expect(favorites(["a"], enabled: false).hydrate(Track(src: "a")).favorited == nil)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test func leavesATrackWithoutIdentityAlone() {
|
|
32
|
+
#expect(favorites(["a"]).hydrate(Track(path: "/browse")).favorited == nil)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test func aFavoritedTheTrackCarriesWins() {
|
|
36
|
+
let set = favorites(["a"])
|
|
37
|
+
#expect(set.hydrate(Track(src: "a", favorited: false)).favorited == false)
|
|
38
|
+
#expect(set.hydrate(Track(src: "b", favorited: true)).favorited == true)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Test func aLocalToggleHoldsUntilTheNextReplace() {
|
|
42
|
+
var set = favorites(["a"])
|
|
43
|
+
set.set("b", favorited: true)
|
|
44
|
+
set.set("a", favorited: false)
|
|
45
|
+
#expect(set.hydrate(Track(src: "a")).favorited == false)
|
|
46
|
+
#expect(set.hydrate(Track(src: "b")).favorited == true)
|
|
47
|
+
_ = set.replace(with: ["a"])
|
|
48
|
+
#expect(set.hydrate(Track(src: "b")).favorited == false)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Test func hydratesEverySectionOfAPage() {
|
|
52
|
+
let page = ResolvedTrack(
|
|
53
|
+
path: "/p",
|
|
54
|
+
sections: [Section(children: [Track(src: "a")]), Section(children: [Track(src: "b")])],
|
|
55
|
+
title: "P",
|
|
56
|
+
)
|
|
57
|
+
let hydrated = favorites(["b"]).hydrate(page)
|
|
58
|
+
#expect(hydrated.sections?.map { $0.children.map(\.favorited) } == [[false], [true]])
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -177,18 +177,42 @@ struct PlayerRecoveringTests {
|
|
|
177
177
|
let (player, engine, _) = makePlaying()
|
|
178
178
|
player.transition(.avPlayerWaiting)
|
|
179
179
|
#expect(player.state == .buffering)
|
|
180
|
-
player.
|
|
180
|
+
player.networkStatusDidChange(isOnline: true)
|
|
181
181
|
#expect(engine.resolveAndLoadCalls.count == 2)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
@Test func theNetworkReturningLeavesAPausedOrPlayingStreamAlone() {
|
|
185
185
|
let (player, engine, _) = makePlaying()
|
|
186
|
-
player.
|
|
186
|
+
player.networkStatusDidChange(isOnline: true)
|
|
187
187
|
player.pause()
|
|
188
|
-
player.
|
|
188
|
+
player.networkStatusDidChange(isOnline: true)
|
|
189
189
|
#expect(engine.resolveAndLoadCalls.count == 1)
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
@Test func theNetworkGoingReRendersTheStallLineWithoutReconnecting() {
|
|
193
|
+
let (player, engine, _) = makePlaying()
|
|
194
|
+
player.transition(.avPlayerWaiting)
|
|
195
|
+
engine.nowPlayingRenderCount = 0
|
|
196
|
+
|
|
197
|
+
player.networkStatusDidChange(isOnline: false)
|
|
198
|
+
|
|
199
|
+
#expect(engine.nowPlayingRenderCount == 1)
|
|
200
|
+
#expect(engine.resolveAndLoadCalls.count == 1)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Test func theNetworkReturningReRendersBeforeReconnecting() {
|
|
204
|
+
let (player, engine, _) = makePlaying()
|
|
205
|
+
player.transition(.avPlayerWaiting)
|
|
206
|
+
var order: [String] = []
|
|
207
|
+
engine.onSeamCall = { order.append($0) }
|
|
208
|
+
let loadsBefore = engine.resolveAndLoadCalls.count
|
|
209
|
+
|
|
210
|
+
player.networkStatusDidChange(isOnline: true)
|
|
211
|
+
|
|
212
|
+
#expect(order.first == "renderNowPlaying")
|
|
213
|
+
#expect(engine.resolveAndLoadCalls.count == loadsBefore + 1)
|
|
214
|
+
}
|
|
215
|
+
|
|
192
216
|
/// A restart from a terminal error is a new Load: fresh retry budgets, unproven playback, the
|
|
193
217
|
/// primer allowed again; a retry within a Load keeps its Load.
|
|
194
218
|
@Test func aRestartFromAnErrorBeginsANewLoad() async {
|
|
@@ -681,13 +681,13 @@ struct NaturalEndPlayIntentTests {
|
|
|
681
681
|
|
|
682
682
|
@Test @MainActor
|
|
683
683
|
func naturalEnd_requestsSessionRelease() {
|
|
684
|
-
let (c, eh,
|
|
684
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
685
685
|
startPlaying(c, eh)
|
|
686
|
-
|
|
686
|
+
eh.scheduleAudioSessionReleaseCount = 0
|
|
687
687
|
|
|
688
688
|
eh.emit(.playedToEnd)
|
|
689
689
|
|
|
690
|
-
#expect(
|
|
690
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 1)
|
|
691
691
|
}
|
|
692
692
|
|
|
693
693
|
/// play() from .ended must reload from the start — startPlayback() alone is a
|
|
@@ -1272,48 +1272,126 @@ struct StopCancelsRetryTests {
|
|
|
1272
1272
|
struct SessionReleaseTests {
|
|
1273
1273
|
@Test @MainActor
|
|
1274
1274
|
func deliberatePause_requestsRelease() {
|
|
1275
|
-
let (c, eh,
|
|
1275
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
1276
1276
|
startPlaying(c, eh)
|
|
1277
|
-
|
|
1277
|
+
eh.scheduleAudioSessionReleaseCount = 0
|
|
1278
1278
|
c.pause()
|
|
1279
|
-
#expect(
|
|
1279
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 1)
|
|
1280
1280
|
}
|
|
1281
1281
|
|
|
1282
1282
|
@Test @MainActor
|
|
1283
1283
|
func play_doesNotRequestRelease() {
|
|
1284
|
-
let (c, eh,
|
|
1284
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
1285
1285
|
startPlaying(c, eh)
|
|
1286
|
-
#expect(
|
|
1286
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 0)
|
|
1287
1287
|
}
|
|
1288
1288
|
|
|
1289
1289
|
@Test @MainActor
|
|
1290
1290
|
func interruptionBegan_doesNotRequestRelease() {
|
|
1291
1291
|
// A phone call pauses (playWhenReady → false) but is meant to resume, so the session must be
|
|
1292
1292
|
// held — the exact race the intent-gating design exists to avoid.
|
|
1293
|
-
let (c, eh,
|
|
1293
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
1294
1294
|
startPlaying(c, eh)
|
|
1295
|
-
|
|
1295
|
+
eh.scheduleAudioSessionReleaseCount = 0
|
|
1296
1296
|
c.handleInterruptionBegan()
|
|
1297
|
-
#expect(
|
|
1297
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 0)
|
|
1298
1298
|
}
|
|
1299
1299
|
|
|
1300
1300
|
@Test @MainActor
|
|
1301
1301
|
func interruptionEnded_withResume_doesNotRequestRelease() {
|
|
1302
|
-
let (c, eh,
|
|
1302
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
1303
1303
|
startPlaying(c, eh)
|
|
1304
1304
|
c.handleInterruptionBegan()
|
|
1305
|
-
|
|
1305
|
+
eh.scheduleAudioSessionReleaseCount = 0
|
|
1306
1306
|
c.handleInterruptionEnded(shouldResume: true)
|
|
1307
|
-
#expect(
|
|
1307
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 0)
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
1310
|
@Test @MainActor
|
|
1311
1311
|
func interruptionEnded_withoutResume_requestsRelease() {
|
|
1312
|
-
let (c, eh,
|
|
1312
|
+
let (c, eh, _, _) = makeCoordinator()
|
|
1313
1313
|
startPlaying(c, eh)
|
|
1314
1314
|
c.handleInterruptionBegan()
|
|
1315
|
-
|
|
1315
|
+
eh.scheduleAudioSessionReleaseCount = 0
|
|
1316
1316
|
c.handleInterruptionEnded(shouldResume: false)
|
|
1317
|
-
#expect(
|
|
1317
|
+
#expect(eh.scheduleAudioSessionReleaseCount == 1)
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// MARK: - Media-stack effects of a publish
|
|
1322
|
+
|
|
1323
|
+
/// The audio-session and now-playing effects the Player drives through its engine, in their
|
|
1324
|
+
/// order relative to the callbacks JS hears.
|
|
1325
|
+
@Suite("Player - media-stack effects")
|
|
1326
|
+
struct MediaStackEffectTests {
|
|
1327
|
+
@MainActor
|
|
1328
|
+
private func makeTraced() -> (Player, MockPlayerEngine, MockPlayerCallbacks) {
|
|
1329
|
+
let (c, eh, cb, _) = makeCoordinator()
|
|
1330
|
+
eh.onSeamCall = { [weak cb] in cb?.publishOrder.append($0) }
|
|
1331
|
+
return (c, eh, cb)
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
@Test @MainActor
|
|
1335
|
+
func playIntent_cancelsTheReleaseBeforeJSHearsIt_thenActivatesOnOutput() {
|
|
1336
|
+
let (c, _, cb) = makeTraced()
|
|
1337
|
+
loadTrack(c)
|
|
1338
|
+
cb.publishOrder.removeAll()
|
|
1339
|
+
|
|
1340
|
+
c.setPlayWhenReady(true)
|
|
1341
|
+
|
|
1342
|
+
#expect(cb.publishOrder == [
|
|
1343
|
+
"cancelAudioSessionRelease", "playWhenReady",
|
|
1344
|
+
"playingState", "activateAudioSession", "renderNowPlaying",
|
|
1345
|
+
])
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
@Test @MainActor
|
|
1349
|
+
func pause_rendersWithoutActivating_thenSchedulesTheRelease() {
|
|
1350
|
+
let (c, eh, cb) = makeTraced()
|
|
1351
|
+
startPlaying(c, eh)
|
|
1352
|
+
cb.publishOrder.removeAll()
|
|
1353
|
+
|
|
1354
|
+
c.pause()
|
|
1355
|
+
|
|
1356
|
+
#expect(cb.publishOrder == [
|
|
1357
|
+
"playWhenReady", "playingState", "renderNowPlaying", "scheduleAudioSessionRelease",
|
|
1358
|
+
])
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
@Test @MainActor
|
|
1362
|
+
func playbackChange_rendersAfterJSHearsIt() {
|
|
1363
|
+
let (c, _, cb) = makeTraced()
|
|
1364
|
+
loadTrack(c)
|
|
1365
|
+
cb.publishOrder.removeAll()
|
|
1366
|
+
|
|
1367
|
+
c.transition(.errorOccurred(.playbackFailed))
|
|
1368
|
+
|
|
1369
|
+
#expect(cb.publishOrder == ["playback", "renderNowPlaying"])
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
@Test @MainActor
|
|
1373
|
+
func activeTrackChange_resetsTheNowPlayingLinesAfterJSHearsIt() {
|
|
1374
|
+
let (c, eh, cb, _) = makeCoordinator()
|
|
1375
|
+
eh.onSeamCall = { [weak cb] call in
|
|
1376
|
+
if call == "nowPlayingTrackChanged" { cb?.queueAndTrackOrder.append(call) }
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
c.setQueue([Track(id: "t1", src: "https://example.com/a.mp3", title: "A")])
|
|
1380
|
+
|
|
1381
|
+
#expect(cb.queueAndTrackOrder == ["queue", "activeTrack", "nowPlayingTrackChanged"])
|
|
1382
|
+
#expect(eh.nowPlayingTrackChangedCount == 1)
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
@Test @MainActor
|
|
1386
|
+
func timedMetadata_reachesJSThenTheNowPlayingLines() {
|
|
1387
|
+
let (c, eh, cb) = makeTraced()
|
|
1388
|
+
let metadata = TimedMetadata(title: "Song", artist: "Artist")
|
|
1389
|
+
|
|
1390
|
+
eh.emit(.timedMetadata(metadata))
|
|
1391
|
+
withExtendedLifetime(c) {}
|
|
1392
|
+
|
|
1393
|
+
#expect(cb.publishOrder == ["timedMetadata", "applyTimedMetadata"])
|
|
1394
|
+
#expect(cb.timedMetadata == [metadata])
|
|
1395
|
+
#expect(eh.appliedTimedMetadata == [metadata])
|
|
1318
1396
|
}
|
|
1319
1397
|
}
|
|
@@ -18,7 +18,6 @@ struct RemoteCommandControllerTests {
|
|
|
18
18
|
func remotePlay() { events.append("play") }
|
|
19
19
|
func remotePause() { events.append("pause") }
|
|
20
20
|
func remoteStop() { events.append("stop") }
|
|
21
|
-
func remotePlayPause() { events.append("playPause") }
|
|
22
21
|
func remoteNext() { events.append("next") }
|
|
23
22
|
func remotePrevious() { events.append("previous") }
|
|
24
23
|
func remoteJumpForward(interval: Double) { events.append("jumpForward:\(interval)") }
|
|
@@ -34,28 +33,23 @@ struct RemoteCommandControllerTests {
|
|
|
34
33
|
private func makeController() -> (RemoteCommandController, SpyCallbacks) {
|
|
35
34
|
let center = MPRemoteCommandCenter.shared()
|
|
36
35
|
let reset = RemoteCommandController(remoteCommandCenter: center)
|
|
37
|
-
reset.enable(commands: RemoteCommand.
|
|
36
|
+
reset.enable(commands: Set(RemoteCommand.allCases))
|
|
38
37
|
reset.disableAll()
|
|
39
38
|
|
|
40
39
|
let spy = SpyCallbacks()
|
|
41
40
|
return (RemoteCommandController(remoteCommandCenter: center, callbacks: spy), spy)
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
/// The reported bug: a changed jump interval used to disable the very command
|
|
45
|
-
/// it had just re-enabled, removing the skip button from the lock screen,
|
|
46
|
-
/// Control Center and CarPlay while `enabledCommands` still reported it on.
|
|
47
43
|
@Test func changedJumpIntervalKeepsCommandEnabled() {
|
|
48
44
|
let (controller, _) = makeController()
|
|
49
45
|
let center = MPRemoteCommandCenter.shared()
|
|
50
46
|
|
|
51
|
-
controller.enable(commands: [
|
|
52
|
-
.play, .skipForward(preferredIntervals: [15]), .skipBackward(preferredIntervals: [15]),
|
|
53
|
-
])
|
|
47
|
+
controller.enable(commands: [.play, .skipForward, .skipBackward])
|
|
54
48
|
#expect(center.skipForwardCommand.isEnabled)
|
|
55
49
|
|
|
56
|
-
controller.enable(
|
|
57
|
-
.play, .skipForward
|
|
58
|
-
|
|
50
|
+
controller.enable(
|
|
51
|
+
commands: [.play, .skipForward, .skipBackward], forwardJumpInterval: 30, backwardJumpInterval: 30,
|
|
52
|
+
)
|
|
59
53
|
|
|
60
54
|
#expect(center.skipForwardCommand.isEnabled)
|
|
61
55
|
#expect(center.skipBackwardCommand.isEnabled)
|
|
@@ -67,8 +61,8 @@ struct RemoteCommandControllerTests {
|
|
|
67
61
|
let (controller, _) = makeController()
|
|
68
62
|
let center = MPRemoteCommandCenter.shared()
|
|
69
63
|
|
|
70
|
-
controller.enable(commands: [.changePlaybackRate
|
|
71
|
-
controller.enable(commands: [.changePlaybackRate
|
|
64
|
+
controller.enable(commands: [.changePlaybackRate], playbackRates: [1.0])
|
|
65
|
+
controller.enable(commands: [.changePlaybackRate], playbackRates: [1.0, 1.5, 2.0])
|
|
72
66
|
|
|
73
67
|
#expect(center.changePlaybackRateCommand.isEnabled)
|
|
74
68
|
#expect(center.changePlaybackRateCommand.supportedPlaybackRates == [1.0, 1.5, 2.0])
|
|
@@ -87,11 +81,46 @@ struct RemoteCommandControllerTests {
|
|
|
87
81
|
#expect(center.playCommand.isEnabled)
|
|
88
82
|
}
|
|
89
83
|
|
|
84
|
+
@Test func retainedCommandStaysEnabledWhenOthersAreAdded() {
|
|
85
|
+
let (controller, _) = makeController()
|
|
86
|
+
let center = MPRemoteCommandCenter.shared()
|
|
87
|
+
|
|
88
|
+
controller.enable(commands: [.play, .pause])
|
|
89
|
+
controller.enable(commands: [.play, .pause, .stop])
|
|
90
|
+
|
|
91
|
+
#expect(center.playCommand.isEnabled)
|
|
92
|
+
#expect(center.pauseCommand.isEnabled)
|
|
93
|
+
#expect(center.stopCommand.isEnabled)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Test func droppedJumpCommandIsDisabled() {
|
|
97
|
+
let (controller, _) = makeController()
|
|
98
|
+
let center = MPRemoteCommandCenter.shared()
|
|
99
|
+
|
|
100
|
+
controller.enable(commands: [.play, .skipForward])
|
|
101
|
+
controller.enable(commands: [.play])
|
|
102
|
+
|
|
103
|
+
#expect(!center.skipForwardCommand.isEnabled)
|
|
104
|
+
#expect(center.playCommand.isEnabled)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Test func enablingNoCommandsDisablesEveryOne() {
|
|
108
|
+
let (controller, _) = makeController()
|
|
109
|
+
let center = MPRemoteCommandCenter.shared()
|
|
110
|
+
|
|
111
|
+
controller.enable(commands: Set(RemoteCommand.allCases))
|
|
112
|
+
controller.enable(commands: [])
|
|
113
|
+
|
|
114
|
+
#expect(!center.playCommand.isEnabled)
|
|
115
|
+
#expect(!center.skipBackwardCommand.isEnabled)
|
|
116
|
+
#expect(!center.changePlaybackRateCommand.isEnabled)
|
|
117
|
+
}
|
|
118
|
+
|
|
90
119
|
@Test func disableAllClearsEveryTarget() {
|
|
91
120
|
let (controller, _) = makeController()
|
|
92
121
|
let center = MPRemoteCommandCenter.shared()
|
|
93
122
|
|
|
94
|
-
controller.enable(commands: [.play, .pause, .skipForward
|
|
123
|
+
controller.enable(commands: [.play, .pause, .skipForward])
|
|
95
124
|
controller.disableAll()
|
|
96
125
|
|
|
97
126
|
#expect(!center.playCommand.isEnabled)
|
|
@@ -126,7 +155,7 @@ struct RemoteCommandControllerTests {
|
|
|
126
155
|
weak var weakController: RemoteCommandController?
|
|
127
156
|
autoreleasepool {
|
|
128
157
|
let (controller, _) = makeController()
|
|
129
|
-
controller.enable(commands: RemoteCommand.
|
|
158
|
+
controller.enable(commands: Set(RemoteCommand.allCases))
|
|
130
159
|
controller.disableAll()
|
|
131
160
|
weakController = controller
|
|
132
161
|
}
|
|
@@ -109,4 +109,120 @@ struct RequestLayerTests {
|
|
|
109
109
|
#expect(RequestLayer.mergeDicts(["a": "1"], nil) == ["a": "1"])
|
|
110
110
|
#expect(RequestLayer.mergeDicts(nil, ["b": "2"]) == ["b": "2"])
|
|
111
111
|
}
|
|
112
|
+
|
|
113
|
+
@Test func baseSetsOnlyThePath() {
|
|
114
|
+
#expect(Config.base(path: "/a") == Config(path: "/a"))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// MARK: - artwork
|
|
118
|
+
|
|
119
|
+
private func artwork(
|
|
120
|
+
_ artwork: Config = Config(),
|
|
121
|
+
over base: Config = Config(path: "/art.png"),
|
|
122
|
+
resolve: (nonisolated(nonsending)() async throws -> Config?)? = nil,
|
|
123
|
+
trackHasArtwork: Bool = true,
|
|
124
|
+
sizeQuery: [String: String] = [:],
|
|
125
|
+
transforms: [nonisolated(nonsending)(Config) async throws -> Config] = [],
|
|
126
|
+
id: String? = nil,
|
|
127
|
+
) async throws -> Config? {
|
|
128
|
+
try await RequestLayer.artwork(
|
|
129
|
+
artwork, over: base, resolve: resolve, trackHasArtwork: trackHasArtwork,
|
|
130
|
+
sizeQuery: sizeQuery, transforms: transforms, id: id,
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test func artworkStaticFieldsMergeOverTheBasePathIncluded() async throws {
|
|
135
|
+
let result = try await artwork(
|
|
136
|
+
Config(path: "/artwork/{id}", baseUrl: "https://img", headers: ["B": "2"]),
|
|
137
|
+
over: Config(path: "/art.png", baseUrl: "https://api", headers: ["A": "1"]),
|
|
138
|
+
id: "42",
|
|
139
|
+
)
|
|
140
|
+
#expect(result == Config(path: "/artwork/42", baseUrl: "https://img", headers: ["A": "1", "B": "2"]))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Test func theResolvedConfigWinsOverTheStaticFields() async throws {
|
|
144
|
+
let result = try await artwork(
|
|
145
|
+
Config(baseUrl: "https://static", userAgent: "static"),
|
|
146
|
+
resolve: { Config(baseUrl: "https://resolved") },
|
|
147
|
+
)
|
|
148
|
+
#expect(result == Config(path: "/art.png", baseUrl: "https://resolved", userAgent: "static"))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Test func aResolverThatProducesNothingKeepsTheTracksArtwork() async throws {
|
|
152
|
+
let result = try await artwork(Config(baseUrl: "https://img"), resolve: { nil })
|
|
153
|
+
#expect(result == Config(path: "/art.png", baseUrl: "https://img"))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@Test func aResolverThatProducesNothingForATrackWithoutArtworkIsNoArtwork() async throws {
|
|
157
|
+
let result = try await artwork(
|
|
158
|
+
Config(path: "/fallback.png"), over: Config(), resolve: { nil }, trackHasArtwork: false,
|
|
159
|
+
)
|
|
160
|
+
#expect(result == nil)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@Test func theSizeQueryMergesBeforeTheTransformsRun() async throws {
|
|
164
|
+
var seen: Config?
|
|
165
|
+
let result = try await artwork(
|
|
166
|
+
over: Config(path: "/art.png", query: ["v": "1"]),
|
|
167
|
+
sizeQuery: ["w": "300"],
|
|
168
|
+
transforms: [{ seen = $0; return $0 }],
|
|
169
|
+
)
|
|
170
|
+
#expect(seen?.query == ["v": "1", "w": "300"])
|
|
171
|
+
#expect(result?.query == ["v": "1", "w": "300"])
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@Test func anEmptySizeQueryLeavesNoQuery() async throws {
|
|
175
|
+
#expect(try await artwork()?.query == nil)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Test func transformsRunInOrderBeforeTheIdIsFilled() async throws {
|
|
179
|
+
let result = try await artwork(
|
|
180
|
+
transforms: [
|
|
181
|
+
{ Config(path: "/t/{id}", baseUrl: $0.baseUrl) },
|
|
182
|
+
{ Config(path: $0.path, baseUrl: "https://second", headers: ["X-Id": "{id}"], query: ["id": "{id}"]) },
|
|
183
|
+
],
|
|
184
|
+
id: "7",
|
|
185
|
+
)
|
|
186
|
+
#expect(result == Config(path: "/t/7", baseUrl: "https://second", headers: ["X-Id": "7"], query: ["id": "7"]))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@Test func withoutAnIdTheTokenStays() async throws {
|
|
190
|
+
let result = try await artwork(Config(path: "/artwork/{id}"), id: nil)
|
|
191
|
+
#expect(result?.path == "/artwork/{id}")
|
|
192
|
+
#expect(RequestLayer.hasUnfilledIdToken(result!))
|
|
193
|
+
#expect(!RequestLayer.hasUnfilledIdToken(Config(path: "/artwork/1")))
|
|
194
|
+
#expect(RequestLayer.hasUnfilledIdToken(Config(headers: ["X": "{id}"])))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@Test func noPathLeftIsNoArtwork() async throws {
|
|
198
|
+
#expect(try await artwork(over: Config(baseUrl: "https://img")) == nil)
|
|
199
|
+
#expect(try await artwork(transforms: [{ _ in Config(baseUrl: "https://img") }]) == nil)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@Test func sizeQueryNamesTheContextsWholePixels() {
|
|
203
|
+
let params = ImageQueryParams(width: "w", height: "h")
|
|
204
|
+
#expect(RequestLayer.sizeQuery(params, ImageContext(width: 300.7, height: 200)) == ["w": "300", "h": "200"])
|
|
205
|
+
#expect(RequestLayer.sizeQuery(ImageQueryParams(width: "w"), ImageContext(width: 300, height: 200)) == ["w": "300"])
|
|
206
|
+
#expect(RequestLayer.sizeQuery(params, ImageContext(width: nil, height: 200)) == ["h": "200"])
|
|
207
|
+
#expect(RequestLayer.sizeQuery(params, nil) == [:])
|
|
208
|
+
#expect(RequestLayer.sizeQuery(nil, ImageContext(width: 300, height: 200)) == [:])
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@Test func imageHeadersAddTheUserAgentUnlessAHeaderSetsIt() {
|
|
212
|
+
#expect(RequestLayer.imageHeaders(Config()) == nil)
|
|
213
|
+
#expect(RequestLayer.imageHeaders(Config(userAgent: "UA")) == ["User-Agent": "UA"])
|
|
214
|
+
#expect(RequestLayer.imageHeaders(Config(headers: ["User-Agent": "mine"], userAgent: "UA")) == ["User-Agent": "mine"])
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@Test func imageHeadersAddTheContentTypeUnlessAHeaderSetsIt() {
|
|
218
|
+
#expect(RequestLayer.imageHeaders(Config(contentType: "image/png")) == ["Content-Type": "image/png"])
|
|
219
|
+
#expect(
|
|
220
|
+
RequestLayer.imageHeaders(Config(headers: ["Content-Type": "mine"], contentType: "image/png"))
|
|
221
|
+
== ["Content-Type": "mine"],
|
|
222
|
+
)
|
|
223
|
+
#expect(
|
|
224
|
+
RequestLayer.imageHeaders(Config(contentType: "image/png", userAgent: "UA"))
|
|
225
|
+
== ["Content-Type": "image/png", "User-Agent": "UA"],
|
|
226
|
+
)
|
|
227
|
+
}
|
|
112
228
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Testing
|
|
2
|
+
|
|
3
|
+
@testable import AudioBrowserTestable
|
|
4
|
+
|
|
5
|
+
struct SearchParamsQueryTests {
|
|
6
|
+
private func params(
|
|
7
|
+
_ query: String,
|
|
8
|
+
mode: SearchMode? = nil,
|
|
9
|
+
genre: String? = nil,
|
|
10
|
+
artist: String? = nil,
|
|
11
|
+
album: String? = nil,
|
|
12
|
+
title: String? = nil,
|
|
13
|
+
playlist: String? = nil,
|
|
14
|
+
reference: MediaReference = .unknown,
|
|
15
|
+
) -> SearchParams {
|
|
16
|
+
SearchParams(
|
|
17
|
+
mode: mode, query: query, genre: genre, artist: artist, album: album,
|
|
18
|
+
title: title, playlist: playlist, reference: reference,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Test func aPlainSearchSendsOnlyQ() {
|
|
23
|
+
#expect(params("jazz").queryParams == ["q": "jazz"])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test func everySetFilterIsSent() {
|
|
27
|
+
let all = params(
|
|
28
|
+
"x", mode: .musicVideo, genre: "g", artist: "a", album: "al", title: "t", playlist: "p", reference: .my,
|
|
29
|
+
)
|
|
30
|
+
#expect(all.queryParams == [
|
|
31
|
+
"q": "x", "mode": "music-video", "genre": "g", "artist": "a", "album": "al",
|
|
32
|
+
"title": "t", "playlist": "p", "reference": "my",
|
|
33
|
+
])
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test func anUnknownReferenceIsNotSent() {
|
|
37
|
+
#expect(params("x", reference: .unknown).queryParams["reference"] == nil)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test func theCacheKeyIsSortedAndDelimited() {
|
|
41
|
+
#expect(params("jazz", genre: "jazz").cacheKey == "genre=jazz\u{1}q=jazz")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test func searchesWithTheSameQueryButDifferentFiltersHaveDifferentKeys() {
|
|
45
|
+
#expect(params("jazz").cacheKey != params("jazz", genre: "jazz").cacheKey)
|
|
46
|
+
#expect(params("a", artist: "b").cacheKey != params("a", album: "b").cacheKey)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -111,4 +111,57 @@ struct SectionScopeTests {
|
|
|
111
111
|
@Test func childlessPageHasNoSections() {
|
|
112
112
|
#expect(ResolvedTrack(path: "/p", title: "P").normalizedSections == nil)
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
// MARK: - Queue
|
|
116
|
+
|
|
117
|
+
private func queue(_ sections: [Section], _ path: String, singleTrack: Bool = false) -> ([String?], Int)? {
|
|
118
|
+
SectionScope.queue(in: sections, path: path, singleTrack: singleTrack).map { ($0.tracks.map(\.src), $0.selectedIndex) }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Test func queuesThePlayableTracksOfTheTappedSection() {
|
|
122
|
+
let page = [
|
|
123
|
+
section("First", [track("a"), Track(id: "off", src: "off", disabled: true), Track(path: "/browse"), track("b")]),
|
|
124
|
+
section("Second", [track("c")]),
|
|
125
|
+
]
|
|
126
|
+
let result = queue(page, "/p?__trackId=b&__index=3")
|
|
127
|
+
#expect(result?.0 == ["a", "b"])
|
|
128
|
+
#expect(result?.1 == 1)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Test func thePinnedCopyIsTheSelectedOne() {
|
|
132
|
+
let page = [section(nil, [track("a"), track("b"), track("a")])]
|
|
133
|
+
#expect(queue(page, "/p?__trackId=a&__index=2")?.1 == 2)
|
|
134
|
+
#expect(queue(page, "/p?__trackId=a")?.1 == 0)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Test func aStaleIndexSelectsTheFirstIdentityMatch() {
|
|
138
|
+
let page = [section(nil, [track("x"), track("a"), track("a")])]
|
|
139
|
+
#expect(queue(page, "/p?__trackId=a&__index=0")?.1 == 1)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@Test func singleTrackQueuesOnlyTheTappedTrack() {
|
|
143
|
+
let page = [section(nil, [track("a"), track("b"), track("c")])]
|
|
144
|
+
let result = queue(page, "/p?__trackId=b&__index=1", singleTrack: true)
|
|
145
|
+
#expect(result?.0 == ["b"])
|
|
146
|
+
#expect(result?.1 == 0)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Test func aDisabledTappedTrackQueuesNothing() {
|
|
150
|
+
let page = [section(nil, [track("a"), Track(id: "off", src: "off", disabled: true)])]
|
|
151
|
+
#expect(queue(page, "/p?__trackId=off&__index=1") == nil)
|
|
152
|
+
#expect(queue(page, "/p?__trackId=off") == nil)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Test func aVanishedIdentityOrAPlainPathQueuesNothing() {
|
|
156
|
+
let page = [section(nil, [track("a")])]
|
|
157
|
+
#expect(queue(page, "/p?__trackId=gone") == nil)
|
|
158
|
+
#expect(queue(page, "/p") == nil)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@Test func isPlayableNeedsASrcAndNoDisabled() {
|
|
162
|
+
#expect(Track(src: "s").isPlayable)
|
|
163
|
+
#expect(Track(src: "s", disabled: false).isPlayable)
|
|
164
|
+
#expect(!Track(src: "s", disabled: true).isPlayable)
|
|
165
|
+
#expect(!Track(path: "/p").isPlayable)
|
|
166
|
+
}
|
|
114
167
|
}
|
|
@@ -7,9 +7,7 @@ private struct TestRoute: RouteEntry {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
private func match(_ path: String, _ patterns: [String]) -> (route: TestRoute, match: RouteMatch)? {
|
|
10
|
-
|
|
11
|
-
let routes = patterns.map { TestRoute(path: $0) }
|
|
12
|
-
return router.findBestMatch(path: path, routes: routes)
|
|
10
|
+
SimpleRouter.findBestMatch(path: path, routes: patterns.map { TestRoute(path: $0) })
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
// MARK: - exact matches
|
|
@@ -137,3 +135,40 @@ private func match(_ path: String, _ patterns: [String]) -> (route: TestRoute, m
|
|
|
137
135
|
let result = match("/api/v1/users", ["/api/{version}/**", "/api/v1/**"])
|
|
138
136
|
#expect(result!.route.path == "/api/v1/**")
|
|
139
137
|
}
|
|
138
|
+
|
|
139
|
+
@Test func treatsADoubleStarBeforeTheEndAsAConstant() {
|
|
140
|
+
#expect(match("/a/**/b", ["/a/**/b"]) != nil)
|
|
141
|
+
#expect(match("/a/x/b", ["/a/**/b"]) == nil)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@Test func theFirstRouteWinsATie() {
|
|
145
|
+
let result = match("/artists/123", ["/artists/{id}", "/artists/{name}"])
|
|
146
|
+
#expect(result!.route.path == "/artists/{id}")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// MARK: - browse route
|
|
150
|
+
|
|
151
|
+
private func browseRoute(_ path: String, _ patterns: [String]) -> (route: TestRoute, match: RouteMatch)? {
|
|
152
|
+
SimpleRouter.browseRoute(for: path, in: patterns.map { TestRoute(path: $0) })
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Test func theSpecialRoutesNeverMatchABrowsePath() {
|
|
156
|
+
#expect(browseRoute("/__tabs__", ["__tabs__", "__search__"]) == nil)
|
|
157
|
+
#expect(browseRoute("__search__", ["__search__"]) == nil)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@Test func aMatchingRouteWinsOverTheDefault() {
|
|
161
|
+
let result = browseRoute("/artists/1", ["__default__", "/artists/{id}"])
|
|
162
|
+
#expect(result!.route.path == "/artists/{id}")
|
|
163
|
+
#expect(result!.match.params == ["id": "1"])
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@Test func withoutAMatchTheDefaultRouteBrowsesThePath() {
|
|
167
|
+
let result = browseRoute("/a/b", ["/artists", "__default__"])
|
|
168
|
+
#expect(result!.route.path == "__default__")
|
|
169
|
+
#expect(result!.match.params == ["path": "/a/b"])
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@Test func withoutAMatchOrADefaultThereIsNoBrowseRoute() {
|
|
173
|
+
#expect(browseRoute("/a/b", ["/artists", "__tabs__"]) == nil)
|
|
174
|
+
}
|