1414import org .robolectric .Robolectric ;
1515import org .robolectric .RobolectricTestRunner ;
1616
17+ import java .util .ArrayList ;
18+ import java .util .Arrays ;
1719import java .util .Collections ;
20+ import java .util .List ;
1821
1922import static org .hamcrest .MatcherAssert .assertThat ;
2023import static org .hamcrest .core .Is .is ;
2124import static org .hamcrest .core .IsNull .notNullValue ;
2225import static org .hamcrest .core .IsNull .nullValue ;
26+ import static org .junit .Assert .assertEquals ;
2327import static org .mockito .Matchers .any ;
2428import static org .mockito .Mockito .mock ;
2529import static org .mockito .Mockito .spy ;
@@ -74,7 +78,7 @@ public void shouldHaveDefaultValues() {
7478 CustomTabsOptions options = CustomTabsOptions .newBuilder ().build ();
7579 assertThat (options , is (notNullValue ()));
7680
77- Intent intent = options .toIntent (context , null );
81+ Intent intent = options .toIntent (context , null , null );
7882
7983 assertThat (intent , is (notNullValue ()));
8084 assertThat (intent .hasExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR ), is (false ));
@@ -89,7 +93,7 @@ public void shouldHaveDefaultValues() {
8993 CustomTabsOptions parceledOptions = CustomTabsOptions .CREATOR .createFromParcel (parcel );
9094 assertThat (parceledOptions , is (notNullValue ()));
9195
92- Intent parceledIntent = parceledOptions .toIntent (context , null );
96+ Intent parceledIntent = parceledOptions .toIntent (context , null , null );
9397 assertThat (parceledIntent , is (notNullValue ()));
9498 assertThat (parceledIntent .hasExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR ), is (false ));
9599 assertThat (parceledIntent .hasExtra (CustomTabsIntent .EXTRA_TITLE_VISIBILITY_STATE ), is (true ));
@@ -105,7 +109,7 @@ public void shouldSetShowTitle() {
105109 .build ();
106110 assertThat (options , is (notNullValue ()));
107111
108- Intent intent = options .toIntent (context , null );
112+ Intent intent = options .toIntent (context , null , null );
109113
110114 assertThat (intent , is (notNullValue ()));
111115 assertThat (intent .hasExtra (CustomTabsIntent .EXTRA_TITLE_VISIBILITY_STATE ), is (true ));
@@ -118,7 +122,7 @@ public void shouldSetShowTitle() {
118122 CustomTabsOptions parceledOptions = CustomTabsOptions .CREATOR .createFromParcel (parcel );
119123 assertThat (parceledOptions , is (notNullValue ()));
120124
121- Intent parceledIntent = parceledOptions .toIntent (context , null );
125+ Intent parceledIntent = parceledOptions .toIntent (context , null , null );
122126 assertThat (parceledIntent , is (notNullValue ()));
123127 assertThat (parceledIntent .hasExtra (CustomTabsIntent .EXTRA_TITLE_VISIBILITY_STATE ), is (true ));
124128 assertThat (parceledIntent .getIntExtra (CustomTabsIntent .EXTRA_TITLE_VISIBILITY_STATE , CustomTabsIntent .NO_TITLE ), is (CustomTabsIntent .SHOW_PAGE_TITLE ));
@@ -131,7 +135,7 @@ public void shouldSetToolbarColor() {
131135 .build ();
132136 assertThat (options , is (notNullValue ()));
133137
134- Intent intent = options .toIntent (context , null );
138+ Intent intent = options .toIntent (context , null , null );
135139
136140 assertThat (intent , is (notNullValue ()));
137141 assertThat (intent .hasExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR ), is (true ));
@@ -145,7 +149,7 @@ public void shouldSetToolbarColor() {
145149 CustomTabsOptions parceledOptions = CustomTabsOptions .CREATOR .createFromParcel (parcel );
146150 assertThat (parceledOptions , is (notNullValue ()));
147151
148- Intent parceledIntent = parceledOptions .toIntent (context , null );
152+ Intent parceledIntent = parceledOptions .toIntent (context , null , null );
149153 assertThat (parceledIntent , is (notNullValue ()));
150154 assertThat (parceledIntent .hasExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR ), is (true ));
151155 assertThat (parceledIntent .getIntExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR , 0 ), is (resolvedColor ));
@@ -174,4 +178,36 @@ public void shouldSetBrowserPicker() {
174178 String preferredPackageNow = parceledOptions .getPreferredPackage (activity .getPackageManager ());
175179 assertThat (preferredPackageNow , is ("com.auth0.browser" ));
176180 }
181+
182+ @ Test
183+ public void shouldSetDisabledCustomTabPackages () {
184+ CustomTabsOptions options = CustomTabsOptions .newBuilder ()
185+ .withDisabledCustomTabsPackages (List .of ("com.auth0.browser" ))
186+ .withToolbarColor (android .R .color .black )
187+ .build ();
188+ assertThat (options , is (notNullValue ()));
189+
190+ Intent intentNoExtras = options .toIntent (context , null , "com.auth0.browser" );
191+
192+ assertThat (intentNoExtras , is (notNullValue ()));
193+ assertThat (intentNoExtras .getExtras (), is (nullValue ()));
194+ assertEquals (intentNoExtras .getAction (), "android.intent.action.VIEW" );
195+
196+ Intent intentWithToolbarExtra = options .toIntent (context , null , "com.another.browser" );
197+ assertThat (intentWithToolbarExtra , is (notNullValue ()));
198+ assertThat (intentWithToolbarExtra .hasExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR ), is (true ));
199+ int resolvedColor = ContextCompat .getColor (context , android .R .color .black );
200+ assertThat (intentWithToolbarExtra .getIntExtra (CustomTabsIntent .EXTRA_TOOLBAR_COLOR , 0 ), is (resolvedColor ));
201+
202+ Parcel parcel = Parcel .obtain ();
203+ options .writeToParcel (parcel , 0 );
204+ parcel .setDataPosition (0 );
205+ CustomTabsOptions parceledOptions = CustomTabsOptions .CREATOR .createFromParcel (parcel );
206+ assertThat (parceledOptions , is (notNullValue ()));
207+
208+ Intent parceledIntent = parceledOptions .toIntent (context , null , "com.auth0.browser" );
209+ assertThat (parceledIntent , is (notNullValue ()));
210+ assertThat (parceledIntent .getExtras (), is (nullValue ()));
211+ assertEquals (parceledIntent .getAction (), "android.intent.action.VIEW" );
212+ }
177213}
0 commit comments