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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "chrome/test/base/testing_profile.h" | 45 #include "chrome/test/base/testing_profile.h" |
46 #include "chrome/test/base/testing_profile_manager.h" | 46 #include "chrome/test/base/testing_profile_manager.h" |
47 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 47 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
48 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
49 #include "content/public/common/content_paths.h" | 49 #include "content/public/common/content_paths.h" |
50 #include "content/public/test/test_browser_thread_bundle.h" | 50 #include "content/public/test/test_browser_thread_bundle.h" |
51 #include "content/public/test/test_utils.h" | 51 #include "content/public/test/test_utils.h" |
52 #include "ipc/ipc_channel_mojo.h" | 52 #include "ipc/ipc_channel_mojo.h" |
53 #include "ipc/ipc_descriptors.h" | 53 #include "ipc/ipc_descriptors.h" |
54 #include "ipc/ipc_multiprocess_test.h" | 54 #include "ipc/ipc_multiprocess_test.h" |
55 #include "ipc/ipc_switches.h" | |
56 #include "mojo/edk/embedder/embedder.h" | 55 #include "mojo/edk/embedder/embedder.h" |
57 #include "mojo/edk/embedder/named_platform_handle.h" | 56 #include "mojo/edk/embedder/named_platform_handle.h" |
58 #include "mojo/edk/embedder/named_platform_handle_utils.h" | 57 #include "mojo/edk/embedder/named_platform_handle_utils.h" |
59 #include "mojo/edk/embedder/scoped_ipc_support.h" | 58 #include "mojo/edk/embedder/scoped_ipc_support.h" |
60 #include "testing/gmock/include/gmock/gmock.h" | 59 #include "testing/gmock/include/gmock/gmock.h" |
61 #include "testing/gtest/include/gtest/gtest.h" | 60 #include "testing/gtest/include/gtest/gtest.h" |
62 #include "testing/multiprocess_func_list.h" | 61 #include "testing/multiprocess_func_list.h" |
63 | 62 |
64 #if defined(OS_MACOSX) | 63 #if defined(OS_MACOSX) |
65 #include "chrome/common/mac/mock_launchd.h" | 64 #include "chrome/common/mac/mock_launchd.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 mojo::edk::ScopedPlatformHandle os_pipe_handle = | 109 mojo::edk::ScopedPlatformHandle os_pipe_handle = |
111 mojo::edk::CreateClientHandle(os_pipe); | 110 mojo::edk::CreateClientHandle(os_pipe); |
112 if (!os_pipe_handle.is_valid()) | 111 if (!os_pipe_handle.is_valid()) |
113 return; | 112 return; |
114 | 113 |
115 mojo::FuseMessagePipes( | 114 mojo::FuseMessagePipes( |
116 mojo::edk::ConnectToPeerProcess(std::move(os_pipe_handle)), | 115 mojo::edk::ConnectToPeerProcess(std::move(os_pipe_handle)), |
117 std::move(handle)); | 116 std::move(handle)); |
118 } | 117 } |
119 | 118 |
| 119 const char kProcessChannelID[] = "process-channel-id"; |
| 120 |
120 } // namespace | 121 } // namespace |
121 | 122 |
122 class TestServiceProcess : public ServiceProcess { | 123 class TestServiceProcess : public ServiceProcess { |
123 public: | 124 public: |
124 TestServiceProcess() { } | 125 TestServiceProcess() { } |
125 ~TestServiceProcess() override {} | 126 ~TestServiceProcess() override {} |
126 | 127 |
127 bool Initialize(base::MessageLoopForUI* message_loop, | 128 bool Initialize(base::MessageLoopForUI* message_loop, |
128 ServiceProcessState* state); | 129 ServiceProcessState* state); |
129 }; | 130 }; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 EXPECT_TRUE(state->SignalReady(service_process.io_task_runner().get(), | 282 EXPECT_TRUE(state->SignalReady(service_process.io_task_runner().get(), |
282 base::Bind(&ShutdownTask))); | 283 base::Bind(&ShutdownTask))); |
283 #if defined(OS_MACOSX) | 284 #if defined(OS_MACOSX) |
284 mock_launchd.SignalReady(); | 285 mock_launchd.SignalReady(); |
285 #endif | 286 #endif |
286 | 287 |
287 // Connect up the parent/child IPC channel to signal that the test can | 288 // Connect up the parent/child IPC channel to signal that the test can |
288 // continue. | 289 // continue. |
289 TestStartupClientChannelListener listener; | 290 TestStartupClientChannelListener listener; |
290 EXPECT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 291 EXPECT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
291 switches::kProcessChannelID)); | 292 kProcessChannelID)); |
292 std::string startup_channel_name = | 293 std::string startup_channel_name = |
293 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 294 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
294 switches::kProcessChannelID); | 295 kProcessChannelID); |
295 std::unique_ptr<IPC::ChannelProxy> startup_channel; | 296 std::unique_ptr<IPC::ChannelProxy> startup_channel; |
296 startup_channel = | 297 startup_channel = |
297 IPC::ChannelProxy::Create(startup_channel_name, | 298 IPC::ChannelProxy::Create(startup_channel_name, |
298 IPC::Channel::MODE_CLIENT, | 299 IPC::Channel::MODE_CLIENT, |
299 &listener, | 300 &listener, |
300 service_process.io_task_runner()); | 301 service_process.io_task_runner()); |
301 | 302 |
302 base::RunLoop().Run(); | 303 base::RunLoop().Run(); |
303 if (!Mock::VerifyAndClearExpectations(&server)) | 304 if (!Mock::VerifyAndClearExpectations(&server)) |
304 return kExpectationsNotMet; | 305 return kExpectationsNotMet; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 EXPECT_EQ(exit_code, 0); | 517 EXPECT_EQ(exit_code, 0); |
517 } | 518 } |
518 | 519 |
519 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32_t peer_pid) { | 520 void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32_t peer_pid) { |
520 observer_.Notify(); | 521 observer_.Notify(); |
521 } | 522 } |
522 | 523 |
523 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( | 524 base::CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine( |
524 const std::string& procname) { | 525 const std::string& procname) { |
525 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname); | 526 base::CommandLine cl = MultiProcessTest::MakeCmdLine(procname); |
526 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); | 527 cl.AppendSwitchASCII(kProcessChannelID, startup_channel_id_); |
527 #if defined(OS_MACOSX) | 528 #if defined(OS_MACOSX) |
528 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); | 529 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); |
529 #endif | 530 #endif |
530 return cl; | 531 return cl; |
531 } | 532 } |
532 | 533 |
533 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { | 534 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { |
534 mojo::edk::Init(); | 535 mojo::edk::Init(); |
535 mojo::edk::ScopedIPCSupport ipc_support( | 536 mojo::edk::ScopedIPCSupport ipc_support( |
536 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 537 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
537 ->task_runner()); | 538 ->task_runner()); |
538 | 539 |
539 TestingBrowserProcess* browser_process = | 540 TestingBrowserProcess* browser_process = |
540 TestingBrowserProcess::GetGlobal(); | 541 TestingBrowserProcess::GetGlobal(); |
541 TestingProfileManager profile_manager(browser_process); | 542 TestingProfileManager profile_manager(browser_process); |
542 ASSERT_TRUE(profile_manager.SetUp()); | 543 ASSERT_TRUE(profile_manager.SetUp()); |
543 | 544 |
544 // Must be created after the TestingProfileManager since that creates the | 545 // Must be created after the TestingProfileManager since that creates the |
545 // LocalState for the BrowserProcess. Must be created before profiles are | 546 // LocalState for the BrowserProcess. Must be created before profiles are |
546 // constructed. | 547 // constructed. |
547 chrome::TestingIOThreadState testing_io_thread_state; | 548 chrome::TestingIOThreadState testing_io_thread_state; |
548 | 549 |
549 base::Process process = | 550 base::Process process = |
550 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 551 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
551 WaitForConnect(); | 552 WaitForConnect(); |
552 ShutdownAndWaitForExitWithTimeout(std::move(process)); | 553 ShutdownAndWaitForExitWithTimeout(std::move(process)); |
553 ServiceProcessControl::GetInstance()->Disconnect(); | 554 ServiceProcessControl::GetInstance()->Disconnect(); |
554 content::RunAllPendingInMessageLoop(); | 555 content::RunAllPendingInMessageLoop(); |
555 } | 556 } |
OLD | NEW |