Chromium Code Reviews| Index: ppapi/tests/test_tcp_socket_private_trusted.cc |
| diff --git a/ppapi/tests/test_tcp_socket_private_trusted.cc b/ppapi/tests/test_tcp_socket_private_trusted.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b86290ffd4468d0c49f59fb286733cde05fca303 |
| --- /dev/null |
| +++ b/ppapi/tests/test_tcp_socket_private_trusted.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/tests/test_tcp_socket_private_trusted.h" |
| + |
| +#include <stdlib.h> |
|
yzshen1
2012/04/06 19:24:33
Why you need this one?
raymes
2012/04/06 23:22:47
Done.
|
| + |
| +#include "ppapi/cpp/private/tcp_socket_private.h" |
| +#include "ppapi/cpp/private/x509_certificate_private.h" |
| +#include "ppapi/tests/testing_instance.h" |
| +#include "ppapi/tests/test_utils.h" |
| + |
| +REGISTER_TEST_CASE(TCPSocketPrivateTrusted); |
| + |
| +TestTCPSocketPrivateTrusted::TestTCPSocketPrivateTrusted( |
| + TestingInstance* instance) |
| + : TestCase(instance) { |
| +} |
| + |
| +bool TestTCPSocketPrivateTrusted::Init() { |
| + if (!pp::TCPSocketPrivate::IsAvailable()) |
| + return false; |
| + |
| + // We need something to connect to, so we connect to the HTTP server whence we |
| + // came. Grab the host and port. |
| + if (!EnsureRunningOverHTTP()) |
| + return false; |
| + |
| + if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) |
| + return false; |
| + |
| + // Get the port for the SSL server. |
| + ssl_port_ = instance_->ssl_server_port(); |
| + |
| + return true; |
| +} |
| + |
| +void TestTCPSocketPrivateTrusted::RunTests(const std::string& filter) { |
| + RUN_TEST_FORCEASYNC_AND_NOT(GetServerCertificate, filter); |
| +} |
| + |
| +std::string TestTCPSocketPrivateTrusted::TestGetServerCertificate() { |
| + pp::TCPSocketPrivate socket(instance_); |
| + TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
| + |
| + int32_t rv = socket.Connect(host_.c_str(), ssl_port_, cb); |
| + ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| + if (rv == PP_OK_COMPLETIONPENDING) |
| + rv = cb.WaitForResult(); |
| + ASSERT_EQ(PP_OK, rv); |
| + |
| + rv = socket.SSLHandshake(host_.c_str(), ssl_port_, cb); |
| + ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| + if (rv == PP_OK_COMPLETIONPENDING) |
| + rv = cb.WaitForResult(); |
| + ASSERT_EQ(PP_OK, rv); |
| + |
| + const pp::X509Certificate& cert = socket.GetServerCertificate(); |
| + ASSERT_EQ(cert.GetField( |
|
yzshen1
2012/04/06 19:24:33
[nit, optional]
ASSERT_EQ(
cert.GetField(...).
raymes
2012/04/06 23:22:47
Done.
|
| + PP_X509CERTIFICATE_PRIVATE_ISSUER_COMMON_NAME).AsString(), "Test CA"); |
| + ASSERT_EQ(cert.GetField( |
| + PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME).AsString(), "127.0.0.1"); |
| + |
| + PASS(); |
| +} |