Invalidate scans when the host volume is unmounted.
[chromium-blink-merge.git] / ppapi / tests / test_tcp_socket_private_trusted.cc
blobcf541c493f3823d9e881956495fb544fe5df9990
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())
21 return false;
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;
28 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_))
29 return false;
31 // Get the port for the SSL server.
32 ssl_port_ = instance_->ssl_server_port();
34 return true;
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());
45 cb.WaitForResult(
46 socket.Connect(host_.c_str(), ssl_port_, cb.GetCallback()));
47 CHECK_CALLBACK_BEHAVIOR(cb);
48 ASSERT_EQ(PP_OK, cb.result());
50 cb.WaitForResult(
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();
56 ASSERT_EQ(
57 cert.GetField(PP_X509CERTIFICATE_PRIVATE_ISSUER_COMMON_NAME).AsString(),
58 "Test Root CA");
59 ASSERT_EQ(
60 cert.GetField(PP_X509CERTIFICATE_PRIVATE_SUBJECT_COMMON_NAME).AsString(),
61 "127.0.0.1");
62 PASS();