OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_frame/test/net/fake_external_tab.h" | 5 #include "chrome_frame/test/net/fake_external_tab.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <exdisp.h> | 9 #include <exdisp.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/debugger.h" | 13 #include "base/debug/debugger.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/file_version_info.h" | 15 #include "base/file_version_info.h" |
16 #include "base/i18n/icu_util.h" | 16 #include "base/i18n/icu_util.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/scoped_temp_dir.h" | 20 #include "base/scoped_temp_dir.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
23 #include "base/system_monitor/system_monitor.h" | 23 #include "base/system_monitor/system_monitor.h" |
24 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
25 #include "base/threading/platform_thread.h" | 25 #include "base/threading/platform_thread.h" |
26 #include "base/threading/thread.h" | |
27 #include "base/win/scoped_com_initializer.h" | 26 #include "base/win/scoped_com_initializer.h" |
28 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
29 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
30 #include "chrome/browser/automation/automation_provider_list.h" | 29 #include "chrome/browser/automation/automation_provider_list.h" |
31 #include "chrome/browser/browser_process_impl.h" // TODO(joi): Remove | |
32 #include "chrome/browser/chrome_content_browser_client.h" | 30 #include "chrome/browser/chrome_content_browser_client.h" |
33 #include "chrome/browser/prefs/browser_prefs.h" | 31 #include "chrome/browser/prefs/browser_prefs.h" |
34 #include "chrome/browser/prefs/pref_service.h" | 32 #include "chrome/browser/prefs/pref_service.h" |
35 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 33 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
36 #include "chrome/browser/process_singleton.h" | 34 #include "chrome/browser/process_singleton.h" |
37 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
38 #include "chrome/browser/renderer_host/web_cache_manager.h" | 36 #include "chrome/browser/renderer_host/web_cache_manager.h" |
39 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
40 #include "chrome/common/chrome_content_client.h" | 38 #include "chrome/common/chrome_content_client.h" |
41 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
42 #include "chrome/common/chrome_paths_internal.h" | 40 #include "chrome/common/chrome_paths_internal.h" |
43 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
45 #include "chrome/renderer/chrome_content_renderer_client.h" | 43 #include "chrome/renderer/chrome_content_renderer_client.h" |
46 #include "chrome_frame/crash_server_init.h" | 44 #include "chrome_frame/crash_server_init.h" |
47 #include "chrome_frame/test/chrome_frame_test_utils.h" | 45 #include "chrome_frame/test/chrome_frame_test_utils.h" |
48 #include "chrome_frame/test/net/test_automation_resource_message_filter.h" | 46 #include "chrome_frame/test/net/test_automation_resource_message_filter.h" |
49 #include "chrome_frame/test/simulate_input.h" | 47 #include "chrome_frame/test/simulate_input.h" |
50 #include "chrome_frame/test/win_event_receiver.h" | 48 #include "chrome_frame/test/win_event_receiver.h" |
51 #include "chrome_frame/utils.h" | 49 #include "chrome_frame/utils.h" |
52 #include "content/browser/plugin_service.h" | 50 #include "content/browser/plugin_service.h" |
53 #include "content/browser/notification_service_impl.h" | 51 #include "content/browser/notification_service_impl.h" |
54 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
55 #include "content/public/common/content_client.h" | 53 #include "content/public/common/content_client.h" |
56 #include "content/public/common/content_paths.h" | 54 #include "content/public/common/content_paths.h" |
57 #include "content/test/test_browser_thread.h" // TODO(joi): Remove | |
58 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
59 #include "ui/base/resource/resource_bundle.h" | 56 #include "ui/base/resource/resource_bundle.h" |
60 #include "ui/base/ui_base_paths.h" | 57 #include "ui/base/ui_base_paths.h" |
61 | 58 |
62 using content::BrowserThread; | 59 using content::BrowserThread; |
63 | 60 |
64 namespace { | 61 namespace { |
65 | 62 |
66 // A special command line switch to allow developers to manually launch the | 63 // A special command line switch to allow developers to manually launch the |
67 // browser and debug CF inside the browser. | 64 // browser and debug CF inside the browser. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 browser_process_.reset(new FakeBrowserProcessImpl(*cmd)); | 266 browser_process_.reset(new FakeBrowserProcessImpl(*cmd)); |
270 // BrowserProcessImpl's constructor should set g_browser_process. | 267 // BrowserProcessImpl's constructor should set g_browser_process. |
271 DCHECK(g_browser_process); | 268 DCHECK(g_browser_process); |
272 g_browser_process->SetApplicationLocale("en-US"); | 269 g_browser_process->SetApplicationLocale("en-US"); |
273 | 270 |
274 content::RenderProcessHost::set_run_renderer_in_process(true); | 271 content::RenderProcessHost::set_run_renderer_in_process(true); |
275 | 272 |
276 browser_process_->local_state()->RegisterBooleanPref( | 273 browser_process_->local_state()->RegisterBooleanPref( |
277 prefs::kMetricsReportingEnabled, false); | 274 prefs::kMetricsReportingEnabled, false); |
278 | 275 |
| 276 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); |
| 277 |
279 // Initialize the content client which that code uses to talk to Chrome. | 278 // Initialize the content client which that code uses to talk to Chrome. |
280 content::SetContentClient(&g_chrome_content_client.Get()); | 279 content::SetContentClient(&g_chrome_content_client.Get()); |
281 | 280 |
282 // Override the default ContentBrowserClient to let Chrome participate in | 281 // Override the default ContentBrowserClient to let Chrome participate in |
283 // content logic. Must be done before any tabs are created. | 282 // content logic. Must be done before any tabs are created. |
284 content::GetContentClient()->set_browser(&g_browser_client.Get()); | 283 content::GetContentClient()->set_browser(&g_browser_client.Get()); |
285 | 284 |
286 content::GetContentClient()->set_renderer(&g_renderer_client.Get()); | 285 content::GetContentClient()->set_renderer(&g_renderer_client.Get()); |
287 } | |
288 | 286 |
289 void FakeExternalTab::InitializePostThreadsCreated() { | |
290 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); | |
291 Profile* profile = | 287 Profile* profile = |
292 g_browser_process->profile_manager()->GetProfile(profile_path); | 288 g_browser_process->profile_manager()->GetProfile(profile_path); |
| 289 |
| 290 // Create the child threads. |
| 291 g_browser_process->db_thread(); |
| 292 g_browser_process->file_thread(); |
| 293 g_browser_process->io_thread(); |
293 } | 294 } |
294 | 295 |
295 void FakeExternalTab::Shutdown() { | 296 void FakeExternalTab::Shutdown() { |
296 browser_process_.reset(); | 297 browser_process_.reset(); |
297 g_browser_process = NULL; | 298 g_browser_process = NULL; |
298 process_singleton_.reset(); | 299 process_singleton_.reset(); |
299 | 300 |
300 ResourceBundle::CleanupSharedInstance(); | 301 ResourceBundle::CleanupSharedInstance(); |
301 } | 302 } |
302 | 303 |
303 // TODO(joi): Remove! | |
304 class ChromeFrameFriendOfBrowserProcessImpl { | |
305 public: | |
306 static void CreateIOThreadState() { | |
307 reinterpret_cast<BrowserProcessImpl*>( | |
308 g_browser_process)->CreateIOThreadState(); | |
309 } | |
310 }; | |
311 | |
312 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv) | 304 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv) |
313 : NetTestSuite(argc, argv), | 305 : NetTestSuite(argc, argv), |
314 chrome_frame_html_("/chrome_frame", kChromeFrameHtml), | 306 chrome_frame_html_("/chrome_frame", kChromeFrameHtml), |
315 registrar_(chrome_frame_test::GetTestBedType()), | 307 registrar_(chrome_frame_test::GetTestBedType()), |
316 test_result_(0) { | 308 test_result_(0) { |
317 // Register the main thread by instantiating it, but don't call any methods. | 309 // Register the main thread by instantiating it, but don't call any methods. |
318 main_thread_.reset(new content::TestBrowserThread( | 310 main_thread_.reset(new content::DeprecatedBrowserThread( |
319 BrowserThread::UI, MessageLoop::current())); | 311 BrowserThread::UI, MessageLoop::current())); |
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
321 fake_chrome_.Initialize(); | 313 fake_chrome_.Initialize(); |
322 | |
323 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); | |
324 db_thread_->Start(); | |
325 | |
326 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE)); | |
327 file_thread_->Start(); | |
328 | |
329 ChromeFrameFriendOfBrowserProcessImpl::CreateIOThreadState(); | |
330 | |
331 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | |
332 io_thread_->StartIOThread(); | |
333 | |
334 fake_chrome_.InitializePostThreadsCreated(); | |
335 | |
336 pss_subclass_.reset(new ProcessSingletonSubclass(this)); | 314 pss_subclass_.reset(new ProcessSingletonSubclass(this)); |
337 EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_.user_data())); | 315 EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_.user_data())); |
338 StartChromeFrameInHostBrowser(); | 316 StartChromeFrameInHostBrowser(); |
339 } | 317 } |
340 | 318 |
341 CFUrlRequestUnittestRunner::~CFUrlRequestUnittestRunner() { | 319 CFUrlRequestUnittestRunner::~CFUrlRequestUnittestRunner() { |
342 fake_chrome_.Shutdown(); | 320 fake_chrome_.Shutdown(); |
343 } | 321 } |
344 | 322 |
345 void CFUrlRequestUnittestRunner::StartChromeFrameInHostBrowser() { | 323 void CFUrlRequestUnittestRunner::StartChromeFrameInHostBrowser() { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 case IE_UNSUPPORTED: | 580 case IE_UNSUPPORTED: |
603 return "Unknown IE Version"; | 581 return "Unknown IE Version"; |
604 case NON_IE: | 582 case NON_IE: |
605 return "Could not find IE"; | 583 return "Could not find IE"; |
606 default: | 584 default: |
607 return "Error."; | 585 return "Error."; |
608 } | 586 } |
609 } | 587 } |
610 | 588 |
611 int main(int argc, char** argv) { | 589 int main(int argc, char** argv) { |
612 // TODO(joi): Remove the "true" part here and fix the log statement below. | 590 if (chrome_frame_test::GetInstalledIEVersion() >= IE_9) { |
613 if (true || chrome_frame_test::GetInstalledIEVersion() >= IE_9) { | |
614 // Adding this here as the command line and the logging stuff gets | 591 // Adding this here as the command line and the logging stuff gets |
615 // initialized in the NetTestSuite constructor. Did not want to break that. | 592 // initialized in the NetTestSuite constructor. Did not want to break that. |
616 base::AtExitManager at_exit_manager; | 593 base::AtExitManager at_exit_manager; |
617 CommandLine::Init(argc, argv); | 594 CommandLine::Init(argc, argv); |
618 CFUrlRequestUnittestRunner::InitializeLogging(); | 595 CFUrlRequestUnittestRunner::InitializeLogging(); |
619 LOG(INFO) << "Temporarily not running any ChromeFrame " | 596 LOG(INFO) << "Not running ChromeFrame net tests on IE9+"; |
620 << "net tests (http://crbug.com/105435)"; | |
621 return 0; | 597 return 0; |
622 } | 598 } |
623 | 599 |
624 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad( | 600 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad( |
625 InitializeCrashReporting(HEADLESS)); | 601 InitializeCrashReporting(HEADLESS)); |
626 | 602 |
627 // TODO(tommi): Stuff be broke. Needs a fixin'. | 603 // TODO(tommi): Stuff be broke. Needs a fixin'. |
628 // This is awkward: the TestSuite derived CFUrlRequestUnittestRunner contains | 604 // This is awkward: the TestSuite derived CFUrlRequestUnittestRunner contains |
629 // the instance of the AtExitManager that RegisterPathProvider() and others | 605 // the instance of the AtExitManager that RegisterPathProvider() and others |
630 // below require. So we have to instantiate this first. | 606 // below require. So we have to instantiate this first. |
(...skipping 21 matching lines...) Expand all Loading... |
652 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); | 628 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); |
653 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); | 629 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); |
654 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which | 630 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which |
655 // check if globals are created and destroyed on the same thread don't fire. | 631 // check if globals are created and destroyed on the same thread don't fire. |
656 // Webkit global objects are created on the inproc renderer thread. | 632 // Webkit global objects are created on the inproc renderer thread. |
657 #if !defined(NDEBUG) | 633 #if !defined(NDEBUG) |
658 ExitProcess(test_suite.test_result()); | 634 ExitProcess(test_suite.test_result()); |
659 #endif // NDEBUG | 635 #endif // NDEBUG |
660 return test_suite.test_result(); | 636 return test_suite.test_result(); |
661 } | 637 } |
OLD | NEW |