| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_TEST_BROWSER_TEST_BASE_H_ | |
| 6 #define CONTENT_TEST_BROWSER_TEST_BASE_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "net/test/test_server.h" | |
| 11 | |
| 12 class CommandLine; | |
| 13 | |
| 14 class BrowserTestBase : public testing::Test { | |
| 15 public: | |
| 16 BrowserTestBase(); | |
| 17 virtual ~BrowserTestBase(); | |
| 18 | |
| 19 // We do this so we can be used in a Task. | |
| 20 void AddRef() {} | |
| 21 void Release() {} | |
| 22 | |
| 23 // Configures everything for an in process browser test, then invokes | |
| 24 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. | |
| 25 virtual void SetUp() OVERRIDE; | |
| 26 | |
| 27 // Restores state configured in SetUp. | |
| 28 virtual void TearDown() OVERRIDE; | |
| 29 | |
| 30 // Override this to add any custom setup code that needs to be done on the | |
| 31 // main thread after the browser is created and just before calling | |
| 32 // RunTestOnMainThread(). | |
| 33 virtual void SetUpOnMainThread() {} | |
| 34 | |
| 35 // Override this to add command line flags specific to your test. | |
| 36 virtual void SetUpCommandLine(CommandLine* command_line) {} | |
| 37 | |
| 38 protected: | |
| 39 // We need these special methods because SetUp is the bottom of the stack | |
| 40 // that winds up calling your test method, so it is not always an option | |
| 41 // to do what you want by overriding it and calling the superclass version. | |
| 42 // | |
| 43 // Override this for things you would normally override SetUp for. It will be | |
| 44 // called before your individual test fixture method is run, but after most | |
| 45 // of the overhead initialization has occured. | |
| 46 virtual void SetUpInProcessBrowserTestFixture() {} | |
| 47 | |
| 48 // Override this for things you would normally override TearDown for. | |
| 49 virtual void TearDownInProcessBrowserTestFixture() {} | |
| 50 | |
| 51 // Override this rather than TestBody. | |
| 52 virtual void RunTestOnMainThread() = 0; | |
| 53 | |
| 54 // This is invoked from main after browser_init/browser_main have completed. | |
| 55 // This prepares for the test by creating a new browser, runs the test | |
| 56 // (RunTestOnMainThread), quits the browsers and returns. | |
| 57 virtual void RunTestOnMainThreadLoop() = 0; | |
| 58 | |
| 59 // Returns the testing server. Guaranteed to be non-NULL. | |
| 60 const net::TestServer* test_server() const { return test_server_.get(); } | |
| 61 net::TestServer* test_server() { return test_server_.get(); } | |
| 62 | |
| 63 #if defined(OS_POSIX) | |
| 64 // This is only needed by a test that raises SIGTERM to ensure that a specific | |
| 65 // codepath is taken. | |
| 66 void DisableSIGTERMHandling() { | |
| 67 handle_sigterm_ = false; | |
| 68 } | |
| 69 #endif | |
| 70 | |
| 71 // This function is meant only for classes that directly derive from this | |
| 72 // class to construct the test server in their constructor. They might need to | |
| 73 // call this after setting up the paths. Actual test cases should never call | |
| 74 // this. | |
| 75 // |test_server_base| is the path, relative to src, to give to the test HTTP | |
| 76 // server. | |
| 77 void CreateTestServer(const char* test_server_base); | |
| 78 | |
| 79 private: | |
| 80 void ProxyRunTestOnMainThreadLoop(); | |
| 81 | |
| 82 // Testing server, started on demand. | |
| 83 scoped_ptr<net::TestServer> test_server_; | |
| 84 | |
| 85 #if defined(OS_POSIX) | |
| 86 bool handle_sigterm_; | |
| 87 #endif | |
| 88 }; | |
| 89 | |
| 90 #endif // CONTENT_TEST_BROWSER_TEST_BASE_H_ | |
| OLD | NEW |