OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 5 #ifndef CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
6 #define CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 6 #define CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
7 | 7 |
| 8 #include "net/base/mock_host_resolver.h" |
8 #include "net/url_request/url_request_unittest.h" | 9 #include "net/url_request/url_request_unittest.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 class Browser; | 12 class Browser; |
12 class Profile; | 13 class Profile; |
13 namespace net { | 14 namespace net { |
14 class RuleBasedHostResolverProc; | 15 class RuleBasedHostResolverProc; |
15 } | 16 } |
16 | 17 |
17 // Base class for tests wanting to bring up a browser in the unit test process. | 18 // Base class for tests wanting to bring up a browser in the unit test process. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Override this rather than TestBody. | 64 // Override this rather than TestBody. |
64 virtual void RunTestOnMainThread() = 0; | 65 virtual void RunTestOnMainThread() = 0; |
65 | 66 |
66 // Override this to add command line flags specific to your test. | 67 // Override this to add command line flags specific to your test. |
67 virtual void SetUpCommandLine(CommandLine* command_line) {} | 68 virtual void SetUpCommandLine(CommandLine* command_line) {} |
68 | 69 |
69 // Override this to add any custom cleanup code that needs to be done on the | 70 // Override this to add any custom cleanup code that needs to be done on the |
70 // main thread before the browser is torn down. | 71 // main thread before the browser is torn down. |
71 virtual void CleanUpOnMainThread() {} | 72 virtual void CleanUpOnMainThread() {} |
72 | 73 |
73 // Allows subclasses to configure the host resolver procedure. By default | |
74 // this blocks requests to google.com as Chrome pings that on startup and we | |
75 // don't want to do that during testing. | |
76 virtual void ConfigureHostResolverProc(net::RuleBasedHostResolverProc* proc); | |
77 | |
78 // Invoked when a test is not finishing in a timely manner. | 74 // Invoked when a test is not finishing in a timely manner. |
79 void TimedOut(); | 75 void TimedOut(); |
80 | 76 |
81 // Sets Initial Timeout value. | 77 // Sets Initial Timeout value. |
82 void SetInitialTimeoutInMS(int initial_timeout); | 78 void SetInitialTimeoutInMS(int initial_timeout); |
83 | 79 |
84 // Starts an HTTP server. | 80 // Starts an HTTP server. |
85 HTTPTestServer* StartHTTPServer(); | 81 HTTPTestServer* StartHTTPServer(); |
86 | 82 |
87 // Creates a browser with a single tab (about:blank), waits for the tab to | 83 // Creates a browser with a single tab (about:blank), waits for the tab to |
88 // finish loading and shows the browser. | 84 // finish loading and shows the browser. |
89 // | 85 // |
90 // This is invoked from Setup. | 86 // This is invoked from Setup. |
91 virtual Browser* CreateBrowser(Profile* profile); | 87 virtual Browser* CreateBrowser(Profile* profile); |
92 | 88 |
| 89 // Returns the host resolver being used for the tests. Subclasses might want |
| 90 // to configure it inside tests. |
| 91 net::RuleBasedHostResolverProc* host_resolver() { |
| 92 return host_resolver_.get(); |
| 93 } |
| 94 |
93 // Sets some test states (see below for comments). Call this in your test | 95 // Sets some test states (see below for comments). Call this in your test |
94 // constructor. | 96 // constructor. |
95 void set_show_window(bool show) { show_window_ = show; } | 97 void set_show_window(bool show) { show_window_ = show; } |
96 void EnableDOMAutomation() { dom_automation_enabled_ = true; } | 98 void EnableDOMAutomation() { dom_automation_enabled_ = true; } |
97 void EnableSingleProcess() { single_process_ = true; } | 99 void EnableSingleProcess() { single_process_ = true; } |
98 | 100 |
99 private: | 101 private: |
100 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and | 102 // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and |
101 // destroys the browser. | 103 // destroys the browser. |
102 void RunTestOnMainThreadLoop(); | 104 void RunTestOnMainThreadLoop(); |
(...skipping 18 matching lines...) Expand all Loading... |
121 // We muck with the global command line for this process. Keep the original | 123 // We muck with the global command line for this process. Keep the original |
122 // so we can reset it when we're done. | 124 // so we can reset it when we're done. |
123 scoped_ptr<CommandLine> original_command_line_; | 125 scoped_ptr<CommandLine> original_command_line_; |
124 | 126 |
125 // Saved to restore the value of RenderProcessHost::run_renderer_in_process. | 127 // Saved to restore the value of RenderProcessHost::run_renderer_in_process. |
126 bool original_single_process_; | 128 bool original_single_process_; |
127 | 129 |
128 // Initial timeout value in ms. | 130 // Initial timeout value in ms. |
129 int initial_timeout_; | 131 int initial_timeout_; |
130 | 132 |
| 133 // Host resolver to use during the test. |
| 134 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_; |
| 135 |
131 DISALLOW_COPY_AND_ASSIGN(InProcessBrowserTest); | 136 DISALLOW_COPY_AND_ASSIGN(InProcessBrowserTest); |
132 }; | 137 }; |
133 | 138 |
134 // We only want to use IN_PROC_BROWSER_TEST in binaries which will properly | 139 // We only want to use IN_PROC_BROWSER_TEST in binaries which will properly |
135 // isolate each test case. Otherwise hard-to-debug, possibly intermittent | 140 // isolate each test case. Otherwise hard-to-debug, possibly intermittent |
136 // crashes caused by carrying state in singletons are very likely. | 141 // crashes caused by carrying state in singletons are very likely. |
137 #if defined(ALLOW_IN_PROC_BROWSER_TEST) | 142 #if defined(ALLOW_IN_PROC_BROWSER_TEST) |
138 | 143 |
139 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ | 144 #define IN_PROC_BROWSER_TEST_(test_case_name, test_name, parent_class,\ |
140 parent_id)\ | 145 parent_id)\ |
(...skipping 20 matching lines...) Expand all Loading... |
161 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ | 166 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ |
162 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() | 167 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::RunTestOnMainThread() |
163 | 168 |
164 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ | 169 #define IN_PROC_BROWSER_TEST_F(test_fixture, test_name)\ |
165 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ | 170 IN_PROC_BROWSER_TEST_(test_fixture, test_name, test_fixture,\ |
166 ::testing::internal::GetTypeId<test_fixture>()) | 171 ::testing::internal::GetTypeId<test_fixture>()) |
167 | 172 |
168 #endif // defined(ALLOW_IN_PROC_BROWSER_TEST) | 173 #endif // defined(ALLOW_IN_PROC_BROWSER_TEST) |
169 | 174 |
170 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ | 175 #endif // CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ |
OLD | NEW |