blob: c348e70bb37565b5e70ee5f4d193c75058b10982 [file] [log] [blame]
Felipe Leme1c7eb0c2018-03-09 14:13:18 -08001/*
2 * Copyright (C) 2018 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 */
16package com.android.server.autofill;
17
18import static com.android.server.autofill.AutofillManagerService.getWhitelistedCompatModePackages;
19
20import static com.google.common.truth.Truth.assertThat;
21
22import org.junit.Test;
23import org.junit.runner.RunWith;
24import org.junit.runners.JUnit4;
25
26import java.util.Map;
27
28@RunWith(JUnit4.class)
29public class AutofillManagerServiceTest {
Felipe Leme86e9405b2018-03-12 10:28:42 -070030 // TODO(b/74445943): temporary work around until P Development Preview 3 is branched
31 private static final boolean ADDS_DEFAULT_BUTTON = true;
Felipe Leme1c7eb0c2018-03-09 14:13:18 -080032
33 @Test
34 public void testGetWhitelistedCompatModePackages_null() {
35 assertThat(getWhitelistedCompatModePackages(null)).isNull();
36 }
37
38 @Test
39 public void testGetWhitelistedCompatModePackages_empty() {
40 assertThat(getWhitelistedCompatModePackages("")).isNull();
41 }
42
43 @Test
44 public void testGetWhitelistedCompatModePackages_onePackageNoUrls() {
Felipe Leme86e9405b2018-03-12 10:28:42 -070045 if (ADDS_DEFAULT_BUTTON) {
46 final Map<String, String[]> result =
47 getWhitelistedCompatModePackages("one_is_the_loniest_package");
48 assertThat(result).hasSize(1);
49 assertThat(result.get("one_is_the_loniest_package")).asList()
50 .containsExactly("url_bar", "location_bar_edit_text");
51 } else {
52 assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package"))
53 .containsExactly("one_is_the_loniest_package", null);
54 }
Felipe Leme1c7eb0c2018-03-09 14:13:18 -080055 }
56
57 @Test
58 public void testGetWhitelistedCompatModePackages_onePackageMissingEndDelimiter() {
59 assertThat(getWhitelistedCompatModePackages("one_is_the_loniest_package[")).isEmpty();
60 }
61
62 @Test
63 public void testGetWhitelistedCompatModePackages_onePackageOneUrl() {
64 final Map<String, String[]> result =
65 getWhitelistedCompatModePackages("one_is_the_loniest_package[url]");
66 assertThat(result).hasSize(1);
67 assertThat(result.get("one_is_the_loniest_package")).asList().containsExactly("url");
68 }
69
70 @Test
71 public void testGetWhitelistedCompatModePackages_onePackageMultipleUrls() {
72 final Map<String, String[]> result =
73 getWhitelistedCompatModePackages("one_is_the_loniest_package[4,5,8,15,16,23,42]");
74 assertThat(result).hasSize(1);
75 assertThat(result.get("one_is_the_loniest_package")).asList()
76 .containsExactly("4", "5", "8", "15", "16", "23", "42");
77 }
78
79 @Test
80 public void testGetWhitelistedCompatModePackages_multiplePackagesOneInvalid() {
81 final Map<String, String[]> result = getWhitelistedCompatModePackages("one:two[");
82 assertThat(result).hasSize(1);
Felipe Leme86e9405b2018-03-12 10:28:42 -070083 if (ADDS_DEFAULT_BUTTON) {
84 assertThat(result.get("one")).asList()
85 .containsExactly("url_bar", "location_bar_edit_text");
86 } else {
87 assertThat(result.get("one")).isNull();
88 }
Felipe Leme1c7eb0c2018-03-09 14:13:18 -080089 }
90
91 @Test
92 public void testGetWhitelistedCompatModePackages_multiplePackagesMultipleUrls() {
93 final Map<String, String[]> result =
94 getWhitelistedCompatModePackages("p1[p1u1]:p2:p3[p3u1,p3u2]");
95 assertThat(result).hasSize(3);
96 assertThat(result.get("p1")).asList().containsExactly("p1u1");
Felipe Leme86e9405b2018-03-12 10:28:42 -070097 if (ADDS_DEFAULT_BUTTON) {
98 assertThat(result.get("p2")).asList()
99 .containsExactly("url_bar", "location_bar_edit_text");
100 } else {
101 assertThat(result.get("p2")).isNull();
102 }
Felipe Leme1c7eb0c2018-03-09 14:13:18 -0800103 assertThat(result.get("p3")).asList().containsExactly("p3u1", "p3u2");
104 }
105
106 @Test
107 public void testGetWhitelistedCompatModePackages_threePackagesOneInvalid() {
108 final Map<String, String[]> result =
109 getWhitelistedCompatModePackages("p1[p1u1]:p2[:p3[p3u1,p3u2]");
110 assertThat(result).hasSize(2);
111 assertThat(result.get("p1")).asList().containsExactly("p1u1");
112 assertThat(result.get("p3")).asList().containsExactly("p3u1", "p3u2");
113 }
114}