Home | History | Annotate | Download | only in message_loop
      1 // Copyright 2013 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 BASE_MESSAGE_LOOP_MESSAGE_LOOP_TEST_H_
      6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_TEST_H_
      7 
      8 #include "base/message_loop/message_loop.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 // This file consists of tests meant to exercise the combination of MessageLoop
     12 // and MessagePump. To use these define the macro RUN_MESSAGE_LOOP_TESTS using
     13 // an ID appropriate for your MessagePump, eg
     14 // RUN_MESSAGE_LOOP_TESTS(UI, factory). Factory is a function called to create
     15 // the MessagePump.
     16 namespace base {
     17 namespace test {
     18 
     19 typedef MessageLoop::MessagePumpFactory MessagePumpFactory;
     20 
     21 void RunTest_PostTask(MessagePumpFactory factory);
     22 void RunTest_PostTask_SEH(MessagePumpFactory factory);
     23 void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory);
     24 void RunTest_PostDelayedTask_InDelayOrder(MessagePumpFactory factory);
     25 void RunTest_PostDelayedTask_InPostOrder(MessagePumpFactory factory);
     26 void RunTest_PostDelayedTask_InPostOrder_2(MessagePumpFactory factory);
     27 void RunTest_PostDelayedTask_InPostOrder_3(MessagePumpFactory factory);
     28 void RunTest_PostDelayedTask_SharedTimer(MessagePumpFactory factory);
     29 void RunTest_EnsureDeletion(MessagePumpFactory factory);
     30 void RunTest_EnsureDeletion_Chain(MessagePumpFactory factory);
     31 void RunTest_Nesting(MessagePumpFactory factory);
     32 void RunTest_RecursiveDenial1(MessagePumpFactory factory);
     33 void RunTest_RecursiveDenial3(MessagePumpFactory factory);
     34 void RunTest_RecursiveSupport1(MessagePumpFactory factory);
     35 void RunTest_NonNestableWithNoNesting(MessagePumpFactory factory);
     36 void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory,
     37                                      bool use_delayed);
     38 void RunTest_QuitNow(MessagePumpFactory factory);
     39 void RunTest_RunLoopQuitTop(MessagePumpFactory factory);
     40 void RunTest_RunLoopQuitNested(MessagePumpFactory factory);
     41 void RunTest_RunLoopQuitBogus(MessagePumpFactory factory);
     42 void RunTest_RunLoopQuitDeep(MessagePumpFactory factory);
     43 void RunTest_RunLoopQuitOrderBefore(MessagePumpFactory factory);
     44 void RunTest_RunLoopQuitOrderDuring(MessagePumpFactory factory);
     45 void RunTest_RunLoopQuitOrderAfter(MessagePumpFactory factory);
     46 void RunTest_RecursivePosts(MessagePumpFactory factory);
     47 
     48 }  // namespace test
     49 }  // namespace base
     50 
     51 #define RUN_MESSAGE_LOOP_TESTS(id, factory) \
     52   TEST(MessageLoopTestType##id, PostTask) { \
     53     base::test::RunTest_PostTask(factory); \
     54   } \
     55   TEST(MessageLoopTestType##id, PostTask_SEH) { \
     56     base::test::RunTest_PostTask_SEH(factory); \
     57   } \
     58   TEST(MessageLoopTestType##id, PostDelayedTask_Basic) { \
     59     base::test::RunTest_PostDelayedTask_Basic(factory); \
     60   } \
     61   TEST(MessageLoopTestType##id, PostDelayedTask_InDelayOrder) { \
     62     base::test::RunTest_PostDelayedTask_InDelayOrder(factory); \
     63   } \
     64   TEST(MessageLoopTestType##id, PostDelayedTask_InPostOrder) { \
     65     base::test::RunTest_PostDelayedTask_InPostOrder(factory); \
     66   } \
     67   TEST(MessageLoopTestType##id, PostDelayedTask_InPostOrder_2) { \
     68     base::test::RunTest_PostDelayedTask_InPostOrder_2(factory); \
     69   } \
     70   TEST(MessageLoopTestType##id, PostDelayedTask_InPostOrder_3) { \
     71     base::test::RunTest_PostDelayedTask_InPostOrder_3(factory); \
     72   } \
     73   TEST(MessageLoopTestType##id, PostDelayedTask_SharedTimer) { \
     74     base::test::RunTest_PostDelayedTask_SharedTimer(factory); \
     75   } \
     76   /* TODO(darin): MessageLoop does not support deleting all tasks in the */ \
     77   /* destructor. */ \
     78   /* Fails, http://crbug.com/50272. */ \
     79   TEST(MessageLoopTestType##id, DISABLED_EnsureDeletion) { \
     80     base::test::RunTest_EnsureDeletion(factory); \
     81   } \
     82   /* TODO(darin): MessageLoop does not support deleting all tasks in the */ \
     83   /* destructor. */ \
     84   /* Fails, http://crbug.com/50272. */ \
     85   TEST(MessageLoopTestType##id, DISABLED_EnsureDeletion_Chain) { \
     86     base::test::RunTest_EnsureDeletion_Chain(factory); \
     87   } \
     88   TEST(MessageLoopTestType##id, Nesting) { \
     89     base::test::RunTest_Nesting(factory); \
     90   } \
     91   TEST(MessageLoopTestType##id, RecursiveDenial1) { \
     92     base::test::RunTest_RecursiveDenial1(factory); \
     93   } \
     94   TEST(MessageLoopTestType##id, RecursiveDenial3) { \
     95     base::test::RunTest_RecursiveDenial3(factory); \
     96   } \
     97   TEST(MessageLoopTestType##id, RecursiveSupport1) { \
     98     base::test::RunTest_RecursiveSupport1(factory); \
     99   } \
    100   TEST(MessageLoopTestType##id, NonNestableWithNoNesting) { \
    101     base::test::RunTest_NonNestableWithNoNesting(factory); \
    102   } \
    103   TEST(MessageLoopTestType##id, NonNestableInNestedLoop) { \
    104     base::test::RunTest_NonNestableInNestedLoop(factory, false); \
    105   } \
    106   TEST(MessageLoopTestType##id, NonNestableDelayedInNestedLoop) { \
    107     base::test::RunTest_NonNestableInNestedLoop(factory, true); \
    108   } \
    109   TEST(MessageLoopTestType##id, QuitNow) { \
    110     base::test::RunTest_QuitNow(factory); \
    111   } \
    112   TEST(MessageLoopTestType##id, RunLoopQuitTop) { \
    113     base::test::RunTest_RunLoopQuitTop(factory); \
    114   } \
    115   TEST(MessageLoopTestType##id, RunLoopQuitNested) { \
    116     base::test::RunTest_RunLoopQuitNested(factory); \
    117   } \
    118   TEST(MessageLoopTestType##id, RunLoopQuitBogus) { \
    119     base::test::RunTest_RunLoopQuitBogus(factory); \
    120   } \
    121   TEST(MessageLoopTestType##id, RunLoopQuitDeep) { \
    122     base::test::RunTest_RunLoopQuitDeep(factory); \
    123   } \
    124   TEST(MessageLoopTestType##id, RunLoopQuitOrderBefore) { \
    125     base::test::RunTest_RunLoopQuitOrderBefore(factory); \
    126   } \
    127   TEST(MessageLoopTestType##id, RunLoopQuitOrderDuring) { \
    128     base::test::RunTest_RunLoopQuitOrderDuring(factory); \
    129   } \
    130   TEST(MessageLoopTestType##id, RunLoopQuitOrderAfter) { \
    131     base::test::RunTest_RunLoopQuitOrderAfter(factory); \
    132   } \
    133   TEST(MessageLoopTestType##id, RecursivePosts) { \
    134     base::test::RunTest_RecursivePosts(factory); \
    135   } \
    136 
    137 #endif  // BASE_MESSAGE_LOOP_MESSAGE_LOOP_TEST_H_
    138