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 #ifndef CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ | 5 #ifndef CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ |
6 #define CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ | 6 #define CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/process.h" |
13 #include "base/win/scoped_handle.h" | 14 #include "base/win/scoped_handle.h" |
14 #include "chrome/app/scoped_ole_initializer.h" | 15 #include "chrome/app/scoped_ole_initializer.h" |
15 #include "chrome/browser/browser_process_impl.h" | 16 #include "chrome/browser/browser_process_impl.h" |
16 #include "chrome_frame/test/net/process_singleton_subclass.h" | 17 #include "chrome_frame/test/net/process_singleton_subclass.h" |
17 #include "chrome_frame/test/net/test_automation_provider.h" | 18 #include "chrome_frame/test/net/test_automation_provider.h" |
18 #include "chrome_frame/test/test_server.h" | 19 #include "chrome_frame/test/test_server.h" |
19 #include "chrome_frame/test_utils.h" | 20 #include "chrome_frame/test_utils.h" |
20 #include "content/test/test_browser_thread.h" | 21 #include "content/public/browser/browser_main_parts.h" |
| 22 #include "content/public/browser/browser_thread.h" |
21 #include "net/base/net_test_suite.h" | 23 #include "net/base/net_test_suite.h" |
22 | 24 |
| 25 class FakeBrowserProcessImpl; |
23 class ProcessSingleton; | 26 class ProcessSingleton; |
24 | 27 |
25 namespace content { | 28 namespace content { |
26 class NotificationService; | 29 class NotificationService; |
27 } | 30 } |
28 | 31 |
29 class FakeExternalTab { | 32 class FakeExternalTab { |
30 public: | 33 public: |
31 FakeExternalTab(); | 34 FakeExternalTab(); |
32 virtual ~FakeExternalTab(); | 35 virtual ~FakeExternalTab(); |
33 | 36 |
34 virtual void Initialize(); | 37 virtual void Initialize(); |
35 virtual void InitializePostThreadsCreated(); | 38 virtual void InitializePostThreadsCreated(); |
36 virtual void Shutdown(); | 39 virtual void Shutdown(); |
37 | 40 |
38 const FilePath& user_data() const { | 41 const FilePath& user_data() const { |
39 return user_data_dir_; | 42 return user_data_dir_; |
40 } | 43 } |
41 | 44 |
42 MessageLoopForUI* ui_loop() { | 45 FakeBrowserProcessImpl* browser_process() const; |
43 return &loop_; | |
44 } | |
45 | 46 |
46 protected: | 47 protected: |
47 MessageLoopForUI loop_; | 48 scoped_ptr<FakeBrowserProcessImpl> browser_process_; |
48 scoped_ptr<BrowserProcess> browser_process_; | |
49 FilePath overridden_user_dir_; | 49 FilePath overridden_user_dir_; |
50 FilePath user_data_dir_; | 50 FilePath user_data_dir_; |
51 scoped_ptr<ProcessSingleton> process_singleton_; | 51 scoped_ptr<ProcessSingleton> process_singleton_; |
52 scoped_ptr<content::NotificationService> notificaton_service_; | 52 scoped_ptr<content::NotificationService> notificaton_service_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(FakeExternalTab); |
53 }; | 55 }; |
54 | 56 |
55 // The "master class" that spins the UI and test threads. | 57 // The "master class" that spins the UI and test threads. |
| 58 // |
| 59 // In this weird test executable that pretends to almost be Chrome, it |
| 60 // plays a similar role to ChromeBrowserMainParts, and must fulfill |
| 61 // the existing contract between ChromeBrowserMainParts and |
| 62 // BrowserProcessImpl, i.e. poking BrowserProcessImpl at certain |
| 63 // lifetime events. |
56 class CFUrlRequestUnittestRunner | 64 class CFUrlRequestUnittestRunner |
57 : public NetTestSuite, | 65 : public NetTestSuite, |
58 public ProcessSingletonSubclassDelegate, | 66 public ProcessSingletonSubclassDelegate, |
59 public TestAutomationProviderDelegate { | 67 public TestAutomationProviderDelegate, |
| 68 public content::BrowserMainParts { |
60 public: | 69 public: |
61 CFUrlRequestUnittestRunner(int argc, char** argv); | 70 CFUrlRequestUnittestRunner(int argc, char** argv); |
62 ~CFUrlRequestUnittestRunner(); | 71 virtual ~CFUrlRequestUnittestRunner(); |
63 | 72 |
64 virtual void StartChromeFrameInHostBrowser(); | 73 virtual void StartChromeFrameInHostBrowser(); |
65 | 74 |
66 virtual void ShutDownHostBrowser(); | 75 virtual void ShutDownHostBrowser(); |
67 | 76 |
68 // Overrides to not call icu initialize | 77 // Overrides to not call icu initialize |
69 virtual void Initialize(); | 78 virtual void Initialize(); |
70 virtual void Shutdown(); | 79 virtual void Shutdown(); |
71 | 80 |
72 // ProcessSingletonSubclassDelegate. | 81 // ProcessSingletonSubclassDelegate. |
73 virtual void OnConnectAutomationProviderToChannel( | 82 virtual void OnConnectAutomationProviderToChannel( |
74 const std::string& channel_id); | 83 const std::string& channel_id); |
75 | 84 |
76 // TestAutomationProviderDelegate. | 85 // TestAutomationProviderDelegate. |
77 virtual void OnInitialTabLoaded(); | 86 virtual void OnInitialTabLoaded(); |
78 | 87 |
79 void RunMainUIThread(); | |
80 | |
81 void StartTests(); | 88 void StartTests(); |
82 | 89 |
83 // Borrowed from TestSuite::Initialize(). | 90 // Borrowed from TestSuite::Initialize(). |
84 static void InitializeLogging(); | 91 static void InitializeLogging(); |
85 | 92 |
86 int test_result() const { | 93 int test_result() const { |
87 return test_result_; | 94 return test_result_; |
88 } | 95 } |
89 | 96 |
| 97 void set_crash_service(base::ProcessHandle handle) { |
| 98 crash_service_ = handle; |
| 99 } |
| 100 |
| 101 // content::BrowserMainParts implementation. |
| 102 virtual void PreEarlyInitialization() OVERRIDE; |
| 103 virtual void PostEarlyInitialization() OVERRIDE {} |
| 104 virtual void PreMainMessageLoopStart() OVERRIDE {} |
| 105 virtual void PostMainMessageLoopStart() OVERRIDE {} |
| 106 virtual void ToolkitInitialized() OVERRIDE {} |
| 107 virtual void PreCreateThreads() OVERRIDE; |
| 108 virtual void PreStartThread(content::BrowserThread::ID identifier) OVERRIDE; |
| 109 virtual void PostStartThread( |
| 110 content::BrowserThread::ID identifier) OVERRIDE; |
| 111 virtual void PreMainMessageLoopRun() OVERRIDE; |
| 112 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; |
| 113 virtual void PostMainMessageLoopRun() OVERRIDE; |
| 114 virtual void PreStopThread(content::BrowserThread::ID identifier) OVERRIDE; |
| 115 virtual void PostStopThread(content::BrowserThread::ID identifier) OVERRIDE; |
| 116 virtual void PostDestroyThreads() OVERRIDE; |
| 117 |
90 protected: | 118 protected: |
91 // This is the thread that runs all the UrlRequest tests. | 119 // This is the thread that runs all the UrlRequest tests. |
92 // Within its context, the Initialize() and Shutdown() routines above | 120 // Within its context, the Initialize() and Shutdown() routines above |
93 // will be called. | 121 // will be called. |
94 static DWORD WINAPI RunAllUnittests(void* param); | 122 static DWORD WINAPI RunAllUnittests(void* param); |
95 | 123 |
96 static void TakeDownBrowser(CFUrlRequestUnittestRunner* me); | 124 static void TakeDownBrowser(CFUrlRequestUnittestRunner* me); |
97 | 125 |
98 protected: | 126 protected: |
99 base::win::ScopedHandle test_thread_; | 127 base::win::ScopedHandle test_thread_; |
| 128 base::ProcessHandle crash_service_; |
100 DWORD test_thread_id_; | 129 DWORD test_thread_id_; |
101 | 130 |
102 scoped_ptr<test_server::SimpleWebServer> test_http_server_; | 131 scoped_ptr<test_server::SimpleWebServer> test_http_server_; |
103 test_server::SimpleResponse chrome_frame_html_; | 132 test_server::SimpleResponse chrome_frame_html_; |
104 | 133 |
105 // The fake chrome instance. This instance owns the UI message loop | 134 // The fake chrome instance. |
106 // on the main thread. | 135 scoped_ptr<FakeExternalTab> fake_chrome_; |
107 FakeExternalTab fake_chrome_; | |
108 scoped_ptr<ProcessSingletonSubclass> pss_subclass_; | 136 scoped_ptr<ProcessSingletonSubclass> pss_subclass_; |
109 scoped_ptr<content::TestBrowserThread> main_thread_; | |
110 ScopedChromeFrameRegistrar registrar_; | 137 ScopedChromeFrameRegistrar registrar_; |
111 int test_result_; | 138 int test_result_; |
112 | 139 |
113 // TODO(joi): This should be fixed so that this test executable uses | 140 DISALLOW_COPY_AND_ASSIGN(CFUrlRequestUnittestRunner); |
114 // content::BrowserMainParts. As it stands it is a horrible hack. | |
115 scoped_ptr<content::TestBrowserThread> db_thread_; | |
116 scoped_ptr<content::TestBrowserThread> file_thread_; | |
117 scoped_ptr<content::TestBrowserThread> io_thread_; | |
118 }; | 141 }; |
119 | 142 |
120 #endif // CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ | 143 #endif // CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_ |
OLD | NEW |