| 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_PUBLIC_TEST_BROWSER_TEST_BASE_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ |
| 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ | 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/public/test/test_host_resolver.h" |
| 12 #include "net/test/embedded_test_server/embedded_test_server.h" | 13 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 13 #include "net/test/spawned_test_server/spawned_test_server.h" | 14 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class CommandLine; | 18 class CommandLine; |
| 18 class FilePath; | 19 class FilePath; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace net { | |
| 22 class RuleBasedHostResolverProc; | |
| 23 } // namespace net | |
| 24 | |
| 25 namespace content { | 22 namespace content { |
| 26 | 23 |
| 27 class BrowserTestBase : public testing::Test { | 24 class BrowserTestBase : public testing::Test { |
| 28 public: | 25 public: |
| 29 BrowserTestBase(); | 26 BrowserTestBase(); |
| 30 ~BrowserTestBase() override; | 27 ~BrowserTestBase() override; |
| 31 | 28 |
| 32 // Configures everything for an in process browser test, then invokes | 29 // Configures everything for an in process browser test, then invokes |
| 33 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. | 30 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. |
| 34 void SetUp() override; | 31 void SetUp() override; |
| 35 | 32 |
| 36 // Restores state configured in SetUp. | 33 // Restores state configured in SetUp. |
| 37 void TearDown() override; | 34 void TearDown() override; |
| 38 | 35 |
| 39 // Override this to add any custom setup code that needs to be done on the | 36 // Override this to add any custom setup code that needs to be done on the |
| 40 // main thread after the browser is created and just before calling | 37 // main thread after the browser is created and just before calling |
| 41 // RunTestOnMainThread(). | 38 // RunTestOnMainThread(). |
| 42 virtual void SetUpOnMainThread() {} | 39 virtual void SetUpOnMainThread() {} |
| 43 | 40 |
| 44 // Override this to add any custom teardown code that needs to be done on the | 41 // Override this to add any custom teardown code that needs to be done on the |
| 45 // main thread right after RunTestOnMainThread(). | 42 // main thread right after RunTestOnMainThread(). |
| 46 virtual void TearDownOnMainThread() {} | 43 virtual void TearDownOnMainThread() {} |
| 47 | 44 |
| 48 // Override this to add command line flags specific to your test. | 45 // Override this to add command line flags specific to your test. |
| 49 virtual void SetUpCommandLine(base::CommandLine* command_line) {} | 46 virtual void SetUpCommandLine(base::CommandLine* command_line) {} |
| 50 | 47 |
| 51 // Returns the host resolver being used for the tests. Subclasses might want | 48 // Returns the host resolver being used for the tests. Subclasses might want |
| 52 // to configure it inside tests. | 49 // to configure it inside tests. |
| 53 net::RuleBasedHostResolverProc* host_resolver() { | 50 net::RuleBasedHostResolverProc* host_resolver() { |
| 54 return rule_based_resolver_.get(); | 51 return test_host_resolver_->host_resolver(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 protected: | 54 protected: |
| 58 // We need these special methods because SetUp is the bottom of the stack | 55 // We need these special methods because SetUp is the bottom of the stack |
| 59 // that winds up calling your test method, so it is not always an option | 56 // that winds up calling your test method, so it is not always an option |
| 60 // to do what you want by overriding it and calling the superclass version. | 57 // to do what you want by overriding it and calling the superclass version. |
| 61 // | 58 // |
| 62 // Override this for things you would normally override SetUp for. It will be | 59 // Override this for things you would normally override SetUp for. It will be |
| 63 // called before your individual test fixture method is run, but after most | 60 // called before your individual test fixture method is run, but after most |
| 64 // of the overhead initialization has occured. | 61 // of the overhead initialization has occured. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Returns true if the test will be using GL acceleration via a software GL. | 128 // Returns true if the test will be using GL acceleration via a software GL. |
| 132 bool UsingSoftwareGL() const; | 129 bool UsingSoftwareGL() const; |
| 133 | 130 |
| 134 // Temporary | 131 // Temporary |
| 135 // TODO(jam): remove this. | 132 // TODO(jam): remove this. |
| 136 void disable_io_checks() { disable_io_checks_ = true; } | 133 void disable_io_checks() { disable_io_checks_ = true; } |
| 137 | 134 |
| 138 private: | 135 private: |
| 139 void ProxyRunTestOnMainThreadLoop(); | 136 void ProxyRunTestOnMainThreadLoop(); |
| 140 | 137 |
| 138 // When using the network process, update the host resolver rules that were |
| 139 // added in SetUpOnMainThread. |
| 140 void InitializeNetworkProcess(); |
| 141 |
| 141 // Testing server, started on demand. | 142 // Testing server, started on demand. |
| 142 std::unique_ptr<net::SpawnedTestServer> spawned_test_server_; | 143 std::unique_ptr<net::SpawnedTestServer> spawned_test_server_; |
| 143 | 144 |
| 144 // Embedded test server, cheap to create, started on demand. | 145 // Embedded test server, cheap to create, started on demand. |
| 145 std::unique_ptr<net::EmbeddedTestServer> embedded_test_server_; | 146 std::unique_ptr<net::EmbeddedTestServer> embedded_test_server_; |
| 146 | 147 |
| 147 // Host resolver used during tests. | 148 // Host resolver used during tests. |
| 148 scoped_refptr<net::RuleBasedHostResolverProc> rule_based_resolver_; | 149 std::unique_ptr<TestHostResolver> test_host_resolver_; |
| 149 | 150 |
| 150 // Expected exit code (default is 0). | 151 // Expected exit code (default is 0). |
| 151 int expected_exit_code_; | 152 int expected_exit_code_; |
| 152 | 153 |
| 153 // When true, the compositor will produce pixel output that can be read back | 154 // When true, the compositor will produce pixel output that can be read back |
| 154 // for pixel tests. | 155 // for pixel tests. |
| 155 bool enable_pixel_output_; | 156 bool enable_pixel_output_; |
| 156 | 157 |
| 157 // When true, do compositing with the software backend instead of using GL. | 158 // When true, do compositing with the software backend instead of using GL. |
| 158 bool use_software_compositing_; | 159 bool use_software_compositing_; |
| 159 | 160 |
| 160 // Whether SetUp was called. This value is checked in the destructor of this | 161 // Whether SetUp was called. This value is checked in the destructor of this |
| 161 // class to ensure that SetUp was called. If it's not called, the test will | 162 // class to ensure that SetUp was called. If it's not called, the test will |
| 162 // not run and report a false positive result. | 163 // not run and report a false positive result. |
| 163 bool set_up_called_; | 164 bool set_up_called_; |
| 164 | 165 |
| 165 // Tests should keep on the IO thread checks to test that production code | 166 // Tests should keep on the IO thread checks to test that production code |
| 166 // paths don't make file access. Keep this for now since src/chrome didn't | 167 // paths don't make file access. Keep this for now since src/chrome didn't |
| 167 // check this. | 168 // check this. |
| 168 bool disable_io_checks_; | 169 bool disable_io_checks_; |
| 169 | 170 |
| 170 #if defined(OS_POSIX) | 171 #if defined(OS_POSIX) |
| 171 bool handle_sigterm_; | 172 bool handle_sigterm_; |
| 172 #endif | 173 #endif |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 } // namespace content | 176 } // namespace content |
| 176 | 177 |
| 177 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ | 178 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ |
| OLD | NEW |