Skip to content

Commit 288c2c9

Browse files
committed
don't pass preferredPackage but use existing fun
1 parent f1ab326 commit 288c2c9

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

auth0/src/main/java/com/auth0/android/provider/CustomTabsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void launchAsDefault(Context context, Uri uri) {
149149
} catch (InterruptedException ignored) {
150150
}
151151
Log.d(TAG, "Launching URI. Custom Tabs available: " + available);
152-
final Intent intent = customTabsOptions.toIntent(context, session.get(), this.preferredPackage);
152+
final Intent intent = customTabsOptions.toIntent(context, session.get());
153153
intent.setData(uri);
154154
context.startActivity(intent);
155155
}

auth0/src/main/java/com/auth0/android/provider/CustomTabsOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public static Builder newBuilder() {
6666

6767

6868
@SuppressLint("ResourceType")
69-
Intent toIntent(@NonNull Context context, @Nullable CustomTabsSession session, @Nullable String preferredPackage) {
69+
Intent toIntent(@NonNull Context context, @Nullable CustomTabsSession session) {
70+
String preferredPackage = this.getPreferredPackage(context.getPackageManager());
7071

7172
if (preferredPackage != null && this.isDisabledCustomTabBrowser(preferredPackage)) {
7273
return new Intent(Intent.ACTION_VIEW);

auth0/src/test/java/com/auth0/android/provider/CustomTabsOptionsTest.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void shouldHaveDefaultValues() {
7878
CustomTabsOptions options = CustomTabsOptions.newBuilder().build();
7979
assertThat(options, is(notNullValue()));
8080

81-
Intent intent = options.toIntent(context, null, null);
81+
Intent intent = options.toIntent(context, null);
8282

8383
assertThat(intent, is(notNullValue()));
8484
assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
@@ -93,7 +93,7 @@ public void shouldHaveDefaultValues() {
9393
CustomTabsOptions parceledOptions = CustomTabsOptions.CREATOR.createFromParcel(parcel);
9494
assertThat(parceledOptions, is(notNullValue()));
9595

96-
Intent parceledIntent = parceledOptions.toIntent(context, null, null);
96+
Intent parceledIntent = parceledOptions.toIntent(context, null);
9797
assertThat(parceledIntent, is(notNullValue()));
9898
assertThat(parceledIntent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
9999
assertThat(parceledIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
@@ -109,7 +109,7 @@ public void shouldSetShowTitle() {
109109
.build();
110110
assertThat(options, is(notNullValue()));
111111

112-
Intent intent = options.toIntent(context, null, null);
112+
Intent intent = options.toIntent(context, null);
113113

114114
assertThat(intent, is(notNullValue()));
115115
assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
@@ -122,7 +122,7 @@ public void shouldSetShowTitle() {
122122
CustomTabsOptions parceledOptions = CustomTabsOptions.CREATOR.createFromParcel(parcel);
123123
assertThat(parceledOptions, is(notNullValue()));
124124

125-
Intent parceledIntent = parceledOptions.toIntent(context, null, null);
125+
Intent parceledIntent = parceledOptions.toIntent(context, null);
126126
assertThat(parceledIntent, is(notNullValue()));
127127
assertThat(parceledIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
128128
assertThat(parceledIntent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.SHOW_PAGE_TITLE));
@@ -135,7 +135,7 @@ public void shouldSetToolbarColor() {
135135
.build();
136136
assertThat(options, is(notNullValue()));
137137

138-
Intent intent = options.toIntent(context, null, null);
138+
Intent intent = options.toIntent(context, null);
139139

140140
assertThat(intent, is(notNullValue()));
141141
assertThat(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(true));
@@ -149,7 +149,7 @@ public void shouldSetToolbarColor() {
149149
CustomTabsOptions parceledOptions = CustomTabsOptions.CREATOR.createFromParcel(parcel);
150150
assertThat(parceledOptions, is(notNullValue()));
151151

152-
Intent parceledIntent = parceledOptions.toIntent(context, null, null);
152+
Intent parceledIntent = parceledOptions.toIntent(context, null);
153153
assertThat(parceledIntent, is(notNullValue()));
154154
assertThat(parceledIntent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(true));
155155
assertThat(parceledIntent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0), is(resolvedColor));
@@ -181,33 +181,47 @@ public void shouldSetBrowserPicker() {
181181

182182
@Test
183183
public void shouldSetDisabledCustomTabPackages() {
184+
Activity activity = spy(Robolectric.setupActivity(Activity.class));
185+
BrowserPickerTest.setupBrowserContext(activity, Collections.singletonList("com.auth0.browser"), null, null);
186+
BrowserPicker browserPicker = BrowserPicker.newBuilder().build();
187+
184188
CustomTabsOptions options = CustomTabsOptions.newBuilder()
189+
.withBrowserPicker(browserPicker)
185190
.withDisabledCustomTabsPackages(List.of("com.auth0.browser"))
186191
.withToolbarColor(android.R.color.black)
187192
.build();
188193
assertThat(options, is(notNullValue()));
189194

190-
Intent intentNoExtras = options.toIntent(context, null, "com.auth0.browser");
195+
Intent intentNoExtras = options.toIntent(activity, null);
191196

192197
assertThat(intentNoExtras, is(notNullValue()));
193198
assertThat(intentNoExtras.getExtras(), is(nullValue()));
194199
assertEquals(intentNoExtras.getAction(), "android.intent.action.VIEW");
195200

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-
202201
Parcel parcel = Parcel.obtain();
203202
options.writeToParcel(parcel, 0);
204203
parcel.setDataPosition(0);
205204
CustomTabsOptions parceledOptions = CustomTabsOptions.CREATOR.createFromParcel(parcel);
206205
assertThat(parceledOptions, is(notNullValue()));
207206

208-
Intent parceledIntent = parceledOptions.toIntent(context, null, "com.auth0.browser");
207+
Intent parceledIntent = parceledOptions.toIntent(activity, null);
209208
assertThat(parceledIntent, is(notNullValue()));
210209
assertThat(parceledIntent.getExtras(), is(nullValue()));
211210
assertEquals(parceledIntent.getAction(), "android.intent.action.VIEW");
211+
212+
BrowserPickerTest.setupBrowserContext(activity, Collections.singletonList("com.another.browser"), null, null);
213+
BrowserPicker browserPicker2 = BrowserPicker.newBuilder().build();
214+
215+
CustomTabsOptions options2 = CustomTabsOptions.newBuilder()
216+
.withBrowserPicker(browserPicker2)
217+
.withDisabledCustomTabsPackages(List.of("com.auth0.browser"))
218+
.withToolbarColor(android.R.color.black)
219+
.build();
220+
221+
Intent intentWithToolbarExtra = options2.toIntent(activity, null);
222+
assertThat(intentWithToolbarExtra, is(notNullValue()));
223+
assertThat(intentWithToolbarExtra.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(true));
224+
int resolvedColor = ContextCompat.getColor(activity, android.R.color.black);
225+
assertThat(intentWithToolbarExtra.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0), is(resolvedColor));
212226
}
213227
}

0 commit comments

Comments
 (0)