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.h" | 11 #include "base/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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 #if defined(OS_MACOSX) | 214 #if defined(OS_MACOSX) |
210 CommandLine* cl = CommandLine::ForCurrentProcess(); | 215 CommandLine* cl = CommandLine::ForCurrentProcess(); |
211 if (!cl->HasSwitch(kTestExecutablePath)) | 216 if (!cl->HasSwitch(kTestExecutablePath)) |
212 return kMissingSwitch; | 217 return kMissingSwitch; |
213 base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath); | 218 base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath); |
214 EXPECT_FALSE(executable_path.empty()); | 219 EXPECT_FALSE(executable_path.empty()); |
215 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); | 220 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); |
216 Launchd::ScopedInstance use_mock(&mock_launchd); | 221 Launchd::ScopedInstance use_mock(&mock_launchd); |
217 #endif | 222 #endif |
218 | 223 |
224 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
Lei Zhang
2013/07/15 22:29:19
Can you just move the same code on line 215 out of
awong
2013/07/16 21:27:28
Done.
| |
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 content::BrowserThread::GetMessageLoopProxyForThread( |
Lei Zhang
2013/07/15 22:29:19
nit: Since you added "using content::BrowserThread
awong
2013/07/16 21:27:28
Done.
| |
305 content::BrowserThread::IO); | |
294 } | 306 } |
295 base::ProcessHandle Launch(const std::string& name); | 307 base::ProcessHandle Launch(const std::string& name); |
296 void WaitForConnect(); | 308 void WaitForConnect(); |
297 bool Send(IPC::Message* message); | 309 bool Send(IPC::Message* message); |
298 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); | 310 void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle); |
299 | 311 |
300 // IPC::Listener implementation | 312 // IPC::Listener implementation |
301 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 313 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
302 return false; | 314 return false; |
303 } | 315 } |
304 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 316 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
305 | 317 |
306 // MultiProcessTest implementation. | 318 // MultiProcessTest implementation. |
307 virtual CommandLine MakeCmdLine(const std::string& procname, | 319 virtual CommandLine MakeCmdLine(const std::string& procname, |
308 bool debug_on_start) OVERRIDE; | 320 bool debug_on_start) OVERRIDE; |
309 | 321 |
310 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { | 322 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { |
311 int return_code = 0; | 323 int return_code = 0; |
312 StartupBrowserCreator browser_creator; | 324 StartupBrowserCreator browser_creator; |
313 return StartupBrowserCreator::ProcessCmdLineImpl( | 325 return StartupBrowserCreator::ProcessCmdLineImpl( |
314 command_line, base::FilePath(), false, profile, | 326 command_line, base::FilePath(), false, profile, |
315 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); | 327 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); |
316 } | 328 } |
317 | 329 |
318 protected: | 330 protected: |
319 base::MessageLoopForUI message_loop_; | 331 content::TestBrowserThreadBundle thread_bundle_; |
320 content::TestBrowserThread ui_thread_; | 332 base::ScopedTempDir temp_user_data_dir_; |
321 base::Thread io_thread_; | |
322 | 333 |
323 std::string startup_channel_id_; | 334 std::string startup_channel_id_; |
324 scoped_ptr<IPC::ChannelProxy> startup_channel_; | 335 scoped_ptr<IPC::ChannelProxy> startup_channel_; |
325 | 336 |
326 #if defined(OS_MACOSX) | 337 #if defined(OS_MACOSX) |
327 base::ScopedTempDir temp_dir_; | 338 base::ScopedTempDir temp_dir_; |
328 base::FilePath executable_path_, bundle_path_; | 339 base::FilePath executable_path_, bundle_path_; |
329 scoped_ptr<MockLaunchd> mock_launchd_; | 340 scoped_ptr<MockLaunchd> mock_launchd_; |
330 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; | 341 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; |
331 #endif | 342 #endif |
(...skipping 20 matching lines...) Expand all Loading... | |
352 | 363 |
353 private: | 364 private: |
354 bool seen_; | 365 bool seen_; |
355 bool running_; | 366 bool running_; |
356 }; | 367 }; |
357 | 368 |
358 WindowedChannelConnectionObserver observer_; | 369 WindowedChannelConnectionObserver observer_; |
359 }; | 370 }; |
360 | 371 |
361 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() | 372 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() |
362 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 373 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) { |
363 io_thread_("CloudPrintProxyPolicyTestThread") { | |
364 } | 374 } |
365 | 375 |
366 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { | 376 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { |
367 } | 377 } |
368 | 378 |
369 void CloudPrintProxyPolicyStartupTest::SetUp() { | 379 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) | 380 #if defined(OS_MACOSX) |
374 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 381 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
375 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), | 382 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), |
376 "CloudPrintProxyTest", | 383 "CloudPrintProxyTest", |
377 &bundle_path_, | 384 &bundle_path_, |
378 &executable_path_)); | 385 &executable_path_)); |
379 mock_launchd_.reset(new MockLaunchd(executable_path_, &message_loop_, | 386 mock_launchd_.reset(new MockLaunchd(executable_path_, |
387 base::MessageLoopForUI::current(), | |
380 true, false)); | 388 true, false)); |
381 scoped_launchd_instance_.reset( | 389 scoped_launchd_instance_.reset( |
382 new Launchd::ScopedInstance(mock_launchd_.get())); | 390 new Launchd::ScopedInstance(mock_launchd_.get())); |
383 #endif | 391 #endif |
392 | |
393 // Ensure test does not use the standard profile directory. This is copied | |
394 // from InProcessBrowserTest::SetUp(). These tests require a more complex | |
395 // process startup so they are unable to just inherit from | |
396 // InProcessBrowserTest. | |
397 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
398 base::FilePath user_data_dir = | |
399 command_line->GetSwitchValuePath(switches::kUserDataDir); | |
400 if (user_data_dir.empty()) { | |
401 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir() && | |
402 temp_user_data_dir_.IsValid()) | |
403 << "Could not create temporary user data directory \"" | |
404 << temp_user_data_dir_.path().value() << "\"."; | |
405 | |
406 user_data_dir = temp_user_data_dir_.path(); | |
407 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); | |
408 } | |
409 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir)); | |
384 } | 410 } |
385 | 411 |
386 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( | 412 base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( |
387 const std::string& name) { | 413 const std::string& name) { |
388 EXPECT_FALSE(CheckServiceProcessReady()); | 414 EXPECT_FALSE(CheckServiceProcessReady()); |
389 | 415 |
390 startup_channel_id_ = | 416 startup_channel_id_ = |
391 base::StringPrintf("%d.%p.%d", | 417 base::StringPrintf("%d.%p.%d", |
392 base::GetCurrentProcId(), this, | 418 base::GetCurrentProcId(), this, |
393 base::RandInt(0, std::numeric_limits<int>::max())); | 419 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) { | 471 bool debug_on_start) { |
446 CommandLine cl = MultiProcessTest::MakeCmdLine(procname, debug_on_start); | 472 CommandLine cl = MultiProcessTest::MakeCmdLine(procname, debug_on_start); |
447 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); | 473 cl.AppendSwitchASCII(switches::kProcessChannelID, startup_channel_id_); |
448 #if defined(OS_MACOSX) | 474 #if defined(OS_MACOSX) |
449 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); | 475 cl.AppendSwitchASCII(kTestExecutablePath, executable_path_.value()); |
450 #endif | 476 #endif |
451 return cl; | 477 return cl; |
452 } | 478 } |
453 | 479 |
454 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { | 480 TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) { |
481 TestingBrowserProcess* browser_process = | |
482 TestingBrowserProcess::GetGlobal(); | |
483 TestingProfileManager profile_manager(browser_process); | |
484 ASSERT_TRUE(profile_manager.SetUp()); | |
485 | |
486 // Must be created after the TestingProfileManager since that creates the | |
487 // LocalState for the BrowserProcess. Must be created before profiles are | |
488 // constructed. | |
489 chrome::TestingIOThreadState testing_io_thread_state; | |
490 | |
455 base::ProcessHandle handle = | 491 base::ProcessHandle handle = |
456 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 492 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
457 WaitForConnect(); | 493 WaitForConnect(); |
458 ShutdownAndWaitForExitWithTimeout(handle); | 494 ShutdownAndWaitForExitWithTimeout(handle); |
495 content::RunAllPendingInMessageLoop(); | |
459 } | 496 } |
460 | 497 |
461 BrowserContextKeyedService* CloudPrintProxyServiceFactoryForPolicyTest( | 498 BrowserContextKeyedService* CloudPrintProxyServiceFactoryForPolicyTest( |
462 content::BrowserContext* profile) { | 499 content::BrowserContext* profile) { |
463 CloudPrintProxyService* service = | 500 CloudPrintProxyService* service = |
464 new CloudPrintProxyService(static_cast<Profile*>(profile)); | 501 new CloudPrintProxyService(static_cast<Profile*>(profile)); |
465 service->Initialize(); | 502 service->Initialize(); |
466 return service; | 503 return service; |
467 } | 504 } |
468 | 505 |
469 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { | 506 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { |
470 base::ProcessHandle handle = | 507 base::ProcessHandle handle = |
471 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | 508 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); |
472 | 509 |
510 // Setup the Browser Process with a full IOThread::Globals. | |
473 TestingBrowserProcess* browser_process = | 511 TestingBrowserProcess* browser_process = |
474 TestingBrowserProcess::GetGlobal(); | 512 TestingBrowserProcess::GetGlobal(); |
513 | |
475 TestingProfileManager profile_manager(browser_process); | 514 TestingProfileManager profile_manager(browser_process); |
476 ASSERT_TRUE(profile_manager.SetUp()); | 515 ASSERT_TRUE(profile_manager.SetUp()); |
477 | 516 |
517 // Must be created after the TestingProfileManager since that creates the | |
518 // LocalState for the BrowserProcess. Must be created before profiles are | |
519 // constructed. | |
520 chrome::TestingIOThreadState testing_io_thread_state; | |
521 | |
478 TestingProfile* profile = | 522 TestingProfile* profile = |
479 profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy"); | 523 profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy"); |
480 CloudPrintProxyServiceFactory::GetInstance()-> | 524 CloudPrintProxyServiceFactory::GetInstance()-> |
481 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | 525 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); |
482 | 526 |
483 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | 527 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); |
484 prefs->SetUserPref(prefs::kCloudPrintEmail, | 528 prefs->SetUserPref(prefs::kCloudPrintEmail, |
485 Value::CreateStringValue( | 529 Value::CreateStringValue( |
486 MockServiceIPCServer::EnabledUserId())); | 530 MockServiceIPCServer::EnabledUserId())); |
487 | 531 |
488 CommandLine command_line(CommandLine::NO_PROGRAM); | 532 CommandLine command_line(CommandLine::NO_PROGRAM); |
489 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | 533 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); |
490 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | 534 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); |
491 | 535 |
492 WaitForConnect(); | 536 WaitForConnect(); |
537 base::RunLoop run_loop; | |
493 base::MessageLoop::current()->PostDelayedTask( | 538 base::MessageLoop::current()->PostDelayedTask( |
494 FROM_HERE, | 539 FROM_HERE, |
495 base::MessageLoop::QuitClosure(), | 540 run_loop.QuitClosure(), |
496 TestTimeouts::action_timeout()); | 541 TestTimeouts::action_timeout()); |
497 | 542 |
498 bool run_loop = LaunchBrowser(command_line, profile); | 543 bool should_run_loop = LaunchBrowser(command_line, profile); |
499 EXPECT_FALSE(run_loop); | 544 EXPECT_FALSE(should_run_loop); |
500 if (run_loop) | 545 if (should_run_loop) |
501 base::MessageLoop::current()->Run(); | 546 run_loop.Run(); |
502 | 547 |
503 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), | 548 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), |
504 prefs->GetString(prefs::kCloudPrintEmail)); | 549 prefs->GetString(prefs::kCloudPrintEmail)); |
505 | 550 |
506 ShutdownAndWaitForExitWithTimeout(handle); | 551 ShutdownAndWaitForExitWithTimeout(handle); |
552 content::RunAllPendingInMessageLoop(); | |
507 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); | 553 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); |
508 } | 554 } |
509 | 555 |
510 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { | 556 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { |
511 base::ProcessHandle handle = | 557 base::ProcessHandle handle = |
512 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); | 558 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); |
513 | 559 |
514 TestingBrowserProcess* browser_process = | 560 TestingBrowserProcess* browser_process = |
515 TestingBrowserProcess::GetGlobal(); | 561 TestingBrowserProcess::GetGlobal(); |
516 TestingProfileManager profile_manager(browser_process); | 562 TestingProfileManager profile_manager(browser_process); |
517 ASSERT_TRUE(profile_manager.SetUp()); | 563 ASSERT_TRUE(profile_manager.SetUp()); |
518 | 564 |
565 // Must be created after the TestingProfileManager since that creates the | |
566 // LocalState for the BrowserProcess. Must be created before profiles are | |
567 // constructed. | |
568 chrome::TestingIOThreadState testing_io_thread_state; | |
569 | |
519 TestingProfile* profile = | 570 TestingProfile* profile = |
520 profile_manager.CreateTestingProfile("StartBrowserWithPolicy"); | 571 profile_manager.CreateTestingProfile("StartBrowserWithPolicy"); |
521 CloudPrintProxyServiceFactory::GetInstance()-> | 572 CloudPrintProxyServiceFactory::GetInstance()-> |
522 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | 573 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); |
523 | 574 |
524 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | 575 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); |
525 prefs->SetUserPref(prefs::kCloudPrintEmail, | 576 prefs->SetUserPref(prefs::kCloudPrintEmail, |
526 Value::CreateStringValue( | 577 Value::CreateStringValue( |
527 MockServiceIPCServer::EnabledUserId())); | 578 MockServiceIPCServer::EnabledUserId())); |
528 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 579 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
529 Value::CreateBooleanValue(false)); | 580 Value::CreateBooleanValue(false)); |
530 | 581 |
531 CommandLine command_line(CommandLine::NO_PROGRAM); | 582 CommandLine command_line(CommandLine::NO_PROGRAM); |
532 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | 583 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); |
533 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | 584 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); |
534 | 585 |
535 WaitForConnect(); | 586 WaitForConnect(); |
587 base::RunLoop run_loop; | |
536 base::MessageLoop::current()->PostDelayedTask( | 588 base::MessageLoop::current()->PostDelayedTask( |
537 FROM_HERE, | 589 FROM_HERE, |
538 base::MessageLoop::QuitClosure(), | 590 run_loop.QuitClosure(), |
539 TestTimeouts::action_timeout()); | 591 TestTimeouts::action_timeout()); |
540 | 592 |
541 bool run_loop = LaunchBrowser(command_line, profile); | 593 bool should_run_loop = LaunchBrowser(command_line, profile); |
542 | 594 |
543 // No expectations on run_loop being true here; that would be a race | 595 // No expectations on run_loop being true here; that would be a race |
544 // condition. | 596 // condition. |
545 if (run_loop) | 597 if (should_run_loop) |
546 base::MessageLoop::current()->Run(); | 598 run_loop.Run(); |
547 | 599 |
548 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | 600 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); |
549 | 601 |
550 ShutdownAndWaitForExitWithTimeout(handle); | 602 ShutdownAndWaitForExitWithTimeout(handle); |
603 content::RunAllPendingInMessageLoop(); | |
551 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | 604 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); |
552 } | 605 } |
OLD | NEW |