Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/macros.h" | |
| 6 #include "base/run_loop.h" | |
| 7 #include "mojo/common/test_common_custom_types.mojom-blink.h" | |
| 8 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 9 #include "public/platform/WebString.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 template <typename T> | |
| 17 struct BounceTestTraits { | |
| 18 static void ExpectEquality(const T& a, const T& b) | |
| 19 { | |
| 20 EXPECT_EQ(a, b); | |
| 21 } | |
| 22 }; | |
| 23 | |
| 24 template <typename T> | |
| 25 struct PassTraits { | |
| 26 using Type = const T&; | |
| 27 }; | |
| 28 | |
| 29 template <typename T> | |
| 30 void DoExpectResponse(T* expectedValue, const base::Closure& closure, typename P assTraits<T>::Type value) | |
| 31 { | |
| 32 BounceTestTraits<T>::ExpectEquality(*expectedValue, value); | |
| 33 closure.Run(); | |
| 34 } | |
| 35 | |
| 36 template <typename T> | |
| 37 base::Callback<void(typename PassTraits<T>::Type)> ExpectResponse(T* expectedVal ue, const base::Closure& closure) | |
| 38 { | |
| 39 return base::Bind(&DoExpectResponse<T>, expectedValue, closure); | |
| 40 } | |
| 41 | |
| 42 class TestString16Impl : public mojo::common::test::blink::TestString16 { | |
| 43 public: | |
| 44 explicit TestString16Impl(mojo::common::test::blink::TestString16Request req uest) | |
| 45 : m_binding(this, std::move(request)) {} | |
| 46 | |
| 47 // TestString16 implementation: | |
| 48 void BounceString16(const WebString& in, const BounceString16Callback& callb ack) override | |
| 49 { | |
| 50 callback.Run(in); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 mojo::Binding<mojo::common::test::blink::TestString16> m_binding; | |
| 55 }; | |
| 56 | |
| 57 class CommonCustomTypesStructTraitsTest : public testing::Test { | |
| 58 protected: | |
| 59 CommonCustomTypesStructTraitsTest() {} | |
| 60 ~CommonCustomTypesStructTraitsTest() override {} | |
| 61 | |
| 62 private: | |
| 63 DISALLOW_COPY_AND_ASSIGN(CommonCustomTypesStructTraitsTest); | |
| 64 }; | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 TEST_F(CommonCustomTypesStructTraitsTest, String16) | |
| 69 { | |
| 70 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 :)
| |
| 71 | |
| 72 mojo::common::test::blink::TestString16Ptr ptr; | |
| 73 TestString16Impl impl(GetProxy(&ptr)); | |
| 74 | |
| 75 WebString str = WebString::fromUTF8("hello world"); | |
| 76 | |
| 77 ptr->BounceString16(str, ExpectResponse(&str, runLoop.QuitClosure())); | |
| 78 | |
| 79 runLoop.Run(); | |
| 80 | |
| 81 } | |
| 82 | |
| 83 TEST_F(CommonCustomTypesStructTraitsTest, EmptyString16) | |
| 84 { | |
| 85 base::RunLoop runLoop; | |
| 86 | |
| 87 mojo::common::test::blink::TestString16Ptr ptr; | |
| 88 TestString16Impl impl(GetProxy(&ptr)); | |
| 89 | |
| 90 // WebString str = WebString::fromUTF8(""); | |
| 91 WebString str = WebString::fromUTF8(""); | |
| 92 | |
| 93 ptr->BounceString16(str, ExpectResponse(&str, runLoop.QuitClosure())); | |
| 94 | |
| 95 runLoop.Run(); | |
| 96 | |
| 97 } | |
| 98 | |
| 99 } // namespace blink | |
| OLD | NEW |