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

Unified Diff: third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraitsTest.cpp

Issue 2379993003: Mojo C++ bindings: make String16 and gfx::Size available in Blink (Closed)
Patch Set: Created 4 years, 3 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: third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraitsTest.cpp
diff --git a/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraitsTest.cpp b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraitsTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..59ee7f320d6469c22733d0093f9c54e92ecbf918
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraitsTest.cpp
@@ -0,0 +1,99 @@
+// Copyright 2016 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 "base/macros.h"
+#include "base/run_loop.h"
+#include "mojo/common/test_common_custom_types.mojom-blink.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
+#include "public/platform/WebString.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+template <typename T>
+struct BounceTestTraits {
+ static void ExpectEquality(const T& a, const T& b)
+ {
+ EXPECT_EQ(a, b);
+ }
+};
+
+template <typename T>
+struct PassTraits {
+ using Type = const T&;
+};
+
+template <typename T>
+void DoExpectResponse(T* expectedValue, const base::Closure& closure, typename PassTraits<T>::Type value)
+{
+ BounceTestTraits<T>::ExpectEquality(*expectedValue, value);
+ closure.Run();
+}
+
+template <typename T>
+base::Callback<void(typename PassTraits<T>::Type)> ExpectResponse(T* expectedValue, const base::Closure& closure)
+{
+ return base::Bind(&DoExpectResponse<T>, expectedValue, closure);
+}
+
+class TestString16Impl : public mojo::common::test::blink::TestString16 {
+public:
+ explicit TestString16Impl(mojo::common::test::blink::TestString16Request request)
+ : m_binding(this, std::move(request)) {}
+
+ // TestString16 implementation:
+ void BounceString16(const WebString& in, const BounceString16Callback& callback) override
+ {
+ callback.Run(in);
+ }
+
+private:
+ mojo::Binding<mojo::common::test::blink::TestString16> m_binding;
+};
+
+class CommonCustomTypesStructTraitsTest : public testing::Test {
+protected:
+ CommonCustomTypesStructTraitsTest() {}
+ ~CommonCustomTypesStructTraitsTest() override {}
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(CommonCustomTypesStructTraitsTest);
+};
+
+} // namespace
+
+TEST_F(CommonCustomTypesStructTraitsTest, String16)
+{
+ base::RunLoop runLoop;
Ken Rockot(use gerrit already) 2016/09/29 22:00:48 nit: You could avoid needing a RunLoop by marking
Zhiqiang Zhang (Slow) 2016/09/30 17:55:53 You're right. Done :)
+
+ mojo::common::test::blink::TestString16Ptr ptr;
+ TestString16Impl impl(GetProxy(&ptr));
+
+ WebString str = WebString::fromUTF8("hello world");
+
+ ptr->BounceString16(str, ExpectResponse(&str, runLoop.QuitClosure()));
+
+ runLoop.Run();
+
+}
+
+TEST_F(CommonCustomTypesStructTraitsTest, EmptyString16)
+{
+ base::RunLoop runLoop;
+
+ mojo::common::test::blink::TestString16Ptr ptr;
+ TestString16Impl impl(GetProxy(&ptr));
+
+ // WebString str = WebString::fromUTF8("");
+ WebString str = WebString::fromUTF8("");
+
+ ptr->BounceString16(str, ExpectResponse(&str, runLoop.QuitClosure()));
+
+ runLoop.Run();
+
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698