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" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 // The return value from this routine is used as the exit code for the mock | 210 // The return value from this routine is used as the exit code for the mock |
211 // service process. Any non-zero return value will be printed out and can help | 211 // service process. Any non-zero return value will be printed out and can help |
212 // determine the failure. | 212 // determine the failure. |
213 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { | 213 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { |
214 base::MessageLoopForUI main_message_loop; | 214 base::MessageLoopForUI main_message_loop; |
215 main_message_loop.set_thread_name("Main Thread"); | 215 main_message_loop.set_thread_name("Main Thread"); |
216 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 216 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
217 content::RegisterPathProvider(); | 217 content::RegisterPathProvider(); |
218 | 218 |
| 219 base::FilePath user_data_dir = |
| 220 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 221 CHECK(!user_data_dir.empty()); |
| 222 CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
| 223 |
219 #if defined(OS_MACOSX) | 224 #if defined(OS_MACOSX) |
220 if (!command_line->HasSwitch(kTestExecutablePath)) | 225 if (!command_line->HasSwitch(kTestExecutablePath)) |
221 return kMissingSwitch; | 226 return kMissingSwitch; |
222 base::FilePath executable_path = | 227 base::FilePath executable_path = |
223 command_line->GetSwitchValuePath(kTestExecutablePath); | 228 command_line->GetSwitchValuePath(kTestExecutablePath); |
224 EXPECT_FALSE(executable_path.empty()); | 229 EXPECT_FALSE(executable_path.empty()); |
225 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); | 230 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); |
226 Launchd::ScopedInstance use_mock(&mock_launchd); | 231 Launchd::ScopedInstance use_mock(&mock_launchd); |
227 #endif | 232 #endif |
228 | 233 |
229 base::FilePath user_data_dir = | |
230 command_line->GetSwitchValuePath(switches::kUserDataDir); | |
231 CHECK(!user_data_dir.empty()); | |
232 CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir)); | |
233 | 234 |
234 ServiceProcessState* state(new ServiceProcessState); | 235 ServiceProcessState* state(new ServiceProcessState); |
235 bool service_process_state_initialized = state->Initialize(); | 236 bool service_process_state_initialized = state->Initialize(); |
236 EXPECT_TRUE(service_process_state_initialized); | 237 EXPECT_TRUE(service_process_state_initialized); |
237 if (!service_process_state_initialized) | 238 if (!service_process_state_initialized) |
238 return kInitializationFailure; | 239 return kInitializationFailure; |
239 | 240 |
240 TestServiceProcess service_process; | 241 TestServiceProcess service_process; |
241 EXPECT_EQ(&service_process, g_service_process); | 242 EXPECT_EQ(&service_process, g_service_process); |
242 | 243 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { | 384 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { |
384 } | 385 } |
385 | 386 |
386 void CloudPrintProxyPolicyStartupTest::SetUp() { | 387 void CloudPrintProxyPolicyStartupTest::SetUp() { |
387 content_client_.reset(new ChromeContentClient); | 388 content_client_.reset(new ChromeContentClient); |
388 content::SetContentClient(content_client_.get()); | 389 content::SetContentClient(content_client_.get()); |
389 browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); | 390 browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); |
390 content::SetBrowserClientForTesting(browser_content_client_.get()); | 391 content::SetBrowserClientForTesting(browser_content_client_.get()); |
391 | 392 |
392 TestingBrowserProcess::CreateInstance(); | 393 TestingBrowserProcess::CreateInstance(); |
393 #if defined(OS_MACOSX) | |
394 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
395 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), | |
396 "CloudPrintProxyTest", | |
397 &bundle_path_, | |
398 &executable_path_)); | |
399 mock_launchd_.reset(new MockLaunchd(executable_path_, | |
400 base::MessageLoopForUI::current(), | |
401 true, false)); | |
402 scoped_launchd_instance_.reset( | |
403 new Launchd::ScopedInstance(mock_launchd_.get())); | |
404 #endif | |
405 | |
406 // Ensure test does not use the standard profile directory. This is copied | 394 // Ensure test does not use the standard profile directory. This is copied |
407 // from InProcessBrowserTest::SetUp(). These tests require a more complex | 395 // from InProcessBrowserTest::SetUp(). These tests require a more complex |
408 // process startup so they are unable to just inherit from | 396 // process startup so they are unable to just inherit from |
409 // InProcessBrowserTest. | 397 // InProcessBrowserTest. |
410 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 398 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
411 base::FilePath user_data_dir = | 399 base::FilePath user_data_dir = |
412 command_line->GetSwitchValuePath(switches::kUserDataDir); | 400 command_line->GetSwitchValuePath(switches::kUserDataDir); |
413 if (user_data_dir.empty()) { | 401 if (user_data_dir.empty()) { |
414 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir() && | 402 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir() && |
415 temp_user_data_dir_.IsValid()) | 403 temp_user_data_dir_.IsValid()) |
416 << "Could not create temporary user data directory \"" | 404 << "Could not create temporary user data directory \"" |
417 << temp_user_data_dir_.path().value() << "\"."; | 405 << temp_user_data_dir_.path().value() << "\"."; |
418 | 406 |
419 user_data_dir = temp_user_data_dir_.path(); | 407 user_data_dir = temp_user_data_dir_.path(); |
420 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); | 408 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
421 } | 409 } |
422 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); | 410 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
| 411 |
| 412 #if defined(OS_MACOSX) |
| 413 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 414 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), |
| 415 "CloudPrintProxyTest", |
| 416 &bundle_path_, |
| 417 &executable_path_)); |
| 418 mock_launchd_.reset(new MockLaunchd(executable_path_, |
| 419 base::MessageLoopForUI::current(), |
| 420 true, false)); |
| 421 scoped_launchd_instance_.reset( |
| 422 new Launchd::ScopedInstance(mock_launchd_.get())); |
| 423 #endif |
423 } | 424 } |
424 | 425 |
425 void CloudPrintProxyPolicyStartupTest::TearDown() { | 426 void CloudPrintProxyPolicyStartupTest::TearDown() { |
426 browser_content_client_.reset(); | 427 browser_content_client_.reset(); |
427 content_client_.reset(); | 428 content_client_.reset(); |
428 content::SetContentClient(NULL); | 429 content::SetContentClient(NULL); |
429 | 430 |
430 TestingBrowserProcess::DeleteInstance(); | 431 TestingBrowserProcess::DeleteInstance(); |
431 } | 432 } |
432 | 433 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // condition. | 618 // condition. |
618 if (should_run_loop) | 619 if (should_run_loop) |
619 run_loop.Run(); | 620 run_loop.Run(); |
620 | 621 |
621 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 622 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
622 | 623 |
623 ShutdownAndWaitForExitWithTimeout(process.Pass()); | 624 ShutdownAndWaitForExitWithTimeout(process.Pass()); |
624 content::RunAllPendingInMessageLoop(); | 625 content::RunAllPendingInMessageLoop(); |
625 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 626 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
626 } | 627 } |
OLD | NEW |