| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_websocket.h" | 5 #include "ppapi/tests/test_websocket.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "ppapi/c/dev/ppb_websocket_dev.h" | 9 #include "ppapi/c/dev/ppb_websocket_dev.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 core_interface_ = static_cast<const PPB_Core*>( | 40 core_interface_ = static_cast<const PPB_Core*>( |
| 41 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 41 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
| 42 if (!websocket_interface_ || !var_interface_ || !core_interface_) | 42 if (!websocket_interface_ || !var_interface_ || !core_interface_) |
| 43 return false; | 43 return false; |
| 44 | 44 |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TestWebSocket::RunTests(const std::string& filter) { | 48 void TestWebSocket::RunTests(const std::string& filter) { |
| 49 RUN_TEST(IsWebSocket, filter); | 49 RUN_TEST(IsWebSocket, filter); |
| 50 RUN_TEST(UninitializedPropertiesAccess, filter); |
| 50 RUN_TEST(InvalidConnect, filter); | 51 RUN_TEST(InvalidConnect, filter); |
| 51 RUN_TEST(GetURL, filter); | 52 RUN_TEST(GetURL, filter); |
| 52 RUN_TEST(ValidConnect, filter); | 53 RUN_TEST(ValidConnect, filter); |
| 53 RUN_TEST(GetProtocol, filter); | 54 RUN_TEST(GetProtocol, filter); |
| 54 RUN_TEST(TextSendReceive, filter); | 55 RUN_TEST(TextSendReceive, filter); |
| 55 } | 56 } |
| 56 | 57 |
| 57 PP_Var TestWebSocket::CreateVar(const char* string) { | 58 PP_Var TestWebSocket::CreateVar(const char* string) { |
| 58 return var_interface_->VarFromUtf8( | 59 return var_interface_->VarFromUtf8( |
| 59 pp::Module::Get()->pp_module(), string, strlen(string)); | 60 pp::Module::Get()->pp_module(), string, strlen(string)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 ASSERT_TRUE(ws); | 112 ASSERT_TRUE(ws); |
| 112 | 113 |
| 113 result = websocket_interface_->IsWebSocket(ws); | 114 result = websocket_interface_->IsWebSocket(ws); |
| 114 ASSERT_TRUE(result); | 115 ASSERT_TRUE(result); |
| 115 | 116 |
| 116 core_interface_->ReleaseResource(ws); | 117 core_interface_->ReleaseResource(ws); |
| 117 | 118 |
| 118 PASS(); | 119 PASS(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // TODO(toyoshim): Add tests to call various interfaces before calling connect. | 122 std::string TestWebSocket::TestUninitializedPropertiesAccess() { |
| 123 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
| 124 ASSERT_TRUE(ws); |
| 125 |
| 126 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); |
| 127 ASSERT_EQ(0, bufferedAmount); |
| 128 |
| 129 uint16_t close_code = websocket_interface_->GetCloseCode(ws); |
| 130 ASSERT_EQ(0, close_code); |
| 131 |
| 132 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); |
| 133 ASSERT_TRUE(AreEqual(close_reason, "")); |
| 134 |
| 135 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); |
| 136 ASSERT_EQ(PP_FALSE, close_was_clean); |
| 137 |
| 138 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
| 139 ASSERT_TRUE(AreEqual(extensions, "")); |
| 140 |
| 141 PP_Var protocol = websocket_interface_->GetProtocol(ws); |
| 142 ASSERT_TRUE(AreEqual(protocol, "")); |
| 143 |
| 144 PP_WebSocketReadyState_Dev ready_state = |
| 145 websocket_interface_->GetReadyState(ws); |
| 146 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); |
| 147 |
| 148 PP_Var url = websocket_interface_->GetURL(ws); |
| 149 ASSERT_TRUE(AreEqual(url, "")); |
| 150 |
| 151 PASS(); |
| 152 } |
| 122 | 153 |
| 123 std::string TestWebSocket::TestInvalidConnect() { | 154 std::string TestWebSocket::TestInvalidConnect() { |
| 124 PP_Var protocols[] = { PP_MakeUndefined() }; | 155 PP_Var protocols[] = { PP_MakeUndefined() }; |
| 125 | 156 |
| 126 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 157 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
| 127 ASSERT_TRUE(ws); | 158 ASSERT_TRUE(ws); |
| 128 | 159 |
| 129 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 160 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 130 int32_t result = websocket_interface_->Connect( | 161 int32_t result = websocket_interface_->Connect( |
| 131 ws, PP_MakeUndefined(), protocols, 1, | 162 ws, PP_MakeUndefined(), protocols, 1, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 PASS(); | 263 PASS(); |
| 233 } | 264 } |
| 234 | 265 |
| 235 // TODO(toyoshim): Add tests for GetBufferedAmount(). | 266 // TODO(toyoshim): Add tests for GetBufferedAmount(). |
| 236 // For now, the function doesn't work fine because update callback in WebKit is | 267 // For now, the function doesn't work fine because update callback in WebKit is |
| 237 // not landed yet. | 268 // not landed yet. |
| 238 | 269 |
| 239 // TODO(toyoshim): Add tests for didReceiveMessageError(). | 270 // TODO(toyoshim): Add tests for didReceiveMessageError(). |
| 240 | 271 |
| 241 // TODO(toyoshim): Add other function tests. | 272 // TODO(toyoshim): Add other function tests. |
| OLD | NEW |