1 // Copyright 2014 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.
5 #ifndef IOS_WEB_PUBLIC_TEST_WEB_TEST_UTIL_H_
6 #define IOS_WEB_PUBLIC_TEST_WEB_TEST_UTIL_H_
8 #include "ios/web/public/web_view_creation_util.h"
10 // A helper macro that allows skipping a unit test on iOS7 and earlier. Example:
12 // TEST_F(WKWebViewTest, WebViewInitializesCorrectly) {
13 // CR_TEST_REQUIRES_WK_WEB_VIEW();
14 // EXPECT_TRUE(NSClassFromString(@"WKWebView") != nil);
16 #define CR_TEST_REQUIRES_WK_WEB_VIEW() \
17 if (!web::IsWKWebViewSupported()) \
20 // Defines a web test that uses two test fixtures and single testing code.
22 // The first two parameters are the corresponding names of UIWebView-based and
23 // WKWebView-based test fixture classes. Those will also be the test case names.
24 // The third parameter is the name of the test within the test case.
26 // A test fixture class must be declared earlier. Test code goes between braces
27 // after using this macro. Example:
29 // typedef web::WebTest UIViewTest;
30 // typedef web::WKWebViewWebTest WKViewTest;
32 // WEB_TEST_F(UIViewTest, WKViewTest, ControllerInitializesCorrectly) {
33 // EXPECT_TRUE(this->webController_);
36 // Makes the name of a parent test class for WK and UI test fixtures.
37 // Only intended for use by WEB_TEST_F, not for direct use.
38 #define WEB_TEST_BASE_CLASS_(ui_fixture, wk_test_case, test_name)\
39 ui_fixture##wk_test_case##_##test_name##_WebTest
41 // Makes the name of a concrete WK or UI test fixture.
42 // Only intended for use by WEB_TEST_F, not for direct use.
43 #define WEB_TEST_TEST_CLASS_(test_case, test_name)\
44 test_case##_##test_name##_WebTest
46 // Makes the testing template class that runs WebTestBody function as the
48 // Only intended for use by WEB_TEST_F, not for direct use.
49 #define GTEST_WEB_TEST_(test_case, test_name, is_wk_web_view) \
50 GTEST_TEST_(test_case, test_name, \
51 WEB_TEST_TEST_CLASS_(test_case, test_name), \
52 ::testing::internal::GetTypeId<test_case>()) { \
53 if (!is_wk_web_view || web::IsWKWebViewSupported()) \
57 #define WEB_TEST_F(ui_fixture, wk_fixture, test_name) \
58 template <typename T> \
59 class WEB_TEST_BASE_CLASS_(ui_fixture, wk_fixture, test_name) \
64 typedef WEB_TEST_BASE_CLASS_( \
65 ui_fixture, wk_fixture, \
66 test_name) <ui_fixture> WEB_TEST_TEST_CLASS_(ui_fixture, test_name); \
67 typedef WEB_TEST_BASE_CLASS_( \
68 ui_fixture, wk_fixture, \
69 test_name) <wk_fixture> WEB_TEST_TEST_CLASS_(wk_fixture, test_name); \
70 GTEST_WEB_TEST_(ui_fixture, test_name, false) \
71 GTEST_WEB_TEST_(wk_fixture, test_name, true) \
72 template <typename T> \
73 void WEB_TEST_BASE_CLASS_(ui_fixture, wk_fixture, \
74 test_name) <T>::WebTestBody()
76 #endif // IOS_WEB_PUBLIC_TEST_WEB_TEST_UTIL_H_