// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <stdint.h> #include "base/check_op.h" #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/run_loop.h" #include "base/test/bind.h" #include "base/test/gtest_util.h" #include "base/test/task_environment.h" #include "build/build_config.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/test_support/test_support.h" #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" #include "testing/gtest/include/gtest/gtest.h" /////////////////////////////////////////////////////////////////////////////// // // The tests in this file are designed to test the interaction between a // Callback and its associated Receiver. If a Callback is deleted before // being used we DCHECK fail--unless the associated Receiver has already // been closed or deleted. This contract must be explained to the Mojo // application developer. For example it is the developer's responsibility to // ensure that the Receiver is destroyed before an unused Callback is destroyed. // /////////////////////////////////////////////////////////////////////////////// namespace mojo { namespace test { namespace { // An implementation of sample::Provider used on the server side. // It only implements one of the methods: EchoInt(). // All it does is save the values and Callbacks it sees. class InterfaceImpl : public sample::Provider { … }; class ReceiverCallbackTest : public testing::Test { … }; // Tests that the Remote and the Receiver can communicate with each other // normally. TEST_F(ReceiverCallbackTest, Basic) { … } // Tests that running the Callback after the Receiver has been deleted // results in a clean failure. TEST_F(ReceiverCallbackTest, DeleteReceiverThenRunCallback) { … } // Tests that deleting a Callback without running it after the corresponding // Receiver has already been deleted does not result in a crash. TEST_F(ReceiverCallbackTest, DeleteReceiverThenDeleteCallback) { … } // Tests that closing a Receiver allows us to delete a callback // without running it without encountering a crash. TEST_F(ReceiverCallbackTest, ResetReceiverBeforeDeletingCallback) { … } // Tests that deleting a Callback without using it before the // Receiver has been destroyed or closed results in a DCHECK. TEST_F(ReceiverCallbackTest, DeleteCallbackBeforeReceiverDeathTest) { … } } // namespace } // namespace test } // namespace mojo