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

Unified Diff: content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.cc

Issue 305923002: test_runner: Migrate MockWebRTCDataChannelHandler to Chromium C++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.cc
diff --git a/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.cc b/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..01668bcb414be0bc7a2e8a51ab2f88ba55b4fa8c
--- /dev/null
+++ b/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.cc
@@ -0,0 +1,108 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h"
+
+#include <assert.h>
+
+#include "content/shell/renderer/test_runner/WebTestDelegate.h"
+#include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
+
+using namespace blink;
+
+namespace content {
+
+class DataChannelReadyStateTask
+ : public WebMethodTask<MockWebRTCDataChannelHandler> {
+ public:
+ DataChannelReadyStateTask(MockWebRTCDataChannelHandler* object,
+ WebRTCDataChannelHandlerClient* data_channel_client,
+ WebRTCDataChannelHandlerClient::ReadyState state)
+ : WebMethodTask<MockWebRTCDataChannelHandler>(object),
+ data_channel_client_(data_channel_client),
+ state_(state) {}
+
+ virtual void runIfValid() OVERRIDE {
+ data_channel_client_->didChangeReadyState(state_);
+ }
+
+ private:
+ WebRTCDataChannelHandlerClient* data_channel_client_;
+ WebRTCDataChannelHandlerClient::ReadyState state_;
+};
+
+/////////////////////
+
+MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(
+ WebString label,
+ const WebRTCDataChannelInit& init,
+ WebTestDelegate* delegate)
+ : client_(0), label_(label), init_(init), delegate_(delegate) {
+ reliable_ = (init.ordered && init.maxRetransmits == -1 &&
+ init.maxRetransmitTime == -1);
+}
+
+void MockWebRTCDataChannelHandler::setClient(
+ WebRTCDataChannelHandlerClient* client) {
+ client_ = client;
+ if (client_)
+ delegate_->postTask(new DataChannelReadyStateTask(
+ this, client_, WebRTCDataChannelHandlerClient::ReadyStateOpen));
+}
+
+blink::WebString MockWebRTCDataChannelHandler::label() {
+ return label_;
+}
+
+bool MockWebRTCDataChannelHandler::isReliable() {
+ return reliable_;
+}
+
+bool MockWebRTCDataChannelHandler::ordered() const {
+ return init_.ordered;
+}
+
+unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const {
+ return init_.maxRetransmitTime;
+}
+
+unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const {
+ return init_.maxRetransmits;
+}
+
+WebString MockWebRTCDataChannelHandler::protocol() const {
+ return init_.protocol;
+}
+
+bool MockWebRTCDataChannelHandler::negotiated() const {
+ return init_.negotiated;
+}
+
+unsigned short MockWebRTCDataChannelHandler::id() const {
+ return init_.id;
+}
+
+unsigned long MockWebRTCDataChannelHandler::bufferedAmount() {
+ return 0;
+}
+
+bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) {
+ assert(client_);
+ client_->didReceiveStringData(data);
+ return true;
+}
+
+bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) {
+ assert(client_);
+ client_->didReceiveRawData(data, size);
+ return true;
+}
+
+void MockWebRTCDataChannelHandler::close() {
+ assert(client_);
+ delegate_->postTask(new DataChannelReadyStateTask(
+ this, client_, WebRTCDataChannelHandlerClient::ReadyStateClosed));
+}
+
+} // namespace content
« no previous file with comments | « content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698