| 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/chrome_content_browser_client.h" |
| 19 #include "chrome/browser/prefs/browser_prefs.h" | 20 #include "chrome/browser/prefs/browser_prefs.h" |
| 20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | 22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
| 22 #include "chrome/browser/service_process/service_process_control.h" | 23 #include "chrome/browser/service_process/service_process_control.h" |
| 23 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 24 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 25 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/service_messages.h" | 28 #include "chrome/common/service_messages.h" |
| 27 #include "chrome/common/service_process_util.h" | 29 #include "chrome/common/service_process_util.h" |
| 28 #include "chrome/service/service_ipc_server.h" | 30 #include "chrome/service/service_ipc_server.h" |
| 29 #include "chrome/service/service_process.h" | 31 #include "chrome/service/service_process.h" |
| 30 #include "chrome/test/base/chrome_unit_test_suite.h" | 32 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 31 #include "chrome/test/base/test_launcher_utils.h" | 33 #include "chrome/test/base/test_launcher_utils.h" |
| 32 #include "chrome/test/base/testing_browser_process.h" | 34 #include "chrome/test/base/testing_browser_process.h" |
| 33 #include "chrome/test/base/testing_io_thread_state.h" | 35 #include "chrome/test/base/testing_io_thread_state.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 command_line, base::FilePath(), false, profile, | 331 command_line, base::FilePath(), false, profile, |
| 330 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); | 332 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); |
| 331 } | 333 } |
| 332 | 334 |
| 333 protected: | 335 protected: |
| 334 content::TestBrowserThreadBundle thread_bundle_; | 336 content::TestBrowserThreadBundle thread_bundle_; |
| 335 base::ScopedTempDir temp_user_data_dir_; | 337 base::ScopedTempDir temp_user_data_dir_; |
| 336 | 338 |
| 337 std::string startup_channel_id_; | 339 std::string startup_channel_id_; |
| 338 scoped_ptr<IPC::ChannelProxy> startup_channel_; | 340 scoped_ptr<IPC::ChannelProxy> startup_channel_; |
| 341 scoped_ptr<ChromeContentClient> content_client_; |
| 342 scoped_ptr<chrome::ChromeContentBrowserClient> browser_content_client_; |
| 339 | 343 |
| 340 #if defined(OS_MACOSX) | 344 #if defined(OS_MACOSX) |
| 341 base::ScopedTempDir temp_dir_; | 345 base::ScopedTempDir temp_dir_; |
| 342 base::FilePath executable_path_, bundle_path_; | 346 base::FilePath executable_path_, bundle_path_; |
| 343 scoped_ptr<MockLaunchd> mock_launchd_; | 347 scoped_ptr<MockLaunchd> mock_launchd_; |
| 344 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; | 348 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; |
| 345 #endif | 349 #endif |
| 346 | 350 |
| 347 private: | 351 private: |
| 348 class WindowedChannelConnectionObserver { | 352 class WindowedChannelConnectionObserver { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 377 // Although is really a unit test which runs in the browser_tests binary, it | 381 // 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. | 382 // doesn't get the unit setup which normally happens in the unit test binary. |
| 379 ChromeUnitTestSuite::InitializeProviders(); | 383 ChromeUnitTestSuite::InitializeProviders(); |
| 380 ChromeUnitTestSuite::InitializeResourceBundle(); | 384 ChromeUnitTestSuite::InitializeResourceBundle(); |
| 381 } | 385 } |
| 382 | 386 |
| 383 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { | 387 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { |
| 384 } | 388 } |
| 385 | 389 |
| 386 void CloudPrintProxyPolicyStartupTest::SetUp() { | 390 void CloudPrintProxyPolicyStartupTest::SetUp() { |
| 391 content_client_.reset(new ChromeContentClient); |
| 392 content::SetContentClient(content_client_.get()); |
| 393 browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); |
| 394 content::SetBrowserClientForTesting(browser_content_client_.get()); |
| 395 |
| 387 TestingBrowserProcess::CreateInstance(); | 396 TestingBrowserProcess::CreateInstance(); |
| 388 #if defined(OS_MACOSX) | 397 #if defined(OS_MACOSX) |
| 389 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 398 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 390 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), | 399 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), |
| 391 "CloudPrintProxyTest", | 400 "CloudPrintProxyTest", |
| 392 &bundle_path_, | 401 &bundle_path_, |
| 393 &executable_path_)); | 402 &executable_path_)); |
| 394 mock_launchd_.reset(new MockLaunchd(executable_path_, | 403 mock_launchd_.reset(new MockLaunchd(executable_path_, |
| 395 base::MessageLoopForUI::current(), | 404 base::MessageLoopForUI::current(), |
| 396 true, false)); | 405 true, false)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 411 << "Could not create temporary user data directory \"" | 420 << "Could not create temporary user data directory \"" |
| 412 << temp_user_data_dir_.path().value() << "\"."; | 421 << temp_user_data_dir_.path().value() << "\"."; |
| 413 | 422 |
| 414 user_data_dir = temp_user_data_dir_.path(); | 423 user_data_dir = temp_user_data_dir_.path(); |
| 415 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); | 424 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 416 } | 425 } |
| 417 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); | 426 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
| 418 } | 427 } |
| 419 | 428 |
| 420 void CloudPrintProxyPolicyStartupTest::TearDown() { | 429 void CloudPrintProxyPolicyStartupTest::TearDown() { |
| 430 browser_content_client_.reset(); |
| 431 content_client_.reset(); |
| 432 content::SetContentClient(NULL); |
| 433 |
| 421 TestingBrowserProcess::DeleteInstance(); | 434 TestingBrowserProcess::DeleteInstance(); |
| 422 } | 435 } |
| 423 | 436 |
| 424 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( | 437 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( |
| 425 const std::string& name) { | 438 const std::string& name) { |
| 426 EXPECT_FALSE(CheckServiceProcessReady()); | 439 EXPECT_FALSE(CheckServiceProcessReady()); |
| 427 | 440 |
| 428 startup_channel_id_ = | 441 startup_channel_id_ = |
| 429 base::StringPrintf("%d.%p.%d", | 442 base::StringPrintf("%d.%p.%d", |
| 430 base::GetCurrentProcId(), this, | 443 base::GetCurrentProcId(), this, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 // condition. | 622 // condition. |
| 610 if (should_run_loop) | 623 if (should_run_loop) |
| 611 run_loop.Run(); | 624 run_loop.Run(); |
| 612 | 625 |
| 613 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 626 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
| 614 | 627 |
| 615 ShutdownAndWaitForExitWithTimeout(handle); | 628 ShutdownAndWaitForExitWithTimeout(handle); |
| 616 content::RunAllPendingInMessageLoop(); | 629 content::RunAllPendingInMessageLoop(); |
| 617 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 630 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
| 618 } | 631 } |
| OLD | NEW |