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 #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 #include <Winsock2.h> | 10 #include <Winsock2.h> |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_); | 480 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_); |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 void FakeExternalTab::Initialize() { | 484 void FakeExternalTab::Initialize() { |
485 DCHECK(g_browser_process == NULL); | 485 DCHECK(g_browser_process == NULL); |
486 | 486 |
487 TestTimeouts::Initialize(); | 487 TestTimeouts::Initialize(); |
488 | 488 |
489 // Load Chrome.dll as our resource dll. | 489 // Load Chrome.dll as our resource dll. |
490 FilePath dll; | 490 base::FilePath dll; |
491 PathService::Get(base::DIR_MODULE, &dll); | 491 PathService::Get(base::DIR_MODULE, &dll); |
492 dll = dll.Append(chrome::kBrowserResourcesDll); | 492 dll = dll.Append(chrome::kBrowserResourcesDll); |
493 HMODULE res_mod = ::LoadLibraryExW(dll.value().c_str(), | 493 HMODULE res_mod = ::LoadLibraryExW(dll.value().c_str(), |
494 NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE); | 494 NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE); |
495 DCHECK(res_mod); | 495 DCHECK(res_mod); |
496 _AtlBaseModule.SetResourceInstance(res_mod); | 496 _AtlBaseModule.SetResourceInstance(res_mod); |
497 | 497 |
498 // Point the ResourceBundle at chrome.dll. | 498 // Point the ResourceBundle at chrome.dll. |
499 ui::SetResourcesDataDLL(_AtlBaseModule.GetResourceInstance()); | 499 ui::SetResourcesDataDLL(_AtlBaseModule.GetResourceInstance()); |
500 | 500 |
501 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); | 501 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
502 | 502 |
503 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 503 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
504 cmd->AppendSwitch(switches::kDisableWebResources); | 504 cmd->AppendSwitch(switches::kDisableWebResources); |
505 cmd->AppendSwitch(switches::kSingleProcess); | 505 cmd->AppendSwitch(switches::kSingleProcess); |
506 | 506 |
507 FilePath local_state_path; | 507 base::FilePath local_state_path; |
508 CHECK(PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path)); | 508 CHECK(PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path)); |
509 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner = | 509 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner = |
510 JsonPrefStore::GetTaskRunnerForFile(local_state_path, | 510 JsonPrefStore::GetTaskRunnerForFile(local_state_path, |
511 BrowserThread::GetBlockingPool()); | 511 BrowserThread::GetBlockingPool()); |
512 browser_process_.reset(new FakeBrowserProcessImpl(local_state_task_runner, | 512 browser_process_.reset(new FakeBrowserProcessImpl(local_state_task_runner, |
513 *cmd)); | 513 *cmd)); |
514 // BrowserProcessImpl's constructor should set g_browser_process. | 514 // BrowserProcessImpl's constructor should set g_browser_process. |
515 DCHECK(g_browser_process); | 515 DCHECK(g_browser_process); |
516 g_browser_process->SetApplicationLocale("en-US"); | 516 g_browser_process->SetApplicationLocale("en-US"); |
517 | 517 |
518 content::RenderProcessHost::SetRunRendererInProcess(true); | 518 content::RenderProcessHost::SetRunRendererInProcess(true); |
519 | 519 |
520 // TODO(joi): Registration should be done up front via browser_prefs.cc | 520 // TODO(joi): Registration should be done up front via browser_prefs.cc |
521 scoped_refptr<PrefRegistrySimple> registry = static_cast<PrefRegistrySimple*>( | 521 scoped_refptr<PrefRegistrySimple> registry = static_cast<PrefRegistrySimple*>( |
522 browser_process_->local_state()->DeprecatedGetPrefRegistry()); | 522 browser_process_->local_state()->DeprecatedGetPrefRegistry()); |
523 if (!browser_process_->local_state()->FindPreference( | 523 if (!browser_process_->local_state()->FindPreference( |
524 prefs::kMetricsReportingEnabled)) { | 524 prefs::kMetricsReportingEnabled)) { |
525 registry->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); | 525 registry->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
529 void FakeExternalTab::InitializePostThreadsCreated() { | 529 void FakeExternalTab::InitializePostThreadsCreated() { |
530 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); | 530 base::FilePath profile_path( |
| 531 ProfileManager::GetDefaultProfileDir(user_data())); |
531 Profile* profile = | 532 Profile* profile = |
532 g_browser_process->profile_manager()->GetProfile(profile_path); | 533 g_browser_process->profile_manager()->GetProfile(profile_path); |
533 } | 534 } |
534 | 535 |
535 void FakeExternalTab::Shutdown() { | 536 void FakeExternalTab::Shutdown() { |
536 browser_process_.reset(); | 537 browser_process_.reset(); |
537 g_browser_process = NULL; | 538 g_browser_process = NULL; |
538 | 539 |
539 ResourceBundle::CleanupSharedInstance(); | 540 ResourceBundle::CleanupSharedInstance(); |
540 } | 541 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 // kills us. OnIEShutdownFailure will log and exit with an error. | 707 // kills us. OnIEShutdownFailure will log and exit with an error. |
707 BrowserThread::PostDelayedTask( | 708 BrowserThread::PostDelayedTask( |
708 BrowserThread::UI, | 709 BrowserThread::UI, |
709 FROM_HERE, | 710 FROM_HERE, |
710 base::Bind(&CFUrlRequestUnittestRunner::OnIEShutdownFailure, | 711 base::Bind(&CFUrlRequestUnittestRunner::OnIEShutdownFailure, |
711 base::Unretained(this)), | 712 base::Unretained(this)), |
712 TestTimeouts::action_max_timeout()); | 713 TestTimeouts::action_max_timeout()); |
713 } | 714 } |
714 | 715 |
715 void CFUrlRequestUnittestRunner::InitializeLogging() { | 716 void CFUrlRequestUnittestRunner::InitializeLogging() { |
716 FilePath exe; | 717 base::FilePath exe; |
717 PathService::Get(base::FILE_EXE, &exe); | 718 PathService::Get(base::FILE_EXE, &exe); |
718 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); | 719 base::FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); |
719 logging::InitLogging( | 720 logging::InitLogging( |
720 log_filename.value().c_str(), | 721 log_filename.value().c_str(), |
721 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, | 722 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
722 logging::LOCK_LOG_FILE, | 723 logging::LOCK_LOG_FILE, |
723 logging::DELETE_OLD_LOG_FILE, | 724 logging::DELETE_OLD_LOG_FILE, |
724 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 725 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
725 // We want process and thread IDs because we may have multiple processes. | 726 // We want process and thread IDs because we may have multiple processes. |
726 // Note: temporarily enabled timestamps in an effort to catch bug 6361. | 727 // Note: temporarily enabled timestamps in an effort to catch bug 6361. |
727 logging::SetLogItems(true, true, true, true); | 728 logging::SetLogItems(true, true, true, true); |
728 } | 729 } |
729 | 730 |
730 void CFUrlRequestUnittestRunner::CancelInitializationTimeout() { | 731 void CFUrlRequestUnittestRunner::CancelInitializationTimeout() { |
731 timeout_closure_.Cancel(); | 732 timeout_closure_.Cancel(); |
732 } | 733 } |
733 | 734 |
734 void CFUrlRequestUnittestRunner::StartInitializationTimeout() { | 735 void CFUrlRequestUnittestRunner::StartInitializationTimeout() { |
735 timeout_closure_.Reset( | 736 timeout_closure_.Reset( |
736 base::Bind(&CFUrlRequestUnittestRunner::OnInitializationTimeout, | 737 base::Bind(&CFUrlRequestUnittestRunner::OnInitializationTimeout, |
737 base::Unretained(this))); | 738 base::Unretained(this))); |
738 MessageLoop::current()->PostDelayedTask( | 739 MessageLoop::current()->PostDelayedTask( |
739 FROM_HERE, | 740 FROM_HERE, |
740 timeout_closure_.callback(), | 741 timeout_closure_.callback(), |
741 TestTimeouts::action_max_timeout()); | 742 TestTimeouts::action_max_timeout()); |
742 } | 743 } |
743 | 744 |
744 void CFUrlRequestUnittestRunner::OnInitializationTimeout() { | 745 void CFUrlRequestUnittestRunner::OnInitializationTimeout() { |
745 LOG(ERROR) << "Failed to start Chrome Frame in the host browser."; | 746 LOG(ERROR) << "Failed to start Chrome Frame in the host browser."; |
746 | 747 |
747 FilePath snapshot; | 748 base::FilePath snapshot; |
748 if (ui_test_utils::SaveScreenSnapshotToDesktop(&snapshot)) | 749 if (ui_test_utils::SaveScreenSnapshotToDesktop(&snapshot)) |
749 LOG(ERROR) << "Screen snapshot saved to " << snapshot.value(); | 750 LOG(ERROR) << "Screen snapshot saved to " << snapshot.value(); |
750 | 751 |
751 StopFileLogger(true); | 752 StopFileLogger(true); |
752 | 753 |
753 if (launch_browser_) | 754 if (launch_browser_) |
754 chrome_frame_test::CloseAllIEWindows(); | 755 chrome_frame_test::CloseAllIEWindows(); |
755 | 756 |
756 if (ie_configurator_.get() != NULL) | 757 if (ie_configurator_.get() != NULL) |
757 ie_configurator_->RevertSettings(); | 758 ie_configurator_->RevertSettings(); |
(...skipping 19 matching lines...) Expand all Loading... |
777 int CFUrlRequestUnittestRunner::PreCreateThreads() { | 778 int CFUrlRequestUnittestRunner::PreCreateThreads() { |
778 fake_chrome_.reset(new FakeExternalTab()); | 779 fake_chrome_.reset(new FakeExternalTab()); |
779 fake_chrome_->Initialize(); | 780 fake_chrome_->Initialize(); |
780 fake_chrome_->browser_process()->PreCreateThreads(); | 781 fake_chrome_->browser_process()->PreCreateThreads(); |
781 process_singleton_.reset(new ProcessSingleton(fake_chrome_->user_data())); | 782 process_singleton_.reset(new ProcessSingleton(fake_chrome_->user_data())); |
782 process_singleton_->Lock(NULL); | 783 process_singleton_->Lock(NULL); |
783 return 0; | 784 return 0; |
784 } | 785 } |
785 | 786 |
786 bool CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback( | 787 bool CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback( |
787 const CommandLine& command_line, const FilePath& current_directory) { | 788 const CommandLine& command_line, const base::FilePath& current_directory) { |
788 std::string channel_id = command_line.GetSwitchValueASCII( | 789 std::string channel_id = command_line.GetSwitchValueASCII( |
789 switches::kAutomationClientChannelID); | 790 switches::kAutomationClientChannelID); |
790 EXPECT_FALSE(channel_id.empty()); | 791 EXPECT_FALSE(channel_id.empty()); |
791 | 792 |
792 Profile* profile = g_browser_process->profile_manager()->GetLastUsedProfile( | 793 Profile* profile = g_browser_process->profile_manager()->GetLastUsedProfile( |
793 fake_chrome_->user_data()); | 794 fake_chrome_->user_data()); |
794 | 795 |
795 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 796 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
796 DCHECK(list); | 797 DCHECK(list); |
797 list->AddProvider( | 798 list->AddProvider( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 // content::InitializeSandboxInfo(&sandbox_info); | 965 // content::InitializeSandboxInfo(&sandbox_info); |
965 FakeMainDelegate delegate; | 966 FakeMainDelegate delegate; |
966 content::ContentMain( | 967 content::ContentMain( |
967 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)), | 968 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)), |
968 &sandbox_info, | 969 &sandbox_info, |
969 &delegate); | 970 &delegate); |
970 | 971 |
971 // Note: In debug builds, we ExitProcess during PostDestroyThreads. | 972 // Note: In debug builds, we ExitProcess during PostDestroyThreads. |
972 return g_test_suite->test_result(); | 973 return g_test_suite->test_result(); |
973 } | 974 } |
OLD | NEW |