diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 19:09:35 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-22 19:09:35 +0000 |
commit | e83e409b5f05357538dad425c2dd6263808eaeb4 (patch) | |
tree | 2ca5fb9dcdd0a34e65f5518bdb683bab1256582d /ppapi/tests | |
parent | e0ff4debd3eceb8cea3e42fb93f9a9bcd2550d19 (diff) | |
download | chromium_src-e83e409b5f05357538dad425c2dd6263808eaeb4.zip chromium_src-e83e409b5f05357538dad425c2dd6263808eaeb4.tar.gz chromium_src-e83e409b5f05357538dad425c2dd6263808eaeb4.tar.bz2 |
Added a pepper test for SSLHandshake. This starts an SSL server which the test can connect to.
BUG=114626
TEST=Ran pepper TCP tests.
Review URL: http://codereview.chromium.org/9791003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_case.html | 7 | ||||
-rw-r--r-- | ppapi/tests/test_tcp_socket_private.cc | 34 | ||||
-rw-r--r-- | ppapi/tests/test_tcp_socket_private.h | 4 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.cc | 3 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.h | 5 |
5 files changed, 50 insertions, 3 deletions
diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html index 1a11546..071608b 100644 --- a/ppapi/tests/test_case.html +++ b/ppapi/tests/test_case.html @@ -34,11 +34,14 @@ function AppendFrame(testcase, i) { var frame = document.createElement("IFRAME"); var mode = ExtractSearchParameter("mode"); var websocket_port = ExtractSearchParameter("websocket_port"); + var ssl_server_port = ExtractSearchParameter("ssl_server_port"); var src = "?testcase=" + testcase; if (mode == "nacl") src += "&mode=nacl"; if (websocket_port != "") src += "&websocket_port=" + websocket_port; + if (ssl_server_port != "") + src += "&ssl_server_port=" + ssl_server_port; frame.setAttribute("src", src); frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")"); @@ -222,6 +225,10 @@ onload = function() { var websocket_port = ExtractSearchParameter("websocket_port"); if (websocket_port != "") obj.setAttribute("websocket_port", websocket_port); + var ssl_server_port = ExtractSearchParameter("ssl_server_port"); + if (ssl_server_port != "") + obj.setAttribute("ssl_server_port", ssl_server_port); + var container = document.getElementById("container"); container.addEventListener("message", handleTestingMessage, true); // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note diff --git a/ppapi/tests/test_tcp_socket_private.cc b/ppapi/tests/test_tcp_socket_private.cc index ee2d71f..6bffe49 100644 --- a/ppapi/tests/test_tcp_socket_private.cc +++ b/ppapi/tests/test_tcp_socket_private.cc @@ -40,12 +40,16 @@ bool TestTCPSocketPrivate::Init() { 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 TestTCPSocketPrivate::RunTests(const std::string& filter) { RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter); + RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSSL, filter); RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter); } @@ -91,6 +95,34 @@ std::string TestTCPSocketPrivate::TestReadWrite() { PASS(); } +std::string TestTCPSocketPrivate::TestReadWriteSSL() { + 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); + + ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n")); + + // Read up to the first \n and check that it looks like valid HTTP response. + std::string s; + ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); + ASSERT_TRUE(ValidateHttpResponse(s)); + + socket.Disconnect(); + + PASS(); +} + std::string TestTCPSocketPrivate::TestConnectAddress() { PP_NetAddress_Private address; @@ -128,8 +160,6 @@ std::string TestTCPSocketPrivate::TestConnectAddress() { PASS(); } -// TODO(viettrungluu): Try testing SSL somehow. - int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( pp::TCPSocketPrivate* socket, std::string* s) { diff --git a/ppapi/tests/test_tcp_socket_private.h b/ppapi/tests/test_tcp_socket_private.h index 4c18a62..4c31853 100644 --- a/ppapi/tests/test_tcp_socket_private.h +++ b/ppapi/tests/test_tcp_socket_private.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -25,6 +25,7 @@ class TestTCPSocketPrivate : public TestCase { private: std::string TestBasic(); std::string TestReadWrite(); + std::string TestReadWriteSSL(); std::string TestConnectAddress(); int32_t ReadFirstLineFromSocket(pp::TCPSocketPrivate* socket, std::string* s); @@ -33,6 +34,7 @@ class TestTCPSocketPrivate : public TestCase { std::string host_; uint16_t port_; + uint16_t ssl_port_; }; #endif // PAPPI_TESTS_TEST_TCP_SOCKET_PRIVATE_H_ diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc index 4ef5152..f19292f 100644 --- a/ppapi/tests/testing_instance.cc +++ b/ppapi/tests/testing_instance.cc @@ -31,6 +31,7 @@ TestingInstance::TestingInstance(PP_Instance instance) current_case_(NULL), executed_tests_(false), nacl_mode_(false), + ssl_server_port_(-1), websocket_port_(-1) { callback_factory_.Initialize(this); } @@ -51,6 +52,8 @@ bool TestingInstance::Init(uint32_t argc, protocol_ = argv[i]; } else if (std::strcmp(argn[i], "websocket_port") == 0) { websocket_port_ = atoi(argv[i]); + } else if (std::strcmp(argn[i], "ssl_server_port") == 0) { + ssl_server_port_ = atoi(argv[i]); } } // Create the proper test case from the argument. diff --git a/ppapi/tests/testing_instance.h b/ppapi/tests/testing_instance.h index c064329..b5a6333 100644 --- a/ppapi/tests/testing_instance.h +++ b/ppapi/tests/testing_instance.h @@ -82,6 +82,8 @@ pp::InstancePrivate { return protocol_; } + int ssl_server_port() { return ssl_server_port_; } + int websocket_port() { return websocket_port_; } // Posts a message to the test page to eval() the script. @@ -149,6 +151,9 @@ pp::InstancePrivate { // with http. std::string protocol_; + // SSL server port. + int ssl_server_port_; + // WebSocket port. int websocket_port_; }; |