summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Joshua Trask <joshtrask@google.com> 2023-05-02 13:48:44 +0000
committer Joshua Trask <joshtrask@google.com> 2023-05-02 14:31:29 +0000
commit061c69f6beea61b1dd8c12935d53ccabcdf35e0e (patch)
tree4f9d647de713fcea5560777a7949547eafc84690 /java/tests
parentd6a6ea70bb58be3f65da5ee8b1a5aee1849ca30b (diff)
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
Diffstat (limited to 'java/tests')
-rw-r--r--java/tests/src/com/android/intentresolver/AnnotatedUserHandlesTest.kt79
1 files changed, 79 insertions, 0 deletions
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)
+ }
+}