aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/tests
diff options
context:
space:
mode:
authorHidehiko Abe <hidehiko@google.com>2018-04-19 20:42:46 +0900
committerHidehiko Abe <hidehiko@google.com>2018-04-20 11:11:59 +0900
commit991e618ea063cc28060d6baa0c0d6ffa3ad29452 (patch)
treed7c62aca68333ccc7dc58e356d515dd01c734a7f /mojo/public/cpp/bindings/tests
parent1e4a1e50aed7593adac78af6f319adb67f03d7bb (diff)
downloadlibmojo-991e618ea063cc28060d6baa0c0d6ffa3ad29452.tar.gz
Uprev libmojo to r462023.
To be aligned with libchrome. Highlights of the update: - r461016: Support sync calls through ThreadSafeInterfacePtr - r458684: mojo: MessageReceiver*::AcceptWithResponder() now take a unique_ptr to the responder - r458630: Mojo C++ Bindings: Support dispatch in nested message loops - r457994: Mojo C++ bindings: rename GetIsolatedProxy to MakeIsolatedRequest to better match other functions. - r457856: Mojo: Move waiting APIs to public library - r457378: Introduce MojoQueryHandleSignalsState API Bug: 73606903 Test: Built locally. Run on DUT. Change-Id: Id3e2f5262eb97345ed2e6b597157d594cb8b4110
Diffstat (limited to 'mojo/public/cpp/bindings/tests')
-rw-r--r--mojo/public/cpp/bindings/tests/BUILD.gn2
-rw-r--r--mojo/public/cpp/bindings/tests/associated_interface_unittest.cc6
-rw-r--r--mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc18
-rw-r--r--mojo/public/cpp/bindings/tests/bindings_perftest.cc10
-rw-r--r--mojo/public/cpp/bindings/tests/handle_passing_unittest.cc4
-rw-r--r--mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc30
-rw-r--r--mojo/public/cpp/bindings/tests/router_test_util.cc16
-rw-r--r--mojo/public/cpp/bindings/tests/router_test_util.h13
-rw-r--r--mojo/public/cpp/bindings/tests/sample_service_unittest.cc5
-rw-r--r--mojo/public/cpp/bindings/tests/struct_traits_unittest.cc4
-rw-r--r--mojo/public/cpp/bindings/tests/struct_unittest.cc21
-rw-r--r--mojo/public/cpp/bindings/tests/sync_method_unittest.cc166
-rw-r--r--mojo/public/cpp/bindings/tests/wtf_map_unittest.cc4
13 files changed, 206 insertions, 93 deletions
diff --git a/mojo/public/cpp/bindings/tests/BUILD.gn b/mojo/public/cpp/bindings/tests/BUILD.gn
index 6244226..668ca6d 100644
--- a/mojo/public/cpp/bindings/tests/BUILD.gn
+++ b/mojo/public/cpp/bindings/tests/BUILD.gn
@@ -49,9 +49,9 @@ source_set("tests") {
"//mojo/public/cpp/test_support:test_utils",
"//mojo/public/interfaces/bindings/tests:test_associated_interfaces",
"//mojo/public/interfaces/bindings/tests:test_export_component",
+ "//mojo/public/interfaces/bindings/tests:test_export_component2",
"//mojo/public/interfaces/bindings/tests:test_exported_import",
"//mojo/public/interfaces/bindings/tests:test_interfaces",
- "//mojo/public/interfaces/bindings/tests:test_interfaces_experimental",
"//mojo/public/interfaces/bindings/tests:test_struct_traits_interfaces",
"//testing/gtest",
]
diff --git a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
index 625c49c..be225e4 100644
--- a/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/associated_interface_unittest.cc
@@ -1178,6 +1178,12 @@ TEST_F(AssociatedInterfaceTest, CloseWithoutBindingAssociatedRequest) {
run_loop.Run();
}
+TEST_F(AssociatedInterfaceTest, GetIsolatedInterface) {
+ IntegerSenderAssociatedPtr sender;
+ GetIsolatedInterface(MakeRequest(&sender).PassHandle());
+ sender->Send(42);
+}
+
} // namespace
} // namespace test
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc b/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
index 0c777ec..569eb51 100644
--- a/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/bind_task_runner_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <utility>
+
#include "base/bind.h"
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
@@ -30,18 +32,18 @@ class TestTaskRunner : public base::SingleThreadTaskRunner {
base::WaitableEvent::InitialState::NOT_SIGNALED) {}
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::OnceClosure task,
base::TimeDelta delay) override {
NOTREACHED();
return false;
}
bool PostDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::OnceClosure task,
base::TimeDelta delay) override {
{
base::AutoLock locker(lock_);
- tasks_.push(task);
+ tasks_.push(std::move(task));
}
task_ready_.Signal();
return true;
@@ -59,12 +61,12 @@ class TestTaskRunner : public base::SingleThreadTaskRunner {
{
base::AutoLock locker(lock_);
while (!tasks_.empty()) {
- auto task = tasks_.front();
+ auto task = std::move(tasks_.front());
tasks_.pop();
{
base::AutoUnlock unlocker(lock_);
- task.Run();
+ std::move(task).Run();
if (quit_called_)
return;
}
@@ -87,12 +89,12 @@ class TestTaskRunner : public base::SingleThreadTaskRunner {
{
base::AutoLock locker(lock_);
if (!tasks_.empty()) {
- auto task = tasks_.front();
+ auto task = std::move(tasks_.front());
tasks_.pop();
{
base::AutoUnlock unlocker(lock_);
- task.Run();
+ std::move(task).Run();
return;
}
}
@@ -110,7 +112,7 @@ class TestTaskRunner : public base::SingleThreadTaskRunner {
// Protect |tasks_|.
base::Lock lock_;
- std::queue<base::Closure> tasks_;
+ std::queue<base::OnceClosure> tasks_;
DISALLOW_COPY_AND_ASSIGN(TestTaskRunner);
};
diff --git a/mojo/public/cpp/bindings/tests/bindings_perftest.cc b/mojo/public/cpp/bindings/tests/bindings_perftest.cc
index 6a50de4..65b3c8c 100644
--- a/mojo/public/cpp/bindings/tests/bindings_perftest.cc
+++ b/mojo/public/cpp/bindings/tests/bindings_perftest.cc
@@ -160,8 +160,9 @@ class PingPongPaddle : public MessageReceiverWithResponderStatus {
return true;
}
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override {
+ bool AcceptWithResponder(
+ Message* message,
+ std::unique_ptr<MessageReceiverWithStatus> responder) override {
NOTREACHED();
return true;
}
@@ -232,8 +233,9 @@ class CounterReceiver : public MessageReceiverWithResponderStatus {
return true;
}
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override {
+ bool AcceptWithResponder(
+ Message* message,
+ std::unique_ptr<MessageReceiverWithStatus> responder) override {
NOTREACHED();
return true;
}
diff --git a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
index 6797fe4..ef977af 100644
--- a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
@@ -10,6 +10,7 @@
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "mojo/public/cpp/system/wait.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -111,8 +112,7 @@ class SampleFactoryImpl : public sample::Factory {
MojoHandleSignalsState state;
ASSERT_EQ(MOJO_RESULT_OK,
- MojoWait(pipe.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, &state));
+ mojo::Wait(pipe.get(), MOJO_HANDLE_SIGNAL_READABLE, &state));
ASSERT_TRUE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
ASSERT_EQ(MOJO_RESULT_OK,
ReadDataRaw(
diff --git a/mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc b/mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc
index 31963e0..8950928 100644
--- a/mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc
@@ -72,8 +72,8 @@ TEST_F(MultiplexRouterTest, BasicRequestResponse) {
MessageQueue message_queue;
base::RunLoop run_loop;
client0.AcceptWithResponder(
- &request,
- new MessageAccumulator(&message_queue, run_loop.QuitClosure()));
+ &request, base::MakeUnique<MessageAccumulator>(&message_queue,
+ run_loop.QuitClosure()));
run_loop.Run();
@@ -91,8 +91,8 @@ TEST_F(MultiplexRouterTest, BasicRequestResponse) {
base::RunLoop run_loop2;
client0.AcceptWithResponder(
- &request2,
- new MessageAccumulator(&message_queue, run_loop2.QuitClosure()));
+ &request2, base::MakeUnique<MessageAccumulator>(&message_queue,
+ run_loop2.QuitClosure()));
run_loop2.Run();
@@ -117,7 +117,8 @@ TEST_F(MultiplexRouterTest, BasicRequestResponse_Synchronous) {
AllocRequestMessage(1, "hello", &request);
MessageQueue message_queue;
- client0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
+ client0.AcceptWithResponder(
+ &request, base::MakeUnique<MessageAccumulator>(&message_queue));
router1_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
router0_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
@@ -134,8 +135,8 @@ TEST_F(MultiplexRouterTest, BasicRequestResponse_Synchronous) {
Message request2;
AllocRequestMessage(1, "hello again", &request2);
- client0.AcceptWithResponder(&request2,
- new MessageAccumulator(&message_queue));
+ client0.AcceptWithResponder(
+ &request2, base::MakeUnique<MessageAccumulator>(&message_queue));
router1_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
router0_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
@@ -167,8 +168,8 @@ TEST_F(MultiplexRouterTest, LazyResponses) {
MessageQueue message_queue;
base::RunLoop run_loop2;
client0.AcceptWithResponder(
- &request,
- new MessageAccumulator(&message_queue, run_loop2.QuitClosure()));
+ &request, base::MakeUnique<MessageAccumulator>(&message_queue,
+ run_loop2.QuitClosure()));
run_loop.Run();
// The request has been received but the response has not been sent yet.
@@ -194,8 +195,8 @@ TEST_F(MultiplexRouterTest, LazyResponses) {
base::RunLoop run_loop4;
client0.AcceptWithResponder(
- &request2,
- new MessageAccumulator(&message_queue, run_loop4.QuitClosure()));
+ &request2, base::MakeUnique<MessageAccumulator>(&message_queue,
+ run_loop4.QuitClosure()));
run_loop3.Run();
// The request has been received but the response has not been sent yet.
@@ -246,7 +247,8 @@ TEST_F(MultiplexRouterTest, MissingResponses) {
AllocRequestMessage(1, "hello", &request);
MessageQueue message_queue;
- client0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
+ client0.AcceptWithResponder(
+ &request, base::MakeUnique<MessageAccumulator>(&message_queue));
run_loop3.Run();
// The request has been received but no response has been sent.
@@ -293,8 +295,8 @@ TEST_F(MultiplexRouterTest, LateResponse) {
AllocRequestMessage(1, "hello", &request);
MessageQueue message_queue;
- client0.AcceptWithResponder(&request,
- new MessageAccumulator(&message_queue));
+ client0.AcceptWithResponder(
+ &request, base::MakeUnique<MessageAccumulator>(&message_queue));
run_loop.Run();
diff --git a/mojo/public/cpp/bindings/tests/router_test_util.cc b/mojo/public/cpp/bindings/tests/router_test_util.cc
index b9b93d8..9bab1cb 100644
--- a/mojo/public/cpp/bindings/tests/router_test_util.cc
+++ b/mojo/public/cpp/bindings/tests/router_test_util.cc
@@ -58,14 +58,13 @@ bool ResponseGenerator::Accept(Message* message) {
bool ResponseGenerator::AcceptWithResponder(
Message* message,
- MessageReceiverWithStatus* responder) {
+ std::unique_ptr<MessageReceiverWithStatus> responder) {
EXPECT_TRUE(message->has_flag(Message::kFlagExpectsResponse));
bool result = SendResponse(message->name(), message->request_id(),
reinterpret_cast<const char*>(message->payload()),
- responder);
+ responder.get());
EXPECT_TRUE(responder->IsValid());
- delete responder;
return result;
}
@@ -84,18 +83,16 @@ bool ResponseGenerator::SendResponse(uint32_t name,
LazyResponseGenerator::LazyResponseGenerator(const base::Closure& closure)
: responder_(nullptr), name_(0), request_id_(0), closure_(closure) {}
-LazyResponseGenerator::~LazyResponseGenerator() {
- delete responder_;
-}
+LazyResponseGenerator::~LazyResponseGenerator() = default;
bool LazyResponseGenerator::AcceptWithResponder(
Message* message,
- MessageReceiverWithStatus* responder) {
+ std::unique_ptr<MessageReceiverWithStatus> responder) {
name_ = message->name();
request_id_ = message->request_id();
request_string_ =
std::string(reinterpret_cast<const char*>(message->payload()));
- responder_ = responder;
+ responder_ = std::move(responder);
if (!closure_.is_null()) {
closure_.Run();
closure_.Reset();
@@ -105,9 +102,8 @@ bool LazyResponseGenerator::AcceptWithResponder(
void LazyResponseGenerator::Complete(bool send_response) {
if (send_response) {
- SendResponse(name_, request_id_, request_string_.c_str(), responder_);
+ SendResponse(name_, request_id_, request_string_.c_str(), responder_.get());
}
- delete responder_;
responder_ = nullptr;
}
diff --git a/mojo/public/cpp/bindings/tests/router_test_util.h b/mojo/public/cpp/bindings/tests/router_test_util.h
index c6fb372..dd6aff6 100644
--- a/mojo/public/cpp/bindings/tests/router_test_util.h
+++ b/mojo/public/cpp/bindings/tests/router_test_util.h
@@ -42,9 +42,9 @@ class ResponseGenerator : public MessageReceiverWithResponderStatus {
bool Accept(Message* message) override;
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override;
-
+ bool AcceptWithResponder(
+ Message* message,
+ std::unique_ptr<MessageReceiverWithStatus> responder) override;
bool SendResponse(uint32_t name,
uint64_t request_id,
const char* request_string,
@@ -58,8 +58,9 @@ class LazyResponseGenerator : public ResponseGenerator {
~LazyResponseGenerator() override;
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override;
+ bool AcceptWithResponder(
+ Message* message,
+ std::unique_ptr<MessageReceiverWithStatus> responder) override;
bool has_responder() const { return !!responder_; }
@@ -78,7 +79,7 @@ class LazyResponseGenerator : public ResponseGenerator {
// also sends a response.
void Complete(bool send_response);
- MessageReceiverWithStatus* responder_;
+ std::unique_ptr<MessageReceiverWithStatus> responder_;
uint32_t name_;
uint64_t request_id_;
std::string request_string_;
diff --git a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
index 579576f..1f95a27 100644
--- a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
@@ -295,8 +295,9 @@ class SimpleMessageReceiver : public mojo::MessageReceiverWithResponder {
return stub.Accept(message);
}
- bool AcceptWithResponder(mojo::Message* message,
- mojo::MessageReceiver* responder) override {
+ bool AcceptWithResponder(
+ mojo::Message* message,
+ std::unique_ptr<mojo::MessageReceiver> responder) override {
return false;
}
};
diff --git a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
index 4c06267..77b448a 100644
--- a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
@@ -15,6 +15,7 @@
#include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h"
#include "mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h"
#include "mojo/public/cpp/bindings/tests/variant_test_util.h"
+#include "mojo/public/cpp/system/wait.h"
#include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h"
@@ -391,8 +392,7 @@ TEST_F(StructTraitsTest, EchoMoveOnlyStructWithTraits) {
WriteMessageRaw(mp.handle1.get(), kHello, kHelloSize, nullptr, 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_OK, Wait(received.get(), MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, nullptr));
+ EXPECT_EQ(MOJO_RESULT_OK, Wait(received.get(), MOJO_HANDLE_SIGNAL_READABLE));
char buffer[10] = {0};
uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
diff --git a/mojo/public/cpp/bindings/tests/struct_unittest.cc b/mojo/public/cpp/bindings/tests/struct_unittest.cc
index 13ba507..a687052 100644
--- a/mojo/public/cpp/bindings/tests/struct_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/struct_unittest.cc
@@ -9,6 +9,7 @@
#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "mojo/public/cpp/system/message_pipe.h"
+#include "mojo/public/interfaces/bindings/tests/test_export2.mojom.h"
#include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -435,7 +436,7 @@ TEST_F(StructTest, Serialization_PublicAPI) {
// Initialize it to non-null.
RectPtr output(Rect::New());
- ASSERT_TRUE(Rect::Deserialize(std::move(data), &output));
+ ASSERT_TRUE(Rect::Deserialize(data, &output));
EXPECT_TRUE(output.is_null());
}
@@ -446,7 +447,7 @@ TEST_F(StructTest, Serialization_PublicAPI) {
EXPECT_FALSE(data.empty());
EmptyStructPtr output;
- ASSERT_TRUE(EmptyStruct::Deserialize(std::move(data), &output));
+ ASSERT_TRUE(EmptyStruct::Deserialize(data, &output));
EXPECT_FALSE(output.is_null());
}
@@ -457,7 +458,7 @@ TEST_F(StructTest, Serialization_PublicAPI) {
auto data = Rect::Serialize(&rect);
RectPtr output;
- ASSERT_TRUE(Rect::Deserialize(std::move(data), &output));
+ ASSERT_TRUE(Rect::Deserialize(data, &output));
EXPECT_TRUE(output.Equals(cloned_rect));
}
@@ -475,7 +476,7 @@ TEST_F(StructTest, Serialization_PublicAPI) {
// Make sure that the serialized result gets pointers encoded properly.
auto cloned_data = data;
NamedRegionPtr output;
- ASSERT_TRUE(NamedRegion::Deserialize(std::move(cloned_data), &output));
+ ASSERT_TRUE(NamedRegion::Deserialize(cloned_data, &output));
EXPECT_TRUE(output.Equals(cloned_region));
}
@@ -485,7 +486,17 @@ TEST_F(StructTest, Serialization_PublicAPI) {
auto data = Rect::Serialize(&rect);
NamedRegionPtr output;
- EXPECT_FALSE(NamedRegion::Deserialize(std::move(data), &output));
+ EXPECT_FALSE(NamedRegion::Deserialize(data, &output));
+ }
+
+ {
+ // A struct from another component.
+ auto pair = test_export2::StringPair::New("hello", "world");
+ auto data = test_export2::StringPair::Serialize(&pair);
+
+ test_export2::StringPairPtr output;
+ ASSERT_TRUE(test_export2::StringPair::Deserialize(data, &output));
+ EXPECT_TRUE(output.Equals(pair));
}
}
diff --git a/mojo/public/cpp/bindings/tests/sync_method_unittest.cc b/mojo/public/cpp/bindings/tests/sync_method_unittest.cc
index d0e5f10..084e080 100644
--- a/mojo/public/cpp/bindings/tests/sync_method_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/sync_method_unittest.cc
@@ -202,6 +202,60 @@ struct ImplTraits<TestSyncMaster> {
};
template <typename Interface>
+using ImplTypeFor = typename ImplTraits<Interface>::Type;
+
+// A wrapper for either an InterfacePtr or scoped_refptr<ThreadSafeInterfacePtr>
+// that exposes the InterfacePtr interface.
+template <typename Interface>
+class PtrWrapper {
+ public:
+ explicit PtrWrapper(InterfacePtr<Interface> ptr) : ptr_(std::move(ptr)) {}
+
+ explicit PtrWrapper(
+ scoped_refptr<ThreadSafeInterfacePtr<Interface>> thread_safe_ptr)
+ : thread_safe_ptr_(thread_safe_ptr) {}
+
+ PtrWrapper(PtrWrapper&& other) = default;
+
+ Interface* operator->() {
+ return thread_safe_ptr_ ? thread_safe_ptr_->get() : ptr_.get();
+ }
+
+ void set_connection_error_handler(const base::Closure& error_handler) {
+ DCHECK(!thread_safe_ptr_);
+ ptr_.set_connection_error_handler(error_handler);
+ }
+
+ void reset() {
+ ptr_ = nullptr;
+ thread_safe_ptr_ = nullptr;
+ }
+
+ private:
+ InterfacePtr<Interface> ptr_;
+ scoped_refptr<ThreadSafeInterfacePtr<Interface>> thread_safe_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(PtrWrapper);
+};
+
+// The type parameter for SyncMethodCommonTests for varying the Interface and
+// whether to use InterfacePtr or ThreadSafeInterfacePtr.
+template <typename InterfaceT, bool use_thread_safe_ptr>
+struct TestParams {
+ using Interface = InterfaceT;
+ static const bool kIsThreadSafeInterfacePtrTest = use_thread_safe_ptr;
+
+ static PtrWrapper<InterfaceT> Wrap(InterfacePtr<Interface> ptr) {
+ if (kIsThreadSafeInterfacePtrTest) {
+ return PtrWrapper<Interface>(
+ ThreadSafeInterfacePtr<Interface>::Create(std::move(ptr)));
+ } else {
+ return PtrWrapper<Interface>(std::move(ptr));
+ }
+ }
+};
+
+template <typename Interface>
class TestSyncServiceThread {
public:
TestSyncServiceThread()
@@ -211,7 +265,7 @@ class TestSyncServiceThread {
void SetUp(InterfaceRequest<Interface> request) {
CHECK(thread_.task_runner()->BelongsToCurrentThread());
- impl_.reset(new typename ImplTraits<Interface>::Type(std::move(request)));
+ impl_.reset(new ImplTypeFor<Interface>(std::move(request)));
impl_->set_ping_handler(
[this](const typename Interface::PingCallback& callback) {
{
@@ -236,7 +290,7 @@ class TestSyncServiceThread {
private:
base::Thread thread_;
- std::unique_ptr<typename ImplTraits<Interface>::Type> impl_;
+ std::unique_ptr<ImplTypeFor<Interface>> impl_;
mutable base::Lock lock_;
bool ping_called_;
@@ -334,12 +388,20 @@ TestSync::AsyncEchoCallback BindAsyncEchoCallback(Func func) {
// TestSync (without associated interfaces) and TestSyncMaster (with associated
// interfaces) exercise MultiplexRouter with different configurations.
-using InterfaceTypes = testing::Types<TestSync, TestSyncMaster>;
+// Each test is run once with an InterfacePtr and once with a
+// ThreadSafeInterfacePtr to ensure that they behave the same with respect to
+// sync calls.
+using InterfaceTypes = testing::Types<TestParams<TestSync, true>,
+ TestParams<TestSync, false>,
+ TestParams<TestSyncMaster, true>,
+ TestParams<TestSyncMaster, false>>;
TYPED_TEST_CASE(SyncMethodCommonTest, InterfaceTypes);
TYPED_TEST(SyncMethodCommonTest, CallSyncMethodAsynchronously) {
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
base::RunLoop run_loop;
ptr->Echo(123, base::Bind(&ExpectValueAndRunClosure, 123,
@@ -348,13 +410,16 @@ TYPED_TEST(SyncMethodCommonTest, CallSyncMethodAsynchronously) {
}
TYPED_TEST(SyncMethodCommonTest, BasicSyncCalls) {
- InterfacePtr<TypeParam> ptr;
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ InterfaceRequest<Interface> request = MakeRequest(&interface_ptr);
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
- TestSyncServiceThread<TypeParam> service_thread;
+ TestSyncServiceThread<Interface> service_thread;
service_thread.thread()->task_runner()->PostTask(
- FROM_HERE, base::Bind(&TestSyncServiceThread<TypeParam>::SetUp,
- base::Unretained(&service_thread),
- base::Passed(MakeRequest(&ptr))));
+ FROM_HERE,
+ base::Bind(&TestSyncServiceThread<Interface>::SetUp,
+ base::Unretained(&service_thread), base::Passed(&request)));
ASSERT_TRUE(ptr->Ping());
ASSERT_TRUE(service_thread.ping_called());
@@ -364,8 +429,9 @@ TYPED_TEST(SyncMethodCommonTest, BasicSyncCalls) {
base::RunLoop run_loop;
service_thread.thread()->task_runner()->PostTaskAndReply(
- FROM_HERE, base::Bind(&TestSyncServiceThread<TypeParam>::TearDown,
- base::Unretained(&service_thread)),
+ FROM_HERE,
+ base::Bind(&TestSyncServiceThread<Interface>::TearDown,
+ base::Unretained(&service_thread)),
run_loop.QuitClosure());
run_loop.Run();
}
@@ -374,9 +440,11 @@ TYPED_TEST(SyncMethodCommonTest, ReenteredBySyncMethodBinding) {
// Test that an interface pointer waiting for a sync call response can be
// reentered by a binding serving sync methods on the same thread.
- InterfacePtr<TypeParam> ptr;
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
// The binding lives on the same thread as the interface pointer.
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
int32_t output_value = -1;
ASSERT_TRUE(ptr->Echo(42, &output_value));
EXPECT_EQ(42, output_value);
@@ -386,8 +454,10 @@ TYPED_TEST(SyncMethodCommonTest, InterfacePtrDestroyedDuringSyncCall) {
// Test that it won't result in crash or hang if an interface pointer is
// destroyed while it is waiting for a sync call response.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
impl.set_ping_handler([&ptr](const TestSync::PingCallback& callback) {
ptr.reset();
callback.Run();
@@ -400,8 +470,10 @@ TYPED_TEST(SyncMethodCommonTest, BindingDestroyedDuringSyncCall) {
// closed (and therefore the message pipe handle is closed) while the
// corresponding interface pointer is waiting for a sync call response.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
impl.set_ping_handler([&impl](const TestSync::PingCallback& callback) {
impl.binding()->Close();
callback.Run();
@@ -413,8 +485,10 @@ TYPED_TEST(SyncMethodCommonTest, NestedSyncCallsWithInOrderResponses) {
// Test that we can call a sync method on an interface ptr, while there is
// already a sync call ongoing. The responses arrive in order.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
// The same variable is used to store the output of the two sync calls, in
// order to test that responses are handled in the correct order.
@@ -439,8 +513,10 @@ TYPED_TEST(SyncMethodCommonTest, NestedSyncCallsWithOutOfOrderResponses) {
// Test that we can call a sync method on an interface ptr, while there is
// already a sync call ongoing. The responses arrive out of order.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
// The same variable is used to store the output of the two sync calls, in
// order to test that responses are handled in the correct order.
@@ -465,8 +541,10 @@ TYPED_TEST(SyncMethodCommonTest, AsyncResponseQueuedDuringSyncCall) {
// Test that while an interface pointer is waiting for the response to a sync
// call, async responses are queued until the sync call completes.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
int32_t async_echo_request_value = -1;
TestSync::AsyncEchoCallback async_echo_request_callback;
@@ -521,8 +599,10 @@ TYPED_TEST(SyncMethodCommonTest, AsyncRequestQueuedDuringSyncCall) {
// call, async requests for a binding running on the same thread are queued
// until the sync call completes.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> interface_ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&interface_ptr));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
bool async_echo_request_dispatched = false;
impl.set_async_echo_handler([&async_echo_request_dispatched](
@@ -572,8 +652,14 @@ TYPED_TEST(SyncMethodCommonTest,
// before the queued messages are processed, the connection error
// notification is delayed until all the queued messages are processed.
- InterfacePtr<TypeParam> ptr;
- typename ImplTraits<TypeParam>::Type impl(MakeRequest(&ptr));
+ // ThreadSafeInterfacePtr doesn't guarantee that messages are delivered before
+ // error notifications, so skip it for this test.
+ if (TypeParam::kIsThreadSafeInterfacePtrTest)
+ return;
+
+ using Interface = typename TypeParam::Interface;
+ InterfacePtr<Interface> ptr;
+ ImplTypeFor<Interface> impl(MakeRequest(&ptr));
int32_t async_echo_request_value = -1;
TestSync::AsyncEchoCallback async_echo_request_callback;
@@ -648,14 +734,15 @@ TYPED_TEST(SyncMethodCommonTest, InvalidMessageDuringSyncCall) {
// the sync call to return false, and run the connection error handler
// asynchronously.
+ using Interface = typename TypeParam::Interface;
MessagePipe pipe;
- InterfacePtr<TypeParam> ptr;
- ptr.Bind(InterfacePtrInfo<TypeParam>(std::move(pipe.handle0), 0u));
+ InterfacePtr<Interface> interface_ptr;
+ interface_ptr.Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u));
+ auto ptr = TypeParam::Wrap(std::move(interface_ptr));
MessagePipeHandle raw_binding_handle = pipe.handle1.get();
- typename ImplTraits<TypeParam>::Type impl(
- MakeRequest<TypeParam>(std::move(pipe.handle1)));
+ ImplTypeFor<Interface> impl(MakeRequest<Interface>(std::move(pipe.handle1)));
impl.set_echo_handler([&raw_binding_handle](
int32_t value, const TestSync::EchoCallback& callback) {
@@ -670,17 +757,22 @@ TYPED_TEST(SyncMethodCommonTest, InvalidMessageDuringSyncCall) {
bool connection_error_dispatched = false;
base::RunLoop run_loop;
- ptr.set_connection_error_handler(
- base::Bind(&SetFlagAndRunClosure, &connection_error_dispatched,
- run_loop.QuitClosure()));
+ // ThreadSafeInterfacePtr doesn't support setting connection error handlers.
+ if (!TypeParam::kIsThreadSafeInterfacePtrTest) {
+ ptr.set_connection_error_handler(base::Bind(&SetFlagAndRunClosure,
+ &connection_error_dispatched,
+ run_loop.QuitClosure()));
+ }
int32_t result_value = -1;
ASSERT_FALSE(ptr->Echo(456, &result_value));
EXPECT_EQ(-1, result_value);
ASSERT_FALSE(connection_error_dispatched);
- run_loop.Run();
- ASSERT_TRUE(connection_error_dispatched);
+ if (!TypeParam::kIsThreadSafeInterfacePtrTest) {
+ run_loop.Run();
+ ASSERT_TRUE(connection_error_dispatched);
+ }
}
TEST_F(SyncMethodAssociatedTest, ReenteredBySyncMethodAssoBindingOfSameRouter) {
diff --git a/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
index 5028087..dc40143 100644
--- a/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
@@ -19,7 +19,7 @@ TEST(WTFMapTest, StructKey) {
ASSERT_NE(map.end(), map.find(key));
ASSERT_EQ(123, map.find(key)->value);
- map.remove(key);
+ map.erase(key);
ASSERT_EQ(0u, map.size());
}
@@ -32,7 +32,7 @@ TEST(WTFMapTest, TypemappedStructKey) {
ASSERT_NE(map.end(), map.find(key));
ASSERT_EQ(123, map.find(key)->value);
- map.remove(key);
+ map.erase(key);
ASSERT_EQ(0u, map.size());
}