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

Unified Diff: mojo/public/cpp/bindings/tests/wtf_types_unittest.cc

Issue 1751563002: Mojo C++ bindings: support mapping mojo string to WTF::String. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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: mojo/public/cpp/bindings/tests/wtf_types_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/wtf_types_unittest.cc b/mojo/public/cpp/bindings/tests/wtf_types_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..65ca93063725fbb79680b5d35b1c02a67ce0ec60
--- /dev/null
+++ b/mojo/public/cpp/bindings/tests/wtf_types_unittest.cc
@@ -0,0 +1,72 @@
+// 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/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom-wtf.h"
+#include "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/wtf/Partitions.h"
+
+namespace mojo {
+namespace test {
+namespace {
+
+class TestWTFImpl : public TestWTF {
+ public:
+ explicit TestWTFImpl(TestWTFRequest request)
+ : binding_(this, std::move(request)) {}
+
+ // mojo::test::TestWTF implementation:
+ void EchoString(const String& str,
+ const EchoStringCallback& callback) override {
+ callback.Run(str);
+ }
+
+ private:
+ Binding<TestWTF> binding_;
+};
+
+class WTFTypesTest : public testing::Test {
+ public:
+ WTFTypesTest() {}
+
+ private:
+ // testing::Test overrides:
+ void SetUp() override { WTF::Partitions::initialize(nullptr); }
+
+ base::MessageLoop loop_;
+};
+
+} // namespace
+
+TEST_F(WTFTypesTest, SendWTFString) {
+ wtf::TestWTFPtr ptr;
+ TestWTFImpl impl(GetProxy(&ptr));
+
+ WTF::String strs[3];
+ // strs[0] is null.
+ // strs[1] is empty.
+ strs[1] = "";
+ strs[2] = "hello world";
+
+ for (size_t i = 0; i < 3; ++i) {
+ base::RunLoop loop;
+ // Test that a WTF::String is unchanged after the following conversion:
+ // - serialized;
+ // - deserialized as mojo::String;
+ // - serialized;
+ // - deserialized as WTF::String.
+ ptr->EchoString(strs[i],
+ [&loop, &strs, &i](const WTF::String& str) {
+ EXPECT_EQ(strs[i], str);
+ loop.Quit();
+ });
+ loop.Run();
+ }
+}
+
+} // namespace test
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698