diff --git a/packages/interactive_media_ads/CHANGELOG.md b/packages/interactive_media_ads/CHANGELOG.md index 1bb1057597ca..23158645b32b 100644 --- a/packages/interactive_media_ads/CHANGELOG.md +++ b/packages/interactive_media_ads/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.6 + +* Adds support to configure ad requests. See `AdsRequest`. + ## 0.2.5+1 * Adds remaining methods for internal wrapper of the Android native `AdsRequest`. diff --git a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt index 6cfcd96e731c..8e2349807d65 100644 --- a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt +++ b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) : * * This must match the version in pubspec.yaml. */ - const val pluginVersion = "0.2.5+1" + const val pluginVersion = "0.2.6" } override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) { diff --git a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift index 38a24e8564db..87a74cf065d0 100644 --- a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift +++ b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest { /// The current version of the `interactive_media_ads` plugin. /// /// This must match the version in pubspec.yaml. - static let pluginVersion = "0.2.5+1" + static let pluginVersion = "0.2.6" func pigeonDefaultConstructor( pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer, diff --git a/packages/interactive_media_ads/lib/src/ads_request.dart b/packages/interactive_media_ads/lib/src/ads_request.dart index ecc8e2f2ccc5..a22d69320c11 100644 --- a/packages/interactive_media_ads/lib/src/ads_request.dart +++ b/packages/interactive_media_ads/lib/src/ads_request.dart @@ -7,14 +7,57 @@ import 'platform_interface/platform_interface.dart'; /// An object containing the data used to request ads from the server. class AdsRequest { - /// Creates an [AdsRequest]. + /// Creates an [AdsRequest] with the given ad tag URL. AdsRequest({ required String adTagUrl, ContentProgressProvider? contentProgressProvider, + bool? adWillAutoPlay, + bool? adWillPlayMuted, + bool? continuousPlayback, + Duration? contentDuration, + List? contentKeywords, + String? contentTitle, + Duration? liveStreamPrefetchMaxWaitTime, + Duration? vastLoadTimeout, }) : this.fromPlatform( - PlatformAdsRequest( + PlatformAdsRequest.withAdTagUrl( adTagUrl: adTagUrl, contentProgressProvider: contentProgressProvider?.platform, + adWillAutoPlay: adWillAutoPlay, + adWillPlayMuted: adWillPlayMuted, + continuousPlayback: continuousPlayback, + contentDuration: contentDuration, + contentKeywords: contentKeywords, + contentTitle: contentTitle, + liveStreamPrefetchMaxWaitTime: liveStreamPrefetchMaxWaitTime, + vastLoadTimeout: vastLoadTimeout, + ), + ); + + /// Creates an [AdsRequest] with the given canned ads response. + AdsRequest.withAdsResponse({ + required String adsResponse, + ContentProgressProvider? contentProgressProvider, + bool? adWillAutoPlay, + bool? adWillPlayMuted, + bool? continuousPlayback, + Duration? contentDuration, + List? contentKeywords, + String? contentTitle, + Duration? liveStreamPrefetchMaxWaitTime, + Duration? vastLoadTimeout, + }) : this.fromPlatform( + PlatformAdsRequest.withAdsResponse( + adsResponse: adsResponse, + contentProgressProvider: contentProgressProvider?.platform, + adWillAutoPlay: adWillAutoPlay, + adWillPlayMuted: adWillPlayMuted, + continuousPlayback: continuousPlayback, + contentDuration: contentDuration, + contentKeywords: contentKeywords, + contentTitle: contentTitle, + liveStreamPrefetchMaxWaitTime: liveStreamPrefetchMaxWaitTime, + vastLoadTimeout: vastLoadTimeout, ), ); @@ -25,7 +68,20 @@ class AdsRequest { final PlatformAdsRequest platform; /// The URL from which ads will be requested. - String get adTagUrl => platform.adTagUrl; + String get adTagUrl => switch (platform) { + final PlatformAdsRequestWithAdTagUrl request => request.adTagUrl, + // TODO(bparrishMines): This returns an empty string rather than null + // to prevent a breaking change. This should be updated to return null + // on the next major release. + PlatformAdsRequestWithAdsResponse() => '', + }; + + /// Specifies a VAST, VMAP, or ad rules response to be used instead of making + /// a request through an ad tag URL. + String? get adsResponse => switch (platform) { + final PlatformAdsRequestWithAdsResponse request => request.adsResponse, + PlatformAdsRequestWithAdTagUrl() => null, + }; /// A [ContentProgressProvider] instance to allow scheduling of ad breaks /// based on content progress (cue points). @@ -34,4 +90,33 @@ class AdsRequest { null ? ContentProgressProvider.fromPlatform(platform.contentProgressProvider!) : null; + + /// Notifies the SDK whether the player intends to start the content and ad in + /// response to a user action or whether it will be automatically played. + bool? get adWillAutoPlay => platform.adWillAutoPlay; + + /// Notifies the SDK whether the player intends to start the content and ad + /// while muted. + bool? get adWillPlayMuted => platform.adWillPlayMuted; + + /// Notifies the SDK whether the player intends to continuously play the + /// content videos one after another similar to TV broadcast. + bool? get continuousPlayback => platform.continuousPlayback; + + /// Specifies the duration of the content to be shown. + Duration? get contentDuration => platform.contentDuration; + + /// Specifies the keywords used to describe the content to be shown. + List? get contentKeywords => platform.contentKeywords; + + /// Specifies the title of the content to be shown. + String? get contentTitle => platform.contentTitle; + + /// Specifies the maximum amount of time to wait, after calling requestAds, + /// before requesting the ad tag URL. + Duration? get liveStreamPrefetchMaxWaitTime => + platform.liveStreamPrefetchMaxWaitTime; + + /// Specifies the VAST load timeout in milliseconds for a single wrapper. + Duration? get vastLoadTimeout => platform.vastLoadTimeout; } diff --git a/packages/interactive_media_ads/lib/src/android/android_ads_loader.dart b/packages/interactive_media_ads/lib/src/android/android_ads_loader.dart index b0e0902f086d..7969893cd690 100644 --- a/packages/interactive_media_ads/lib/src/android/android_ads_loader.dart +++ b/packages/interactive_media_ads/lib/src/android/android_ads_loader.dart @@ -89,10 +89,36 @@ base class AndroidAdsLoader extends PlatformAdsLoader { final ima.AdsRequest androidRequest = await _sdkFactory.createAdsRequest(); await Future.wait(>[ - androidRequest.setAdTagUrl(request.adTagUrl), - if (request.contentProgressProvider != null) + if (request case final PlatformAdsRequestWithAdTagUrl request) + androidRequest.setAdTagUrl(request.adTagUrl), + if (request case final PlatformAdsRequestWithAdsResponse request) + androidRequest.setAdTagUrl(request.adsResponse), + if (request.adWillAutoPlay case final bool adWillAutoPlay) + androidRequest.setAdWillAutoPlay(adWillAutoPlay), + if (request.adWillPlayMuted case final bool adWillPlayMuted) + androidRequest.setAdWillPlayMuted(adWillPlayMuted), + if (request.continuousPlayback case final bool continuousPlayback) + androidRequest.setContinuousPlayback(continuousPlayback), + if (request.contentDuration case final Duration contentDuration) + androidRequest.setContentDuration( + contentDuration.inMilliseconds / Duration.millisecondsPerSecond), + if (request.contentKeywords case final List contentKeywords) + androidRequest.setContentKeywords(contentKeywords), + if (request.contentTitle case final String contentTitle) + androidRequest.setContentTitle(contentTitle), + if (request.liveStreamPrefetchMaxWaitTime + case final Duration liveStreamPrefetchMaxWaitTime) + androidRequest.setLiveStreamPrefetchSeconds( + liveStreamPrefetchMaxWaitTime.inMilliseconds / + Duration.millisecondsPerSecond, + ), + if (request.vastLoadTimeout case final Duration vastLoadTimeout) + androidRequest + .setVastLoadTimeout(vastLoadTimeout.inMilliseconds.toDouble()), + if (request.contentProgressProvider + case final PlatformContentProgressProvider contentProgressProvider) androidRequest.setContentProgressProvider( - (request.contentProgressProvider! as AndroidContentProgressProvider) + (contentProgressProvider as AndroidContentProgressProvider) .progressProvider, ), adsLoader.requestAds(androidRequest), diff --git a/packages/interactive_media_ads/lib/src/ios/ios_ads_loader.dart b/packages/interactive_media_ads/lib/src/ios/ios_ads_loader.dart index 276faead7cf9..5fbca3d22929 100644 --- a/packages/interactive_media_ads/lib/src/ios/ios_ads_loader.dart +++ b/packages/interactive_media_ads/lib/src/ios/ios_ads_loader.dart @@ -73,16 +73,55 @@ base class IOSAdsLoader extends PlatformAdsLoader { } @override - Future requestAds(PlatformAdsRequest request) async { - return _adsLoader.requestAds(_iosParams._proxy.newIMAAdsRequest( - adTagUrl: request.adTagUrl, - adDisplayContainer: - (_iosParams.container as IOSAdDisplayContainer).adDisplayContainer!, - contentPlayhead: request.contentProgressProvider != null - ? (request.contentProgressProvider! as IOSContentProgressProvider) - .contentPlayhead - : null, - )); + Future requestAds(PlatformAdsRequest request) { + final IMAAdDisplayContainer adDisplayContainer = + (_iosParams.container as IOSAdDisplayContainer).adDisplayContainer!; + final IMAContentPlayhead? contentProgressProvider = + request.contentProgressProvider != null + ? (request.contentProgressProvider! as IOSContentProgressProvider) + .contentPlayhead + : null; + + final IMAAdsRequest adsRequest = switch (request) { + final PlatformAdsRequestWithAdTagUrl request => IMAAdsRequest( + adTagUrl: request.adTagUrl, + adDisplayContainer: adDisplayContainer, + contentPlayhead: contentProgressProvider, + ), + PlatformAdsRequestWithAdsResponse() => IMAAdsRequest.withAdsResponse( + adsResponse: request.adsResponse, + adDisplayContainer: adDisplayContainer, + contentPlayhead: contentProgressProvider, + ), + }; + + return Future.wait(>[ + if (request.adWillAutoPlay case final bool adWillAutoPlay) + adsRequest.setAdWillAutoPlay(adWillAutoPlay), + if (request.adWillPlayMuted case final bool adWillPlayMuted) + adsRequest.setAdWillPlayMuted(adWillPlayMuted), + if (request.continuousPlayback case final bool continuousPlayback) + adsRequest.setContinuousPlayback(continuousPlayback), + if (request.contentDuration case final Duration contentDuration) + adsRequest.setContentDuration( + contentDuration.inMilliseconds / Duration.millisecondsPerSecond, + ), + if (request.contentKeywords case final List contentKeywords) + adsRequest.setContentKeywords(contentKeywords), + if (request.contentTitle case final String contentTitle) + adsRequest.setContentTitle(contentTitle), + if (request.liveStreamPrefetchMaxWaitTime + case final Duration liveStreamPrefetchMaxWaitTime) + adsRequest.setLiveStreamPrefetchSeconds( + liveStreamPrefetchMaxWaitTime.inMilliseconds / + Duration.millisecondsPerSecond, + ), + if (request.vastLoadTimeout case final Duration vastLoadTimeout) + adsRequest.setVastLoadTimeout( + vastLoadTimeout.inMilliseconds.toDouble(), + ), + _adsLoader.requestAds(adsRequest), + ]); } // This value is created in a static method because the callback methods for diff --git a/packages/interactive_media_ads/lib/src/platform_interface/platform_ads_request.dart b/packages/interactive_media_ads/lib/src/platform_interface/platform_ads_request.dart index b9ef51b0ec8c..2bf8605d3cc4 100644 --- a/packages/interactive_media_ads/lib/src/platform_interface/platform_ads_request.dart +++ b/packages/interactive_media_ads/lib/src/platform_interface/platform_ads_request.dart @@ -5,17 +5,143 @@ import 'platform_content_progress_provider.dart'; /// An object containing the data used to request ads from the server. -class PlatformAdsRequest { - /// Creates an [PlatformAdsRequest]. - PlatformAdsRequest({ - required this.adTagUrl, +sealed class PlatformAdsRequest { + PlatformAdsRequest._({ this.contentProgressProvider, + this.adWillAutoPlay, + this.adWillPlayMuted, + this.continuousPlayback, + this.contentDuration, + this.contentKeywords, + this.contentTitle, + this.liveStreamPrefetchMaxWaitTime, + this.vastLoadTimeout, }); - /// The URL from which ads will be requested. - final String adTagUrl; + /// Creates a [PlatformAdsRequest] with the given ad tag URL. + factory PlatformAdsRequest.withAdTagUrl({ + required String adTagUrl, + PlatformContentProgressProvider? contentProgressProvider, + bool? adWillAutoPlay, + bool? adWillPlayMuted, + bool? continuousPlayback, + Duration? contentDuration, + List? contentKeywords, + String? contentTitle, + Duration? liveStreamPrefetchMaxWaitTime, + Duration? vastLoadTimeout, + }) => + PlatformAdsRequestWithAdTagUrl._( + adTagUrl: adTagUrl, + contentProgressProvider: contentProgressProvider, + adWillAutoPlay: adWillAutoPlay, + adWillPlayMuted: adWillPlayMuted, + continuousPlayback: continuousPlayback, + contentDuration: contentDuration, + contentKeywords: contentKeywords, + contentTitle: contentTitle, + liveStreamPrefetchMaxWaitTime: liveStreamPrefetchMaxWaitTime, + vastLoadTimeout: vastLoadTimeout, + ); + + /// Creates a [PlatformAdsRequest] with the given canned ads response. + factory PlatformAdsRequest.withAdsResponse({ + required String adsResponse, + PlatformContentProgressProvider? contentProgressProvider, + bool? adWillAutoPlay, + bool? adWillPlayMuted, + bool? continuousPlayback, + Duration? contentDuration, + List? contentKeywords, + String? contentTitle, + Duration? liveStreamPrefetchMaxWaitTime, + Duration? vastLoadTimeout, + }) => + PlatformAdsRequestWithAdsResponse._( + adsResponse: adsResponse, + contentProgressProvider: contentProgressProvider, + adWillAutoPlay: adWillAutoPlay, + adWillPlayMuted: adWillPlayMuted, + continuousPlayback: continuousPlayback, + contentDuration: contentDuration, + contentKeywords: contentKeywords, + contentTitle: contentTitle, + liveStreamPrefetchMaxWaitTime: liveStreamPrefetchMaxWaitTime, + vastLoadTimeout: vastLoadTimeout, + ); /// A [PlatformContentProgressProvider] instance to allow scheduling of ad /// breaks based on content progress (cue points). final PlatformContentProgressProvider? contentProgressProvider; + + /// Notifies the SDK whether the player intends to start the content and ad in + /// response to a user action or whether it will be automatically played. + final bool? adWillAutoPlay; + + /// Notifies the SDK whether the player intends to start the content and ad + /// while muted. + final bool? adWillPlayMuted; + + /// Notifies the SDK whether the player intends to continuously play the + /// content videos one after another similar to TV broadcast. + final bool? continuousPlayback; + + /// Specifies the duration of the content to be shown. + final Duration? contentDuration; + + /// Specifies the keywords used to describe the content to be shown. + final List? contentKeywords; + + /// Specifies the title of the content to be shown. + final String? contentTitle; + + /// Specifies the maximum amount of time to wait, after calling requestAds, + /// before requesting the ad tag URL. + final Duration? liveStreamPrefetchMaxWaitTime; + + /// Specifies the VAST load timeout for a single wrapper. + final Duration? vastLoadTimeout; +} + +/// An object containing the data used to request ads from the server with an +/// ad tag URL. +base class PlatformAdsRequestWithAdTagUrl extends PlatformAdsRequest { + /// Constructs a [PlatformAdsRequestWithAdTagUrl]. + PlatformAdsRequestWithAdTagUrl._({ + required this.adTagUrl, + super.contentProgressProvider, + super.adWillAutoPlay, + super.adWillPlayMuted, + super.continuousPlayback, + super.contentDuration, + super.contentKeywords, + super.contentTitle, + super.liveStreamPrefetchMaxWaitTime, + super.vastLoadTimeout, + }) : super._(); + + /// The URL from which ads will be requested. + final String adTagUrl; +} + +/// An object containing the data used to request ads from the server with an +/// ad rules response. +base class PlatformAdsRequestWithAdsResponse extends PlatformAdsRequest { + /// Constructs a [PlatformAdsRequestWithAdsResponse]. + PlatformAdsRequestWithAdsResponse._({ + required this.adsResponse, + super.contentProgressProvider, + super.adWillAutoPlay, + super.adWillPlayMuted, + super.continuousPlayback, + super.contentDuration, + super.contentKeywords, + super.contentTitle, + super.liveStreamPrefetchMaxWaitTime, + super.vastLoadTimeout, + }) : super._(); + + /// Specifies a VAST, VMAP, or ad rules response to be used instead of making + /// a request through an ad tag URL. + final String adsResponse; } diff --git a/packages/interactive_media_ads/pubspec.yaml b/packages/interactive_media_ads/pubspec.yaml index 5996d4391d45..5215dce3ee49 100644 --- a/packages/interactive_media_ads/pubspec.yaml +++ b/packages/interactive_media_ads/pubspec.yaml @@ -2,7 +2,7 @@ name: interactive_media_ads description: A Flutter plugin for using the Interactive Media Ads SDKs on Android and iOS. repository: https://github.com/flutter/packages/tree/main/packages/interactive_media_ads issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+interactive_media_ads%22 -version: 0.2.5+1 # This must match the version in +version: 0.2.6 # This must match the version in # `android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt` and # `ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift` diff --git a/packages/interactive_media_ads/test/ads_loader_test.dart b/packages/interactive_media_ads/test/ads_loader_test.dart index 736895a8f8a7..2eb2d4bd1667 100644 --- a/packages/interactive_media_ads/test/ads_loader_test.dart +++ b/packages/interactive_media_ads/test/ads_loader_test.dart @@ -27,8 +27,16 @@ void main() { }); test('requestAds', () async { - final PlatformAdsRequest platformRequest = PlatformAdsRequest( + final PlatformAdsRequest platformRequest = PlatformAdsRequest.withAdTagUrl( adTagUrl: 'adTagUrl', + adWillAutoPlay: true, + adWillPlayMuted: false, + continuousPlayback: true, + contentDuration: const Duration(seconds: 2), + contentKeywords: ['keyword1', 'keyword2'], + contentTitle: 'contentTitle', + liveStreamPrefetchMaxWaitTime: const Duration(seconds: 3), + vastLoadTimeout: const Duration(milliseconds: 5000), contentProgressProvider: TestContentProgressProvider( const PlatformContentProgressProviderCreationParams(), ), @@ -42,13 +50,45 @@ void main() { onAdsLoadError: (AdsLoadErrorData data) {}, ), onRequestAds: expectAsync1((PlatformAdsRequest request) async { - expect(request, platformRequest); + expect( + (request as PlatformAdsRequestWithAdTagUrl).adTagUrl, + (platformRequest as PlatformAdsRequestWithAdTagUrl).adTagUrl, + ); + expect(request.adWillAutoPlay, platformRequest.adWillAutoPlay); + expect(request.adWillPlayMuted, platformRequest.adWillPlayMuted); + expect(request.continuousPlayback, platformRequest.continuousPlayback); + expect(request.contentDuration, platformRequest.contentDuration); + expect(request.contentKeywords, platformRequest.contentKeywords); + expect(request.contentTitle, platformRequest.contentTitle); + expect( + request.liveStreamPrefetchMaxWaitTime, + platformRequest.liveStreamPrefetchMaxWaitTime, + ); + expect(request.vastLoadTimeout, platformRequest.vastLoadTimeout); + expect( + request.contentProgressProvider, + platformRequest.contentProgressProvider, + ); }), onContentComplete: () async {}, ); final AdsLoader loader = AdsLoader.fromPlatform(adsLoader); - await loader.requestAds(AdsRequest.fromPlatform(platformRequest)); + await loader.requestAds(AdsRequest( + adTagUrl: (platformRequest as PlatformAdsRequestWithAdTagUrl).adTagUrl, + adWillAutoPlay: platformRequest.adWillAutoPlay, + adWillPlayMuted: platformRequest.adWillPlayMuted, + continuousPlayback: platformRequest.continuousPlayback, + contentDuration: platformRequest.contentDuration, + contentKeywords: platformRequest.contentKeywords, + contentTitle: platformRequest.contentTitle, + liveStreamPrefetchMaxWaitTime: + platformRequest.liveStreamPrefetchMaxWaitTime, + vastLoadTimeout: platformRequest.vastLoadTimeout, + contentProgressProvider: ContentProgressProvider.fromPlatform( + platformRequest.contentProgressProvider!, + ), + )); }); } diff --git a/packages/interactive_media_ads/test/android/ads_loader_test.dart b/packages/interactive_media_ads/test/android/ads_loader_test.dart index 084ad3edef3a..a721a40ba0d2 100644 --- a/packages/interactive_media_ads/test/android/ads_loader_test.dart +++ b/packages/interactive_media_ads/test/android/ads_loader_test.dart @@ -133,14 +133,30 @@ void main() { AndroidContentProgressProviderCreationParams(proxy: proxy), ); await adsLoader.requestAds( - PlatformAdsRequest( + PlatformAdsRequest.withAdTagUrl( adTagUrl: 'url', + adWillAutoPlay: true, + adWillPlayMuted: false, + continuousPlayback: true, + contentDuration: const Duration(seconds: 2), + contentKeywords: ['keyword1', 'keyword2'], + contentTitle: 'contentTitle', + liveStreamPrefetchMaxWaitTime: const Duration(seconds: 3), + vastLoadTimeout: const Duration(milliseconds: 5000), contentProgressProvider: progressProvider, ), ); verifyInOrder(>[ mockAdsRequest.setAdTagUrl('url'), + mockAdsRequest.setAdWillAutoPlay(true), + mockAdsRequest.setAdWillPlayMuted(false), + mockAdsRequest.setContinuousPlayback(true), + mockAdsRequest.setContentDuration(2.0), + mockAdsRequest.setContentKeywords(['keyword1', 'keyword2']), + mockAdsRequest.setContentTitle('contentTitle'), + mockAdsRequest.setLiveStreamPrefetchSeconds(3.0), + mockAdsRequest.setVastLoadTimeout(5000.0), mockAdsRequest.setContentProgressProvider( progressProvider.progressProvider, ), diff --git a/packages/interactive_media_ads/test/android/ads_loader_test.mocks.dart b/packages/interactive_media_ads/test/android/ads_loader_test.mocks.dart index b5375b6e5e58..beb7cf9d8e44 100644 --- a/packages/interactive_media_ads/test/android/ads_loader_test.mocks.dart +++ b/packages/interactive_media_ads/test/android/ads_loader_test.mocks.dart @@ -918,6 +918,101 @@ class MockAdsRequest extends _i1.Mock implements _i2.AdsRequest { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i5.Future setAdWillAutoPlay(bool? willAutoPlay) => (super.noSuchMethod( + Invocation.method( + #setAdWillAutoPlay, + [willAutoPlay], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setAdWillPlayMuted(bool? willPlayMuted) => + (super.noSuchMethod( + Invocation.method( + #setAdWillPlayMuted, + [willPlayMuted], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setAdsResponse(String? cannedAdResponse) => + (super.noSuchMethod( + Invocation.method( + #setAdsResponse, + [cannedAdResponse], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setContentDuration(double? duration) => (super.noSuchMethod( + Invocation.method( + #setContentDuration, + [duration], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setContentKeywords(List? keywords) => + (super.noSuchMethod( + Invocation.method( + #setContentKeywords, + [keywords], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setContentTitle(String? title) => (super.noSuchMethod( + Invocation.method( + #setContentTitle, + [title], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setContinuousPlayback(bool? continuousPlayback) => + (super.noSuchMethod( + Invocation.method( + #setContinuousPlayback, + [continuousPlayback], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setLiveStreamPrefetchSeconds(double? prefetchTime) => + (super.noSuchMethod( + Invocation.method( + #setLiveStreamPrefetchSeconds, + [prefetchTime], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setVastLoadTimeout(double? timeout) => (super.noSuchMethod( + Invocation.method( + #setVastLoadTimeout, + [timeout], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + @override _i2.AdsRequest pigeon_copy() => (super.noSuchMethod( Invocation.method( diff --git a/packages/interactive_media_ads/test/ios/ads_loader_test.dart b/packages/interactive_media_ads/test/ios/ads_loader_test.dart index 812878726d8d..ae96c774539c 100644 --- a/packages/interactive_media_ads/test/ios/ads_loader_test.dart +++ b/packages/interactive_media_ads/test/ios/ads_loader_test.dart @@ -85,21 +85,23 @@ void main() { final MockIMAAdsLoader mockLoader = MockIMAAdsLoader(); final ima.IMAContentPlayhead contentPlayheadInstance = ima.IMAContentPlayhead(); + final MockIMAAdsRequest mockRequest = MockIMAAdsRequest(); final InteractiveMediaAdsProxy imaProxy = InteractiveMediaAdsProxy( newIMAAdsLoader: ({ima.IMASettings? settings}) => mockLoader, - newIMAAdsRequest: ({ - required String adTagUrl, - required ima.IMAAdDisplayContainer adDisplayContainer, - ima.IMAContentPlayhead? contentPlayhead, - }) { - expect(adTagUrl, adTag); - expect(adDisplayContainer, container.adDisplayContainer); - expect(contentPlayhead, contentPlayheadInstance); - return MockIMAAdsRequest(); - }, newIMAContentPlayhead: () => contentPlayheadInstance, ); + ima.PigeonOverrides.iMAAdsRequest_new = ({ + required String adTagUrl, + required ima.IMAAdDisplayContainer adDisplayContainer, + ima.IMAContentPlayhead? contentPlayhead, + }) { + expect(adTagUrl, adTag); + expect(adDisplayContainer, container.adDisplayContainer); + expect(contentPlayhead, contentPlayheadInstance); + return mockRequest; + }; + final IOSAdsLoader loader = IOSAdsLoader( IOSAdsLoaderCreationParams( container: container, @@ -114,11 +116,28 @@ void main() { IOSContentProgressProviderCreationParams(proxy: imaProxy), ); - await loader.requestAds(PlatformAdsRequest( + await loader.requestAds(PlatformAdsRequest.withAdTagUrl( adTagUrl: adTag, + adWillAutoPlay: true, + adWillPlayMuted: false, + continuousPlayback: true, + contentDuration: const Duration(seconds: 2), + contentKeywords: ['keyword1', 'keyword2'], + contentTitle: 'contentTitle', + liveStreamPrefetchMaxWaitTime: const Duration(seconds: 3), + vastLoadTimeout: const Duration(milliseconds: 5000), contentProgressProvider: provider, )); + verify(mockRequest.setAdWillAutoPlay(true)); + verify(mockRequest.setAdWillPlayMuted(false)); + verify(mockRequest.setContinuousPlayback(true)); + verify(mockRequest.setContentDuration(2.0)); + verify(mockRequest.setContentKeywords(['keyword1', 'keyword2'])); + verify(mockRequest.setContentTitle('contentTitle')); + verify(mockRequest.setLiveStreamPrefetchSeconds(3.0)); + verify(mockRequest.setVastLoadTimeout(5000.0)); + verify(mockLoader.requestAds(any)); }); diff --git a/packages/interactive_media_ads/test/ios/ads_loader_test.mocks.dart b/packages/interactive_media_ads/test/ios/ads_loader_test.mocks.dart index 0976c9b8e419..f847c4e50f47 100644 --- a/packages/interactive_media_ads/test/ios/ads_loader_test.mocks.dart +++ b/packages/interactive_media_ads/test/ios/ads_loader_test.mocks.dart @@ -515,6 +515,146 @@ class MockIMAAdsRequest extends _i1.Mock implements _i2.IMAAdsRequest { ), ) as _i2.PigeonInstanceManager); + @override + _i3.Future getAdTagUrl() => (super.noSuchMethod( + Invocation.method( + #getAdTagUrl, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future getAdsResponse() => (super.noSuchMethod( + Invocation.method( + #getAdsResponse, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future<_i2.IMAAdDisplayContainer> getAdDisplayContainer() => + (super.noSuchMethod( + Invocation.method( + #getAdDisplayContainer, + [], + ), + returnValue: _i3.Future<_i2.IMAAdDisplayContainer>.value( + _FakeIMAAdDisplayContainer_2( + this, + Invocation.method( + #getAdDisplayContainer, + [], + ), + )), + returnValueForMissingStub: _i3.Future<_i2.IMAAdDisplayContainer>.value( + _FakeIMAAdDisplayContainer_2( + this, + Invocation.method( + #getAdDisplayContainer, + [], + ), + )), + ) as _i3.Future<_i2.IMAAdDisplayContainer>); + + @override + _i3.Future setAdWillAutoPlay(bool? adWillAutoPlay) => + (super.noSuchMethod( + Invocation.method( + #setAdWillAutoPlay, + [adWillAutoPlay], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setAdWillPlayMuted(bool? adWillPlayMuted) => + (super.noSuchMethod( + Invocation.method( + #setAdWillPlayMuted, + [adWillPlayMuted], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContinuousPlayback(bool? continuousPlayback) => + (super.noSuchMethod( + Invocation.method( + #setContinuousPlayback, + [continuousPlayback], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContentDuration(double? duration) => (super.noSuchMethod( + Invocation.method( + #setContentDuration, + [duration], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContentKeywords(List? keywords) => + (super.noSuchMethod( + Invocation.method( + #setContentKeywords, + [keywords], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContentTitle(String? title) => (super.noSuchMethod( + Invocation.method( + #setContentTitle, + [title], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContentURL(String? contentURL) => (super.noSuchMethod( + Invocation.method( + #setContentURL, + [contentURL], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setVastLoadTimeout(double? timeout) => (super.noSuchMethod( + Invocation.method( + #setVastLoadTimeout, + [timeout], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setLiveStreamPrefetchSeconds(double? seconds) => + (super.noSuchMethod( + Invocation.method( + #setLiveStreamPrefetchSeconds, + [seconds], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + @override _i2.IMAAdsRequest pigeon_copy() => (super.noSuchMethod( Invocation.method(