From 1e3c80c9fc160e08be6daec95061f6e8d922021c Mon Sep 17 00:00:00 2001 From: Henning Nielsen Lund Date: Sat, 28 Jul 2018 15:32:01 +0200 Subject: [PATCH] add getBrowserDescriptor() Make it possible to get the BrowserDescriptor used by AuthorizationService. fixes: #387 Signed-off-by: Henning Nielsen Lund --- .../java/net/openid/appauth/AuthorizationService.java | 8 ++++++++ .../net/openid/appauth/AuthorizationServiceTest.java | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index 5b9d90fd..f2a3256a 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -121,6 +121,14 @@ public CustomTabManager getCustomTabManager() { return mCustomTabManager; } + /** + * Returns the BrowserDescriptor of the chosen browser. + * Can for example be used to set the browsers package name to a CustomTabsIntent. + */ + public BrowserDescriptor getBrowserDescriptor() { + return mBrowser; + } + /** * Creates a custom tab builder, that will use a tab session from an existing connection to * a web browser, if available. diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index bfda6b87..fce8419d 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -27,6 +27,7 @@ import net.openid.appauth.AppAuthConfiguration.Builder; import net.openid.appauth.AuthorizationException.GeneralErrors; +import net.openid.appauth.browser.BrowserDescriptor; import net.openid.appauth.browser.Browsers; import net.openid.appauth.browser.CustomTabManager; import net.openid.appauth.connectivity.ConnectionBuilder; @@ -119,6 +120,7 @@ public class AuthorizationServiceTest { private RegistrationCallback mRegistrationCallback; private AuthorizationService mService; private OutputStream mOutputStream; + private BrowserDescriptor mBrowserDescriptor; @Mock ConnectionBuilder mConnectionBuilder; @Mock HttpURLConnection mHttpConnection; @Mock PendingIntent mPendingIntent; @@ -132,12 +134,13 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mAuthCallback = new AuthorizationCallback(); mRegistrationCallback = new RegistrationCallback(); + mBrowserDescriptor = Browsers.Chrome.customTab("46"); mService = new AuthorizationService( mContext, new Builder() .setConnectionBuilder(mConnectionBuilder) .build(), - Browsers.Chrome.customTab("46"), + mBrowserDescriptor, mCustomTabManager); mOutputStream = new ByteArrayOutputStream(); when(mConnectionBuilder.openConnection(any(Uri.class))).thenReturn(mHttpConnection); @@ -397,6 +400,11 @@ public void testCreateCustomTabsIntentBuilder_afterDispose() throws Exception { mService.createCustomTabsIntentBuilder(); } + @Test + public void testGetBrowserDescriptor_browserAvailable() { + assertEquals(mService.getBrowserDescriptor(), mBrowserDescriptor); + } + private Intent captureAuthRequestIntent() { ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContext).startActivity(intentCaptor.capture());