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

Unified Diff: content/renderer/presentation/presentation_connection_proxy_unittest.cc

Issue 2471263003: [Presentation API] (4th)(1-UA blink side) Add WebPresentationConnection and WebPresentationConnecti… (Closed)
Patch Set: resolve code review comments from Derek and Mark Created 3 years, 11 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
Index: content/renderer/presentation/presentation_connection_proxy_unittest.cc
diff --git a/content/renderer/presentation/presentation_connection_proxy_unittest.cc b/content/renderer/presentation/presentation_connection_proxy_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dac90d6d193b2fcf8eed56976a1dd588e9c7f404
--- /dev/null
+++ b/content/renderer/presentation/presentation_connection_proxy_unittest.cc
@@ -0,0 +1,114 @@
+// Copyright 2017 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 <memory>
+#include <utility>
+
+#include "base/run_loop.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/renderer/presentation/presentation_connection_proxy.h"
+#include "content/renderer/presentation/test_presentation_connection.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationConnection.h"
+#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h"
+
+using ::testing::_;
+
+namespace content {
+
+class PresentationConnectionProxyTest : public ::testing::Test {
+ public:
+ PresentationConnectionProxyTest() {}
+ ~PresentationConnectionProxyTest() override {}
+
+ void SetUp() override {
+ // Set up test connections and test connection proxies.
+ controller_connection_ = base::MakeUnique<TestPresentationConnection>();
+ receiver_connection_ = base::MakeUnique<TestPresentationConnection>();
+
+ controller_connection_proxy_ =
+ new ControllerConnectionProxy(controller_connection_.get());
+ controller_connection_->bindProxy(
+ base::WrapUnique(controller_connection_proxy_));
+ receiver_connection_proxy_ =
+ new ReceiverConnectionProxy(receiver_connection_.get());
+ receiver_connection_->bindProxy(
+ base::WrapUnique(receiver_connection_proxy_));
+
+ EXPECT_CALL(
+ *controller_connection_,
+ didChangeState(blink::WebPresentationConnectionState::Connected));
+ EXPECT_CALL(
+ *receiver_connection_,
+ didChangeState(blink::WebPresentationConnectionState::Connected));
+
+ receiver_connection_proxy_->Bind(
+ controller_connection_proxy_->MakeRemoteRequest());
+ receiver_connection_proxy_->BindControllerConnection(
+ controller_connection_proxy_->Bind());
+ }
+
+ void TearDown() override {
+ controller_connection_.reset();
+ receiver_connection_.reset();
+ }
+
+ void ExpectSendConnectionMessageCallback(bool success) {
+ EXPECT_TRUE(success);
+ }
+
+ protected:
+ std::unique_ptr<TestPresentationConnection> controller_connection_;
+ std::unique_ptr<TestPresentationConnection> receiver_connection_;
+ ControllerConnectionProxy* controller_connection_proxy_;
+ ReceiverConnectionProxy* receiver_connection_proxy_;
+
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
+};
+
+TEST_F(PresentationConnectionProxyTest, TestSendString) {
+ blink::WebString message = blink::WebString::fromUTF8("test message");
+ blink::mojom::ConnectionMessagePtr session_message =
+ blink::mojom::ConnectionMessage::New();
+ session_message->type = blink::mojom::PresentationMessageType::TEXT;
+ session_message->message = message.utf8();
+
+ base::RunLoop run_loop;
+ EXPECT_CALL(*receiver_connection_, didReceiveTextMessage(message));
+ controller_connection_proxy_->SendConnectionMessage(
+ std::move(session_message),
+ base::Bind(
+ &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback,
+ base::Unretained(this)));
+ run_loop.RunUntilIdle();
+}
+
+TEST_F(PresentationConnectionProxyTest, TestSendArrayBuffer) {
+ std::vector<uint8_t> expected_data;
+ expected_data.push_back(42);
+ expected_data.push_back(36);
+
+ blink::mojom::ConnectionMessagePtr session_message =
+ blink::mojom::ConnectionMessage::New();
+ session_message->type = blink::mojom::PresentationMessageType::BINARY;
+ session_message->data = expected_data;
+
+ base::RunLoop run_loop;
+ EXPECT_CALL(*receiver_connection_, didReceiveBinaryMessage(_, _))
+ .WillOnce(::testing::Invoke(
+ [this, &expected_data](const uint8_t* data, size_t length) {
+ std::vector<uint8_t> message_data(data, data + length);
+ EXPECT_EQ(expected_data, message_data);
+ }));
+
+ controller_connection_proxy_->SendConnectionMessage(
+ std::move(session_message),
+ base::Bind(
+ &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback,
+ base::Unretained(this)));
+ run_loop.RunUntilIdle();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698