Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome_frame/test/net/fake_external_tab.cc

Issue 9959106: Modify chrome_frame_net_tests to integrate the refactoring to ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Convert some includes to forward declarations. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_paths_internal.h" 43 #include "chrome/common/chrome_paths_internal.h"
44 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
46 #include "chrome/renderer/chrome_content_renderer_client.h" 46 #include "chrome/renderer/chrome_content_renderer_client.h"
47 #include "chrome/test/logging/win/file_logger.h" 47 #include "chrome/test/logging/win/file_logger.h"
48 #include "chrome/test/logging/win/log_file_printer.h" 48 #include "chrome/test/logging/win/log_file_printer.h"
49 #include "chrome/test/logging/win/test_log_collector.h" 49 #include "chrome/test/logging/win/test_log_collector.h"
50 #include "chrome_frame/crash_server_init.h" 50 #include "chrome_frame/crash_server_init.h"
51 #include "chrome_frame/test/chrome_frame_test_utils.h" 51 #include "chrome_frame/test/chrome_frame_test_utils.h"
52 #include "chrome_frame/test/ie_configurator.h"
52 #include "chrome_frame/test/net/test_automation_resource_message_filter.h" 53 #include "chrome_frame/test/net/test_automation_resource_message_filter.h"
53 #include "chrome_frame/test/simulate_input.h" 54 #include "chrome_frame/test/simulate_input.h"
54 #include "chrome_frame/test/win_event_receiver.h" 55 #include "chrome_frame/test/win_event_receiver.h"
55 #include "chrome_frame/utils.h" 56 #include "chrome_frame/utils.h"
56 #include "content/public/app/content_main.h" 57 #include "content/public/app/content_main.h"
57 #include "content/public/app/startup_helper_win.h" 58 #include "content/public/app/startup_helper_win.h"
58 #include "content/public/browser/browser_thread.h" 59 #include "content/public/browser/browser_thread.h"
59 #include "content/public/browser/notification_service.h" 60 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/render_process_host.h" 61 #include "content/public/browser/render_process_host.h"
61 #include "content/public/common/content_client.h" 62 #include "content/public/common/content_client.h"
62 #include "content/public/common/content_paths.h" 63 #include "content/public/common/content_paths.h"
63 #include "net/base/net_util.h" 64 #include "net/base/net_util.h"
65 #include "net/url_request/url_request_test_util.h"
64 #include "sandbox/src/sandbox_types.h" 66 #include "sandbox/src/sandbox_types.h"
65 #include "testing/gtest/include/gtest/gtest.h" 67 #include "testing/gtest/include/gtest/gtest.h"
66 #include "ui/base/resource/resource_bundle.h" 68 #include "ui/base/resource/resource_bundle.h"
67 #include "ui/base/ui_base_paths.h" 69 #include "ui/base/ui_base_paths.h"
68 70
69 using content::BrowserThread; 71 using content::BrowserThread;
70 72
71 namespace { 73 namespace {
72 74
73 // We must store this globally so that our main delegate can set it. 75 // We must store this globally so that our main delegate can set it.
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (file_util::PathExists(user_data_dir_)) { 429 if (file_util::PathExists(user_data_dir_)) {
428 VLOG(1) << __FUNCTION__ << " deleting IE Profile user data directory " 430 VLOG(1) << __FUNCTION__ << " deleting IE Profile user data directory "
429 << user_data_dir_.value(); 431 << user_data_dir_.value();
430 bool deleted = file_util::Delete(user_data_dir_, true); 432 bool deleted = file_util::Delete(user_data_dir_, true);
431 LOG_IF(ERROR, !deleted) << "Failed to delete user data directory directory " 433 LOG_IF(ERROR, !deleted) << "Failed to delete user data directory directory "
432 << user_data_dir_.value(); 434 << user_data_dir_.value();
433 } 435 }
434 436
435 PathService::Get(chrome::DIR_USER_DATA, &overridden_user_dir_); 437 PathService::Get(chrome::DIR_USER_DATA, &overridden_user_dir_);
436 PathService::Override(chrome::DIR_USER_DATA, user_data_dir_); 438 PathService::Override(chrome::DIR_USER_DATA, user_data_dir_);
437 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
438 } 439 }
439 440
440 FakeExternalTab::~FakeExternalTab() { 441 FakeExternalTab::~FakeExternalTab() {
441 if (!overridden_user_dir_.empty()) { 442 if (!overridden_user_dir_.empty()) {
442 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_); 443 PathService::Override(chrome::DIR_USER_DATA, overridden_user_dir_);
443 } 444 }
444 } 445 }
445 446
446 void FakeExternalTab::Initialize() { 447 void FakeExternalTab::Initialize() {
447 DCHECK(g_browser_process == NULL); 448 DCHECK(g_browser_process == NULL);
(...skipping 28 matching lines...) Expand all
476 477
477 void FakeExternalTab::InitializePostThreadsCreated() { 478 void FakeExternalTab::InitializePostThreadsCreated() {
478 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data())); 479 FilePath profile_path(ProfileManager::GetDefaultProfileDir(user_data()));
479 Profile* profile = 480 Profile* profile =
480 g_browser_process->profile_manager()->GetProfile(profile_path); 481 g_browser_process->profile_manager()->GetProfile(profile_path);
481 } 482 }
482 483
483 void FakeExternalTab::Shutdown() { 484 void FakeExternalTab::Shutdown() {
484 browser_process_.reset(); 485 browser_process_.reset();
485 g_browser_process = NULL; 486 g_browser_process = NULL;
486 process_singleton_.reset();
487 487
488 ResourceBundle::CleanupSharedInstance(); 488 ResourceBundle::CleanupSharedInstance();
489 } 489 }
490 490
491 FakeBrowserProcessImpl* FakeExternalTab::browser_process() const { 491 FakeBrowserProcessImpl* FakeExternalTab::browser_process() const {
492 return browser_process_.get(); 492 return browser_process_.get();
493 } 493 }
494 494
495 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv) 495 CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv)
496 : NetTestSuite(argc, argv, false), 496 : NetTestSuite(argc, argv, false),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // http://crbug.com/114369 . 575 // http://crbug.com/114369 .
576 OverrideHttpHost(); 576 OverrideHttpHost();
577 } 577 }
578 578
579 void CFUrlRequestUnittestRunner::Shutdown() { 579 void CFUrlRequestUnittestRunner::Shutdown() {
580 DCHECK(::GetCurrentThreadId() == test_thread_id_); 580 DCHECK(::GetCurrentThreadId() == test_thread_id_);
581 NetTestSuite::Shutdown(); 581 NetTestSuite::Shutdown();
582 OleUninitialize(); 582 OleUninitialize();
583 } 583 }
584 584
585 void CFUrlRequestUnittestRunner::OnConnectAutomationProviderToChannel(
586 const std::string& channel_id) {
587 Profile* profile = g_browser_process->profile_manager()->
588 GetDefaultProfile(fake_chrome_->user_data());
589
590 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
591 DCHECK(list);
592 list->AddProvider(
593 TestAutomationProvider::NewAutomationProvider(profile, channel_id, this));
594 }
595
596 void CFUrlRequestUnittestRunner::OnInitialTabLoaded() { 585 void CFUrlRequestUnittestRunner::OnInitialTabLoaded() {
597 test_http_server_.reset(); 586 test_http_server_.reset();
598 BrowserThread::PostTask( 587 BrowserThread::PostTask(
599 BrowserThread::UI, 588 BrowserThread::UI,
600 FROM_HERE, 589 FROM_HERE,
601 base::Bind(&CFUrlRequestUnittestRunner::CancelInitializationTimeout, 590 base::Bind(&CFUrlRequestUnittestRunner::CancelInitializationTimeout,
602 base::Unretained(this))); 591 base::Unretained(this)));
603 StartTests(); 592 StartTests();
604 } 593 }
605 594
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } 744 }
756 745
757 MessageLoop* CFUrlRequestUnittestRunner::GetMainMessageLoop() { 746 MessageLoop* CFUrlRequestUnittestRunner::GetMainMessageLoop() {
758 return NULL; 747 return NULL;
759 } 748 }
760 749
761 int CFUrlRequestUnittestRunner::PreCreateThreads() { 750 int CFUrlRequestUnittestRunner::PreCreateThreads() {
762 fake_chrome_.reset(new FakeExternalTab()); 751 fake_chrome_.reset(new FakeExternalTab());
763 fake_chrome_->Initialize(); 752 fake_chrome_->Initialize();
764 fake_chrome_->browser_process()->PreCreateThreads(); 753 fake_chrome_->browser_process()->PreCreateThreads();
754 process_singleton_.reset(new ProcessSingleton(fake_chrome_->user_data()));
755 process_singleton_->Lock(NULL);
756 return 0;
757 }
765 758
766 pss_subclass_.reset(new ProcessSingletonSubclass(this)); 759 bool CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback(
767 EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_->user_data())); 760 const CommandLine& command_line, const FilePath& current_directory) {
768 StartChromeFrameInHostBrowser(); 761 std::string channel_id = command_line.GetSwitchValueASCII(
769 return 0; 762 switches::kAutomationClientChannelID);
763 EXPECT_FALSE(channel_id.empty());
764
765 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(
766 fake_chrome_->user_data());
767
768 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
769 DCHECK(list);
770 list->AddProvider(
771 TestAutomationProvider::NewAutomationProvider(profile, channel_id, this));
772 return true;
770 } 773 }
771 774
772 void CFUrlRequestUnittestRunner::PreMainMessageLoopRun() { 775 void CFUrlRequestUnittestRunner::PreMainMessageLoopRun() {
773 fake_chrome_->InitializePostThreadsCreated(); 776 fake_chrome_->InitializePostThreadsCreated();
777 ProcessSingleton::NotificationCallback callback(
778 base::Bind(
779 &CFUrlRequestUnittestRunner::ProcessSingletonNotificationCallback,
780 base::Unretained(this)));
781 if (!process_singleton_->Create(callback)) {
782 LOG(FATAL) << "Failed to start up ProcessSingleton. Is another test "
783 << "executable or Chrome Frame running?";
784 if (crash_service_)
785 base::KillProcess(crash_service_, 0, false);
786 ::ExitProcess(1);
787 }
788
789 StartChromeFrameInHostBrowser();
774 } 790 }
775 791
776 bool CFUrlRequestUnittestRunner::MainMessageLoopRun(int* result_code) { 792 bool CFUrlRequestUnittestRunner::MainMessageLoopRun(int* result_code) {
777 DCHECK(MessageLoop::current()); 793 DCHECK(MessageLoop::current());
778 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); 794 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
robertshield 2012/04/05 17:24:45 I suggest adding a DCHECK(process_singleton_) here
779 795
780 // We need to allow IO on the main thread for these tests. 796 // We need to allow IO on the main thread for these tests.
781 base::ThreadRestrictions::SetIOAllowed(true); 797 base::ThreadRestrictions::SetIOAllowed(true);
782 798 process_singleton_->Unlock();
783 StartInitializationTimeout(); 799 StartInitializationTimeout();
784 return false; 800 return false;
785 } 801 }
786 802
787 void CFUrlRequestUnittestRunner::PostMainMessageLoopRun() { 803 void CFUrlRequestUnittestRunner::PostMainMessageLoopRun() {
804 process_singleton_->Cleanup();
788 fake_chrome_->browser_process()->StartTearDown(); 805 fake_chrome_->browser_process()->StartTearDown();
789 806
790 // Must do this separately as the mock profile_manager_ is not the 807 // Must do this separately as the mock profile_manager_ is not the
791 // same member as BrowserProcessImpl::StartTearDown resets. 808 // same member as BrowserProcessImpl::StartTearDown resets.
792 fake_chrome_->browser_process()->DestroyProfileManager(); 809 fake_chrome_->browser_process()->DestroyProfileManager();
793 810
794 if (crash_service_) 811 if (crash_service_)
795 base::KillProcess(crash_service_, 0, false); 812 base::KillProcess(crash_service_, 0, false);
796 813
797 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); 814 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL);
798 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); 815 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL);
799 } 816 }
800 817
801 void CFUrlRequestUnittestRunner::PostDestroyThreads() { 818 void CFUrlRequestUnittestRunner::PostDestroyThreads() {
819 process_singleton_.reset();
802 fake_chrome_->browser_process()->PostDestroyThreads(); 820 fake_chrome_->browser_process()->PostDestroyThreads();
803 fake_chrome_->Shutdown(); 821 fake_chrome_->Shutdown();
804 fake_chrome_.reset(); 822 fake_chrome_.reset();
805 823
806 #ifndef NDEBUG 824 #ifndef NDEBUG
807 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which 825 // Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which
808 // check if globals are created and destroyed on the same thread don't fire. 826 // check if globals are created and destroyed on the same thread don't fire.
809 // Webkit global objects are created on the inproc renderer thread. 827 // Webkit global objects are created on the inproc renderer thread.
810 ::ExitProcess(test_result()); 828 ::ExitProcess(test_result());
811 #endif 829 #endif
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // content::InitializeSandboxInfo(&sandbox_info); 935 // content::InitializeSandboxInfo(&sandbox_info);
918 FakeMainDelegate delegate; 936 FakeMainDelegate delegate;
919 content::ContentMain( 937 content::ContentMain(
920 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)), 938 reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)),
921 &sandbox_info, 939 &sandbox_info,
922 &delegate); 940 &delegate);
923 941
924 // Note: In debug builds, we ExitProcess during PostDestroyThreads. 942 // Note: In debug builds, we ExitProcess during PostDestroyThreads.
925 return g_test_suite->test_result(); 943 return g_test_suite->test_result();
926 } 944 }
OLDNEW
« no previous file with comments | « chrome_frame/test/net/fake_external_tab.h ('k') | chrome_frame/test/net/process_singleton_subclass.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698