Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: third_party/WebKit/Source/modules/peerconnection/RTCDataChannelTest.cpp

Issue 2888043003: Prevent access to null handler in RTCDataChannel. (Closed)
Patch Set: Add unit tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/peerconnection/RTCDataChannel.h" 5 #include "modules/peerconnection/RTCDataChannel.h"
6 6
7 #include <string>
7 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/dom/DOMArrayBuffer.h" 9 #include "core/dom/DOMArrayBuffer.h"
9 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
10 #include "core/events/Event.h" 11 #include "core/events/Event.h"
11 #include "platform/heap/Heap.h" 12 #include "platform/heap/Heap.h"
12 #include "platform/wtf/PtrUtil.h" 13 #include "platform/wtf/PtrUtil.h"
13 #include "platform/wtf/RefPtr.h" 14 #include "platform/wtf/RefPtr.h"
14 #include "platform/wtf/text/WTFString.h" 15 #include "platform/wtf/text/WTFString.h"
15 #include "public/platform/WebRTCDataChannelHandler.h" 16 #include "public/platform/WebRTCDataChannelHandler.h"
16 #include "public/platform/WebVector.h" 17 #include "public/platform/WebVector.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 EXPECT_EQ(4U, channel->scheduled_events_.size()); // No new events. 140 EXPECT_EQ(4U, channel->scheduled_events_.size()); // No new events.
140 141
141 handler->DrainBuffer(1); 142 handler->DrainBuffer(1);
142 EXPECT_EQ(97U, channel->bufferedAmount()); 143 EXPECT_EQ(97U, channel->bufferedAmount());
143 EXPECT_EQ(5U, channel->scheduled_events_.size()); // New event. 144 EXPECT_EQ(5U, channel->scheduled_events_.size()); // New event.
144 EXPECT_EQ( 145 EXPECT_EQ(
145 "bufferedamountlow", 146 "bufferedamountlow",
146 std::string(channel->scheduled_events_.back()->type().Utf8().data())); 147 std::string(channel->scheduled_events_.back()->type().Utf8().data()));
147 } 148 }
148 149
150 TEST(RTCDataChannelTest, SendAfterContextDestroyed) {
151 MockHandler* handler = new MockHandler();
152 RTCDataChannel* channel = RTCDataChannel::Create(0, WTF::WrapUnique(handler));
153 handler->ChangeState(WebRTCDataChannelHandlerClient::kReadyStateOpen);
154 channel->ContextDestroyed(nullptr);
155
156 String message(std::string(100, 'A').c_str());
157 DummyExceptionStateForTesting exception_state;
158 channel->send(message, exception_state);
159
160 EXPECT_TRUE(exception_state.HadException());
161 }
162
163 TEST(RTCDataChannelTest, CloseAfterContextDestroyed) {
164 MockHandler* handler = new MockHandler();
165 RTCDataChannel* channel = RTCDataChannel::Create(0, WTF::WrapUnique(handler));
166 handler->ChangeState(WebRTCDataChannelHandlerClient::kReadyStateOpen);
167 channel->ContextDestroyed(nullptr);
168 channel->close();
169 EXPECT_EQ(String::FromUTF8("closed"), channel->readyState());
170 }
171
149 } // namespace blink 172 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698