| 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 "net/test/spawned_test_server/spawned_test_server.h" | 10 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 class CommandLine; | 13 class CommandLine; |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class FilePath; | 16 class FilePath; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace net { |
| 20 namespace test_server { |
| 21 class EmbeddedTestServer; |
| 22 } |
| 23 } |
| 24 |
| 19 namespace content { | 25 namespace content { |
| 20 | 26 |
| 21 class BrowserTestBase : public testing::Test { | 27 class BrowserTestBase : public testing::Test { |
| 22 public: | 28 public: |
| 23 BrowserTestBase(); | 29 BrowserTestBase(); |
| 24 virtual ~BrowserTestBase(); | 30 virtual ~BrowserTestBase(); |
| 25 | 31 |
| 26 // We do this so we can be used in a Task. | 32 // We do this so we can be used in a Task. |
| 27 void AddRef() {} | 33 void AddRef() {} |
| 28 void Release() {} | 34 void Release() {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 | 63 |
| 58 // Override this rather than TestBody. | 64 // Override this rather than TestBody. |
| 59 virtual void RunTestOnMainThread() = 0; | 65 virtual void RunTestOnMainThread() = 0; |
| 60 | 66 |
| 61 // This is invoked from main after browser_init/browser_main have completed. | 67 // This is invoked from main after browser_init/browser_main have completed. |
| 62 // This prepares for the test by creating a new browser, runs the test | 68 // This prepares for the test by creating a new browser, runs the test |
| 63 // (RunTestOnMainThread), quits the browsers and returns. | 69 // (RunTestOnMainThread), quits the browsers and returns. |
| 64 virtual void RunTestOnMainThreadLoop() = 0; | 70 virtual void RunTestOnMainThreadLoop() = 0; |
| 65 | 71 |
| 66 // Returns the testing server. Guaranteed to be non-NULL. | 72 // Returns the testing server. Guaranteed to be non-NULL. |
| 73 // TODO(phajdan.jr): Remove test_server accessor (http://crbug.com/96594). |
| 67 const net::SpawnedTestServer* test_server() const { | 74 const net::SpawnedTestServer* test_server() const { |
| 68 return test_server_.get(); | 75 return test_server_.get(); |
| 69 } | 76 } |
| 70 net::SpawnedTestServer* test_server() { return test_server_.get(); } | 77 net::SpawnedTestServer* test_server() { return test_server_.get(); } |
| 71 | 78 |
| 79 // Returns the embedded test server. Guaranteed to be non-NULL. |
| 80 const net::test_server::EmbeddedTestServer* embedded_test_server() const { |
| 81 return embedded_test_server_.get(); |
| 82 } |
| 83 net::test_server::EmbeddedTestServer* embedded_test_server() { |
| 84 return embedded_test_server_.get(); |
| 85 } |
| 86 |
| 72 #if defined(OS_POSIX) | 87 #if defined(OS_POSIX) |
| 73 // This is only needed by a test that raises SIGTERM to ensure that a specific | 88 // This is only needed by a test that raises SIGTERM to ensure that a specific |
| 74 // codepath is taken. | 89 // codepath is taken. |
| 75 void DisableSIGTERMHandling() { | 90 void DisableSIGTERMHandling() { |
| 76 handle_sigterm_ = false; | 91 handle_sigterm_ = false; |
| 77 } | 92 } |
| 78 #endif | 93 #endif |
| 79 | 94 |
| 80 // This function is meant only for classes that directly derive from this | 95 // This function is meant only for classes that directly derive from this |
| 81 // class to construct the test server in their constructor. They might need to | 96 // class to construct the test server in their constructor. They might need to |
| 82 // call this after setting up the paths. Actual test cases should never call | 97 // call this after setting up the paths. Actual test cases should never call |
| 83 // this. | 98 // this. |
| 84 // |test_server_base| is the path, relative to src, to give to the test HTTP | 99 // |test_server_base| is the path, relative to src, to give to the test HTTP |
| 85 // server. | 100 // server. |
| 86 void CreateTestServer(const base::FilePath& test_server_base); | 101 void CreateTestServer(const base::FilePath& test_server_base); |
| 87 | 102 |
| 88 // When the test is running in --single-process mode, runs the given task on | 103 // When the test is running in --single-process mode, runs the given task on |
| 89 // the in-process renderer thread. A nested message loop is run until it | 104 // the in-process renderer thread. A nested message loop is run until it |
| 90 // returns. | 105 // returns. |
| 91 void PostTaskToInProcessRendererAndWait(const base::Closure& task); | 106 void PostTaskToInProcessRendererAndWait(const base::Closure& task); |
| 92 | 107 |
| 93 private: | 108 private: |
| 94 void ProxyRunTestOnMainThreadLoop(); | 109 void ProxyRunTestOnMainThreadLoop(); |
| 95 | 110 |
| 96 // Testing server, started on demand. | 111 // Testing server, started on demand. |
| 97 scoped_ptr<net::SpawnedTestServer> test_server_; | 112 scoped_ptr<net::SpawnedTestServer> test_server_; |
| 98 | 113 |
| 114 // Embedded test server, cheap to create, started on demand. |
| 115 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; |
| 116 |
| 99 #if defined(OS_POSIX) | 117 #if defined(OS_POSIX) |
| 100 bool handle_sigterm_; | 118 bool handle_sigterm_; |
| 101 #endif | 119 #endif |
| 102 }; | 120 }; |
| 103 | 121 |
| 104 } // namespace content | 122 } // namespace content |
| 105 | 123 |
| 106 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ | 124 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_BASE_H_ |
| OLD | NEW |