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