Chromium Code Reviews| 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 <stdlib.h> | |
|
yzshen1
2012/04/06 19:24:33
Why you need this one?
raymes
2012/04/06 23:22:47
Done.
| |
| 8 | |
| 9 #include "ppapi/cpp/private/tcp_socket_private.h" | |
| 10 #include "ppapi/cpp/private/x509_certificate_private.h" | |
| 11 #include "ppapi/tests/testing_instance.h" | |
| 12 #include "ppapi/tests/test_utils.h" | |
| 13 | |
| 14 REGISTER_TEST_CASE(TCPSocketPrivateTrusted); | |
| 15 | |
| 16 TestTCPSocketPrivateTrusted::TestTCPSocketPrivateTrusted( | |
| 17 TestingInstance* instance) | |
| 18 : TestCase(instance) { | |
| 19 } | |
| 20 | |
| 21 bool TestTCPSocketPrivateTrusted::Init() { | |
| 22 if (!pp::TCPSocketPrivate::IsAvailable()) | |
| 23 return false; | |
| 24 | |
| 25 // We need something to connect to, so we connect to the HTTP server whence we | |
| 26 // came. Grab the host and port. | |
| 27 if (!EnsureRunningOverHTTP()) | |
| 28 return false; | |
| 29 | |
| 30 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) | |
| 31 return false; | |
| 32 | |
| 33 // Get the port for the SSL server. | |
| 34 ssl_port_ = instance_->ssl_server_port(); | |
| 35 | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 void TestTCPSocketPrivateTrusted::RunTests(const std::string& filter) { | |
| 40 RUN_TEST_FORCEASYNC_AND_NOT(GetServerCertificate, filter); | |
| 41 } | |
| 42 | |
| 43 std::string TestTCPSocketPrivateTrusted::TestGetServerCertificate() { | |
| 44 pp::TCPSocketPrivate socket(instance_); | |
| 45 TestCompletionCallback cb(instance_->pp_instance(), force_async_); | |
| 46 | |
| 47 int32_t rv = socket.Connect(host_.c_str(), ssl_port_, cb); | |
| 48 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); | |
| 49 if (rv == PP_OK_COMPLETIONPENDING) | |
| 50 rv = cb.WaitForResult(); | |
| 51 ASSERT_EQ(PP_OK, rv); | |
| 52 | |
| 53 rv = socket.SSLHandshake(host_.c_str(), ssl_port_, cb); | |
| 54 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); | |
| 55 if (rv == PP_OK_COMPLETIONPENDING) | |
| 56 rv = cb.WaitForResult(); | |
| 57 ASSERT_EQ(PP_OK, rv); | |
| 58 | |
| 59 const pp::X509Certificate& cert = socket.GetServerCertificate(); | |
| 60 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.
| |
| 61 PP_X509CERTIFICATE_PRIVATE_ISSUER_COMMON_NAME).AsString(), "Test CA"); | |
| 62 ASSERT_EQ(cert.GetField( | |
| 63 PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME).AsString(), "127.0.0.1"); | |
| 64 | |
| 65 PASS(); | |
| 66 } | |
| OLD | NEW |