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 | 18 |
18 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ | 19 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ |
19 parent_id)\ | 20 parent_id)\ |
20 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ | 21 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ |
21 public:\ | 22 public:\ |
22 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ | 23 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ |
23 protected:\ | 24 protected:\ |
24 virtual void RunTestOnMainThread() OVERRIDE;\ | 25 virtual void RunTestOnMainThread() OVERRIDE;\ |
25 private:\ | 26 private:\ |
26 virtual void TestBody() OVERRIDE {}\ | 27 virtual void TestBody() OVERRIDE {}\ |
(...skipping 10 matching lines...) Expand all Loading... |
37 parent_class::SetUpTestCase, \ | 38 parent_class::SetUpTestCase, \ |
38 parent_class::TearDownTestCase, \ | 39 parent_class::TearDownTestCase, \ |
39 new ::testing::internal::TestFactoryImpl<\ | 40 new ::testing::internal::TestFactoryImpl<\ |
40 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 41 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ |
41 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 42 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
42 | 43 |
43 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 44 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
44 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 45 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
45 ::testing::internal::GetTypeId<test_fixture>()) | 46 ::testing::internal::GetTypeId<test_fixture>()) |
46 | 47 |
47 #define IN_PROC_BROWSER_TEST_P(test_case_name, test_name) \ | 48 #define IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) \ |
48 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ | 49 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ |
49 : public test_case_name { \ | 50 : public test_case_name { \ |
50 public: \ | 51 public: \ |
51 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ | 52 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ |
52 protected: \ | 53 protected: \ |
53 virtual void RunTestOnMainThread() OVERRIDE; \ | 54 virtual void RunTestOnMainThread() OVERRIDE; \ |
54 private: \ | 55 private: \ |
55 virtual void TestBody() OVERRIDE {} \ | 56 virtual void TestBody() OVERRIDE {} \ |
56 static int AddToRegistry() { \ | 57 static int AddToRegistry() { \ |
57 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ | 58 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ |
58 GetTestCasePatternHolder<test_case_name>(\ | 59 GetTestCasePatternHolder<test_case_name>(\ |
59 #test_case_name, __FILE__, __LINE__)->AddTestPattern(\ | 60 #test_case_name, __FILE__, __LINE__)->AddTestPattern(\ |
60 #test_case_name, \ | 61 #test_case_name, \ |
61 #test_name, \ | 62 #test_name, \ |
62 new ::testing::internal::TestMetaFactory< \ | 63 new ::testing::internal::TestMetaFactory< \ |
63 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \ | 64 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \ |
64 return 0; \ | 65 return 0; \ |
65 } \ | 66 } \ |
66 static int gtest_registering_dummy_; \ | 67 static int gtest_registering_dummy_; \ |
67 GTEST_DISALLOW_COPY_AND_ASSIGN_(\ | 68 GTEST_DISALLOW_COPY_AND_ASSIGN_(\ |
68 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ | 69 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ |
69 }; \ | 70 }; \ |
70 int GTEST_TEST_CLASS_NAME_(test_case_name, \ | 71 int GTEST_TEST_CLASS_NAME_(test_case_name, \ |
71 test_name)::gtest_registering_dummy_ = \ | 72 test_name)::gtest_registering_dummy_ = \ |
72 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ | 73 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ |
73 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 74 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
74 | 75 |
| 76 // 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_). |
| 78 #define IN_PROC_BROWSER_TEST_P(test_case_name, test_name) \ |
| 79 IN_PROC_BROWSER_TEST_P_(test_case_name, test_name) |
| 80 |
75 #endif // defined(HAS_OUT_OF_PROC_TEST_RUNNER) | 81 #endif // defined(HAS_OUT_OF_PROC_TEST_RUNNER) |
76 | 82 |
77 #endif // CONTENT_TEST_BROWSER_TEST_H_ | 83 #endif // CONTENT_TEST_BROWSER_TEST_H_ |
OLD | NEW |