File: multi_class_browser_test.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 6,352 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VR_TEST_MULTI_CLASS_BROWSER_TEST_H_
#define CHROME_BROWSER_VR_TEST_MULTI_CLASS_BROWSER_TEST_H_

#include "build/build_config.h"
#include "content/public/test/browser_test.h"
#include "device/vr/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"

// A collection of macros to automatically run a browser test multiple times
// with different test classes/test fixtures. These are used the same way as
// the standard IN_PROC_BROWSER_TEST_F and IN_PROC_BROWSER_TEST_P macros, except
// that multiple test classes/fixtures are specified instead of one and a common
// base class must be provided. The number suffix indicates how many classes the
// macro expects, e.g. IN_PROC_MULTI_CLASS_BROWSER_TEST_F2 takes two classes.

// One important note is that while IN_PROC_BROWSER_TEST_F would normally
// provide the constructed test class as "this", the reference to the
// constructed class when using the multi class macros is instead provided as
// "t". t's type will also be the provided base class, so if you need behavior
// specific to one of the subclasses, you must first cast it. Although in such
// cases, you should probably reconsider whether use of these macros is really
// appropriate instead of having separate implementations.

// In essence:
//
// IN_PROC_MULTI_CLASS_BROWSER_TEST_F2(sub1, sub2, base, name) { impl }
//
// Is shorthand for:
//
// void TestImpl(base* t) { impl }
// IN_PROC_BROWSER_TEST_F(sub1, name) { TestImpl(this); }
// IN_PROC_BROWSER_TEST_F(sub2, name) { TestImpl(this); }

// We essentially create a dummy class for the test which contains a declaration
// for a static function that will have the actual test implementation. We then
// define as many IN_PROC_BROWSER_TEST_Fs as necesasry and have each call the
// static function with its "this" reference. Finally, we start the definition
// for the static function but leave it unfinished so that the definition
// provided by the caller is used (which is also what IN_PROC_BROWSER_TEST_F
// does under the hood).

#define MULTI_CLASS_RUNNER_NAME_(test_name) RunMultiClassBrowserTest_##test_name

#define DEFINE_RUN_TEST_IMPL_(test_name, base_class)        \
  class MULTI_CLASS_RUNNER_NAME_(test_name) {               \
   public:                                                  \
    MULTI_CLASS_RUNNER_NAME_(test_name)() {}                \
    static void ActuallyRunTestOnMainThread(base_class* t); \
  };

#define DEFINE_BROWSER_TEST_(test_class, test_name)                         \
  IN_PROC_BROWSER_TEST_F(test_class, test_name) {                           \
    MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread(this); \
  }

#define DEFINE_INCOGNITO_BROWSER_TEST_(test_class, test_name)               \
  IN_PROC_BROWSER_TEST_F(test_class, test_name##Incognito) {                \
    SetIncognito();                                                         \
    MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread(this); \
  }

// TODO(crbug.com/40736732): The "MULTI_CLASS" macros are not really
// needed anymore, and the individual tests should be wrapped with a check to
// the openxr buildflag. However, there is a non-trivial amount of churn to move
// the tests off of the "ALL_RUNTIMES" macros. So this lets us stage the work in
// the meantime.
#define MULTI_CLASS_BROWSER_TEST_STUB(base_class, test_name)             \
  DEFINE_RUN_TEST_IMPL_(test_name, base_class)                           \
  void MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread( \
      base_class* t)

#define IN_PROC_MULTI_CLASS_BROWSER_TEST_F1(test_class1, base_class,     \
                                            test_name)                   \
  DEFINE_RUN_TEST_IMPL_(test_name, base_class)                           \
  DEFINE_BROWSER_TEST_(test_class1, test_name)                           \
  void MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread( \
      base_class* t)

#if BUILDFLAG(ENABLE_OPENXR)
#define WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(test_name)         \
  IN_PROC_MULTI_CLASS_BROWSER_TEST_F1(WebXrVrOpenXrBrowserTest, \
                                      WebXrVrBrowserTestBase, test_name)
#else
#define WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(test_name) \
  MULTI_CLASS_BROWSER_TEST_STUB(WebXrVrBrowserTestBase, test_name)
#endif  // BUILDFLAG(ENABLE_OPENXR)

#if !BUILDFLAG(IS_ANDROID)
#define IN_PROC_NORMAL_PLUS_INCOGNITO_BROWSER_TEST_F(test_class1, base_class, \
                                                     test_name)               \
  DEFINE_RUN_TEST_IMPL_(test_name, base_class)                                \
  DEFINE_BROWSER_TEST_(test_class1, test_name)                                \
  DEFINE_INCOGNITO_BROWSER_TEST_(test_class1, test_name)                      \
  void MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread(      \
      base_class* t)
#else
// TODO(https://crbug.com/381000093): ContextualNotificationPermissionRequester
// needs to be setup in Java before we can run incognito tests on Android. At
// least one test installs this in a Java Setup step; otherwise, it seems to
// happen via things that *are* part of chrome_java_sources.
#define IN_PROC_NORMAL_PLUS_INCOGNITO_BROWSER_TEST_F(test_class1, base_class, \
                                                     test_name)               \
  IN_PROC_MULTI_CLASS_BROWSER_TEST_F1(test_class1, base_class, test_name)
#endif  // BUILDFLAG(IS_ANDROID)

// The same as WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F, but runs the tests in
// incognito mode as well.
#if BUILDFLAG(ENABLE_OPENXR)
#define WEBXR_VR_ALL_RUNTIMES_PLUS_INCOGNITO_BROWSER_TEST_F(test_name) \
  IN_PROC_NORMAL_PLUS_INCOGNITO_BROWSER_TEST_F(                        \
      WebXrVrOpenXrBrowserTest, WebXrVrBrowserTestBase, test_name)
#else
#define WEBXR_VR_ALL_RUNTIMES_PLUS_INCOGNITO_BROWSER_TEST_F(test_name) \
  MULTI_CLASS_BROWSER_TEST_STUB(WebXrVrBrowserTestBase, test_name)
#endif  // ENABLE_OPENXR

// Helper class to disable a specific runtime of the above
#define WEBXR_VR_DISABLE_TEST_ON(runtime) \
  if (t->GetRuntimeType() == runtime)     \
  return

#endif  // CHROME_BROWSER_VR_TEST_MULTI_CLASS_BROWSER_TEST_H_