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_testing_dev.h" |
9 #include "ppapi/c/dev/ppb_websocket_dev.h" | 10 #include "ppapi/c/dev/ppb_websocket_dev.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
14 #include "ppapi/c/ppb_var.h" | 15 #include "ppapi/c/ppb_var.h" |
15 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
16 #include "ppapi/cpp/module.h" | 17 #include "ppapi/cpp/module.h" |
17 #include "ppapi/tests/test_utils.h" | 18 #include "ppapi/tests/test_utils.h" |
18 #include "ppapi/tests/testing_instance.h" | 19 #include "ppapi/tests/testing_instance.h" |
(...skipping 21 matching lines...) Expand all Loading... |
40 bool TestWebSocket::Init() { | 41 bool TestWebSocket::Init() { |
41 websocket_interface_ = static_cast<const PPB_WebSocket_Dev*>( | 42 websocket_interface_ = static_cast<const PPB_WebSocket_Dev*>( |
42 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_DEV_INTERFACE)); | 43 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_DEV_INTERFACE)); |
43 var_interface_ = static_cast<const PPB_Var*>( | 44 var_interface_ = static_cast<const PPB_Var*>( |
44 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); | 45 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); |
45 core_interface_ = static_cast<const PPB_Core*>( | 46 core_interface_ = static_cast<const PPB_Core*>( |
46 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 47 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
47 if (!websocket_interface_ || !var_interface_ || !core_interface_) | 48 if (!websocket_interface_ || !var_interface_ || !core_interface_) |
48 return false; | 49 return false; |
49 | 50 |
50 return true; | 51 return InitTestingInterface(); |
51 } | 52 } |
52 | 53 |
53 void TestWebSocket::RunTests(const std::string& filter) { | 54 void TestWebSocket::RunTests(const std::string& filter) { |
54 RUN_TEST(IsWebSocket, filter); | 55 RUN_TEST_WITH_REFERENCE_CHECK(IsWebSocket, filter); |
55 RUN_TEST(UninitializedPropertiesAccess, filter); | 56 RUN_TEST_WITH_REFERENCE_CHECK(UninitializedPropertiesAccess, filter); |
56 RUN_TEST(InvalidConnect, filter); | 57 RUN_TEST_WITH_REFERENCE_CHECK(InvalidConnect, filter); |
57 RUN_TEST(Protocols, filter); | 58 RUN_TEST_WITH_REFERENCE_CHECK(Protocols, filter); |
58 RUN_TEST(GetURL, filter); | 59 RUN_TEST_WITH_REFERENCE_CHECK(GetURL, filter); |
59 RUN_TEST(ValidConnect, filter); | 60 RUN_TEST_WITH_REFERENCE_CHECK(ValidConnect, filter); |
60 RUN_TEST(InvalidClose, filter); | 61 RUN_TEST_WITH_REFERENCE_CHECK(InvalidClose, filter); |
61 RUN_TEST(ValidClose, filter); | 62 RUN_TEST_WITH_REFERENCE_CHECK(ValidClose, filter); |
62 RUN_TEST(GetProtocol, filter); | 63 RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter); |
63 RUN_TEST(TextSendReceive, filter); | 64 RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter); |
64 } | 65 } |
65 | 66 |
66 PP_Var TestWebSocket::CreateVar(const char* string) { | 67 PP_Var TestWebSocket::CreateVar(const char* string) { |
67 return var_interface_->VarFromUtf8(string, strlen(string)); | 68 return var_interface_->VarFromUtf8(string, strlen(string)); |
68 } | 69 } |
69 | 70 |
70 void TestWebSocket::ReleaseVar(const PP_Var& var) { | 71 void TestWebSocket::ReleaseVar(const PP_Var& var) { |
71 var_interface_->Release(var); | 72 var_interface_->Release(var); |
72 } | 73 } |
73 | 74 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ASSERT_TRUE(ws); | 132 ASSERT_TRUE(ws); |
132 | 133 |
133 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); | 134 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); |
134 ASSERT_EQ(0U, bufferedAmount); | 135 ASSERT_EQ(0U, bufferedAmount); |
135 | 136 |
136 uint16_t close_code = websocket_interface_->GetCloseCode(ws); | 137 uint16_t close_code = websocket_interface_->GetCloseCode(ws); |
137 ASSERT_EQ(0U, close_code); | 138 ASSERT_EQ(0U, close_code); |
138 | 139 |
139 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); | 140 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); |
140 ASSERT_TRUE(AreEqual(close_reason, "")); | 141 ASSERT_TRUE(AreEqual(close_reason, "")); |
| 142 ReleaseVar(close_reason); |
141 | 143 |
142 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); | 144 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); |
143 ASSERT_EQ(PP_FALSE, close_was_clean); | 145 ASSERT_EQ(PP_FALSE, close_was_clean); |
144 | 146 |
145 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 147 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
146 ASSERT_TRUE(AreEqual(extensions, "")); | 148 ASSERT_TRUE(AreEqual(extensions, "")); |
| 149 ReleaseVar(extensions); |
147 | 150 |
148 PP_Var protocol = websocket_interface_->GetProtocol(ws); | 151 PP_Var protocol = websocket_interface_->GetProtocol(ws); |
149 ASSERT_TRUE(AreEqual(protocol, "")); | 152 ASSERT_TRUE(AreEqual(protocol, "")); |
| 153 ReleaseVar(protocol); |
150 | 154 |
151 PP_WebSocketReadyState_Dev ready_state = | 155 PP_WebSocketReadyState_Dev ready_state = |
152 websocket_interface_->GetReadyState(ws); | 156 websocket_interface_->GetReadyState(ws); |
153 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); | 157 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); |
154 | 158 |
155 PP_Var url = websocket_interface_->GetURL(ws); | 159 PP_Var url = websocket_interface_->GetURL(ws); |
156 ASSERT_TRUE(AreEqual(url, "")); | 160 ASSERT_TRUE(AreEqual(url, "")); |
| 161 ReleaseVar(url); |
| 162 |
| 163 core_interface_->ReleaseResource(ws); |
157 | 164 |
158 PASS(); | 165 PASS(); |
159 } | 166 } |
160 | 167 |
161 std::string TestWebSocket::TestInvalidConnect() { | 168 std::string TestWebSocket::TestInvalidConnect() { |
162 PP_Var protocols[] = { PP_MakeUndefined() }; | 169 PP_Var protocols[] = { PP_MakeUndefined() }; |
163 | 170 |
164 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 171 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
165 ASSERT_TRUE(ws); | 172 ASSERT_TRUE(ws); |
166 | 173 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 PASS(); | 407 PASS(); |
401 } | 408 } |
402 | 409 |
403 // TODO(toyoshim): Add tests for GetBufferedAmount(). | 410 // TODO(toyoshim): Add tests for GetBufferedAmount(). |
404 // For now, the function doesn't work fine because update callback in WebKit is | 411 // For now, the function doesn't work fine because update callback in WebKit is |
405 // not landed yet. | 412 // not landed yet. |
406 | 413 |
407 // TODO(toyoshim): Add tests for didReceiveMessageError(). | 414 // TODO(toyoshim): Add tests for didReceiveMessageError(). |
408 | 415 |
409 // TODO(toyoshim): Add other function tests. | 416 // TODO(toyoshim): Add other function tests. |
OLD | NEW |