| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "ppapi/tests/test_tcp_socket_private_trusted.h" |
| 6 |
| 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" |
| 11 |
| 12 REGISTER_TEST_CASE(TCPSocketPrivateTrusted); |
| 13 |
| 14 TestTCPSocketPrivateTrusted::TestTCPSocketPrivateTrusted( |
| 15 TestingInstance* instance) |
| 16 : TestCase(instance) { |
| 17 } |
| 18 |
| 19 bool TestTCPSocketPrivateTrusted::Init() { |
| 20 if (!pp::TCPSocketPrivate::IsAvailable()) |
| 21 return false; |
| 22 |
| 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()) |
| 26 return false; |
| 27 |
| 28 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) |
| 29 return false; |
| 30 |
| 31 // Get the port for the SSL server. |
| 32 ssl_port_ = instance_->ssl_server_port(); |
| 33 |
| 34 return true; |
| 35 } |
| 36 |
| 37 void TestTCPSocketPrivateTrusted::RunTests(const std::string& filter) { |
| 38 RUN_TEST_FORCEASYNC_AND_NOT(GetServerCertificate, filter); |
| 39 } |
| 40 |
| 41 std::string TestTCPSocketPrivateTrusted::TestGetServerCertificate() { |
| 42 pp::TCPSocketPrivate socket(instance_); |
| 43 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
| 44 |
| 45 int32_t rv = socket.Connect(host_.c_str(), ssl_port_, cb); |
| 46 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 47 if (rv == PP_OK_COMPLETIONPENDING) |
| 48 rv = cb.WaitForResult(); |
| 49 ASSERT_EQ(PP_OK, rv); |
| 50 |
| 51 rv = socket.SSLHandshake(host_.c_str(), ssl_port_, cb); |
| 52 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 53 if (rv == PP_OK_COMPLETIONPENDING) |
| 54 rv = cb.WaitForResult(); |
| 55 ASSERT_EQ(PP_OK, rv); |
| 56 |
| 57 const pp::X509CertificatePrivate& cert = socket.GetServerCertificate(); |
| 58 ASSERT_EQ( |
| 59 cert.GetField(PP_X509CERTIFICATE_PRIVATE_ISSUER_COMMON_NAME).AsString(), |
| 60 "Test CA"); |
| 61 ASSERT_EQ( |
| 62 cert.GetField(PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME).AsString(), |
| 63 "127.0.0.1"); |
| 64 PASS(); |
| 65 } |
| OLD | NEW |