OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_TEST_BROWSER_TEST_H_ | 5 #ifndef CONTENT_TEST_BROWSER_TEST_H_ |
6 #define CONTENT_TEST_BROWSER_TEST_H_ | 6 #define CONTENT_TEST_BROWSER_TEST_H_ |
7 | 7 |
8 // We only want to use InProcessBrowserTest in test targets which properly | 8 // We only want to use InProcessBrowserTest in test targets which properly |
9 // isolate each test case by running each test in a separate process. | 9 // isolate each test case by running each test in a separate process. |
10 // This way if a test hangs the test launcher can reliably terminate it. | 10 // This way if a test hangs the test launcher can reliably terminate it. |
11 // | 11 // |
12 // InProcessBrowserTest cannot be run more than once in the same address space | 12 // InProcessBrowserTest cannot be run more than once in the same address space |
13 // anyway - otherwise the second test crashes. | 13 // anyway - otherwise the second test crashes. |
14 #if defined(HAS_OUT_OF_PROC_TEST_RUNNER) | 14 #if defined(HAS_OUT_OF_PROC_TEST_RUNNER) |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ | 19 #define IN_PROC_BROWSER_TEST_( \ |
20 parent_id)\ | 20 test_case_name, test_name, parent_class, parent_id) \ |
21 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ | 21 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ |
22 public:\ | 22 : public parent_class { \ |
23 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ | 23 public: \ |
24 protected:\ | 24 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ |
25 virtual void RunTestOnMainThread() override;\ | 25 \ |
26 private:\ | 26 protected: \ |
27 virtual void TestBody() override {}\ | 27 void RunTestOnMainThread() override; \ |
28 static ::testing::TestInfo* const test_info_;\ | 28 \ |
29 GTEST_DISALLOW_COPY_AND_ASSIGN_(\ | 29 private: \ |
30 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ | 30 void TestBody() override {} \ |
31 };\ | 31 static ::testing::TestInfo* const test_info_; \ |
32 \ | 32 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \ |
33 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ | 33 test_name)); \ |
34 ::test_info_ =\ | 34 }; \ |
35 ::testing::internal::MakeAndRegisterTestInfo(\ | 35 \ |
36 #test_case_name, #test_name, "", "", \ | 36 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, \ |
37 (parent_id), \ | 37 test_name)::test_info_ = \ |
38 parent_class::SetUpTestCase, \ | 38 ::testing::internal::MakeAndRegisterTestInfo( \ |
39 parent_class::TearDownTestCase, \ | 39 #test_case_name, \ |
40 new ::testing::internal::TestFactoryImpl<\ | 40 #test_name, \ |
41 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 41 "", \ |
42 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 42 "", \ |
| 43 (parent_id), \ |
| 44 parent_class::SetUpTestCase, \ |
| 45 parent_class::TearDownTestCase, \ |
| 46 new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \ |
| 47 test_case_name, test_name)>); \ |
| 48 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
43 | 49 |
44 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 50 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
45 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 51 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
46 ::testing::internal::GetTypeId<test_fixture>()) | 52 ::testing::internal::GetTypeId<test_fixture>()) |
47 | 53 |
48 #define IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) \ | 54 #define IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) \ |
49 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ | 55 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ |
50 : public test_case_name { \ | 56 : public test_case_name { \ |
51 public: \ | 57 public: \ |
52 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ | 58 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ |
53 protected: \ | 59 \ |
54 virtual void RunTestOnMainThread() override; \ | 60 protected: \ |
55 private: \ | 61 void RunTestOnMainThread() override; \ |
56 virtual void TestBody() override {} \ | 62 \ |
57 static int AddToRegistry() { \ | 63 private: \ |
58 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ | 64 void TestBody() override {} \ |
59 GetTestCasePatternHolder<test_case_name>(\ | 65 static int AddToRegistry() { \ |
60 #test_case_name, __FILE__, __LINE__)->AddTestPattern(\ | 66 ::testing::UnitTest::GetInstance() \ |
61 #test_case_name, \ | 67 ->parameterized_test_registry() \ |
62 #test_name, \ | 68 .GetTestCasePatternHolder<test_case_name>( \ |
63 new ::testing::internal::TestMetaFactory< \ | 69 #test_case_name, __FILE__, __LINE__) \ |
64 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \ | 70 ->AddTestPattern( \ |
65 return 0; \ | 71 #test_case_name, \ |
66 } \ | 72 #test_name, \ |
67 static int gtest_registering_dummy_; \ | 73 new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \ |
68 GTEST_DISALLOW_COPY_AND_ASSIGN_(\ | 74 test_case_name, test_name)>()); \ |
69 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ | 75 return 0; \ |
70 }; \ | 76 } \ |
71 int GTEST_TEST_CLASS_NAME_(test_case_name, \ | 77 static int gtest_registering_dummy_; \ |
72 test_name)::gtest_registering_dummy_ = \ | 78 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \ |
73 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ | 79 test_name)); \ |
| 80 }; \ |
| 81 int GTEST_TEST_CLASS_NAME_(test_case_name, \ |
| 82 test_name)::gtest_registering_dummy_ = \ |
| 83 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ |
74 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 84 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
75 | 85 |
76 // Wrap the real macro with an outer macro to ensure that the parameters are | 86 // Wrap the real macro with an outer macro to ensure that the parameters are |
77 // evaluated (e.g., if |test_name| is prefixed with MAYBE_). | 87 // evaluated (e.g., if |test_name| is prefixed with MAYBE_). |
78 #define IN_PROC_BROWSER_TEST_P(test_case_name, test_name) \ | 88 #define IN_PROC_BROWSER_TEST_P(test_case_name, test_name) \ |
79 IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) | 89 IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) |
80 | 90 |
81 #endif // defined(HAS_OUT_OF_PROC_TEST_RUNNER) | 91 #endif // defined(HAS_OUT_OF_PROC_TEST_RUNNER) |
82 | 92 |
83 #endif // CONTENT_TEST_BROWSER_TEST_H_ | 93 #endif // CONTENT_TEST_BROWSER_TEST_H_ |
OLD | NEW |