diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-15 09:35:23 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-15 09:35:23 +0000 |
commit | 4f73884441d6a5c6ba4af7e5026807822aa034a0 (patch) | |
tree | 0329901240818b16106c9a391165d84c2ba2f236 /sdksandbox/tests/unittest/src/com/android/sdksandbox | |
parent | 0856715d45086bed852b1cade242e59c57d36912 (diff) | |
parent | b76a4baee27df1f378c4bdfbf8853dff806b27a0 (diff) | |
download | AdServices-4f73884441d6a5c6ba4af7e5026807822aa034a0.tar.gz |
Snap for 11224086 from b76a4baee27df1f378c4bdfbf8853dff806b27a0 to mainline-tzdata5-release
Change-Id: I95c339f285645996dcabbcdad85dd1a9be945531
Diffstat (limited to 'sdksandbox/tests/unittest/src/com/android/sdksandbox')
3 files changed, 121 insertions, 284 deletions
diff --git a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxLatencyInfoUnitTest.java b/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxLatencyInfoUnitTest.java deleted file mode 100644 index 7c9703c8a6..0000000000 --- a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxLatencyInfoUnitTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.sdksandbox; - -import static com.google.common.truth.Truth.assertThat; - -import android.os.Parcel; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests {@link SandboxLatencyInfo} APIs. */ -@RunWith(JUnit4.class) -public class SandboxLatencyInfoUnitTest { - - private static final long TIME_SYSTEM_SERVER_CALLED_SANDBOX = 1; - private static final long TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER = 2; - private static final long TIME_SANDBOX_CALLED_SDK = 3; - private static final long TIME_SDK_CALL_COMPLETED = 4; - private static final long TIME_SANDBOX_CALLED_SYSTEM_SERVER = 5; - - @Test - public void testSandboxLatencyInfo_describeContents() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.describeContents()).isEqualTo(0); - } - - @Test - public void testSandboxLatencyInfo_isParcelable() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - final Parcel sandboxLatencyInfoParcel = Parcel.obtain(); - sandboxLatencyInfo.writeToParcel(sandboxLatencyInfoParcel, /*flags=*/ 0); - - sandboxLatencyInfoParcel.setDataPosition(0); - final SandboxLatencyInfo sandboxLatencyInfoCreatedWithParcel = - SandboxLatencyInfo.CREATOR.createFromParcel(sandboxLatencyInfoParcel); - - assertThat(sandboxLatencyInfo).isEqualTo(sandboxLatencyInfoCreatedWithParcel); - } - - @Test - public void testTimeSandboxCalledSdk() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.getTimeSandboxCalledSdk()).isEqualTo(TIME_SANDBOX_CALLED_SDK); - } - - @Test - public void testSandboxLatencyInfo_getLatencySystemServerToSandbox() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - final int systemServerToSandboxLatency = - (int) - (TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER - - TIME_SYSTEM_SERVER_CALLED_SANDBOX); - assertThat(sandboxLatencyInfo.getLatencySystemServerToSandbox()) - .isEqualTo(systemServerToSandboxLatency); - } - - @Test - public void testSandboxLatencyInfo_getSandboxLatency() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - final int sdkLatency = (int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK); - final int sandboxLatency = - (int) - (TIME_SANDBOX_CALLED_SYSTEM_SERVER - - TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER) - - sdkLatency; - assertThat(sandboxLatencyInfo.getSandboxLatency()).isEqualTo(sandboxLatency); - } - - @Test - public void testSandboxLatencyInfo_getSandboxLatency_timeFieldsNotSetForSdk() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - - // Reset the values - sandboxLatencyInfo.setTimeSandboxCalledSdk(-1); - sandboxLatencyInfo.setTimeSdkCallCompleted(-1); - - final int sandboxLatency = - (int) - (TIME_SANDBOX_CALLED_SYSTEM_SERVER - - TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER); - - assertThat(sandboxLatencyInfo.getSandboxLatency()).isEqualTo(sandboxLatency); - } - - @Test - public void testSandboxLatencyInfo_getSdkLatency() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - final int sdkLatency = (int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK); - assertThat(sandboxLatencyInfo.getSdkLatency()).isEqualTo(sdkLatency); - } - - @Test - public void testSandboxLatencyInfo_getSdkLatency_timeFieldsNotSetForSdk() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - - // Reset the values - sandboxLatencyInfo.setTimeSandboxCalledSdk(-1); - sandboxLatencyInfo.setTimeSdkCallCompleted(-1); - - assertThat(sandboxLatencyInfo.getSdkLatency()).isEqualTo(-1); - } - - @Test - public void testSandboxLatencyInfo_isSuccessfulAtSdk() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue(); - } - - @Test - public void testSandboxLatencyInfo_sandboxStatus_failedAtSdk() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - - // Verify state before status change - assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue(); - - sandboxLatencyInfo.setSandboxStatus(SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SDK); - - // Verify state after status change - assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isFalse(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue(); - } - - @Test - public void testSandboxLatencyInfo_isSuccessfulAtSandbox() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue(); - } - - @Test - public void testSandboxLatencyInfo_sandboxStatus_failedAtSandbox() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - - // Verify state before status change - assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isTrue(); - - sandboxLatencyInfo.setSandboxStatus(SandboxLatencyInfo.SANDBOX_STATUS_FAILED_AT_SANDBOX); - - // Verify state after status change - assertThat(sandboxLatencyInfo.isSuccessfulAtSandbox()).isFalse(); - assertThat(sandboxLatencyInfo.isSuccessfulAtSdk()).isTrue(); - } - - @Test - public void testGetTimeSystemServerCalledSandbox() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.getTimeSystemServerCalledSandbox()) - .isEqualTo(TIME_SYSTEM_SERVER_CALLED_SANDBOX); - } - - @Test - public void testGetTimeSandboxCalledSystemServer() { - final SandboxLatencyInfo sandboxLatencyInfo = getSandboxLatencyObjectWithAllFieldsSet(); - assertThat(sandboxLatencyInfo.getTimeSandboxCalledSystemServer()) - .isEqualTo(TIME_SANDBOX_CALLED_SYSTEM_SERVER); - } - - private SandboxLatencyInfo getSandboxLatencyObjectWithAllFieldsSet() { - final SandboxLatencyInfo sandboxLatencyInfo = new SandboxLatencyInfo(); - sandboxLatencyInfo.setTimeSystemServerCalledSandbox(TIME_SYSTEM_SERVER_CALLED_SANDBOX); - sandboxLatencyInfo.setTimeSandboxReceivedCallFromSystemServer( - TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER); - sandboxLatencyInfo.setTimeSandboxCalledSdk(TIME_SANDBOX_CALLED_SDK); - sandboxLatencyInfo.setTimeSdkCallCompleted(TIME_SDK_CALL_COMPLETED); - sandboxLatencyInfo.setTimeSandboxCalledSystemServer(TIME_SANDBOX_CALLED_SYSTEM_SERVER); - return sandboxLatencyInfo; - } -} diff --git a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxedActivityTest.java b/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxedActivityTest.java index ba6775f701..653c5c6553 100644 --- a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxedActivityTest.java +++ b/sdksandbox/tests/unittest/src/com/android/sdksandbox/SandboxedActivityTest.java @@ -17,12 +17,13 @@ package com.android.sdksandbox; import static com.google.common.truth.Truth.assertThat; - import static org.junit.Assume.assumeTrue; +import android.app.sdksandbox.SandboxedSdkContext; import android.app.sdksandbox.SdkSandboxManager; import android.app.sdksandbox.sdkprovider.SdkSandboxActivityHandler; import android.app.sdksandbox.sdkprovider.SdkSandboxActivityRegistry; +import android.content.Context; import android.content.Intent; import android.os.Binder; import android.os.Bundle; @@ -32,6 +33,7 @@ import android.os.Looper; import com.android.modules.utils.build.SdkLevel; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -41,25 +43,27 @@ import org.mockito.Mockito; @RunWith(JUnit4.class) public class SandboxedActivityTest { - @Test - public void testSandboxedActivityCreation() { + private static final String SDK_NAME = "SDK_NAME"; + private SandboxedSdkContext mSdkContext; + + @Before + public void setUp() { assumeTrue(SdkLevel.isAtLeastU()); + mSdkContext = Mockito.mock(SandboxedSdkContext.class); + Mockito.when(mSdkContext.getSdkName()).thenReturn(SDK_NAME); + } + @Test + public void testSandboxedActivityCreation() { SdkSandboxActivityHandler sdkSandboxActivityHandler = Mockito.spy(activity -> {}); SdkSandboxActivityRegistry registry = SdkSandboxActivityRegistry.getInstance(); - IBinder token = registry.register("SDK_NAME", sdkSandboxActivityHandler); + IBinder token = registry.register(mSdkContext, sdkSandboxActivityHandler); new Handler(Looper.getMainLooper()) .runWithScissors( () -> { SandboxedActivity sandboxedActivity = new SandboxedActivity(); - - Intent intent = new Intent(); - intent.setAction(SdkSandboxManager.ACTION_START_SANDBOXED_ACTIVITY); - Bundle extras = new Bundle(); - extras.putBinder( - sandboxedActivity.getSandboxedActivityHandlerKey(), token); - intent.putExtras(extras); + Intent intent = buildIntent(sandboxedActivity, token); sandboxedActivity.setIntent(intent); sandboxedActivity.notifySdkOnActivityCreation(); @@ -76,8 +80,6 @@ public class SandboxedActivityTest { @Test public void testSandboxedActivityFinishIfNoIntentExtras() { - assumeTrue(SdkLevel.isAtLeastU()); - new Handler(Looper.getMainLooper()) .runWithScissors( () -> { @@ -93,8 +95,6 @@ public class SandboxedActivityTest { @Test public void testSandboxedActivityFinishIfNoIntentExtrasNotHavingTheHandlerToken() { - assumeTrue(SdkLevel.isAtLeastU()); - new Handler(Looper.getMainLooper()) .runWithScissors( () -> { @@ -114,8 +114,6 @@ public class SandboxedActivityTest { @Test public void testSandboxedActivityFinishIfHandlerTokenIsWrongType() { - assumeTrue(SdkLevel.isAtLeastU()); - new Handler(Looper.getMainLooper()) .runWithScissors( () -> { @@ -142,13 +140,7 @@ public class SandboxedActivityTest { () -> { SandboxedActivity sandboxedActivity = Mockito.spy(new SandboxedActivity()); - - Intent intent = new Intent(); - Bundle extras = new Bundle(); - extras.putBinder( - sandboxedActivity.getSandboxedActivityHandlerKey(), - new Binder()); - intent.putExtras(extras); + Intent intent = buildIntent(sandboxedActivity, new Binder()); sandboxedActivity.setIntent(intent); sandboxedActivity.notifySdkOnActivityCreation(); @@ -158,35 +150,105 @@ public class SandboxedActivityTest { } @Test - public void testSandboxedActivityFinishIfHandlerNotifiedAlreadyAboutAnotherActivity() { + public void testMultipleSandboxedActivitiesForTheSameHandler() { SdkSandboxActivityHandler sdkSandboxActivityHandler = activity -> {}; SdkSandboxActivityRegistry registry = SdkSandboxActivityRegistry.getInstance(); - IBinder token = registry.register("SDK_NAME", sdkSandboxActivityHandler); + IBinder token = registry.register(mSdkContext, sdkSandboxActivityHandler); new Handler(Looper.getMainLooper()) .runWithScissors( () -> { SandboxedActivity sandboxedActivity1 = Mockito.spy(new SandboxedActivity()); - - Intent intent = new Intent(); - intent.setAction(SdkSandboxManager.ACTION_START_SANDBOXED_ACTIVITY); - Bundle extras = new Bundle(); - extras.putBinder( - sandboxedActivity1.getSandboxedActivityHandlerKey(), token); - intent.putExtras(extras); + Intent intent = buildIntent(sandboxedActivity1, token); sandboxedActivity1.setIntent(intent); sandboxedActivity1.notifySdkOnActivityCreation(); SandboxedActivity sandboxedActivity2 = Mockito.spy(new SandboxedActivity()); - sandboxedActivity1.setIntent(intent); + sandboxedActivity2.setIntent(intent); sandboxedActivity2.notifySdkOnActivityCreation(); Mockito.verify(sandboxedActivity1, Mockito.never()).finish(); - Mockito.verify(sandboxedActivity2).finish(); + Mockito.verify(sandboxedActivity1, Mockito.never()).finish(); }, 1000); } + + /** + * If customized SDK context flag is enabled, the activity base context should be wrapped in a + * new instance of `SandboxedSdkContext`. + */ + @Test + public void testAttachBaseContextWrapsTheBaseContextIfCustomizedSdkContextFlagIsEnabled() { + SdkSandboxActivityHandler sdkSandboxActivityHandler = Mockito.spy(activity -> {}); + SdkSandboxActivityRegistry registry = SdkSandboxActivityRegistry.getInstance(); + IBinder token = registry.register(mSdkContext, sdkSandboxActivityHandler); + Mockito.when(mSdkContext.isCustomizedSdkContextEnabled()).thenReturn(true); + + new Handler(Looper.getMainLooper()) + .runWithScissors( + () -> { + SandboxedActivity sandboxedActivity = new SandboxedActivity(); + Intent intent = buildIntent(sandboxedActivity, token); + sandboxedActivity.setIntent(intent); + + Context activityBaseContext = Mockito.mock(Context.class); + + Mockito.when(mSdkContext.createContextWithNewBase(activityBaseContext)) + .thenCallRealMethod(); + Mockito.when(mSdkContext.getBaseContext()).thenCallRealMethod(); + + sandboxedActivity.attachBaseContext(activityBaseContext); + + SandboxedSdkContext newBaseContext = + (SandboxedSdkContext) sandboxedActivity.getBaseContext(); + assertThat(newBaseContext).isNotNull(); + assertThat(newBaseContext.getBaseContext()) + .isEqualTo(activityBaseContext); + }, + 1000); + } + + /** + * If customized SDK context flag is disabled, the base context should be used directly without + * wrapping. + */ + @Test + public void testAttachBaseContextUseTheBaseContextIfCustomizedSdkContextFlagIsDisabled() { + SdkSandboxActivityHandler sdkSandboxActivityHandler = Mockito.spy(activity -> {}); + SdkSandboxActivityRegistry registry = SdkSandboxActivityRegistry.getInstance(); + IBinder token = registry.register(mSdkContext, sdkSandboxActivityHandler); + Mockito.when(mSdkContext.isCustomizedSdkContextEnabled()).thenReturn(false); + + new Handler(Looper.getMainLooper()) + .runWithScissors( + () -> { + SandboxedActivity sandboxedActivity = new SandboxedActivity(); + Intent intent = buildIntent(sandboxedActivity, token); + sandboxedActivity.setIntent(intent); + + Context activityBaseContext = Mockito.mock(Context.class); + + Mockito.when(mSdkContext.createContextWithNewBase(activityBaseContext)) + .thenCallRealMethod(); + Mockito.when(mSdkContext.getBaseContext()).thenCallRealMethod(); + + sandboxedActivity.attachBaseContext(activityBaseContext); + + Context newBaseContext = sandboxedActivity.getBaseContext(); + assertThat(newBaseContext).isNotInstanceOf(SandboxedSdkContext.class); + }, + 1000); + } + + private Intent buildIntent(SandboxedActivity sandboxedActivity, IBinder token) { + Intent intent = new Intent(); + intent.setAction(SdkSandboxManager.ACTION_START_SANDBOXED_ACTIVITY); + Bundle extras = new Bundle(); + extras.putBinder(sandboxedActivity.getSandboxedActivityHandlerKey(), token); + intent.putExtras(extras); + return intent; + } } diff --git a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SdkSandboxTest.java b/sdksandbox/tests/unittest/src/com/android/sdksandbox/SdkSandboxTest.java index 4e5eac0eb2..bbd0f65018 100644 --- a/sdksandbox/tests/unittest/src/com/android/sdksandbox/SdkSandboxTest.java +++ b/sdksandbox/tests/unittest/src/com/android/sdksandbox/SdkSandboxTest.java @@ -22,17 +22,18 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import android.app.sdksandbox.LoadSdkException; +import android.app.sdksandbox.SandboxLatencyInfo; import android.app.sdksandbox.SandboxedSdk; import android.app.sdksandbox.SandboxedSdkContext; import android.app.sdksandbox.SdkSandboxLocalSingleton; import android.app.sdksandbox.SharedPreferencesKey; import android.app.sdksandbox.SharedPreferencesUpdate; import android.app.sdksandbox.sdkprovider.SdkSandboxActivityRegistry; +import android.app.sdksandbox.testutils.SdkSandboxDeviceSupportedRule; import android.app.sdksandbox.testutils.StubSdkToServiceLink; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Binder; import android.os.Build; @@ -54,6 +55,7 @@ import dalvik.system.PathClassLoader; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -89,7 +91,7 @@ public class SdkSandboxTest { private static final String SDK_PROVIDER_CLASS = "com.android.testprovider.TestProvider"; // Key passed to TestProvider to trigger a load error. private static final String THROW_EXCEPTION_KEY = "throw-exception"; - private static final long TIME_SYSTEM_SERVER_CALLED_SANDBOX = 3; + private static final long TIME_SYSTEM_SERVER_CALL_FINISHED = 3; private static final long TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER = 5; private static final long TIME_SANDBOX_CALLED_SDK = 7; private static final long TIME_SDK_CALL_COMPLETED = 9; @@ -109,7 +111,7 @@ public class SdkSandboxTest { new SharedPreferencesUpdate(KEYS_TO_SYNC, getBundleFromMap(TEST_DATA)); private static final SandboxLatencyInfo SANDBOX_LATENCY_INFO = new SandboxLatencyInfo(); - private static boolean sCustomizedSdkContextEnabled; + private static boolean sCustomizedSdkContextEnabled = SdkLevel.isAtLeastU(); private static SdkSandboxActivityRegistry sSdkSandboxActivityRegistry; private Context mContext; @@ -144,6 +146,9 @@ public class SdkSandboxTest { } } + @Rule + public final SdkSandboxDeviceSupportedRule supportedRule = new SdkSandboxDeviceSupportedRule(); + @BeforeClass public static void setupClass() { // Required to create a SurfaceControlViewHost @@ -154,7 +159,7 @@ public class SdkSandboxTest { InstrumentationRegistry.getInstrumentation().getContext(), DeviceConfig.NAMESPACE_ADSERVICES, "sdksandbox_customized_sdk_context_enabled"); - sCustomizedSdkContextEnabled = Boolean.parseBoolean(stateManager.get()); + sCustomizedSdkContextEnabled &= Boolean.parseBoolean(stateManager.get()); sSdkSandboxActivityRegistry = Mockito.spy(SdkSandboxActivityRegistry.getInstance()); } @@ -270,8 +275,6 @@ public class SdkSandboxTest { SdkSandboxStorageCallback sdkSandboxStorageCallback = new SdkSandboxStorageCallback(); mService.computeSdkStorage(sharedPaths, sdkPaths, sdkSandboxStorageCallback); - Thread.sleep(5000); - assertThat(sdkSandboxStorageCallback.getSdkStorage()).isEqualTo(1024F); assertThat(sdkSandboxStorageCallback.getSharedStorage()).isEqualTo(1024F); } @@ -403,30 +406,6 @@ public class SdkSandboxTest { } @Test - public void testDisabledWhenWebviewNotResolvable() throws Exception { - // WebView provider cannot be resolved, therefore sandbox should be disabled. - Mockito.doReturn(null) - .when(mSpyPackageManager) - .getPackageInfo( - Mockito.anyString(), Mockito.any(PackageManager.PackageInfoFlags.class)); - SdkSandboxDisabledCallback callback = new SdkSandboxDisabledCallback(); - mService.isDisabled(callback); - assertThat(callback.mIsDisabled).isTrue(); - } - - @Test - public void testNotDisabledWhenWebviewResolvable() throws Exception { - // WebView provider can be resolved, therefore sandbox should not be disabled. - Mockito.doReturn(new PackageInfo()) - .when(mSpyPackageManager) - .getPackageInfo( - Mockito.anyString(), Mockito.any(PackageManager.PackageInfoFlags.class)); - SdkSandboxDisabledCallback callback = new SdkSandboxDisabledCallback(); - mService.isDisabled(callback); - assertThat(callback.isDisabled()).isFalse(); - } - - @Test public void testSyncDataFromClient_StoresInClientSharedPreference() throws Exception { mService.syncDataFromClient(TEST_UPDATE); @@ -505,11 +484,11 @@ public class SdkSandboxTest { @Test public void testLatencyMetrics_loadSdk_success() throws Exception { - SANDBOX_LATENCY_INFO.setTimeSystemServerCalledSandbox(TIME_SYSTEM_SERVER_CALLED_SANDBOX); + SANDBOX_LATENCY_INFO.setTimeSystemServerCallFinished(TIME_SYSTEM_SERVER_CALL_FINISHED); SANDBOX_LATENCY_INFO.setTimeSandboxReceivedCallFromSystemServer( TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER); - Mockito.when(mInjector.getCurrentTime()) + Mockito.when(mInjector.elapsedRealtime()) .thenReturn( TIME_SANDBOX_CALLED_SDK, TIME_SDK_CALL_COMPLETED, @@ -528,11 +507,11 @@ public class SdkSandboxTest { SANDBOX_LATENCY_INFO); loadSdkCallback.assertLoadSdkIsSuccessful(); - assertThat(loadSdkCallback.mSandboxLatencyInfo.getLatencySystemServerToSandbox()) + assertThat(loadSdkCallback.mSandboxLatencyInfo.getSystemServerToSandboxLatency()) .isEqualTo( (int) (TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER - - TIME_SYSTEM_SERVER_CALLED_SANDBOX)); + - TIME_SYSTEM_SERVER_CALL_FINISHED)); assertThat(loadSdkCallback.mSandboxLatencyInfo.getSdkLatency()) .isEqualTo((int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK)); @@ -548,11 +527,11 @@ public class SdkSandboxTest { @Test public void testLatencyMetrics_unloadSdk_success() throws Exception { - SANDBOX_LATENCY_INFO.setTimeSystemServerCalledSandbox(TIME_SYSTEM_SERVER_CALLED_SANDBOX); + SANDBOX_LATENCY_INFO.setTimeSystemServerCallFinished(TIME_SYSTEM_SERVER_CALL_FINISHED); SANDBOX_LATENCY_INFO.setTimeSandboxReceivedCallFromSystemServer( TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER); - Mockito.when(mInjector.getCurrentTime()) + Mockito.when(mInjector.elapsedRealtime()) .thenReturn( // loadSdk mocks TIME_SANDBOX_CALLED_SDK, @@ -576,10 +555,11 @@ public class SdkSandboxTest { SANDBOX_LATENCY_INFO); loadSdkCallback.assertLoadSdkIsSuccessful(); - final UnloadSdkCallbackImpl unloadSdkCallback = new UnloadSdkCallbackImpl(); - mService.unloadSdk(SDK_NAME, unloadSdkCallback, SANDBOX_LATENCY_INFO); + UnloadSdkInSandboxCallbackImpl unloadSdkInSandboxCallback = + new UnloadSdkInSandboxCallbackImpl(); + mService.unloadSdk(SDK_NAME, unloadSdkInSandboxCallback, SANDBOX_LATENCY_INFO); - final SandboxLatencyInfo sandboxLatencyInfo = unloadSdkCallback.getSandboxLatencyInfo(); + SandboxLatencyInfo sandboxLatencyInfo = unloadSdkInSandboxCallback.getSandboxLatencyInfo(); assertThat(sandboxLatencyInfo.getSdkLatency()) .isEqualTo((int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK)); @@ -602,7 +582,7 @@ public class SdkSandboxTest { @Test public void testLatencyMetrics_requestSurfacePackage_success() throws Exception { - Mockito.when(mInjector.getCurrentTime()) + Mockito.when(mInjector.elapsedRealtime()) .thenReturn( // loadSdk mocks TIME_SANDBOX_CALLED_SDK, @@ -642,11 +622,11 @@ public class SdkSandboxTest { callback); assertThat(surfaceLatch.await(1, TimeUnit.MINUTES)).isTrue(); assertThat(callback.mSurfacePackage).isNotNull(); - assertThat(callback.mSandboxLatencyInfo.getLatencySystemServerToSandbox()) + assertThat(callback.mSandboxLatencyInfo.getSystemServerToSandboxLatency()) .isEqualTo( (int) (TIME_SANDBOX_RECEIVED_CALL_FROM_SYSTEM_SERVER - - TIME_SYSTEM_SERVER_CALLED_SANDBOX)); + - TIME_SYSTEM_SERVER_CALL_FINISHED)); assertThat(callback.mSandboxLatencyInfo.getSdkLatency()) .isEqualTo((int) (TIME_SDK_CALL_COMPLETED - TIME_SANDBOX_CALLED_SDK)); assertThat(callback.mSandboxLatencyInfo.getSandboxLatency()) @@ -679,7 +659,7 @@ public class SdkSandboxTest { null, null, false), - new InjectorForTest(mContext), + new SdkSandboxServiceImpl.Injector(mContext), SANDBOX_LATENCY_INFO, sdkHolderCallback); mCallback.assertLoadSdkIsSuccessful(); @@ -779,7 +759,7 @@ public class SdkSandboxTest { } } - private static class UnloadSdkCallbackImpl extends IUnloadSdkCallback.Stub { + private static class UnloadSdkInSandboxCallbackImpl extends IUnloadSdkInSandboxCallback.Stub { private SandboxLatencyInfo mSandboxLatencyInfo; @Override @@ -836,26 +816,6 @@ public class SdkSandboxTest { } } - private static class SdkSandboxDisabledCallback extends ISdkSandboxDisabledCallback.Stub { - private final CountDownLatch mLatch; - private boolean mIsDisabled; - - SdkSandboxDisabledCallback() { - mLatch = new CountDownLatch(1); - } - - @Override - public void onResult(boolean isDisabled) { - mIsDisabled = isDisabled; - mLatch.countDown(); - } - - boolean isDisabled() throws Exception { - assertThat(mLatch.await(1, TimeUnit.SECONDS)).isTrue(); - return mIsDisabled; - } - } - private static class SdkSandboxStorageCallback extends IComputeSdkStorageCallback.Stub { private float mSharedStorage; private float mSdkStorage; |