1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h"
#include <memory>
#include <string>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/test_simple_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_rtc_data_channel_state.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/testing/null_execution_context.h"
#include "third_party/blink/renderer/modules/peerconnection/mock_rtc_peer_connection_handler_platform.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/page_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
using testing::_;
void RunSynchronous(base::TestSimpleTaskRunner* thread,
CrossThreadOnceClosure closure) {
if (thread->BelongsToCurrentThread()) {
std::move(closure).Run();
return;
}
base::WaitableEvent waitable_event(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
PostCrossThreadTask(
*thread, FROM_HERE,
CrossThreadBindOnce(
[](CrossThreadOnceClosure closure, base::WaitableEvent* event) {
std::move(closure).Run();
event->Signal();
},
std::move(closure), CrossThreadUnretained(&waitable_event)));
waitable_event.Wait();
}
class MockEventListener final : public NativeEventListener {
public:
MOCK_METHOD(void, Invoke, (ExecutionContext * executionContext, Event*));
};
class MockPeerConnectionHandler : public MockRTCPeerConnectionHandlerPlatform {
public:
MockPeerConnectionHandler(
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread)
: signaling_thread_(signaling_thread) {}
MockPeerConnectionHandler(const MockPeerConnectionHandler&) = delete;
MockPeerConnectionHandler& operator=(const MockPeerConnectionHandler&) =
delete;
scoped_refptr<base::SingleThreadTaskRunner> signaling_thread()
const override {
return signaling_thread_;
}
private:
void RunOnceClosure() {
DCHECK(signaling_thread_->BelongsToCurrentThread());
std::move(closure_).Run();
}
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread_;
CrossThreadOnceClosure closure_;
};
class MockDataChannel : public webrtc::DataChannelInterface {
public:
explicit MockDataChannel(
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread)
: signaling_thread_(signaling_thread),
buffered_amount_(0),
observer_(nullptr),
state_(webrtc::DataChannelInterface::kConnecting) {}
MockDataChannel(const MockDataChannel&) = delete;
MockDataChannel& operator=(const MockDataChannel&) = delete;
std::string label() const override { return std::string(); }
bool reliable() const override { return false; }
bool ordered() const override { return false; }
std::optional<int> maxPacketLifeTime() const override { return std::nullopt; }
std::optional<int> maxRetransmitsOpt() const override { return std::nullopt; }
std::string protocol() const override { return std::string(); }
bool negotiated() const override { return false; }
int id() const override { return 0; }
uint32_t messages_sent() const override { return 0; }
uint64_t bytes_sent() const override { return 0; }
uint32_t messages_received() const override { return 0; }
uint64_t bytes_received() const override { return 0; }
void Close() override {}
void RegisterObserver(webrtc::DataChannelObserver* observer) override {
RunSynchronous(
signaling_thread_.get(),
CrossThreadBindOnce(&MockDataChannel::RegisterObserverOnSignalingThread,
CrossThreadUnretained(this),
CrossThreadUnretained(observer)));
}
void UnregisterObserver() override {
RunSynchronous(signaling_thread_.get(),
CrossThreadBindOnce(
&MockDataChannel::UnregisterObserverOnSignalingThread,
CrossThreadUnretained(this)));
}
uint64_t buffered_amount() const override {
uint64_t buffered_amount;
RunSynchronous(signaling_thread_.get(),
CrossThreadBindOnce(
&MockDataChannel::GetBufferedAmountOnSignalingThread,
CrossThreadUnretained(this),
CrossThreadUnretained(&buffered_amount)));
return buffered_amount;
}
DataState state() const override {
DataState state;
RunSynchronous(
signaling_thread_.get(),
CrossThreadBindOnce(&MockDataChannel::GetStateOnSignalingThread,
CrossThreadUnretained(this),
CrossThreadUnretained(&state)));
return state;
}
bool Send(const webrtc::DataBuffer& buffer) override {
RunSynchronous(
signaling_thread_.get(),
CrossThreadBindOnce(&MockDataChannel::SendOnSignalingThread,
CrossThreadUnretained(this), buffer.size()));
return true;
}
void SendAsync(
webrtc::DataBuffer buffer,
absl::AnyInvocable<void(webrtc::RTCError) &&> on_complete) override {
base::WaitableEvent waitable_event(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
auto* adapter = new absl::AnyInvocable<void(webrtc::RTCError) &&>(
std::move(on_complete));
PostCrossThreadTask(
*signaling_thread_.get(), FROM_HERE,
CrossThreadBindOnce(
[](MockDataChannel* channel, uint64_t buffer_size,
absl::AnyInvocable<void(webrtc::RTCError) &&>* adapter) {
channel->SendOnSignalingThread(buffer_size);
if (*adapter) {
std::move (*adapter)(webrtc::RTCError::OK());
}
delete adapter;
},
CrossThreadUnretained(this), buffer.size(),
CrossThreadUnretained(adapter)));
}
// For testing.
void ChangeState(DataState state) {
RunSynchronous(
signaling_thread_.get(),
CrossThreadBindOnce(&MockDataChannel::ChangeStateOnSignalingThread,
CrossThreadUnretained(this), state));
// The observer posts the state change from the signaling thread to the main
// thread. Wait for the posted task to be executed.
base::RunLoop().RunUntilIdle();
}
protected:
~MockDataChannel() override = default;
private:
void RegisterObserverOnSignalingThread(
webrtc::DataChannelObserver* observer) {
DCHECK(signaling_thread_->BelongsToCurrentThread());
observer_ = observer;
}
void UnregisterObserverOnSignalingThread() {
DCHECK(signaling_thread_->BelongsToCurrentThread());
observer_ = nullptr;
}
void GetBufferedAmountOnSignalingThread(uint64_t* buffered_amount) const {
DCHECK(signaling_thread_->BelongsToCurrentThread());
*buffered_amount = buffered_amount_;
}
void GetStateOnSignalingThread(DataState* state) const {
DCHECK(signaling_thread_->BelongsToCurrentThread());
*state = state_;
}
void SendOnSignalingThread(uint64_t buffer_size) {
DCHECK(signaling_thread_->BelongsToCurrentThread());
buffered_amount_ += buffer_size;
}
void ChangeStateOnSignalingThread(DataState state) {
DCHECK(signaling_thread_->BelongsToCurrentThread());
state_ = state;
if (observer_) {
observer_->OnStateChange();
}
}
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread_;
// Accessed on signaling thread.
uint64_t buffered_amount_;
raw_ptr<webrtc::DataChannelObserver> observer_;
webrtc::DataChannelInterface::DataState state_;
};
class RTCDataChannelTest : public ::testing::Test {
public:
RTCDataChannelTest() : signaling_thread_(new base::TestSimpleTaskRunner()) {}
RTCDataChannelTest(const RTCDataChannelTest&) = delete;
RTCDataChannelTest& operator=(const RTCDataChannelTest&) = delete;
~RTCDataChannelTest() override {
execution_context_->NotifyContextDestroyed();
}
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread() {
return signaling_thread_;
}
void VerifyNoTransfersAfterSend(
base::OnceCallback<void(RTCDataChannel*)> send_data_callback) {
V8TestingScope scope;
ScopedTransferableRTCDataChannelForTest scoped_feature(/*enabled=*/true);
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
EXPECT_TRUE(channel->IsTransferable());
// Perform a `send()` operation. We do not care that `channel` is in the
// "opening" state and that the `send()` operation will throw.
std::move(send_data_callback).Run(channel);
// The channel should no longer be transferable after `send()` has been
// called.
EXPECT_FALSE(channel->IsTransferable());
}
protected:
test::TaskEnvironment task_environment_;
Persistent<NullExecutionContext> execution_context_ =
MakeGarbageCollected<NullExecutionContext>();
private:
scoped_refptr<base::TestSimpleTaskRunner> signaling_thread_;
};
} // namespace
TEST_F(RTCDataChannelTest, ChangeStateEarly) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
// Change state on the webrtc channel before creating the blink channel.
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
// In RTCDataChannel::Create, the state change update is posted from the
// signaling thread to the main thread. Wait for posted the task to be
// executed.
base::RunLoop().RunUntilIdle();
// Verify that the early state change was not lost.
EXPECT_EQ(V8RTCDataChannelState::Enum::kOpen, channel->readyState());
}
TEST_F(RTCDataChannelTest, BufferedAmount) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
String message(std::string(100, 'A').c_str());
channel->send(message, IGNORE_EXCEPTION_FOR_TESTING);
EXPECT_EQ(100U, channel->bufferedAmount());
// The actual send operation is posted to the signaling thread; wait for it
// to run to avoid a memory leak.
signaling_thread()->RunUntilIdle();
}
TEST_F(RTCDataChannelTest, BufferedAmountLow) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* onbufferedamountlow_handler = MakeGarbageCollected<MockEventListener>();
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
channel->addEventListener(event_type_names::kBufferedamountlow,
onbufferedamountlow_handler);
EXPECT_CALL(*onbufferedamountlow_handler, Invoke(_, _));
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
channel->setBufferedAmountLowThreshold(1);
channel->send("TEST", IGNORE_EXCEPTION_FOR_TESTING);
EXPECT_EQ(4U, channel->bufferedAmount());
channel->OnBufferedAmountChange(4);
// The actual send operation is posted to the signaling thread; wait for it
// to run to avoid a memory leak.
signaling_thread()->RunUntilIdle();
}
TEST_F(RTCDataChannelTest, Open) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
channel->OnStateChange(webrtc::DataChannelInterface::kOpen);
EXPECT_EQ(V8RTCDataChannelState::Enum::kOpen, channel->readyState());
}
TEST_F(RTCDataChannelTest, Close) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
channel->OnStateChange(webrtc::DataChannelInterface::kClosed);
EXPECT_EQ(V8RTCDataChannelState::Enum::kClosed, channel->readyState());
}
TEST_F(RTCDataChannelTest, Message) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* onmessage_handler = MakeGarbageCollected<MockEventListener>();
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
channel->addEventListener(event_type_names::kMessage, onmessage_handler);
EXPECT_CALL(*onmessage_handler, Invoke(_, _));
channel->OnMessage(webrtc::DataBuffer("A"));
}
TEST_F(RTCDataChannelTest, SendAfterContextDestroyed) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
channel->ContextDestroyed();
String message(std::string(100, 'A').c_str());
DummyExceptionStateForTesting exception_state;
channel->send(message, exception_state);
EXPECT_TRUE(exception_state.HadException());
}
TEST_F(RTCDataChannelTest, CloseAfterContextDestroyed) {
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel =
MakeGarbageCollected<RTCDataChannel>(execution_context_, webrtc_channel);
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
channel->ContextDestroyed();
channel->close();
EXPECT_EQ(V8RTCDataChannelState::Enum::kClosed, channel->readyState());
}
TEST_F(RTCDataChannelTest, StopsThrottling) {
V8TestingScope scope;
auto* scheduler = scope.GetFrame().GetFrameScheduler()->GetPageScheduler();
EXPECT_FALSE(scheduler->OptedOutFromAggressiveThrottlingForTest());
// Creating an RTCDataChannel doesn't enable the opt-out.
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
EXPECT_EQ(V8RTCDataChannelState::Enum::kConnecting, channel->readyState());
EXPECT_FALSE(scheduler->OptedOutFromAggressiveThrottlingForTest());
// Transitioning to 'open' enables the opt-out.
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kOpen);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(V8RTCDataChannelState::Enum::kOpen, channel->readyState());
EXPECT_TRUE(scheduler->OptedOutFromAggressiveThrottlingForTest());
// Transitioning to 'closing' keeps the opt-out enabled.
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kClosing);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(V8RTCDataChannelState::Enum::kClosing, channel->readyState());
EXPECT_TRUE(scheduler->OptedOutFromAggressiveThrottlingForTest());
// Transitioning to 'closed' stops the opt-out.
webrtc_channel->ChangeState(webrtc::DataChannelInterface::kClosed);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(V8RTCDataChannelState::Enum::kClosed, channel->readyState());
EXPECT_FALSE(scheduler->OptedOutFromAggressiveThrottlingForTest());
}
TEST_F(RTCDataChannelTest, TransfersDisabled) {
V8TestingScope scope;
ScopedTransferableRTCDataChannelForTest scoped_feature(/*enabled=*/false);
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
EXPECT_FALSE(channel->IsTransferable());
}
TEST_F(RTCDataChannelTest, TransferableInCreationScopeOnly) {
V8TestingScope scope;
ScopedTransferableRTCDataChannelForTest scoped_feature(/*enabled=*/true);
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
EXPECT_TRUE(channel->IsTransferable());
// RTCDataChannel cannot be transferred once it has connected to
// `webrtc_channel`, as we could lose incoming messages during the transfer.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(channel->IsTransferable());
}
TEST_F(RTCDataChannelTest, TransferAllowedOnlyOnce) {
V8TestingScope scope;
ScopedTransferableRTCDataChannelForTest scoped_feature(/*enabled=*/true);
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
EXPECT_TRUE(channel->IsTransferable());
EXPECT_NE(channel->TransferUnderlyingChannel(), nullptr);
// The channel should no longer be transferable.
EXPECT_FALSE(channel->IsTransferable());
}
TEST_F(RTCDataChannelTest, SendPreventsTransfers) {
{
SCOPED_TRACE("RTCDataChannel::send(const string&)");
VerifyNoTransfersAfterSend(WTF::BindOnce([](RTCDataChannel* channel) {
String message(std::string(100, 'A').c_str());
channel->send(message, IGNORE_EXCEPTION_FOR_TESTING);
}));
}
{
SCOPED_TRACE("RTCDataChannel::send(DOMArrayBuffer*)");
VerifyNoTransfersAfterSend(WTF::BindOnce([](RTCDataChannel* channel) {
DOMArrayBuffer* buffer = DOMArrayBuffer::Create(10, 4);
channel->send(buffer, IGNORE_EXCEPTION_FOR_TESTING);
}));
}
{
SCOPED_TRACE("RTCDataChannel::send(NotShared<DOMArrayBufferView>)");
VerifyNoTransfersAfterSend(WTF::BindOnce([](RTCDataChannel* channel) {
DOMArrayBuffer* buffer = DOMArrayBuffer::Create(10, 4);
channel->send(
NotShared<DOMArrayBufferView>(DOMDataView::Create(buffer, 0, 10)),
IGNORE_EXCEPTION_FOR_TESTING);
}));
}
{
SCOPED_TRACE("RTCDataChannel::send(Blob*)");
VerifyNoTransfersAfterSend(WTF::BindOnce([](RTCDataChannel* channel) {
const char kHelloWorld[] = "Hello world!";
Blob* blob = Blob::Create(
base::as_bytes(base::span_with_nul_from_cstring(kHelloWorld)),
"text/plain");
channel->send(blob, IGNORE_EXCEPTION_FOR_TESTING);
}));
}
}
TEST_F(RTCDataChannelTest, NoSendAfterClose) {
V8TestingScope scope;
webrtc::scoped_refptr<MockDataChannel> webrtc_channel(
new webrtc::RefCountedObject<MockDataChannel>(signaling_thread()));
auto* channel = MakeGarbageCollected<RTCDataChannel>(
scope.GetExecutionContext(), webrtc_channel);
channel->close();
{
SCOPED_TRACE("RTCDataChannel::send(const string&)");
String message(std::string(100, 'A').c_str());
DummyExceptionStateForTesting exception_state;
channel->send(message, exception_state);
EXPECT_TRUE(exception_state.HadException());
}
{
SCOPED_TRACE("RTCDataChannel::send(DOMArrayBuffer*)");
DOMArrayBuffer* buffer = DOMArrayBuffer::Create(10, 4);
DummyExceptionStateForTesting exception_state;
channel->send(buffer, exception_state);
EXPECT_TRUE(exception_state.HadException());
}
{
SCOPED_TRACE("RTCDataChannel::send(NotShared<DOMArrayBufferView>)");
DOMArrayBuffer* buffer = DOMArrayBuffer::Create(10, 4);
DummyExceptionStateForTesting exception_state;
channel->send(
NotShared<DOMArrayBufferView>(DOMDataView::Create(buffer, 0, 10)),
exception_state);
EXPECT_TRUE(exception_state.HadException());
}
{
SCOPED_TRACE("RTCDataChannel::send(Blob*)");
const char kHelloWorld[] = "Hello world!";
Blob* blob = Blob::Create(
base::as_bytes(base::span_with_nul_from_cstring(kHelloWorld)),
"text/plain");
DummyExceptionStateForTesting exception_state;
channel->send(blob, exception_state);
EXPECT_TRUE(exception_state.HadException());
}
}
} // namespace blink
|