1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app.sdksandbox;
18 
19 import static android.app.sdksandbox.SandboxLatencyInfo.RESULT_CODE_LOAD_SDK_NOT_FOUND;
20 import static android.app.sdksandbox.SandboxLatencyInfo.RESULT_CODE_UNSPECIFIED;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.os.Parcel;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
29 
30 /** Tests {@link SandboxLatencyInfo} APIs. */
31 @RunWith(JUnit4.class)
32 public class SandboxLatencyInfoUnitTest {
33 
34     private static final long TIME_APP_CALLED_SYSTEM_SERVER = 1;
35     private static final long TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_APP = 2;
36     private static final long TIME_LOAD_SANDBOX_STARTED = 3;
37     private static final long TIME_SANDBOX_LOADED = 4;
38     private static final long TIME_SYSTEM_SERVER_CALL_FINISHED = 5;
39     private static final long TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER = 6;
40     private static final long TIME_SANDBOX_CALLED_SDK = 7;
41     private static final long TIME_SDK_CALL_COMPLETED = 8;
42     private static final long TIME_SANDBOX_CALLED_SYSTEM_SERVER = 9;
43     private static final long TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_SANDBOX = 10;
44     private static final long TIME_SYSTEM_SERVER_CALLED_APP = 11;
45     private static final long TIME_APP_RECEIVED_CALL_FROM_SYSTEM_SERVER = 12;
46 
47     @Test
testDescribeContents()48     public void testDescribeContents() {
49         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
50         assertThat(sandboxLatencyInfo.describeContents()).isEqualTo(0);
51     }
52 
53     @Test
testIsParcelable()54     public void testIsParcelable() {
55         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
56         Parcel sandboxLatencyInfoParcel = Parcel.obtain();
57         sandboxLatencyInfo.writeToParcel(sandboxLatencyInfoParcel, /*flags=*/ 0);
58 
59         sandboxLatencyInfoParcel.setDataPosition(0);
60         SandboxLatencyInfo sandboxLatencyInfoCreatedWithParcel =
61                 SandboxLatencyInfo.CREATOR.createFromParcel(sandboxLatencyInfoParcel);
62 
63         assertThat(sandboxLatencyInfo).isEqualTo(sandboxLatencyInfoCreatedWithParcel);
64     }
65 
66     @Test
testMethodIsSet()67     public void testMethodIsSet() {
68         SandboxLatencyInfo sandboxLatencyInfo =
69                 new SandboxLatencyInfo(SandboxLatencyInfo.METHOD_LOAD_SDK);
70         assertThat(sandboxLatencyInfo.getMethod()).isEqualTo(SandboxLatencyInfo.METHOD_LOAD_SDK);
71     }
72 
73     @Test
testMethodIsUnspecified()74     public void testMethodIsUnspecified() {
75         SandboxLatencyInfo sandboxLatencyInfo = new SandboxLatencyInfo();
76         assertThat(sandboxLatencyInfo.getMethod()).isEqualTo(SandboxLatencyInfo.METHOD_UNSPECIFIED);
77     }
78 
79     @Test
testGetAppToSystemServerLatency()80     public void testGetAppToSystemServerLatency() {
81         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
82         int appToSystemServerLatency =
83                 (int) (TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_APP - TIME_APP_CALLED_SYSTEM_SERVER);
84         assertThat(sandboxLatencyInfo.getAppToSystemServerLatency())
85                 .isEqualTo(appToSystemServerLatency);
86     }
87 
88     @Test
testGetSystemServerAppToSandboxLatency()89     public void testGetSystemServerAppToSandboxLatency() {
90         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
91         int systemServerAppToSandboxLatency =
92                 (int)
93                         (TIME_SYSTEM_SERVER_CALL_FINISHED
94                                 - TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_APP
95                                 - (TIME_SANDBOX_LOADED - TIME_LOAD_SANDBOX_STARTED));
96         assertThat(sandboxLatencyInfo.getSystemServerAppToSandboxLatency())
97                 .isEqualTo(systemServerAppToSandboxLatency);
98     }
99 
100     @Test
testGetLoadSandboxLatency()101     public void testGetLoadSandboxLatency() {
102         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
103         int loadSandboxLatency = (int) (TIME_SANDBOX_LOADED - TIME_LOAD_SANDBOX_STARTED);
104         assertThat(sandboxLatencyInfo.getLoadSandboxLatency()).isEqualTo(loadSandboxLatency);
105     }
106 
107     @Test
testGetSystemServerToSandboxLatency()108     public void testGetSystemServerToSandboxLatency() {
109         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
110         int systemServerToSandboxLatency =
111                 (int)
112                         (TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER
113                                 - TIME_SYSTEM_SERVER_CALL_FINISHED);
114         assertThat(sandboxLatencyInfo.getSystemServerToSandboxLatency())
115                 .isEqualTo(systemServerToSandboxLatency);
116     }
117 
118     @Test
testGetSandboxLatency()119     public void testGetSandboxLatency() {
120         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
121         int sdkLatency = (int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK);
122         int sandboxLatency =
123                 (int)
124                                 (TIME_SANDBOX_CALLED_SYSTEM_SERVER
125                                         - TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER)
126                         - sdkLatency;
127         assertThat(sandboxLatencyInfo.getSandboxLatency()).isEqualTo(sandboxLatency);
128     }
129 
130     @Test
testGetSandboxLatency_timeFieldsNotSetForSdk()131     public void testGetSandboxLatency_timeFieldsNotSetForSdk() {
132         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
133 
134         // Reset the values
135         sandboxLatencyInfo.setTimeSandboxCalledSdk(-1);
136         sandboxLatencyInfo.setTimeSdkCallCompleted(-1);
137 
138         int sandboxLatency =
139                 (int)
140                         (TIME_SANDBOX_CALLED_SYSTEM_SERVER
141                                 - TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER);
142 
143         assertThat(sandboxLatencyInfo.getSandboxLatency()).isEqualTo(sandboxLatency);
144     }
145 
146     @Test
testGetSdkLatency()147     public void testGetSdkLatency() {
148         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
149         int sdkLatency = (int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK);
150         assertThat(sandboxLatencyInfo.getSdkLatency()).isEqualTo(sdkLatency);
151     }
152 
153     @Test
testGetSdkLatency_timeFieldsNotSetForSdk()154     public void testGetSdkLatency_timeFieldsNotSetForSdk() {
155         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
156 
157         // Reset the values
158         sandboxLatencyInfo.setTimeSandboxCalledSdk(-1);
159         sandboxLatencyInfo.setTimeSdkCallCompleted(-1);
160 
161         assertThat(sandboxLatencyInfo.getSdkLatency()).isEqualTo(-1);
162     }
163 
164     @Test
testGetSandboxToSystemServerLatency()165     public void testGetSandboxToSystemServerLatency() {
166         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
167         int sandboxToSystemServerLatency =
168                 (int)
169                         (TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_SANDBOX
170                                 - TIME_SANDBOX_CALLED_SYSTEM_SERVER);
171         assertThat(sandboxLatencyInfo.getSandboxToSystemServerLatency())
172                 .isEqualTo(sandboxToSystemServerLatency);
173     }
174 
175     @Test
testGetSystemServerSandboxToAppLatency()176     public void testGetSystemServerSandboxToAppLatency() {
177         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
178         int systemServerSandboxToAppLatency =
179                 (int)
180                         (TIME_SYSTEM_SERVER_CALLED_APP
181                                 - TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_SANDBOX);
182         assertThat(sandboxLatencyInfo.getSystemServerSandboxToAppLatency())
183                 .isEqualTo(systemServerSandboxToAppLatency);
184     }
185 
186     @Test
testGetSystemServerToAppLatency()187     public void testGetSystemServerToAppLatency() {
188         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
189         int systemServerToAppLatency =
190                 (int) (TIME_APP_RECEIVED_CALL_FROM_SYSTEM_SERVER - TIME_SYSTEM_SERVER_CALLED_APP);
191         assertThat(sandboxLatencyInfo.getSystemServerToAppLatency())
192                 .isEqualTo(systemServerToAppLatency);
193     }
194 
195     @Test
testGetTotalCallLatency_finishesAtAppReceivedCallFromSystemServerStage()196     public void testGetTotalCallLatency_finishesAtAppReceivedCallFromSystemServerStage() {
197         SandboxLatencyInfo sandboxLatencyInfo =
198                 getSandboxLatencyObjectWithAllFieldsSet(SandboxLatencyInfo.METHOD_LOAD_SDK);
199         int totalCallLatency =
200                 (int) (TIME_APP_RECEIVED_CALL_FROM_SYSTEM_SERVER - TIME_APP_CALLED_SYSTEM_SERVER);
201 
202         assertThat(sandboxLatencyInfo.getTotalCallLatency()).isEqualTo(totalCallLatency);
203     }
204 
205     @Test
testGetTotalCallLatency_finishesAtSystemServerCalledSandboxStage()206     public void testGetTotalCallLatency_finishesAtSystemServerCalledSandboxStage() {
207         SandboxLatencyInfo sandboxLatencyInfo =
208                 getSandboxLatencyObjectWithAllFieldsSet(
209                         SandboxLatencyInfo.METHOD_GET_SANDBOXED_SDKS);
210         int totalCallLatency =
211                 (int) (TIME_SYSTEM_SERVER_CALL_FINISHED - TIME_APP_CALLED_SYSTEM_SERVER);
212 
213         assertThat(sandboxLatencyInfo.getTotalCallLatency()).isEqualTo(totalCallLatency);
214     }
215 
216     @Test
testGetTotalCallLatency_finishesAtSystemServerReceivedCallFromAppStage()217     public void testGetTotalCallLatency_finishesAtSystemServerReceivedCallFromAppStage() {
218         SandboxLatencyInfo sandboxLatencyInfo =
219                 getSandboxLatencyObjectWithAllFieldsSet(
220                         SandboxLatencyInfo.METHOD_SYNC_DATA_FROM_CLIENT);
221         int totalCallLatency =
222                 (int) (TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_APP - TIME_APP_CALLED_SYSTEM_SERVER);
223 
224         assertThat(sandboxLatencyInfo.getTotalCallLatency()).isEqualTo(totalCallLatency);
225     }
226 
227     @Test
testGetTotalCallLatency_finishesAtSystemServerCalledAppStage()228     public void testGetTotalCallLatency_finishesAtSystemServerCalledAppStage() {
229         SandboxLatencyInfo sandboxLatencyInfo =
230                 getSandboxLatencyObjectWithAllFieldsSet(SandboxLatencyInfo.METHOD_UNLOAD_SDK);
231         int totalCallLatency =
232                 (int) (TIME_SYSTEM_SERVER_CALLED_APP - TIME_APP_CALLED_SYSTEM_SERVER);
233 
234         assertThat(sandboxLatencyInfo.getTotalCallLatency()).isEqualTo(totalCallLatency);
235     }
236 
237     @Test
testSandboxStatus_isSuccessfulAtAppToSystemServer()238     public void testSandboxStatus_isSuccessfulAtAppToSystemServer() {
239         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
240         assertThat(sandboxLatencyInfo.isSuccessfulAtAppToSystemServer()).isTrue();
241     }
242 
243     @Test
testSandboxStatus_failedAtAppToSystemServer()244     public void testSandboxStatus_failedAtAppToSystemServer() {
245         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
246         // Verify state before status change
247         assertThat(sandboxLatencyInfo.isSuccessfulAtAppToSystemServer()).isTrue();
248 
249         sandboxLatencyInfo.setSandboxStatus(
250                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_APP_TO_SYSTEM_SERVER);
251 
252         // Verify state after status change
253         assertThat(sandboxLatencyInfo.isSuccessfulAtAppToSystemServer()).isFalse();
254     }
255 
256     @Test
testSandboxStatus_isSuccessfulAtSystemServerAppToSandbox()257     public void testSandboxStatus_isSuccessfulAtSystemServerAppToSandbox() {
258         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
259         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerAppToSandbox()).isTrue();
260     }
261 
262     @Test
testSandboxStatus_failedAtSystemServerAppToSandbox()263     public void testSandboxStatus_failedAtSystemServerAppToSandbox() {
264         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
265         // Verify state before status change
266         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerAppToSandbox()).isTrue();
267 
268         sandboxLatencyInfo.setSandboxStatus(
269                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SYSTEM_SERVER_APP_TO_SANDBOX);
270 
271         // Verify state after status change
272         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerAppToSandbox()).isFalse();
273     }
274 
275     @Test
testSandboxStatus_isSuccessfulAtLoadSandbox()276     public void testSandboxStatus_isSuccessfulAtLoadSandbox() {
277         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
278         assertThat(sandboxLatencyInfo.isSuccessfulAtLoadSandbox()).isTrue();
279     }
280 
281     @Test
testSandboxStatus_failedAtLoadSandbox()282     public void testSandboxStatus_failedAtLoadSandbox() {
283         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
284         // Verify state before status change
285         assertThat(sandboxLatencyInfo.isSuccessfulAtLoadSandbox()).isTrue();
286 
287         sandboxLatencyInfo.setSandboxStatus(
288                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_LOAD_SANDBOX);
289 
290         // Verify state after status change
291         assertThat(sandboxLatencyInfo.isSuccessfulAtLoadSandbox()).isFalse();
292     }
293 
294     @Test
testSandboxStatus_isSuccessfulAtSystemServerToSandbox()295     public void testSandboxStatus_isSuccessfulAtSystemServerToSandbox() {
296         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
297         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToSandbox()).isTrue();
298     }
299 
300     @Test
testSandboxStatus_failedAtSystemServerToSandbox()301     public void testSandboxStatus_failedAtSystemServerToSandbox() {
302         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
303         // Verify state before status change
304         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToSandbox()).isTrue();
305 
306         sandboxLatencyInfo.setSandboxStatus(
307                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SYSTEM_SERVER_TO_SANDBOX);
308 
309         // Verify state after status change
310         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToSandbox()).isFalse();
311     }
312 
313     @Test
testIsSuccessfulAtSdk()314     public void testIsSuccessfulAtSdk() {
315         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
316         assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue();
317     }
318 
319     @Test
testSandboxStatus_failedAtSdk()320     public void testSandboxStatus_failedAtSdk() {
321         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
322 
323         // Verify state before status change
324         assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue();
325         assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue();
326 
327         sandboxLatencyInfo.setSandboxStatus(SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SDK);
328 
329         // Verify state after status change
330         assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isFalse();
331         assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue();
332     }
333 
334     @Test
testIsSuccessfulAtSandbox()335     public void testIsSuccessfulAtSandbox() {
336         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
337         assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue();
338     }
339 
340     @Test
testSandboxStatus_failedAtSandbox()341     public void testSandboxStatus_failedAtSandbox() {
342         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
343 
344         // Verify state before status change
345         assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue();
346         assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue();
347 
348         sandboxLatencyInfo.setSandboxStatus(SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SANDBOX);
349 
350         // Verify state after status change
351         assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isFalse();
352         assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue();
353     }
354 
355     @Test
testSandboxStatus_isSuccessfulAtSandboxToSystemServer()356     public void testSandboxStatus_isSuccessfulAtSandboxToSystemServer() {
357         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
358         assertThat(sandboxLatencyInfo.isSuccessfulAtSandboxToSystemServer()).isTrue();
359     }
360 
361     @Test
testSandboxStatus_failedAtSandboxToSystemServer()362     public void testSandboxStatus_failedAtSandboxToSystemServer() {
363         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
364         // Verify state before status change
365         assertThat(sandboxLatencyInfo.isSuccessfulAtSandboxToSystemServer()).isTrue();
366 
367         sandboxLatencyInfo.setSandboxStatus(
368                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SANDBOX_TO_SYSTEM_SERVER);
369 
370         // Verify state after status change
371         assertThat(sandboxLatencyInfo.isSuccessfulAtSandboxToSystemServer()).isFalse();
372     }
373 
374     @Test
testSandboxStatus_isSuccessfulAtSystemServerSandboxToApp()375     public void testSandboxStatus_isSuccessfulAtSystemServerSandboxToApp() {
376         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
377         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerSandboxToApp()).isTrue();
378     }
379 
380     @Test
testSandboxStatus_failedAtSystemServerSandboxToApp()381     public void testSandboxStatus_failedAtSystemServerSandboxToApp() {
382         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
383         // Verify state before status change
384         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerSandboxToApp()).isTrue();
385 
386         sandboxLatencyInfo.setSandboxStatus(
387                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SYSTEM_SERVER_SANDBOX_TO_APP);
388 
389         // Verify state after status change
390         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerSandboxToApp()).isFalse();
391     }
392 
393     @Test
testSandboxStatus_isSuccessfulAtSystemServerToApp()394     public void testSandboxStatus_isSuccessfulAtSystemServerToApp() {
395         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
396         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToApp()).isTrue();
397     }
398 
399     @Test
testSandboxStatus_failedAtSystemServerToApp()400     public void testSandboxStatus_failedAtSystemServerToApp() {
401         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
402         // Verify state before status change
403         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToApp()).isTrue();
404 
405         sandboxLatencyInfo.setSandboxStatus(
406                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SYSTEM_SERVER_TO_APP);
407 
408         // Verify state after status change
409         assertThat(sandboxLatencyInfo.isSuccessfulAtSystemServerToApp()).isFalse();
410     }
411 
412     @Test
testSandboxStatus_isTotalCallSuccessful()413     public void testSandboxStatus_isTotalCallSuccessful() {
414         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
415         assertThat(sandboxLatencyInfo.isTotalCallSuccessful()).isTrue();
416     }
417 
418     @Test
testSandboxStatus_failedTotalCall()419     public void testSandboxStatus_failedTotalCall() {
420         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
421         // Verify state before status change
422         assertThat(sandboxLatencyInfo.isTotalCallSuccessful()).isTrue();
423 
424         // Total call is considered failed if any of the call stages failed
425         sandboxLatencyInfo.setSandboxStatus(
426                 SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_APP_TO_SYSTEM_SERVER);
427 
428         // Verify state after status change
429         assertThat(sandboxLatencyInfo.isTotalCallSuccessful()).isFalse();
430     }
431 
432     @Test
testGetTimeSystemServerCallFinished()433     public void testGetTimeSystemServerCallFinished() {
434         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
435         assertThat(sandboxLatencyInfo.getTimeSystemServerCallFinished())
436                 .isEqualTo(TIME_SYSTEM_SERVER_CALL_FINISHED);
437     }
438 
439     @Test
testGetTimeSandboxCalledSystemServer()440     public void testGetTimeSandboxCalledSystemServer() {
441         SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet();
442         assertThat(sandboxLatencyInfo.getTimeSandboxCalledSystemServer())
443                 .isEqualTo(TIME_SANDBOX_CALLED_SYSTEM_SERVER);
444     }
445 
446     @Test
testGetResultCode_default_isUnspecified()447     public void testGetResultCode_default_isUnspecified() {
448         SandboxLatencyInfo sandboxLatencyInfo = new SandboxLatencyInfo();
449         assertThat(sandboxLatencyInfo.getResultCode()).isEqualTo(RESULT_CODE_UNSPECIFIED);
450     }
451 
452     @Test
testGetResultCode_setLoadSdkNotFound_isLoadSdkNotFound()453     public void testGetResultCode_setLoadSdkNotFound_isLoadSdkNotFound() {
454         SandboxLatencyInfo sandboxLatencyInfo = new SandboxLatencyInfo();
455         sandboxLatencyInfo.setResultCode(RESULT_CODE_LOAD_SDK_NOT_FOUND);
456         assertThat(sandboxLatencyInfo.getResultCode()).isEqualTo(RESULT_CODE_LOAD_SDK_NOT_FOUND);
457     }
458 
getSandboxLatencyObjectWithAllFieldsSet()459     private SandboxLatencyInfo getSandboxLatencyObjectWithAllFieldsSet() {
460         return getSandboxLatencyObjectWithAllFieldsSet(SandboxLatencyInfo.METHOD_UNSPECIFIED);
461     }
462 
getSandboxLatencyObjectWithAllFieldsSet(int method)463     private SandboxLatencyInfo getSandboxLatencyObjectWithAllFieldsSet(int method) {
464         SandboxLatencyInfo sandboxLatencyInfo = new SandboxLatencyInfo(method);
465         sandboxLatencyInfo.setTimeAppCalledSystemServer(TIME_APP_CALLED_SYSTEM_SERVER);
466         sandboxLatencyInfo.setTimeSystemServerReceivedCallFromApp(
467                 TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_APP);
468         sandboxLatencyInfo.setTimeLoadSandboxStarted(TIME_LOAD_SANDBOX_STARTED);
469         sandboxLatencyInfo.setTimeSandboxLoaded(TIME_SANDBOX_LOADED);
470         sandboxLatencyInfo.setTimeSystemServerCallFinished(TIME_SYSTEM_SERVER_CALL_FINISHED);
471         sandboxLatencyInfo.setTimeSandboxReceivedCallFromSystemServer(
472                 TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER);
473         sandboxLatencyInfo.setTimeSandboxCalledSdk(TIME_SANDBOX_CALLED_SDK);
474         sandboxLatencyInfo.setTimeSdkCallCompleted(TIME_SDK_CALL_COMPLETED);
475         sandboxLatencyInfo.setTimeSandboxCalledSystemServer(TIME_SANDBOX_CALLED_SYSTEM_SERVER);
476         sandboxLatencyInfo.setTimeSystemServerReceivedCallFromSandbox(
477                 TIME_SYSTEM_SERVER_RECEIVED_CALL_FROM_SANDBOX);
478         sandboxLatencyInfo.setTimeSystemServerCalledApp(TIME_SYSTEM_SERVER_CALLED_APP);
479         sandboxLatencyInfo.setTimeAppReceivedCallFromSystemServer(
480                 TIME_APP_RECEIVED_CALL_FROM_SYSTEM_SERVER);
481         return sandboxLatencyInfo;
482     }
483 }
484