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 // Create a service process that uses a Mock to respond to the browser in order | 5 // Create a service process that uses a Mock to respond to the browser in order |
6 // to test launching the browser using the cloud print policy check command | 6 // to test launching the browser using the cloud print policy check command |
7 // line switch. | 7 // line switch. |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
19 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "base/test/multiprocess_test.h" | 22 #include "base/test/multiprocess_test.h" |
23 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
| 24 #include "base/threading/platform_thread.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
25 #include "base/time/default_tick_clock.h" | 26 #include "base/time/default_tick_clock.h" |
26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "chrome/browser/chrome_content_browser_client.h" | 29 #include "chrome/browser/chrome_content_browser_client.h" |
29 #include "chrome/browser/prefs/browser_prefs.h" | 30 #include "chrome/browser/prefs/browser_prefs.h" |
30 #include "chrome/browser/service_process/service_process_control.h" | 31 #include "chrome/browser/service_process/service_process_control.h" |
31 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 32 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
32 #include "chrome/common/chrome_content_client.h" | 33 #include "chrome/common/chrome_content_client.h" |
33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return true; | 208 return true; |
208 } | 209 } |
209 | 210 |
210 typedef base::Callback<void(MockServiceIPCServer* server)> | 211 typedef base::Callback<void(MockServiceIPCServer* server)> |
211 SetExpectationsCallback; | 212 SetExpectationsCallback; |
212 | 213 |
213 // The return value from this routine is used as the exit code for the mock | 214 // The return value from this routine is used as the exit code for the mock |
214 // service process. Any non-zero return value will be printed out and can help | 215 // service process. Any non-zero return value will be printed out and can help |
215 // determine the failure. | 216 // determine the failure. |
216 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { | 217 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { |
| 218 base::PlatformThread::SetName("Main Thread"); |
217 base::MessageLoopForUI main_message_loop; | 219 base::MessageLoopForUI main_message_loop; |
218 main_message_loop.set_thread_name("Main Thread"); | |
219 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 220 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
220 content::RegisterPathProvider(); | 221 content::RegisterPathProvider(); |
221 | 222 |
222 base::FilePath user_data_dir = | 223 base::FilePath user_data_dir = |
223 command_line->GetSwitchValuePath(switches::kUserDataDir); | 224 command_line->GetSwitchValuePath(switches::kUserDataDir); |
224 CHECK(!user_data_dir.empty()); | 225 CHECK(!user_data_dir.empty()); |
225 CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir)); | 226 CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
226 | 227 |
227 #if defined(OS_MACOSX) | 228 #if defined(OS_MACOSX) |
228 if (!command_line->HasSwitch(kTestExecutablePath)) | 229 if (!command_line->HasSwitch(kTestExecutablePath)) |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 // LocalState for the BrowserProcess. Must be created before profiles are | 516 // LocalState for the BrowserProcess. Must be created before profiles are |
516 // constructed. | 517 // constructed. |
517 chrome::TestingIOThreadState testing_io_thread_state; | 518 chrome::TestingIOThreadState testing_io_thread_state; |
518 | 519 |
519 base::Process process = | 520 base::Process process = |
520 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 521 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
521 WaitForConnect(); | 522 WaitForConnect(); |
522 ShutdownAndWaitForExitWithTimeout(std::move(process)); | 523 ShutdownAndWaitForExitWithTimeout(std::move(process)); |
523 content::RunAllPendingInMessageLoop(); | 524 content::RunAllPendingInMessageLoop(); |
524 } | 525 } |
OLD | NEW |