• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.credentials.cts.unittests.selection;
18 
19 import static android.credentials.flags.Flags.FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.testng.Assert.assertThrows;
24 
25 import android.app.slice.Slice;
26 import android.content.Intent;
27 import android.credentials.selection.CreateCredentialProviderInfo;
28 import android.credentials.selection.Entry;
29 import android.net.Uri;
30 import android.platform.test.annotations.AppModeFull;
31 import android.platform.test.annotations.RequiresFlagsEnabled;
32 import android.platform.test.flag.junit.CheckFlagsRule;
33 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
34 
35 import androidx.test.ext.junit.runners.AndroidJUnit4;
36 import androidx.test.filters.SmallTest;
37 
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 
42 import java.util.ArrayList;
43 import java.util.List;
44 
45 @SmallTest
46 @AppModeFull(reason = "unit test")
47 @RunWith(AndroidJUnit4.class)
48 public class CreateCredentialProviderInfoTest {
49 
50     @Rule
51     public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
52 
53     private static final Slice SLICE = new Slice.Builder(Uri.parse("foo://bar"), null)
54             .addText("some text", null, List.of(Slice.HINT_TITLE)).build();
55 
56     private static final Entry REMOTE_ENTRY = new Entry("remote_entry_key",
57             "remote_entry_subkey", SLICE, new Intent("fake action"));
58 
59     @Test
60     @RequiresFlagsEnabled(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
testConstruction()61     public void testConstruction() {
62         final List<Entry> saveEntryList = new ArrayList<>();
63         saveEntryList.add(new Entry("k2", "subkey1", new Slice.Builder(Uri.parse("scheme://foo"),
64                 null)
65                 .addText("test text", null, List.of(Slice.HINT_KEYWORDS)).build(),
66                 new Intent("action2")));
67         saveEntryList.add(new Entry("key3", "subkey", new Slice.Builder(Uri.parse("scheme://bar"),
68                 null)
69                 .addText("text", null, List.of(Slice.HINT_SEE_MORE)).build(),
70                 new Intent("action3")));
71         saveEntryList.add(new Entry("k1", "subkey1", SLICE, new Intent("action1")));
72         CreateCredentialProviderInfo createCredentialProviderInfo =
73                 new CreateCredentialProviderInfo.Builder("fake provider")
74                         .setSaveEntries(saveEntryList)
75                         .setRemoteEntry(REMOTE_ENTRY)
76                         .build();
77         assertThat(createCredentialProviderInfo.getProviderName()).isEqualTo("fake provider");
78         assertThat(createCredentialProviderInfo.getSaveEntries()).containsExactlyElementsIn(
79                 saveEntryList).inOrder();
80         assertThat(createCredentialProviderInfo.getRemoteEntry()).isEqualTo((REMOTE_ENTRY));
81     }
82 
83     @Test
84     @RequiresFlagsEnabled(FLAG_CONFIGURABLE_SELECTOR_UI_ENABLED)
testBuilder_nullProviderInfo_throws()85     public void testBuilder_nullProviderInfo_throws() {
86         assertThrows(IllegalArgumentException.class, () ->
87                 new CreateCredentialProviderInfo.Builder(null)
88                         .setSaveEntries(new ArrayList<>())
89                         .setRemoteEntry(REMOTE_ENTRY)
90                         .build());
91     }
92 }
93