Home | History | Annotate | Download | only in tests
      1 // Copyright 2017 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_BINDINGS_TEST_BASE_H_
      6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_BINDINGS_TEST_BASE_H_
      7 
      8 #include "base/test/scoped_task_environment.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace mojo {
     12 
     13 // Used to parameterize tests which inherit from BindingsTestBase to exercise
     14 // various message serialization-related code paths for intra-process bindings
     15 // usage.
     16 enum class BindingsTestSerializationMode {
     17   // Messages should be serialized immediately before sending.
     18   kSerializeBeforeSend,
     19 
     20   // Messages should be serialized immediately before dispatching.
     21   kSerializeBeforeDispatch,
     22 
     23   // Messages should never be serialized.
     24   kNeverSerialize,
     25 };
     26 
     27 class BindingsTestBase
     28     : public testing::Test,
     29       public testing::WithParamInterface<BindingsTestSerializationMode> {
     30  public:
     31   BindingsTestBase();
     32   ~BindingsTestBase();
     33 
     34   // Helper which other test fixtures can use.
     35   static void SetupSerializationBehavior(BindingsTestSerializationMode mode);
     36 
     37  private:
     38   base::test::ScopedTaskEnvironment task_environment_;
     39 };
     40 
     41 }  // namespace mojo
     42 
     43 #define INSTANTIATE_MOJO_BINDINGS_TEST_CASE_P(fixture)                   \
     44   INSTANTIATE_TEST_CASE_P(                                               \
     45       , fixture,                                                         \
     46       testing::Values(                                                   \
     47           mojo::BindingsTestSerializationMode::kSerializeBeforeSend,     \
     48           mojo::BindingsTestSerializationMode::kSerializeBeforeDispatch, \
     49           mojo::BindingsTestSerializationMode::kNeverSerialize))
     50 
     51 #endif  // MOJO_PUBLIC_CPP_BINDINGS_TESTS_BINDINGS_TEST_BASE_H_
     52