| 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/test/multiprocess_test.h" | 15 #include "base/test/multiprocess_test.h" |
| 16 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 17 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/prefs/browser_prefs.h" | 19 #include "chrome/browser/prefs/browser_prefs.h" |
| 20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
| 22 #include "chrome/browser/service_process/service_process_control.h" | 22 #include "chrome/browser/service_process/service_process_control.h" |
| 23 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 23 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/service_messages.h" | 26 #include "chrome/common/service_messages.h" |
| 27 #include "chrome/common/service_process_util.h" | 27 #include "chrome/common/service_process_util.h" |
| 28 #include "chrome/service/service_ipc_server.h" | 28 #include "chrome/service/service_ipc_server.h" |
| 29 #include "chrome/service/service_process.h" | 29 #include "chrome/service/service_process.h" |
| 30 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 30 #include "chrome/test/base/test_launcher_utils.h" | 31 #include "chrome/test/base/test_launcher_utils.h" |
| 31 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 32 #include "chrome/test/base/testing_io_thread_state.h" | 33 #include "chrome/test/base/testing_io_thread_state.h" |
| 33 #include "chrome/test/base/testing_pref_service_syncable.h" | 34 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 34 #include "chrome/test/base/testing_profile.h" | 35 #include "chrome/test/base/testing_profile.h" |
| 35 #include "chrome/test/base/testing_profile_manager.h" | 36 #include "chrome/test/base/testing_profile_manager.h" |
| 36 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
| 37 #include "components/keyed_service/core/keyed_service.h" | 38 #include "components/keyed_service/core/keyed_service.h" |
| 38 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/common/content_paths.h" |
| 39 #include "content/public/test/test_browser_thread_bundle.h" | 41 #include "content/public/test/test_browser_thread_bundle.h" |
| 40 #include "ipc/ipc_descriptors.h" | 42 #include "ipc/ipc_descriptors.h" |
| 41 #include "ipc/ipc_multiprocess_test.h" | 43 #include "ipc/ipc_multiprocess_test.h" |
| 42 #include "ipc/ipc_switches.h" | 44 #include "ipc/ipc_switches.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "testing/multiprocess_func_list.h" | 47 #include "testing/multiprocess_func_list.h" |
| 46 | 48 |
| 47 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
| 48 #include "chrome/common/mac/mock_launchd.h" | 50 #include "chrome/common/mac/mock_launchd.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 typedef base::Callback<void(MockServiceIPCServer* server)> | 206 typedef base::Callback<void(MockServiceIPCServer* server)> |
| 205 SetExpectationsCallback; | 207 SetExpectationsCallback; |
| 206 | 208 |
| 207 // The return value from this routine is used as the exit code for the mock | 209 // The return value from this routine is used as the exit code for the mock |
| 208 // service process. Any non-zero return value will be printed out and can help | 210 // service process. Any non-zero return value will be printed out and can help |
| 209 // determine the failure. | 211 // determine the failure. |
| 210 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { | 212 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { |
| 211 base::MessageLoopForUI main_message_loop; | 213 base::MessageLoopForUI main_message_loop; |
| 212 main_message_loop.set_thread_name("Main Thread"); | 214 main_message_loop.set_thread_name("Main Thread"); |
| 213 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 215 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 216 content::RegisterPathProvider(); |
| 214 | 217 |
| 215 #if defined(OS_MACOSX) | 218 #if defined(OS_MACOSX) |
| 216 if (!command_line->HasSwitch(kTestExecutablePath)) | 219 if (!command_line->HasSwitch(kTestExecutablePath)) |
| 217 return kMissingSwitch; | 220 return kMissingSwitch; |
| 218 base::FilePath executable_path = | 221 base::FilePath executable_path = |
| 219 command_line->GetSwitchValuePath(kTestExecutablePath); | 222 command_line->GetSwitchValuePath(kTestExecutablePath); |
| 220 EXPECT_FALSE(executable_path.empty()); | 223 EXPECT_FALSE(executable_path.empty()); |
| 221 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); | 224 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); |
| 222 Launchd::ScopedInstance use_mock(&mock_launchd); | 225 Launchd::ScopedInstance use_mock(&mock_launchd); |
| 223 #endif | 226 #endif |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 private: | 367 private: |
| 365 bool seen_; | 368 bool seen_; |
| 366 bool running_; | 369 bool running_; |
| 367 }; | 370 }; |
| 368 | 371 |
| 369 WindowedChannelConnectionObserver observer_; | 372 WindowedChannelConnectionObserver observer_; |
| 370 }; | 373 }; |
| 371 | 374 |
| 372 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() | 375 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() |
| 373 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) { | 376 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) { |
| 377 // Although is really a unit test which runs in the browser_tests binary, it |
| 378 // doesn't get the unit setup which normally happens in the unit test binary. |
| 379 ChromeUnitTestSuite::InitializeProviders(); |
| 380 ChromeUnitTestSuite::InitializeResourceBundle(); |
| 374 } | 381 } |
| 375 | 382 |
| 376 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { | 383 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { |
| 377 } | 384 } |
| 378 | 385 |
| 379 void CloudPrintProxyPolicyStartupTest::SetUp() { | 386 void CloudPrintProxyPolicyStartupTest::SetUp() { |
| 380 TestingBrowserProcess::CreateInstance(); | 387 TestingBrowserProcess::CreateInstance(); |
| 381 #if defined(OS_MACOSX) | 388 #if defined(OS_MACOSX) |
| 382 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 389 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 383 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), | 390 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 // condition. | 609 // condition. |
| 603 if (should_run_loop) | 610 if (should_run_loop) |
| 604 run_loop.Run(); | 611 run_loop.Run(); |
| 605 | 612 |
| 606 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 613 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
| 607 | 614 |
| 608 ShutdownAndWaitForExitWithTimeout(handle); | 615 ShutdownAndWaitForExitWithTimeout(handle); |
| 609 content::RunAllPendingInMessageLoop(); | 616 content::RunAllPendingInMessageLoop(); |
| 610 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 617 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
| 611 } | 618 } |
| OLD | NEW |