| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/native/aw_contents_client_bridge.h" | 5 #include "android_webview/native/aw_contents_client_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void AwContentsClientBridgeTest::TestCertType(SSLClientCertType type, | 104 void AwContentsClientBridgeTest::TestCertType(SSLClientCertType type, |
| 105 const std::string& expected_name) { | 105 const std::string& expected_name) { |
| 106 cert_request_info_->cert_key_types.clear(); | 106 cert_request_info_->cert_key_types.clear(); |
| 107 cert_request_info_->cert_key_types.push_back(type); | 107 cert_request_info_->cert_key_types.push_back(type); |
| 108 bridge_->SelectClientCertificate( | 108 bridge_->SelectClientCertificate( |
| 109 cert_request_info_.get(), | 109 cert_request_info_.get(), |
| 110 base::WrapUnique(new TestClientCertificateDelegate(this))); | 110 base::WrapUnique(new TestClientCertificateDelegate(this))); |
| 111 base::RunLoop().RunUntilIdle(); | 111 base::RunLoop().RunUntilIdle(); |
| 112 EXPECT_EQ(0, cert_selected_callbacks_); | 112 EXPECT_EQ(0, cert_selected_callbacks_); |
| 113 ScopedJavaLocalRef<jobjectArray> key_types = | 113 ScopedJavaLocalRef<jobjectArray> key_types = |
| 114 Java_MockAwContentsClientBridge_getKeyTypes(env_, jbridge_.obj()); | 114 Java_MockAwContentsClientBridge_getKeyTypes(env_, jbridge_); |
| 115 std::vector<std::string> vec; | 115 std::vector<std::string> vec; |
| 116 base::android::AppendJavaStringArrayToStringVector(env_, | 116 base::android::AppendJavaStringArrayToStringVector(env_, |
| 117 key_types.obj(), | 117 key_types.obj(), |
| 118 &vec); | 118 &vec); |
| 119 EXPECT_EQ(1u, vec.size()); | 119 EXPECT_EQ(1u, vec.size()); |
| 120 EXPECT_EQ(expected_name, vec[0]); | 120 EXPECT_EQ(expected_name, vec[0]); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Verify that ProvideClientCertificateResponse works properly when the client | 123 // Verify that ProvideClientCertificateResponse works properly when the client |
| 124 // responds with a null key. | 124 // responds with a null key. |
| 125 TEST_F(AwContentsClientBridgeTest, | 125 TEST_F(AwContentsClientBridgeTest, |
| 126 TestProvideClientCertificateResponseCallsCallbackOnNullKey) { | 126 TestProvideClientCertificateResponseCallsCallbackOnNullKey) { |
| 127 // Call SelectClientCertificate to create a callback id that mock java object | 127 // Call SelectClientCertificate to create a callback id that mock java object |
| 128 // can call on. | 128 // can call on. |
| 129 bridge_->SelectClientCertificate( | 129 bridge_->SelectClientCertificate( |
| 130 cert_request_info_.get(), | 130 cert_request_info_.get(), |
| 131 base::WrapUnique(new TestClientCertificateDelegate(this))); | 131 base::WrapUnique(new TestClientCertificateDelegate(this))); |
| 132 bridge_->ProvideClientCertificateResponse( | 132 bridge_->ProvideClientCertificateResponse( |
| 133 env_, jbridge_, | 133 env_, jbridge_, |
| 134 Java_MockAwContentsClientBridge_getRequestId(env_, jbridge_.obj()), | 134 Java_MockAwContentsClientBridge_getRequestId(env_, jbridge_), |
| 135 Java_MockAwContentsClientBridge_createTestCertChain(env_, jbridge_.obj()), | 135 Java_MockAwContentsClientBridge_createTestCertChain(env_, jbridge_), |
| 136 nullptr); | 136 nullptr); |
| 137 base::RunLoop().RunUntilIdle(); | 137 base::RunLoop().RunUntilIdle(); |
| 138 EXPECT_EQ(nullptr, selected_cert_); | 138 EXPECT_EQ(nullptr, selected_cert_); |
| 139 EXPECT_EQ(1, cert_selected_callbacks_); | 139 EXPECT_EQ(1, cert_selected_callbacks_); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Verify that ProvideClientCertificateResponse calls the callback with | 142 // Verify that ProvideClientCertificateResponse calls the callback with |
| 143 // null parameters when private key is not provided. | 143 // null parameters when private key is not provided. |
| 144 TEST_F(AwContentsClientBridgeTest, | 144 TEST_F(AwContentsClientBridgeTest, |
| 145 TestProvideClientCertificateResponseCallsCallbackOnNullChain) { | 145 TestProvideClientCertificateResponseCallsCallbackOnNullChain) { |
| 146 // Call SelectClientCertificate to create a callback id that mock java object | 146 // Call SelectClientCertificate to create a callback id that mock java object |
| 147 // can call on. | 147 // can call on. |
| 148 bridge_->SelectClientCertificate( | 148 bridge_->SelectClientCertificate( |
| 149 cert_request_info_.get(), | 149 cert_request_info_.get(), |
| 150 base::WrapUnique(new TestClientCertificateDelegate(this))); | 150 base::WrapUnique(new TestClientCertificateDelegate(this))); |
| 151 int requestId = | 151 int requestId = Java_MockAwContentsClientBridge_getRequestId(env_, jbridge_); |
| 152 Java_MockAwContentsClientBridge_getRequestId(env_, jbridge_.obj()); | |
| 153 bridge_->ProvideClientCertificateResponse(env_, jbridge_, requestId, nullptr, | 152 bridge_->ProvideClientCertificateResponse(env_, jbridge_, requestId, nullptr, |
| 154 nullptr); | 153 nullptr); |
| 155 base::RunLoop().RunUntilIdle(); | 154 base::RunLoop().RunUntilIdle(); |
| 156 EXPECT_EQ(nullptr, selected_cert_); | 155 EXPECT_EQ(nullptr, selected_cert_); |
| 157 EXPECT_EQ(1, cert_selected_callbacks_); | 156 EXPECT_EQ(1, cert_selected_callbacks_); |
| 158 } | 157 } |
| 159 | 158 |
| 160 } // android_webview | 159 } // android_webview |
| OLD | NEW |