From 061c69f6beea61b1dd8c12935d53ccabcdf35e0e Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Tue, 2 May 2023 13:48:44 +0000 Subject: Scaffolding for AnnotatedUserHandles testing. This provides (test-only) capacities to inject different UserHandle values than the ones we'd normally determine, so that we can test under artificially-constructed scenarios just by injecting the appropriate fake AnnotatedUserHandles value. Test: `atest AnnotatedUserHandlesTest` (& presubmits/etc) Bug: 280237072 Change-Id: Idc2f7a5a46f49f9e4c11d361e01e6943404262b2 --- .../intentresolver/AnnotatedUserHandlesTest.kt | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 java/tests/src/com/android/intentresolver/AnnotatedUserHandlesTest.kt (limited to 'java/tests') diff --git a/java/tests/src/com/android/intentresolver/AnnotatedUserHandlesTest.kt b/java/tests/src/com/android/intentresolver/AnnotatedUserHandlesTest.kt new file mode 100644 index 00000000..a17a560c --- /dev/null +++ b/java/tests/src/com/android/intentresolver/AnnotatedUserHandlesTest.kt @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2023 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.intentresolver + +import android.os.UserHandle + +import com.google.common.truth.Truth.assertThat + +import org.junit.Test + +class AnnotatedUserHandlesTest { + + @Test + fun testBasicProperties() { // Fields that are reflected back w/o logic. + val info = AnnotatedUserHandles.newBuilder() + .setUserIdOfCallingApp(42) + .setUserHandleSharesheetLaunchedAs(UserHandle.of(116)) + .setPersonalProfileUserHandle(UserHandle.of(117)) + .setWorkProfileUserHandle(UserHandle.of(118)) + .setCloneProfileUserHandle(UserHandle.of(119)) + .build() + + assertThat(info.userIdOfCallingApp).isEqualTo(42) + assertThat(info.userHandleSharesheetLaunchedAs.identifier).isEqualTo(116) + assertThat(info.personalProfileUserHandle.identifier).isEqualTo(117) + assertThat(info.workProfileUserHandle.identifier).isEqualTo(118) + assertThat(info.cloneProfileUserHandle.identifier).isEqualTo(119) + } + + @Test + fun testWorkTabInitiallySelectedWhenLaunchedFromWorkProfile() { + val info = AnnotatedUserHandles.newBuilder() + .setUserIdOfCallingApp(42) + .setPersonalProfileUserHandle(UserHandle.of(101)) + .setWorkProfileUserHandle(UserHandle.of(202)) + .setUserHandleSharesheetLaunchedAs(UserHandle.of(202)) + .build() + + assertThat(info.tabOwnerUserHandleForLaunch.identifier).isEqualTo(202) + } + + @Test + fun testPersonalTabInitiallySelectedWhenLaunchedFromPersonalProfile() { + val info = AnnotatedUserHandles.newBuilder() + .setUserIdOfCallingApp(42) + .setPersonalProfileUserHandle(UserHandle.of(101)) + .setWorkProfileUserHandle(UserHandle.of(202)) + .setUserHandleSharesheetLaunchedAs(UserHandle.of(101)) + .build() + + assertThat(info.tabOwnerUserHandleForLaunch.identifier).isEqualTo(101) + } + + @Test + fun testPersonalTabInitiallySelectedWhenLaunchedFromOtherProfile() { + val info = AnnotatedUserHandles.newBuilder() + .setUserIdOfCallingApp(42) + .setPersonalProfileUserHandle(UserHandle.of(101)) + .setWorkProfileUserHandle(UserHandle.of(202)) + .setUserHandleSharesheetLaunchedAs(UserHandle.of(303)) + .build() + + assertThat(info.tabOwnerUserHandleForLaunch.identifier).isEqualTo(101) + } +} -- cgit v1.2.3-59-g8ed1b