After migration to Credential Manager I can't find a way how to test sign-in scenarios for different cases.
When I used to use GoogleSignIn it was simple. The following code helped me:
protected fun setupAndClickSignInButton(signInAccountJson: String) {
val intent = Intent()
intent.putExtra("googleSignInAccount", GoogleSignInAccount.zab(signInAccountJson))
val signInIntent = GoogleSignIn.getClient(
getTargetContext(),
GoogleApiClientHelper.generateGoogleSignInOptions()
).signInIntent
intending(hasComponent(signInIntent.component))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, intent))
onView(withId(R.id.buttonSignInWithGmail))
.check(matches(isDisplayed()))
.perform(click())
}
protected fun genMockGoogleSignInAccountJson(
email: String,
tokenId: String = genMockGoogleSignInTokenId(email)
): String {
return "{\n" +
" \"id\":\"111111111111111111111\",\n" +
" \"tokenId\":\"$tokenId\",\n" +
" \"email\":\"" + email + "\",\n" +
" \"displayName\":\"Test\",\n" +
" \"givenName\":\"Test\",\n" +
" \"familyName\":\"Test\",\n" +
" \"photoUrl\":\"https:\\/\\/example.com\",\n" +
" \"expirationTime\":1572537339,\n" +
" \"obfuscatedIdentifier\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" +
" \"grantedScopes\":[\n" +
" \"email\",\n" +
" \"https:\\/\\/mail.google.com\\/\",\n" +
" \"https:\\/\\/www.googleapis.com\\/auth\\/userinfo.email\",\n" +
" \"https:\\/\\/www.googleapis.com\\/auth\\/userinfo.profile\",\n" +
" \"openid\",\n" +
" \"profile\"\n" +
" ]\n" +
"}"
}
I didn't need to to sign-in(provide a real email address and password). Just returned a mock response and based on input tokenId decided what to do next.
Question: is it possible to mock the sign-in process with Credential Manager? Need to add that after migration, authentication and authorization are separate flows now. Authorization is based on Authorize access to user data on Android. It looks like it can be intented as it uses onActivityResult approach. So now Credential Manager is main problem here. After a short deepdiving in the source code it looks like it uses AIDL. I have no idea how to mock it.