@@ -59,22 +59,12 @@ void main() {
5959 PatrolIntegrationTester $,
6060 ) async {
6161 final Completer <void > hasArrived = Completer <void >();
62+ final Completer <void > newSessionFired = Completer <void >();
6263
6364 /// Set up navigation view and controller.
6465 final GoogleNavigationViewController viewController =
6566 await startNavigationWithoutDestination ($);
6667
67- /// Set audio guidance settings.
68- /// Cannot be verified, because native SDK lacks getter methods,
69- /// but exercise the API for basic sanity testing
70- final NavigationAudioGuidanceSettings settings =
71- NavigationAudioGuidanceSettings (
72- isBluetoothAudioEnabled: true ,
73- isVibrationEnabled: true ,
74- guidanceType: NavigationAudioGuidanceType .alertsAndGuidance,
75- );
76- await GoogleMapsNavigator .setAudioGuidance (settings);
77-
7868 /// Specify tolerance and navigation end coordinates.
7969 const double tolerance = 0.001 ;
8070 const double endLat = 68.59451829688189 , endLng = 23.512277951523007 ;
@@ -86,8 +76,28 @@ void main() {
8676 await GoogleMapsNavigator .stopGuidance ();
8777 }
8878
79+ /// Set up listener for new navigation session event.
80+ Future <void > onNewNavigationSession () async {
81+ newSessionFired.complete ();
82+
83+ /// Sets audio guidance settings for the current navigation session.
84+ /// Cannot be verified, because native SDK lacks getter methods,
85+ /// but exercise the API for basic sanity testing.
86+ await GoogleMapsNavigator .setAudioGuidance (
87+ NavigationAudioGuidanceSettings (
88+ isBluetoothAudioEnabled: true ,
89+ isVibrationEnabled: true ,
90+ guidanceType: NavigationAudioGuidanceType .alertsAndGuidance,
91+ ),
92+ );
93+ }
94+
8995 final StreamSubscription <OnArrivalEvent > onArrivalSubscription =
9096 GoogleMapsNavigator .setOnArrivalListener (onArrivalEvent);
97+ final StreamSubscription <void > onNewNavigationSessionSubscription =
98+ GoogleMapsNavigator .setOnNewNavigationSessionListener (
99+ onNewNavigationSession,
100+ );
91101
92102 /// Simulate location and test it.
93103 await setSimulatedUserLocationWithCheck (
@@ -143,11 +153,24 @@ void main() {
143153 await GoogleMapsNavigator .simulator.simulateLocationsAlongExistingRoute ();
144154
145155 expect (await GoogleMapsNavigator .isGuidanceRunning (), true );
156+
157+ /// Wait for new navigation session event.
158+ await newSessionFired.future.timeout (
159+ const Duration (seconds: 30 ),
160+ onTimeout:
161+ () =>
162+ throw TimeoutException (
163+ 'New navigation session event was not fired' ,
164+ ),
165+ );
166+ expect (newSessionFired.isCompleted, true );
167+
146168 await hasArrived.future;
147169 expect (await GoogleMapsNavigator .isGuidanceRunning (), false );
148170
149171 // Cancel subscriptions before cleanup
150172 await onArrivalSubscription.cancel ();
173+ await onNewNavigationSessionSubscription.cancel ();
151174 await roadSnappedSubscription.cancel ();
152175 await GoogleMapsNavigator .cleanup ();
153176 });
@@ -156,24 +179,14 @@ void main() {
156179 'Test navigating to multiple destinations' ,
157180 (PatrolIntegrationTester $) async {
158181 final Completer <void > navigationFinished = Completer <void >();
182+ Completer <void > newSessionFired = Completer <void >();
159183 int arrivalEventCount = 0 ;
160184 List <NavigationWaypoint > waypoints = < NavigationWaypoint > [];
161185
162186 /// Set up navigation view and controller.
163187 final GoogleNavigationViewController viewController =
164188 await startNavigationWithoutDestination ($);
165189
166- /// Set audio guidance settings.
167- /// Cannot be verified, because native SDK lacks getter methods,
168- /// but exercise the API for basic sanity testing
169- final NavigationAudioGuidanceSettings settings =
170- NavigationAudioGuidanceSettings (
171- isBluetoothAudioEnabled: false ,
172- isVibrationEnabled: false ,
173- guidanceType: NavigationAudioGuidanceType .alertsOnly,
174- );
175- await GoogleMapsNavigator .setAudioGuidance (settings);
176-
177190 /// Specify tolerance and navigation destination coordinates.
178191 const double tolerance = 0.001 ;
179192 const double midLat = 68.59781164189049 ,
@@ -184,6 +197,9 @@ void main() {
184197 Future <void > onArrivalEvent (OnArrivalEvent msg) async {
185198 arrivalEventCount += 1 ;
186199 if (arrivalEventCount < 2 ) {
200+ // Reset the completer to test that new session event fires again
201+ newSessionFired = Completer <void >();
202+
187203 if (multipleDestinationsVariants.currentValue ==
188204 'continueToNextDestination' ) {
189205 // Note: continueToNextDestination is deprecated.
@@ -220,12 +236,23 @@ void main() {
220236 ),
221237 );
222238 await GoogleMapsNavigator .setDestinations (updatedDestinations);
239+
223240 await GoogleMapsNavigator .simulator
224241 .simulateLocationsAlongExistingRouteWithOptions (
225242 SimulationOptions (speedMultiplier: 5 ),
226243 );
227244 }
228245 }
246+
247+ // Wait for new session event after updating destinations
248+ await newSessionFired.future.timeout (
249+ const Duration (seconds: 10 ),
250+ onTimeout:
251+ () =>
252+ throw TimeoutException (
253+ 'New navigation session event was not fired after updating destinations' ,
254+ ),
255+ );
229256 } else {
230257 $.log ('Got second arrival event, stopping guidance' );
231258 // Stop guidance after the last destination
@@ -234,8 +261,28 @@ void main() {
234261 }
235262 }
236263
264+ /// Set up listener for new navigation session event.
265+ Future <void > onNewNavigationSession () async {
266+ newSessionFired.complete ();
267+
268+ /// Sets audio guidance settings for the current navigation session.
269+ /// Cannot be verified, because native SDK lacks getter methods,
270+ /// but exercise the API for basic sanity testing.
271+ await GoogleMapsNavigator .setAudioGuidance (
272+ NavigationAudioGuidanceSettings (
273+ isBluetoothAudioEnabled: true ,
274+ isVibrationEnabled: true ,
275+ guidanceType: NavigationAudioGuidanceType .alertsAndGuidance,
276+ ),
277+ );
278+ }
279+
237280 final StreamSubscription <OnArrivalEvent > onArrivalSubscription =
238281 GoogleMapsNavigator .setOnArrivalListener (onArrivalEvent);
282+ final StreamSubscription <void > onNewNavigationSessionSubscription =
283+ GoogleMapsNavigator .setOnNewNavigationSessionListener (
284+ onNewNavigationSession,
285+ );
239286
240287 /// Simulate location and test it.
241288 await setSimulatedUserLocationWithCheck (
@@ -317,11 +364,24 @@ void main() {
317364 );
318365
319366 expect (await GoogleMapsNavigator .isGuidanceRunning (), true );
367+
368+ /// Wait for new navigation session event.
369+ await newSessionFired.future.timeout (
370+ const Duration (seconds: 30 ),
371+ onTimeout:
372+ () =>
373+ throw TimeoutException (
374+ 'New navigation session event was not fired' ,
375+ ),
376+ );
377+ expect (newSessionFired.isCompleted, true );
378+
320379 await navigationFinished.future;
321380 expect (await GoogleMapsNavigator .isGuidanceRunning (), false );
322381
323382 // Cancel subscriptions before cleanup
324383 await onArrivalSubscription.cancel ();
384+ await onNewNavigationSessionSubscription.cancel ();
325385 await roadSnappedSubscription.cancel ();
326386 await GoogleMapsNavigator .cleanup ();
327387 },
0 commit comments