HttpNegotiateAuthenticatorTest.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:chromium-net-for-android 作者:
/**
 * Test of callback called when getting the auth token completes.
 */
@Test
public void testAccountManagerCallbackRun() {
    HttpNegotiateAuthenticator authenticator = createWithoutNative("Dummy_Account");

    Robolectric.buildActivity(Activity.class).create().start().resume().visible();

    // Call getNextAuthToken to get the callback
    authenticator.getNextAuthToken(1234, "test_principal", "", true);
    verify(sMockAccountManager)
            .getAuthTokenByFeatures(anyString(), anyString(), any(String[].class),
                    any(Activity.class), any(Bundle.class), any(Bundle.class),
                    mBundleCallbackCaptor.capture(), any(Handler.class));

    Bundle resultBundle = new Bundle();
    Bundle context = new Bundle();
    context.putString("String", "test_context");
    resultBundle.putInt(HttpNegotiateConstants.KEY_SPNEGO_RESULT, HttpNegotiateConstants.OK);
    resultBundle.putBundle(HttpNegotiateConstants.KEY_SPNEGO_CONTEXT, context);
    resultBundle.putString(AccountManager.KEY_AUTHTOKEN, "output_token");
    mBundleCallbackCaptor.getValue().run(makeFuture(resultBundle));
    verify(authenticator).nativeSetResult(1234, 0, "output_token");

    // Check that the next call to getNextAuthToken uses the correct context
    authenticator.getNextAuthToken(5678, "test_principal", "", true);
    verify(sMockAccountManager, times(2))
            .getAuthTokenByFeatures(anyString(), anyString(), any(String[].class),
                    any(Activity.class), any(Bundle.class), mBundleCaptor.capture(),
                    mBundleCallbackCaptor.capture(), any(Handler.class));

    assertThat("The spnego context is preserved between calls",
            mBundleCaptor.getValue().getBundle(HttpNegotiateConstants.KEY_SPNEGO_CONTEXT),
            equalTo(context));

    // Test exception path
    mBundleCallbackCaptor.getValue().run(
            this.<Bundle>makeFuture(new OperationCanceledException()));
    verify(authenticator).nativeSetResult(5678, NetError.ERR_UNEXPECTED, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号