1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_tcp_socket_private_trusted.h"
7 #include "ppapi/cpp/private/tcp_socket_private.h"
8 #include "ppapi/cpp/private/x509_certificate_private.h"
9 #include "ppapi/tests/testing_instance.h"
10 #include "ppapi/tests/test_utils.h"
12 REGISTER_TEST_CASE(TCPSocketPrivateTrusted
);
14 TestTCPSocketPrivateTrusted::TestTCPSocketPrivateTrusted(
15 TestingInstance
* instance
)
16 : TestCase(instance
) {
19 bool TestTCPSocketPrivateTrusted::Init() {
20 if (!pp::TCPSocketPrivate::IsAvailable())
23 // We need something to connect to, so we connect to the HTTP server whence we
24 // came. Grab the host and port.
25 if (!EnsureRunningOverHTTP())
28 if (!GetLocalHostPort(instance_
->pp_instance(), &host_
, &port_
))
31 // Get the port for the SSL server.
32 ssl_port_
= instance_
->ssl_server_port();
37 void TestTCPSocketPrivateTrusted::RunTests(const std::string
& filter
) {
38 RUN_CALLBACK_TEST(TestTCPSocketPrivateTrusted
, GetServerCertificate
, filter
);
41 std::string
TestTCPSocketPrivateTrusted::TestGetServerCertificate() {
42 pp::TCPSocketPrivate
socket(instance_
);
43 TestCompletionCallback
cb(instance_
->pp_instance(), callback_type());
46 socket
.Connect(host_
.c_str(), ssl_port_
, cb
.GetCallback()));
47 CHECK_CALLBACK_BEHAVIOR(cb
);
48 ASSERT_EQ(PP_OK
, cb
.result());
51 socket
.SSLHandshake(host_
.c_str(), ssl_port_
, cb
.GetCallback()));
52 CHECK_CALLBACK_BEHAVIOR(cb
);
53 ASSERT_EQ(PP_OK
, cb
.result());
55 const pp::X509CertificatePrivate
& cert
= socket
.GetServerCertificate();
57 cert
.GetField(PP_X509CERTIFICATE_PRIVATE_ISSUER_COMMON_NAME
).AsString(),
60 cert
.GetField(PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME
).AsString(),