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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "chrome/common/chrome_paths_internal.h" | 44 #include "chrome/common/chrome_paths_internal.h" |
45 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/pref_names.h" | 46 #include "chrome/common/pref_names.h" |
47 #include "chrome/renderer/chrome_content_renderer_client.h" | 47 #include "chrome/renderer/chrome_content_renderer_client.h" |
48 #include "chrome/test/base/ui_test_utils.h" | 48 #include "chrome/test/base/ui_test_utils.h" |
49 #include "chrome/test/logging/win/file_logger.h" | 49 #include "chrome/test/logging/win/file_logger.h" |
50 #include "chrome/test/logging/win/log_file_printer.h" | 50 #include "chrome/test/logging/win/log_file_printer.h" |
51 #include "chrome/test/logging/win/test_log_collector.h" | 51 #include "chrome/test/logging/win/test_log_collector.h" |
52 #include "chrome_frame/crash_server_init.h" | 52 #include "chrome_frame/crash_server_init.h" |
53 #include "chrome_frame/test/chrome_frame_test_utils.h" | 53 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 54 #include "chrome_frame/test/ie_configurator.h" |
54 #include "chrome_frame/test/net/test_automation_resource_message_filter.h" | 55 #include "chrome_frame/test/net/test_automation_resource_message_filter.h" |
55 #include "chrome_frame/test/simulate_input.h" | 56 #include "chrome_frame/test/simulate_input.h" |
56 #include "chrome_frame/test/win_event_receiver.h" | 57 #include "chrome_frame/test/win_event_receiver.h" |
57 #include "chrome_frame/utils.h" | 58 #include "chrome_frame/utils.h" |
58 #include "content/public/app/content_main.h" | 59 #include "content/public/app/content_main.h" |
59 #include "content/public/app/startup_helper_win.h" | 60 #include "content/public/app/startup_helper_win.h" |
60 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
61 #include "content/public/browser/notification_service.h" | 62 #include "content/public/browser/notification_service.h" |
62 #include "content/public/browser/render_process_host.h" | 63 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/common/content_client.h" | 64 #include "content/public/common/content_client.h" |
64 #include "content/public/common/content_paths.h" | 65 #include "content/public/common/content_paths.h" |
65 #include "net/base/net_util.h" | 66 #include "net/base/net_util.h" |
| 67 #include "net/url_request/url_request_test_util.h" |
66 #include "sandbox/win/src/sandbox_types.h" | 68 #include "sandbox/win/src/sandbox_types.h" |
67 #include "testing/gtest/include/gtest/gtest.h" | 69 #include "testing/gtest/include/gtest/gtest.h" |
68 #include "ui/base/resource/resource_bundle.h" | 70 #include "ui/base/resource/resource_bundle.h" |
69 #include "ui/base/ui_base_paths.h" | 71 #include "ui/base/ui_base_paths.h" |
70 | 72 |
71 using content::BrowserThread; | 73 using content::BrowserThread; |
72 | 74 |
73 namespace { | 75 namespace { |
74 | 76 |
75 // We must store this globally so that our main delegate can set it. | 77 // We must store this globally so that our main delegate can set it. |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (file_util::PathExists(user_data_dir_)) { | 436 if (file_util::PathExists(user_data_dir_)) { |
435 VLOG(1) << __FUNCTION__ << " deleting IE Profile user data directory " | 437 VLOG(1) << __FUNCTION__ << " deleting IE Profile user data directory " |
436 << user_data_dir_.value(); | 438 << user_data_dir_.value(); |
437 bool deleted = file_util::Delete(user_data_dir_, true); | 439 bool deleted = file_util::Delete(user_data_dir_, true); |
438 LOG_IF(ERROR, !deleted) << "Failed to delete user data directory directory " | 440 LOG_IF(ERROR, !deleted) << "Failed to delete user data directory directory " |
439 << user_data_dir_.value(); | 441 << user_data_dir_.value(); |
440 } | 442 } |
441 | 443 |
442 PathService::Get(chrome::DIR_USER_DATA, &overridden_user_dir_); | 444 PathService::Get(chrome::DIR_USER_DATA, &overridden_user_dir_); |
443 PathService::Override(chrome::DIR_USER_DATA, user_data_dir_); | 445 PathService::Override(chrome::DIR_USER_DATA, user_data_dir_); |
444 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); | |
445 } | 446 } |
446 | 447 |
447 FakeExternalTab::~FakeExternalTab() { | 448 FakeExternalTab::~FakeExternalTab() { |
448 if (!overridden_user_dir_.empty()) { | 449 if (!overridden_user_dir_.empty()) { |
449 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_); | 450 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_); |
450 } | 451 } |
451 } | 452 } |
452 | 453 |
453 void FakeExternalTab::Initialize() { | 454 void FakeExternalTab::Initialize() { |
454 DCHECK(g_browser_process == NULL); | 455 DCHECK(g_browser_process == NULL); |
(...skipping 28 matching lines...) Expand all Loading... |
483 | 484 |
484 void FakeExternalTab::InitializePostThreadsCreated() { | 485 void FakeExternalTab::InitializePostThreadsCreated() { |
485 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); | 486 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); |
486 Profile* profile = | 487 Profile* profile = |
487 g_browser_process->profile_manager()->GetProfile(profile_path); | 488 g_browser_process->profile_manager()->GetProfile(profile_path); |
488 } | 489 } |
489 | 490 |
490 void FakeExternalTab::Shutdown() { | 491 void FakeExternalTab::Shutdown() { |
491 browser_process_.reset(); | 492 browser_process_.reset(); |
492 g_browser_process = NULL; | 493 g_browser_process = NULL; |
493 process_singleton_.reset(); | |
494 | 494 |
495 ResourceBundle::CleanupSharedInstance(); | 495 ResourceBundle::CleanupSharedInstance(); |
496 } | 496 } |
497 | 497 |
498 FakeBrowserProcessImpl* FakeExternalTab::browser_process() const { | 498 FakeBrowserProcessImpl* FakeExternalTab::browser_process() const { |
499 return browser_process_.get(); | 499 return browser_process_.get(); |
500 } | 500 } |
501 | 501 |
502 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv) | 502 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv) |
503 : NetTestSuite(argc, argv, false), | 503 : NetTestSuite(argc, argv, false), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 // http://crbug.com/114369 . | 585 // http://crbug.com/114369 . |
586 OverrideHttpHost(); | 586 OverrideHttpHost(); |
587 } | 587 } |
588 | 588 |
589 void CFUrlRequestUnittestRunner::Shutdown() { | 589 void CFUrlRequestUnittestRunner::Shutdown() { |
590 DCHECK(::GetCurrentThreadId() == test_thread_id_); | 590 DCHECK(::GetCurrentThreadId() == test_thread_id_); |
591 NetTestSuite::Shutdown(); | 591 NetTestSuite::Shutdown(); |
592 OleUninitialize(); | 592 OleUninitialize(); |
593 } | 593 } |
594 | 594 |
595 void CFUrlRequestUnittestRunner::OnConnectAutomationProviderToChannel( | |
596 const std::string& channel_id) { | |
597 Profile* profile = g_browser_process->profile_manager()-> | |
598 GetDefaultProfile(fake_chrome_->user_data()); | |
599 | |
600 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | |
601 DCHECK(list); | |
602 list->AddProvider( | |
603 TestAutomationProvider::NewAutomationProvider(profile, channel_id, this)); | |
604 } | |
605 | |
606 void CFUrlRequestUnittestRunner::OnInitialTabLoaded() { | 595 void CFUrlRequestUnittestRunner::OnInitialTabLoaded() { |
607 test_http_server_.reset(); | 596 test_http_server_.reset(); |
608 BrowserThread::PostTask( | 597 BrowserThread::PostTask( |
609 BrowserThread::UI, | 598 BrowserThread::UI, |
610 FROM_HERE, | 599 FROM_HERE, |
611 base::Bind(&CFUrlRequestUnittestRunner::CancelInitializationTimeout, | 600 base::Bind(&CFUrlRequestUnittestRunner::CancelInitializationTimeout, |
612 base::Unretained(this))); | 601 base::Unretained(this))); |
613 StartTests(); | 602 StartTests(); |
614 } | 603 } |
615 | 604 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 void CFUrlRequestUnittestRunner::PreEarlyInitialization() { | 732 void CFUrlRequestUnittestRunner::PreEarlyInitialization() { |
744 testing::InitGoogleTest(&g_argc, g_argv); | 733 testing::InitGoogleTest(&g_argc, g_argv); |
745 FilterDisabledTests(); | 734 FilterDisabledTests(); |
746 StartFileLogger(); | 735 StartFileLogger(); |
747 } | 736 } |
748 | 737 |
749 int CFUrlRequestUnittestRunner::PreCreateThreads() { | 738 int CFUrlRequestUnittestRunner::PreCreateThreads() { |
750 fake_chrome_.reset(new FakeExternalTab()); | 739 fake_chrome_.reset(new FakeExternalTab()); |
751 fake_chrome_->Initialize(); | 740 fake_chrome_->Initialize(); |
752 fake_chrome_->browser_process()->PreCreateThreads(); | 741 fake_chrome_->browser_process()->PreCreateThreads(); |
| 742 process_singleton_.reset(new ProcessSingleton(fake_chrome_->user_data())); |
| 743 process_singleton_->Lock(NULL); |
| 744 return 0; |
| 745 } |
753 | 746 |
754 pss_subclass_.reset(new ProcessSingletonSubclass(this)); | 747 bool CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback( |
755 EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_->user_data())); | 748 const CommandLine& command_line, const FilePath& current_directory) { |
756 StartChromeFrameInHostBrowser(); | 749 std::string channel_id = command_line.GetSwitchValueASCII( |
757 return 0; | 750 switches::kAutomationClientChannelID); |
| 751 EXPECT_FALSE(channel_id.empty()); |
| 752 |
| 753 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile( |
| 754 fake_chrome_->user_data()); |
| 755 |
| 756 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
| 757 DCHECK(list); |
| 758 list->AddProvider( |
| 759 TestAutomationProvider::NewAutomationProvider(profile, channel_id, this)); |
| 760 return true; |
758 } | 761 } |
759 | 762 |
760 void CFUrlRequestUnittestRunner::PreMainMessageLoopRun() { | 763 void CFUrlRequestUnittestRunner::PreMainMessageLoopRun() { |
761 fake_chrome_->InitializePostThreadsCreated(); | 764 fake_chrome_->InitializePostThreadsCreated(); |
| 765 ProcessSingleton::NotificationCallback callback( |
| 766 base::Bind( |
| 767 &CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback, |
| 768 base::Unretained(this))); |
| 769 if (!process_singleton_->Create(callback)) { |
| 770 LOG(FATAL) << "Failed to start up ProcessSingleton. Is another test " |
| 771 << "executable or Chrome Frame running?"; |
| 772 if (crash_service_) |
| 773 base::KillProcess(crash_service_, 0, false); |
| 774 ::ExitProcess(1); |
| 775 } |
| 776 |
| 777 StartChromeFrameInHostBrowser(); |
762 } | 778 } |
763 | 779 |
764 bool CFUrlRequestUnittestRunner::MainMessageLoopRun(int* result_code) { | 780 bool CFUrlRequestUnittestRunner::MainMessageLoopRun(int* result_code) { |
765 DCHECK(MessageLoop::current()); | 781 DCHECK(MessageLoop::current()); |
766 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); | 782 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); |
767 | 783 |
768 // We need to allow IO on the main thread for these tests. | 784 // We need to allow IO on the main thread for these tests. |
769 base::ThreadRestrictions::SetIOAllowed(true); | 785 base::ThreadRestrictions::SetIOAllowed(true); |
770 | 786 process_singleton_->Unlock(); |
771 StartInitializationTimeout(); | 787 StartInitializationTimeout(); |
772 return false; | 788 return false; |
773 } | 789 } |
774 | 790 |
775 void CFUrlRequestUnittestRunner::PostMainMessageLoopRun() { | 791 void CFUrlRequestUnittestRunner::PostMainMessageLoopRun() { |
| 792 process_singleton_->Cleanup(); |
776 fake_chrome_->browser_process()->StartTearDown(); | 793 fake_chrome_->browser_process()->StartTearDown(); |
777 | 794 |
778 // Must do this separately as the mock profile_manager_ is not the | 795 // Must do this separately as the mock profile_manager_ is not the |
779 // same member as BrowserProcessImpl::StartTearDown resets. | 796 // same member as BrowserProcessImpl::StartTearDown resets. |
780 fake_chrome_->browser_process()->DestroyProfileManager(); | 797 fake_chrome_->browser_process()->DestroyProfileManager(); |
781 | 798 |
782 if (crash_service_) | 799 if (crash_service_) |
783 base::KillProcess(crash_service_, 0, false); | 800 base::KillProcess(crash_service_, 0, false); |
784 | 801 |
785 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); | 802 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); |
786 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); | 803 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); |
787 } | 804 } |
788 | 805 |
789 void CFUrlRequestUnittestRunner::PostDestroyThreads() { | 806 void CFUrlRequestUnittestRunner::PostDestroyThreads() { |
| 807 process_singleton_.reset(); |
790 fake_chrome_->browser_process()->PostDestroyThreads(); | 808 fake_chrome_->browser_process()->PostDestroyThreads(); |
791 fake_chrome_->Shutdown(); | 809 fake_chrome_->Shutdown(); |
792 fake_chrome_.reset(); | 810 fake_chrome_.reset(); |
793 | 811 |
794 #ifndef NDEBUG | 812 #ifndef NDEBUG |
795 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which | 813 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which |
796 // check if globals are created and destroyed on the same thread don't fire. | 814 // check if globals are created and destroyed on the same thread don't fire. |
797 // Webkit global objects are created on the inproc renderer thread. | 815 // Webkit global objects are created on the inproc renderer thread. |
798 ::ExitProcess(test_result()); | 816 ::ExitProcess(test_result()); |
799 #endif | 817 #endif |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 // content::InitializeSandboxInfo(&sandbox_info); | 923 // content::InitializeSandboxInfo(&sandbox_info); |
906 FakeMainDelegate delegate; | 924 FakeMainDelegate delegate; |
907 content::ContentMain( | 925 content::ContentMain( |
908 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)), | 926 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)), |
909 &sandbox_info, | 927 &sandbox_info, |
910 &delegate); | 928 &delegate); |
911 | 929 |
912 // Note: In debug builds, we ExitProcess during PostDestroyThreads. | 930 // Note: In debug builds, we ExitProcess during PostDestroyThreads. |
913 return g_test_suite->test_result(); | 931 return g_test_suite->test_result(); |
914 } | 932 } |
OLD | NEW |