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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ 6 #define CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ 7 8 #include <string> 9 10 #include "base/cancelable_callback.h" 11 #include "base/files/file_path.h" 12 #include "base/message_loop/message_loop.h" 13 #include "base/process/process.h" 14 #include "base/win/scoped_handle.h" 15 #include "chrome/browser/browser_process_impl.h" 16 #include "chrome_frame/test/net/test_automation_provider.h" 17 #include "chrome_frame/test/test_server.h" 18 #include "chrome_frame/test_utils.h" 19 #include "content/public/browser/browser_main_parts.h" 20 #include "content/public/browser/browser_thread.h" 21 #include "net/test/net_test_suite.h" 22 23 class CommandLine; 24 class FakeBrowserProcessImpl; 25 class ProcessSingleton; 26 27 namespace net { 28 class ScopedCustomUrlRequestTestHttpHost; 29 } // namespace net 30 31 namespace content { 32 class NotificationService; 33 } // namespace content 34 35 namespace logging_win { 36 class FileLogger; 37 } // namespace logging_win 38 39 namespace chrome_frame_test { 40 class IEConfigurator; 41 } // namespace chrome_frame_test 42 43 class FakeExternalTab { 44 public: 45 FakeExternalTab(); 46 virtual ~FakeExternalTab(); 47 48 virtual void Initialize(); 49 virtual void InitializePostThreadsCreated(); 50 virtual void Shutdown(); 51 52 const base::FilePath& user_data() const { 53 return user_data_dir_; 54 } 55 56 FakeBrowserProcessImpl* browser_process() const; 57 58 private: 59 scoped_ptr<FakeBrowserProcessImpl> browser_process_; 60 base::FilePath overridden_user_dir_; 61 base::FilePath user_data_dir_; 62 scoped_ptr<content::NotificationService> notificaton_service_; 63 64 DISALLOW_COPY_AND_ASSIGN(FakeExternalTab); 65 }; 66 67 // The "master class" that spins the UI and test threads. 68 // 69 // In this weird test executable that pretends to almost be Chrome, it 70 // plays a similar role to ChromeBrowserMainParts, and must fulfill 71 // the existing contract between ChromeBrowserMainParts and 72 // BrowserProcessImpl, i.e. poking BrowserProcessImpl at certain 73 // lifetime events. 74 class CFUrlRequestUnittestRunner 75 : public NetTestSuite, 76 public TestAutomationProviderDelegate, 77 public content::BrowserMainParts { 78 public: 79 CFUrlRequestUnittestRunner(int argc, char** argv); 80 virtual ~CFUrlRequestUnittestRunner(); 81 82 virtual void StartChromeFrameInHostBrowser(); 83 84 virtual void ShutDownHostBrowser(); 85 86 // Overrides to not call icu initialize 87 virtual void Initialize(); 88 virtual void Shutdown(); 89 90 // TestAutomationProviderDelegate. 91 virtual void OnInitialTabLoaded(); 92 virtual void OnProviderDestroyed(); 93 94 void StartTests(); 95 96 // Borrowed from TestSuite::Initialize(). 97 void InitializeLogging(); 98 99 int test_result() const { 100 return test_result_; 101 } 102 103 void set_crash_service(base::ProcessHandle handle) { 104 crash_service_ = handle; 105 } 106 107 // content::BrowserMainParts implementation. 108 virtual void PreEarlyInitialization() OVERRIDE; 109 virtual int PreCreateThreads() OVERRIDE; 110 virtual void PreMainMessageLoopRun() OVERRIDE; 111 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; 112 virtual void PostMainMessageLoopRun() OVERRIDE; 113 virtual void PostDestroyThreads() OVERRIDE; 114 115 protected: 116 // This is the thread that runs all the UrlRequest tests. 117 // Within its context, the Initialize() and Shutdown() routines above 118 // will be called. 119 static DWORD WINAPI RunAllUnittests(void* param); 120 121 void TakeDownBrowser(); 122 123 protected: 124 base::win::ScopedHandle test_thread_; 125 base::ProcessHandle crash_service_; 126 DWORD test_thread_id_; 127 128 scoped_ptr<net::ScopedCustomUrlRequestTestHttpHost> override_http_host_; 129 130 scoped_ptr<test_server::SimpleWebServer> test_http_server_; 131 test_server::SimpleResponse chrome_frame_html_; 132 133 // The fake chrome instance. 134 scoped_ptr<FakeExternalTab> fake_chrome_; 135 ScopedChromeFrameRegistrar registrar_; 136 int test_result_; 137 138 private: 139 // Causes HTTP tests to run over an external address rather than 127.0.0.1. 140 // See http://crbug.com/114369 . 141 void OverrideHttpHost(); 142 void StartFileLogger(); 143 void StopFileLogger(bool print); 144 void OnIEShutdownFailure(); 145 146 void CancelInitializationTimeout(); 147 void StartInitializationTimeout(); 148 void OnInitializationTimeout(); 149 150 bool ProcessSingletonNotificationCallback( 151 const CommandLine& command_line, 152 const base::FilePath& current_directory); 153 154 bool launch_browser_; 155 bool prompt_after_setup_; 156 bool tests_ran_; 157 scoped_ptr<ProcessSingleton> process_singleton_; 158 base::CancelableClosure timeout_closure_; 159 scoped_ptr<logging_win::FileLogger> file_logger_; 160 base::FilePath log_file_; 161 scoped_ptr<chrome_frame_test::IEConfigurator> ie_configurator_; 162 163 DISALLOW_COPY_AND_ASSIGN(CFUrlRequestUnittestRunner); 164 }; 165 166 #endif // CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ 167