@ -1,10 +1,17 @@
# include "inspector_socket.h"
# include "gtest/gtest.h"
# define PORT 9444
using namespace node : : inspector ;
namespace {
using node : : inspector : : InspectorSocket ;
using node : : inspector : : inspector_from_stream ;
using node : : inspector : : inspector_handshake_event ;
using node : : inspector : : kInspectorHandshakeFailed ;
using node : : inspector : : kInspectorHandshakeHttpGet ;
using node : : inspector : : kInspectorHandshakeUpgraded ;
using node : : inspector : : kInspectorHandshakeUpgrading ;
static const int MAX_LOOP_ITERATIONS = 10000 ;
@ -24,7 +31,7 @@ static enum inspector_handshake_event last_event = kInspectorHandshakeHttpGet;
static uv_loop_t loop ;
static uv_tcp_t server , client_socket ;
static InspectorSocket inspector ;
static std : : string last_path ;
static std : : string last_path ; // NOLINT(runtime/string)
static void ( * handshake_delegate ) ( enum inspector_handshake_event state ,
const std : : string & path ,
bool * should_continue ) ;
@ -58,7 +65,9 @@ public:
uv_run ( & loop , UV_RUN_NOWAIT ) ;
}
}
bool timed_out ;
private :
static void set_flag ( uv_timer_t * timer ) {
Timeout * t = node : : ContainerOf ( & Timeout : : timer_ , timer ) ;
@ -128,7 +137,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread,
EXPECT_TRUE ( nread > = 0 & & nread ! = UV_EOF ) ;
ssize_t i ;
char c , actual ;
ASSERT_TRUE ( expectation - > expected_len > 0 ) ;
ASSERT_G T ( expectation - > expected_len , 0 ) ;
for ( i = 0 ; i < nread & & expectation - > pos < = expectation - > expected_len ; i + + ) {
c = expectation - > expected [ expectation - > pos + + ] ;
actual = buf - > base [ i ] ;
@ -419,7 +428,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) {
}
TEST_F ( InspectorSocketTest , BufferEdgeCases ) {
do_write ( const_cast < char * > ( HANDSHAKE_REQ ) , sizeof ( HANDSHAKE_REQ ) - 1 ) ;
expect_handshake ( ) ;
@ -497,7 +505,8 @@ TEST_F(InspectorSocketTest, AcceptsRequestInSeveralWrites) {
SPIN_WHILE ( ! inspector_ready ) ;
expect_handshake ( ) ;
inspector_read_stop ( & inspector ) ;
GTEST_ASSERT_EQ ( uv_is_active ( reinterpret_cast < uv_handle_t * > ( & client_socket ) ) , 0 ) ;
GTEST_ASSERT_EQ ( uv_is_active ( reinterpret_cast < uv_handle_t * > ( & client_socket ) ) ,
0 ) ;
manual_inspector_socket_cleanup ( ) ;
}
@ -530,7 +539,6 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) {
" Upgrade: websocket \r \n "
" Connection: Upgrade \r \n "
" Sec-WebSocket-Version: 13 \r \n \r \n " ;
;
do_write ( const_cast < char * > ( BROKEN_REQUEST ) , sizeof ( BROKEN_REQUEST ) - 1 ) ;
SPIN_WHILE ( last_event ! = kInspectorHandshakeFailed ) ;
@ -548,7 +556,8 @@ TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) {
const char SERVER_FRAME [ ] = " I'm not a good WS frame. Nope! " ;
do_write ( SERVER_FRAME , sizeof ( SERVER_FRAME ) ) ;
expect_server_read_error ( ) ;
GTEST_ASSERT_EQ ( uv_is_active ( reinterpret_cast < uv_handle_t * > ( & client_socket ) ) , 0 ) ;
GTEST_ASSERT_EQ ( uv_is_active ( reinterpret_cast < uv_handle_t * > ( & client_socket ) ) ,
0 ) ;
}
TEST_F ( InspectorSocketTest , CanStopReadingFromInspector ) {
@ -895,3 +904,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
SPIN_WHILE ( err > 0 ) ;
EXPECT_EQ ( UV_EPROTO , err ) ;
}
} // anonymous namespace