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_util.h" | 12 #include "base/process_util.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/synchronization/waitable_event.h" |
14 #include "base/test/multiprocess_test.h" | 15 #include "base/test/multiprocess_test.h" |
15 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 17 #include "base/time/default_tick_clock.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/prefs/browser_prefs.h" |
17 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
18 #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" |
19 #include "chrome/browser/service/service_process_control.h" | 22 #include "chrome/browser/service/service_process_control.h" |
20 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 23 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/service_messages.h" | 26 #include "chrome/common/service_messages.h" |
24 #include "chrome/common/service_process_util.h" | 27 #include "chrome/common/service_process_util.h" |
25 #include "chrome/service/service_ipc_server.h" | 28 #include "chrome/service/service_ipc_server.h" |
26 #include "chrome/service/service_process.h" | 29 #include "chrome/service/service_process.h" |
27 #include "chrome/test/base/test_launcher_utils.h" | 30 #include "chrome/test/base/test_launcher_utils.h" |
28 #include "chrome/test/base/testing_browser_process.h" | 31 #include "chrome/test/base/testing_browser_process.h" |
| 32 #include "chrome/test/base/testing_io_thread_state.h" |
29 #include "chrome/test/base/testing_pref_service_syncable.h" | 33 #include "chrome/test/base/testing_pref_service_syncable.h" |
30 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
31 #include "chrome/test/base/testing_profile_manager.h" | 35 #include "chrome/test/base/testing_profile_manager.h" |
32 #include "chrome/test/base/ui_test_utils.h" | 36 #include "chrome/test/base/ui_test_utils.h" |
33 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 37 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
34 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
35 #include "content/public/test/test_browser_thread.h" | 39 #include "content/public/test/test_browser_thread_bundle.h" |
36 #include "ipc/ipc_descriptors.h" | 40 #include "ipc/ipc_descriptors.h" |
37 #include "ipc/ipc_multiprocess_test.h" | 41 #include "ipc/ipc_multiprocess_test.h" |
38 #include "ipc/ipc_switches.h" | 42 #include "ipc/ipc_switches.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "testing/multiprocess_func_list.h" | 45 #include "testing/multiprocess_func_list.h" |
42 | 46 |
43 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
44 #include "chrome/common/mac/mock_launchd.h" | 48 #include "chrome/common/mac/mock_launchd.h" |
45 #endif | 49 #endif |
46 #if defined(OS_POSIX) | 50 #if defined(OS_POSIX) |
47 #include "base/posix/global_descriptors.h" | 51 #include "base/posix/global_descriptors.h" |
48 #endif | 52 #endif |
49 | 53 |
50 using ::testing::AnyNumber; | 54 using ::testing::AnyNumber; |
51 using ::testing::Assign; | 55 using ::testing::Assign; |
52 using ::testing::AtLeast; | 56 using ::testing::AtLeast; |
53 using ::testing::DoAll; | 57 using ::testing::DoAll; |
54 using ::testing::Invoke; | 58 using ::testing::Invoke; |
55 using ::testing::Mock; | 59 using ::testing::Mock; |
56 using ::testing::Property; | 60 using ::testing::Property; |
57 using ::testing::Return; | 61 using ::testing::Return; |
58 using ::testing::WithoutArgs; | 62 using ::testing::WithoutArgs; |
59 using ::testing::_; | 63 using ::testing::_; |
| 64 using content::BrowserThread; |
60 | 65 |
61 namespace { | 66 namespace { |
62 | 67 |
63 enum MockServiceProcessExitCodes { | 68 enum MockServiceProcessExitCodes { |
64 kMissingSwitch = 1, | 69 kMissingSwitch = 1, |
65 kInitializationFailure, | 70 kInitializationFailure, |
66 kExpectationsNotMet, | 71 kExpectationsNotMet, |
67 kShutdownNotGood | 72 kShutdownNotGood |
68 }; | 73 }; |
69 | 74 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 203 |
199 typedef base::Callback<void(MockServiceIPCServer* server)> | 204 typedef base::Callback<void(MockServiceIPCServer* server)> |
200 SetExpectationsCallback; | 205 SetExpectationsCallback; |
201 | 206 |
202 // The return value from this routine is used as the exit code for the mock | 207 // The return value from this routine is used as the exit code for the mock |
203 // service process. Any non-zero return value will be printed out and can help | 208 // service process. Any non-zero return value will be printed out and can help |
204 // determine the failure. | 209 // determine the failure. |
205 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { | 210 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { |
206 base::MessageLoopForUI main_message_loop; | 211 base::MessageLoopForUI main_message_loop; |
207 main_message_loop.set_thread_name("Main Thread"); | 212 main_message_loop.set_thread_name("Main Thread"); |
| 213 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
208 | 214 |
209 #if defined(OS_MACOSX) | 215 #if defined(OS_MACOSX) |
210 CommandLine* cl = CommandLine::ForCurrentProcess(); | 216 if (!command_line->HasSwitch(kTestExecutablePath)) |
211 if (!cl->HasSwitch(kTestExecutablePath)) | |
212 return kMissingSwitch; | 217 return kMissingSwitch; |
213 base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath); | 218 base::FilePath executable_path = |
| 219 command_line->GetSwitchValuePath(kTestExecutablePath); |
214 EXPECT_FALSE(executable_path.empty()); | 220 EXPECT_FALSE(executable_path.empty()); |
215 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); | 221 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); |
216 Launchd::ScopedInstance use_mock(&mock_launchd); | 222 Launchd::ScopedInstance use_mock(&mock_launchd); |
217 #endif | 223 #endif |
218 | 224 |
| 225 base::FilePath user_data_dir = |
| 226 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 227 CHECK(!user_data_dir.empty()); |
| 228 CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
| 229 |
219 ServiceProcessState* state(new ServiceProcessState); | 230 ServiceProcessState* state(new ServiceProcessState); |
220 bool service_process_state_initialized = state->Initialize(); | 231 bool service_process_state_initialized = state->Initialize(); |
221 EXPECT_TRUE(service_process_state_initialized); | 232 EXPECT_TRUE(service_process_state_initialized); |
222 if (!service_process_state_initialized) | 233 if (!service_process_state_initialized) |
223 return kInitializationFailure; | 234 return kInitializationFailure; |
224 | 235 |
225 TestServiceProcess service_process; | 236 TestServiceProcess service_process; |
226 EXPECT_EQ(&service_process, g_service_process); | 237 EXPECT_EQ(&service_process, g_service_process); |
227 | 238 |
228 // Takes ownership of the pointer, but we can use it since we have the same | 239 // Takes ownership of the pointer, but we can use it since we have the same |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 base::Bind(&SetServiceWillBeDisabledExpectations)); | 293 base::Bind(&SetServiceWillBeDisabledExpectations)); |
283 } | 294 } |
284 | 295 |
285 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, | 296 class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, |
286 public IPC::Listener { | 297 public IPC::Listener { |
287 public: | 298 public: |
288 CloudPrintProxyPolicyStartupTest(); | 299 CloudPrintProxyPolicyStartupTest(); |
289 virtual ~CloudPrintProxyPolicyStartupTest(); | 300 virtual ~CloudPrintProxyPolicyStartupTest(); |
290 | 301 |
291 virtual void SetUp(); | 302 virtual void SetUp(); |
292 base::MessageLoopProxy* IOMessageLoopProxy() { | 303 scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() { |
293 return io_thread_.message_loop_proxy().get(); | 304 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
294 } | 305 } |
295 base::ProcessHandle Launch(const std::string& name); | 306 base::ProcessHandle Launch(const std::string& name); |
296 void WaitForConnect(); | 307 void WaitForConnect(); |
297 bool Send(IPC::Message* message); | 308 bool Send(IPC::Message* message); |
298 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); | 309 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); |
299 | 310 |
300 // IPC::Listener implementation | 311 // IPC::Listener implementation |
301 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 312 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
302 return false; | 313 return false; |
303 } | 314 } |
304 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 315 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
305 | 316 |
306 // MultiProcessTest implementation. | 317 // MultiProcessTest implementation. |
307 virtual CommandLine MakeCmdLine(const std::string& procname, | 318 virtual CommandLine MakeCmdLine(const std::string& procname, |
308 bool debug_on_start) OVERRIDE; | 319 bool debug_on_start) OVERRIDE; |
309 | 320 |
310 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { | 321 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { |
311 int return_code = 0; | 322 int return_code = 0; |
312 StartupBrowserCreator browser_creator; | 323 StartupBrowserCreator browser_creator; |
313 return StartupBrowserCreator::ProcessCmdLineImpl( | 324 return StartupBrowserCreator::ProcessCmdLineImpl( |
314 command_line, base::FilePath(), false, profile, | 325 command_line, base::FilePath(), false, profile, |
315 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); | 326 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); |
316 } | 327 } |
317 | 328 |
318 protected: | 329 protected: |
319 base::MessageLoopForUI message_loop_; | 330 content::TestBrowserThreadBundle thread_bundle_; |
320 content::TestBrowserThread ui_thread_; | 331 base::ScopedTempDir temp_user_data_dir_; |
321 base::Thread io_thread_; | |
322 | 332 |
323 std::string startup_channel_id_; | 333 std::string startup_channel_id_; |
324 scoped_ptr<IPC::ChannelProxy> startup_channel_; | 334 scoped_ptr<IPC::ChannelProxy> startup_channel_; |
325 | 335 |
326 #if defined(OS_MACOSX) | 336 #if defined(OS_MACOSX) |
327 base::ScopedTempDir temp_dir_; | 337 base::ScopedTempDir temp_dir_; |
328 base::FilePath executable_path_, bundle_path_; | 338 base::FilePath executable_path_, bundle_path_; |
329 scoped_ptr<MockLaunchd> mock_launchd_; | 339 scoped_ptr<MockLaunchd> mock_launchd_; |
330 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; | 340 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; |
331 #endif | 341 #endif |
(...skipping 20 matching lines...) Expand all Loading... |
352 | 362 |
353 private: | 363 private: |
354 bool seen_; | 364 bool seen_; |
355 bool running_; | 365 bool running_; |
356 }; | 366 }; |
357 | 367 |
358 WindowedChannelConnectionObserver observer_; | 368 WindowedChannelConnectionObserver observer_; |
359 }; | 369 }; |
360 | 370 |
361 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() | 371 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() |
362 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 372 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) { |
363 io_thread_("CloudPrintProxyPolicyTestThread") { | |
364 } | 373 } |
365 | 374 |
366 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { | 375 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { |
367 } | 376 } |
368 | 377 |
369 void CloudPrintProxyPolicyStartupTest::SetUp() { | 378 void CloudPrintProxyPolicyStartupTest::SetUp() { |
370 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | |
371 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | |
372 | |
373 #if defined(OS_MACOSX) | 379 #if defined(OS_MACOSX) |
374 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 380 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
375 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), | 381 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), |
376 "CloudPrintProxyTest", | 382 "CloudPrintProxyTest", |
377 &bundle_path_, | 383 &bundle_path_, |
378 &executable_path_)); | 384 &executable_path_)); |
379 mock_launchd_.reset(new MockLaunchd(executable_path_, &message_loop_, | 385 mock_launchd_.reset(new MockLaunchd(executable_path_, |
| 386 base::MessageLoopForUI::current(), |
380 true, false)); | 387 true, false)); |
381 scoped_launchd_instance_.reset( | 388 scoped_launchd_instance_.reset( |
382 new Launchd::ScopedInstance(mock_launchd_.get())); | 389 new Launchd::ScopedInstance(mock_launchd_.get())); |
383 #endif | 390 #endif |
| 391 |
| 392 // Ensure test does not use the standard profile directory. This is copied |
| 393 // from InProcessBrowserTest::SetUp(). These tests require a more complex |
| 394 // process startup so they are unable to just inherit from |
| 395 // InProcessBrowserTest. |
| 396 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 397 base::FilePath user_data_dir = |
| 398 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 399 if (user_data_dir.empty()) { |
| 400 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir() && |
| 401 temp_user_data_dir_.IsValid()) |
| 402 << "Could not create temporary user data directory \"" |
| 403 << temp_user_data_dir_.path().value() << "\"."; |
| 404 |
| 405 user_data_dir = temp_user_data_dir_.path(); |
| 406 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 407 } |
| 408 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); |
384 } | 409 } |
385 | 410 |
386 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( | 411 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( |
387 const std::string& name) { | 412 const std::string& name) { |
388 EXPECT_FALSE(CheckServiceProcessReady()); | 413 EXPECT_FALSE(CheckServiceProcessReady()); |
389 | 414 |
390 startup_channel_id_ = | 415 startup_channel_id_ = |
391 base::StringPrintf("%d.%p.%d", | 416 base::StringPrintf("%d.%p.%d", |
392 base::GetCurrentProcId(), this, | 417 base::GetCurrentProcId(), this, |
393 base::RandInt(0, std::numeric_limits<int>::max())); | 418 base::RandInt(0, std::numeric_limits<int>::max())); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 bool debug_on_start) { | 470 bool debug_on_start) { |
446 CommandLine cl = MultiProcessTest::MakeCmdLine(procname, debug_on_start); | 471 CommandLine cl = MultiProcessTest::MakeCmdLine(procname, debug_on_start); |
447 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); | 472 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); |
448 #if defined(OS_MACOSX) | 473 #if defined(OS_MACOSX) |
449 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); | 474 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); |
450 #endif | 475 #endif |
451 return cl; | 476 return cl; |
452 } | 477 } |
453 | 478 |
454 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { | 479 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { |
| 480 TestingBrowserProcess* browser_process = |
| 481 TestingBrowserProcess::GetGlobal(); |
| 482 TestingProfileManager profile_manager(browser_process); |
| 483 ASSERT_TRUE(profile_manager.SetUp()); |
| 484 |
| 485 // Must be created after the TestingProfileManager since that creates the |
| 486 // LocalState for the BrowserProcess. Must be created before profiles are |
| 487 // constructed. |
| 488 chrome::TestingIOThreadState testing_io_thread_state; |
| 489 |
455 base::ProcessHandle handle = | 490 base::ProcessHandle handle = |
456 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 491 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
457 WaitForConnect(); | 492 WaitForConnect(); |
458 ShutdownAndWaitForExitWithTimeout(handle); | 493 ShutdownAndWaitForExitWithTimeout(handle); |
| 494 content::RunAllPendingInMessageLoop(); |
459 } | 495 } |
460 | 496 |
461 BrowserContextKeyedService* CloudPrintProxyServiceFactoryForPolicyTest( | 497 BrowserContextKeyedService* CloudPrintProxyServiceFactoryForPolicyTest( |
462 content::BrowserContext* profile) { | 498 content::BrowserContext* profile) { |
463 CloudPrintProxyService* service = | 499 CloudPrintProxyService* service = |
464 new CloudPrintProxyService(static_cast<Profile*>(profile)); | 500 new CloudPrintProxyService(static_cast<Profile*>(profile)); |
465 service->Initialize(); | 501 service->Initialize(); |
466 return service; | 502 return service; |
467 } | 503 } |
468 | 504 |
469 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { | 505 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { |
470 base::ProcessHandle handle = | 506 base::ProcessHandle handle = |
471 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 507 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
472 | 508 |
| 509 // Setup the Browser Process with a full IOThread::Globals. |
473 TestingBrowserProcess* browser_process = | 510 TestingBrowserProcess* browser_process = |
474 TestingBrowserProcess::GetGlobal(); | 511 TestingBrowserProcess::GetGlobal(); |
| 512 |
475 TestingProfileManager profile_manager(browser_process); | 513 TestingProfileManager profile_manager(browser_process); |
476 ASSERT_TRUE(profile_manager.SetUp()); | 514 ASSERT_TRUE(profile_manager.SetUp()); |
477 | 515 |
| 516 // Must be created after the TestingProfileManager since that creates the |
| 517 // LocalState for the BrowserProcess. Must be created before profiles are |
| 518 // constructed. |
| 519 chrome::TestingIOThreadState testing_io_thread_state; |
| 520 |
478 TestingProfile* profile = | 521 TestingProfile* profile = |
479 profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy"); | 522 profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy"); |
480 CloudPrintProxyServiceFactory::GetInstance()-> | 523 CloudPrintProxyServiceFactory::GetInstance()-> |
481 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | 524 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); |
482 | 525 |
483 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | 526 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); |
484 prefs->SetUserPref(prefs::kCloudPrintEmail, | 527 prefs->SetUserPref(prefs::kCloudPrintEmail, |
485 Value::CreateStringValue( | 528 Value::CreateStringValue( |
486 MockServiceIPCServer::EnabledUserId())); | 529 MockServiceIPCServer::EnabledUserId())); |
487 | 530 |
488 CommandLine command_line(CommandLine::NO_PROGRAM); | 531 CommandLine command_line(CommandLine::NO_PROGRAM); |
489 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | 532 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); |
490 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | 533 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); |
491 | 534 |
492 WaitForConnect(); | 535 WaitForConnect(); |
| 536 base::RunLoop run_loop; |
493 base::MessageLoop::current()->PostDelayedTask( | 537 base::MessageLoop::current()->PostDelayedTask( |
494 FROM_HERE, | 538 FROM_HERE, |
495 base::MessageLoop::QuitClosure(), | 539 run_loop.QuitClosure(), |
496 TestTimeouts::action_timeout()); | 540 TestTimeouts::action_timeout()); |
497 | 541 |
498 bool run_loop = LaunchBrowser(command_line, profile); | 542 bool should_run_loop = LaunchBrowser(command_line, profile); |
499 EXPECT_FALSE(run_loop); | 543 EXPECT_FALSE(should_run_loop); |
500 if (run_loop) | 544 if (should_run_loop) |
501 base::MessageLoop::current()->Run(); | 545 run_loop.Run(); |
502 | 546 |
503 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), | 547 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), |
504 prefs->GetString(prefs::kCloudPrintEmail)); | 548 prefs->GetString(prefs::kCloudPrintEmail)); |
505 | 549 |
506 ShutdownAndWaitForExitWithTimeout(handle); | 550 ShutdownAndWaitForExitWithTimeout(handle); |
| 551 content::RunAllPendingInMessageLoop(); |
507 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); | 552 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); |
508 } | 553 } |
509 | 554 |
510 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { | 555 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { |
511 base::ProcessHandle handle = | 556 base::ProcessHandle handle = |
512 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); | 557 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); |
513 | 558 |
514 TestingBrowserProcess* browser_process = | 559 TestingBrowserProcess* browser_process = |
515 TestingBrowserProcess::GetGlobal(); | 560 TestingBrowserProcess::GetGlobal(); |
516 TestingProfileManager profile_manager(browser_process); | 561 TestingProfileManager profile_manager(browser_process); |
517 ASSERT_TRUE(profile_manager.SetUp()); | 562 ASSERT_TRUE(profile_manager.SetUp()); |
518 | 563 |
| 564 // Must be created after the TestingProfileManager since that creates the |
| 565 // LocalState for the BrowserProcess. Must be created before profiles are |
| 566 // constructed. |
| 567 chrome::TestingIOThreadState testing_io_thread_state; |
| 568 |
519 TestingProfile* profile = | 569 TestingProfile* profile = |
520 profile_manager.CreateTestingProfile("StartBrowserWithPolicy"); | 570 profile_manager.CreateTestingProfile("StartBrowserWithPolicy"); |
521 CloudPrintProxyServiceFactory::GetInstance()-> | 571 CloudPrintProxyServiceFactory::GetInstance()-> |
522 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | 572 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); |
523 | 573 |
524 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | 574 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); |
525 prefs->SetUserPref(prefs::kCloudPrintEmail, | 575 prefs->SetUserPref(prefs::kCloudPrintEmail, |
526 Value::CreateStringValue( | 576 Value::CreateStringValue( |
527 MockServiceIPCServer::EnabledUserId())); | 577 MockServiceIPCServer::EnabledUserId())); |
528 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 578 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
529 Value::CreateBooleanValue(false)); | 579 Value::CreateBooleanValue(false)); |
530 | 580 |
531 CommandLine command_line(CommandLine::NO_PROGRAM); | 581 CommandLine command_line(CommandLine::NO_PROGRAM); |
532 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | 582 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); |
533 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | 583 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); |
534 | 584 |
535 WaitForConnect(); | 585 WaitForConnect(); |
| 586 base::RunLoop run_loop; |
536 base::MessageLoop::current()->PostDelayedTask( | 587 base::MessageLoop::current()->PostDelayedTask( |
537 FROM_HERE, | 588 FROM_HERE, |
538 base::MessageLoop::QuitClosure(), | 589 run_loop.QuitClosure(), |
539 TestTimeouts::action_timeout()); | 590 TestTimeouts::action_timeout()); |
540 | 591 |
541 bool run_loop = LaunchBrowser(command_line, profile); | 592 bool should_run_loop = LaunchBrowser(command_line, profile); |
542 | 593 |
543 // No expectations on run_loop being true here; that would be a race | 594 // No expectations on run_loop being true here; that would be a race |
544 // condition. | 595 // condition. |
545 if (run_loop) | 596 if (should_run_loop) |
546 base::MessageLoop::current()->Run(); | 597 run_loop.Run(); |
547 | 598 |
548 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 599 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
549 | 600 |
550 ShutdownAndWaitForExitWithTimeout(handle); | 601 ShutdownAndWaitForExitWithTimeout(handle); |
| 602 content::RunAllPendingInMessageLoop(); |
551 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 603 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
552 } | 604 } |
OLD | NEW |