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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_
6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/threading/thread.h"
11 #include "net/test/spawned_test_server/spawned_test_server.h"
12 #include "testing/gtest/include/gtest/gtest.h"
21 namespace test_server
{
22 class EmbeddedTestServer
;
25 class RuleBasedHostResolverProc
;
30 class BrowserTestBase
: public testing::Test
{
33 virtual ~BrowserTestBase();
35 // We do this so we can be used in a Task.
39 // Configures everything for an in process browser test, then invokes
40 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
41 virtual void SetUp() OVERRIDE
;
43 // Restores state configured in SetUp.
44 virtual void TearDown() OVERRIDE
;
46 // Override this to add any custom setup code that needs to be done on the
47 // main thread after the browser is created and just before calling
48 // RunTestOnMainThread().
49 virtual void SetUpOnMainThread() {}
51 // Override this to add any custom teardown code that needs to be done on the
52 // main thread right after RunTestOnMainThread().
53 virtual void TearDownOnMainThread() {}
55 // Override this to add command line flags specific to your test.
56 virtual void SetUpCommandLine(CommandLine
* command_line
) {}
58 // Returns the host resolver being used for the tests. Subclasses might want
59 // to configure it inside tests.
60 net::RuleBasedHostResolverProc
* host_resolver() {
61 return rule_based_resolver_
.get();
65 // We need these special methods because SetUp is the bottom of the stack
66 // that winds up calling your test method, so it is not always an option
67 // to do what you want by overriding it and calling the superclass version.
69 // Override this for things you would normally override SetUp for. It will be
70 // called before your individual test fixture method is run, but after most
71 // of the overhead initialization has occured.
72 virtual void SetUpInProcessBrowserTestFixture() {}
74 // Override this for things you would normally override TearDown for.
75 virtual void TearDownInProcessBrowserTestFixture() {}
77 // Override this rather than TestBody.
78 virtual void RunTestOnMainThread() = 0;
80 // This is invoked from main after browser_init/browser_main have completed.
81 // This prepares for the test by creating a new browser, runs the test
82 // (RunTestOnMainThread), quits the browsers and returns.
83 virtual void RunTestOnMainThreadLoop() = 0;
85 // Returns the testing server. Guaranteed to be non-NULL.
86 // TODO(phajdan.jr): Remove test_server accessor (http://crbug.com/96594).
87 const net::SpawnedTestServer
* test_server() const {
88 return test_server_
.get();
90 net::SpawnedTestServer
* test_server() { return test_server_
.get(); }
92 // Returns the embedded test server. Guaranteed to be non-NULL.
93 const net::test_server::EmbeddedTestServer
* embedded_test_server() const {
94 return embedded_test_server_
.get();
96 net::test_server::EmbeddedTestServer
* embedded_test_server() {
97 return embedded_test_server_
.get();
100 #if defined(OS_POSIX)
101 // This is only needed by a test that raises SIGTERM to ensure that a specific
102 // codepath is taken.
103 void DisableSIGTERMHandling() {
104 handle_sigterm_
= false;
108 // This function is meant only for classes that directly derive from this
109 // class to construct the test server in their constructor. They might need to
110 // call this after setting up the paths. Actual test cases should never call
112 // |test_server_base| is the path, relative to src, to give to the test HTTP
114 void CreateTestServer(const base::FilePath
& test_server_base
);
116 // When the test is running in --single-process mode, runs the given task on
117 // the in-process renderer thread. A nested message loop is run until it
119 void PostTaskToInProcessRendererAndWait(const base::Closure
& task
);
121 // Call this before SetUp() to use real GL contexts in Compositor for the
123 void UseRealGLContexts();
125 // Call this before SetUp() to use real GL drivers instead of OSMesa for the
127 void UseRealGLBindings();
129 // Call this before SetUp() to not use GL, but use software compositing
131 void UseSoftwareCompositing();
134 void ProxyRunTestOnMainThreadLoop();
136 // Testing server, started on demand.
137 scoped_ptr
<net::SpawnedTestServer
> test_server_
;
139 // Embedded test server, cheap to create, started on demand.
140 scoped_ptr
<net::test_server::EmbeddedTestServer
> embedded_test_server_
;
142 // Host resolver used during tests.
143 scoped_refptr
<net::RuleBasedHostResolverProc
> rule_based_resolver_
;
145 // When false, the ui::Compositor will be forced to use real GL contexts for
146 // the test, so that it produces real pixel output.
147 bool allow_test_contexts_
;
149 // When false, the GL backend will use a real GPU. When true, it uses OSMesa
150 // to run GL on the CPU in a way that works across all platforms.
153 // When true, do compositing with the software backend instead of using GL.
154 bool use_software_compositing_
;
156 #if defined(OS_POSIX)
157 bool handle_sigterm_
;
161 } // namespace content
163 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_