Make sure webrtc::VideoSourceInterface is released on the main render thread.
[chromium-blink-merge.git] / content / public / test / browser_test_base.h
blob7e36ce64411c4f12e1d4d7ce9712c139d481fb55
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"
14 namespace base {
15 class CommandLine;
16 class FilePath;
19 namespace net {
20 namespace test_server {
21 class EmbeddedTestServer;
24 class RuleBasedHostResolverProc;
25 } // namespace net
27 namespace content {
29 class BrowserTestBase : public testing::Test {
30 public:
31 BrowserTestBase();
32 virtual ~BrowserTestBase();
34 // We do this so we can be used in a Task.
35 void AddRef() {}
36 void Release() {}
38 // Configures everything for an in process browser test, then invokes
39 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
40 virtual void SetUp() OVERRIDE;
42 // Restores state configured in SetUp.
43 virtual void TearDown() OVERRIDE;
45 // Override this to add any custom setup code that needs to be done on the
46 // main thread after the browser is created and just before calling
47 // RunTestOnMainThread().
48 virtual void SetUpOnMainThread() {}
50 // Override this to add any custom teardown code that needs to be done on the
51 // main thread right after RunTestOnMainThread().
52 virtual void TearDownOnMainThread() {}
54 // Override this to add command line flags specific to your test.
55 virtual void SetUpCommandLine(base::CommandLine* command_line) {}
57 // Returns the host resolver being used for the tests. Subclasses might want
58 // to configure it inside tests.
59 net::RuleBasedHostResolverProc* host_resolver() {
60 return rule_based_resolver_.get();
63 protected:
64 // We need these special methods because SetUp is the bottom of the stack
65 // that winds up calling your test method, so it is not always an option
66 // to do what you want by overriding it and calling the superclass version.
68 // Override this for things you would normally override SetUp for. It will be
69 // called before your individual test fixture method is run, but after most
70 // of the overhead initialization has occured.
71 virtual void SetUpInProcessBrowserTestFixture() {}
73 // Override this for things you would normally override TearDown for.
74 virtual void TearDownInProcessBrowserTestFixture() {}
76 // Override this rather than TestBody.
77 virtual void RunTestOnMainThread() = 0;
79 // This is invoked from main after browser_init/browser_main have completed.
80 // This prepares for the test by creating a new browser, runs the test
81 // (RunTestOnMainThread), quits the browsers and returns.
82 virtual void RunTestOnMainThreadLoop() = 0;
84 // Returns the testing server. Guaranteed to be non-NULL.
85 // TODO(phajdan.jr): Remove test_server accessor (http://crbug.com/96594).
86 const net::SpawnedTestServer* test_server() const {
87 return test_server_.get();
89 net::SpawnedTestServer* test_server() { return test_server_.get(); }
91 // Returns the embedded test server. Guaranteed to be non-NULL.
92 const net::test_server::EmbeddedTestServer* embedded_test_server() const {
93 return embedded_test_server_.get();
95 net::test_server::EmbeddedTestServer* embedded_test_server() {
96 return embedded_test_server_.get();
99 #if defined(OS_POSIX)
100 // This is only needed by a test that raises SIGTERM to ensure that a specific
101 // codepath is taken.
102 void DisableSIGTERMHandling() {
103 handle_sigterm_ = false;
105 #endif
107 // This function is meant only for classes that directly derive from this
108 // class to construct the test server in their constructor. They might need to
109 // call this after setting up the paths. Actual test cases should never call
110 // this.
111 // |test_server_base| is the path, relative to src, to give to the test HTTP
112 // server.
113 void CreateTestServer(const base::FilePath& test_server_base);
115 // When the test is running in --single-process mode, runs the given task on
116 // the in-process renderer thread. A nested message loop is run until it
117 // returns.
118 void PostTaskToInProcessRendererAndWait(const base::Closure& task);
120 // Call this before SetUp() to cause the test to generate pixel output.
121 void EnablePixelOutput();
123 // Call this before SetUp() to not use GL, but use software compositing
124 // instead.
125 void UseSoftwareCompositing();
127 // Returns true if the test will be using GL acceleration via OSMesa.
128 bool UsingOSMesa() const;
130 private:
131 void ProxyRunTestOnMainThreadLoop();
133 // Testing server, started on demand.
134 scoped_ptr<net::SpawnedTestServer> test_server_;
136 // Embedded test server, cheap to create, started on demand.
137 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_;
139 // Host resolver used during tests.
140 scoped_refptr<net::RuleBasedHostResolverProc> rule_based_resolver_;
142 // When true, the compositor will produce pixel output that can be read back
143 // for pixel tests.
144 bool enable_pixel_output_;
146 // When true, do compositing with the software backend instead of using GL.
147 bool use_software_compositing_;
149 #if defined(OS_POSIX)
150 bool handle_sigterm_;
151 #endif
154 } // namespace content
156 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_