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 #include "chrome/test/in_process_browser_test.h" | 5 #include "chrome/test/in_process_browser_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
12 #include "chrome/browser/browser_list.h" | |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
14 #include "chrome/browser/browser_window.h" | 15 #include "chrome/browser/browser_window.h" |
15 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/profile_manager.h" | 17 #include "chrome/browser/profile_manager.h" |
17 #include "chrome/browser/renderer_host/render_process_host.h" | 18 #include "chrome/browser/renderer_host/render_process_host.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include "chrome/browser/views/frame/browser_view.h" | 21 #include "chrome/browser/views/frame/browser_view.h" |
21 #endif | 22 #endif |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 browser_shutdown::delete_resources_on_shutdown = true; | 137 browser_shutdown::delete_resources_on_shutdown = true; |
137 | 138 |
138 #if defined(WIN) | 139 #if defined(WIN) |
139 BrowserView::SetShowState(-1); | 140 BrowserView::SetShowState(-1); |
140 #endif | 141 #endif |
141 | 142 |
142 *CommandLine::ForCurrentProcessMutable() = *original_command_line_; | 143 *CommandLine::ForCurrentProcessMutable() = *original_command_line_; |
143 RenderProcessHost::set_run_renderer_in_process(original_single_process_); | 144 RenderProcessHost::set_run_renderer_in_process(original_single_process_); |
144 } | 145 } |
145 | 146 |
146 void InProcessBrowserTest::Observe(NotificationType type, | |
147 const NotificationSource& source, | |
148 const NotificationDetails& details) { | |
149 if (type == NotificationType::BROWSER_CLOSED) { | |
150 DCHECK(Source<Browser>(source).ptr() == browser_); | |
151 browser_ = NULL; | |
152 } else { | |
153 NOTREACHED(); | |
154 } | |
155 } | |
156 | |
157 HTTPTestServer* InProcessBrowserTest::StartHTTPServer() { | 147 HTTPTestServer* InProcessBrowserTest::StartHTTPServer() { |
158 // The HTTPServer must run on the IO thread. | 148 // The HTTPServer must run on the IO thread. |
159 DCHECK(!http_server_.get()); | 149 DCHECK(!http_server_.get()); |
160 http_server_ = HTTPTestServer::CreateServer( | 150 http_server_ = HTTPTestServer::CreateServer( |
161 L"chrome/test/data", | 151 L"chrome/test/data", |
162 g_browser_process->io_thread()->message_loop()); | 152 g_browser_process->io_thread()->message_loop()); |
163 return http_server_.get(); | 153 return http_server_.get(); |
164 } | 154 } |
165 | 155 |
166 // Creates a browser with a single tab (about:blank), waits for the tab to | 156 // Creates a browser with a single tab (about:blank), waits for the tab to |
(...skipping 25 matching lines...) Expand all Loading... | |
192 if (!profile) { | 182 if (!profile) { |
193 // We should only be able to get here if the profile already exists and | 183 // We should only be able to get here if the profile already exists and |
194 // has been created. | 184 // has been created. |
195 NOTREACHED(); | 185 NOTREACHED(); |
196 MessageLoopForUI::current()->Quit(); | 186 MessageLoopForUI::current()->Quit(); |
197 return; | 187 return; |
198 } | 188 } |
199 | 189 |
200 browser_ = CreateBrowser(profile); | 190 browser_ = CreateBrowser(profile); |
201 | 191 |
202 registrar_.Add(this, | |
203 NotificationType::BROWSER_CLOSED, | |
204 Source<Browser>(browser_)); | |
205 | |
206 RunTestOnMainThread(); | 192 RunTestOnMainThread(); |
207 | 193 |
208 if (browser_) | 194 BrowserList::const_reverse_iterator browser = |
209 browser_->CloseAllTabs(); | 195 BrowserList::begin_last_active(); |
210 | 196 for (; browser != BrowserList::end_last_active(); ++browser) { |
sky
2009/06/16 00:04:48
nit: no {}
| |
211 // Remove all registered notifications, otherwise by the time the | 197 (*browser)->CloseAllTabs(); |
212 // destructor is run the NotificationService is dead. | 198 } |
213 registrar_.RemoveAll(); | |
214 | 199 |
215 // Stop the HTTP server. | 200 // Stop the HTTP server. |
216 http_server_ = NULL; | 201 http_server_ = NULL; |
217 | 202 |
218 MessageLoopForUI::current()->Quit(); | 203 MessageLoopForUI::current()->Quit(); |
219 } | 204 } |
220 | 205 |
221 void InProcessBrowserTest::ConfigureHostMapper( | 206 void InProcessBrowserTest::ConfigureHostMapper( |
222 net::RuleBasedHostMapper* host_mapper) { | 207 net::RuleBasedHostMapper* host_mapper) { |
223 host_mapper->AllowDirectLookup("*.google.com"); | 208 host_mapper->AllowDirectLookup("*.google.com"); |
224 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | 209 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
225 // We don't want the test code to use it. | 210 // We don't want the test code to use it. |
226 host_mapper->AddSimulatedFailure("wpad"); | 211 host_mapper->AddSimulatedFailure("wpad"); |
227 } | 212 } |
OLD | NEW |