| 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 } | 518 } |
| 519 | 519 |
| 520 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( | 520 KeyedService* CloudPrintProxyServiceFactoryForPolicyTest( |
| 521 content::BrowserContext* profile) { | 521 content::BrowserContext* profile) { |
| 522 CloudPrintProxyService* service = | 522 CloudPrintProxyService* service = |
| 523 new CloudPrintProxyService(static_cast<Profile*>(profile)); | 523 new CloudPrintProxyService(static_cast<Profile*>(profile)); |
| 524 service->Initialize(); | 524 service->Initialize(); |
| 525 return service; | 525 return service; |
| 526 } | 526 } |
| 527 | 527 |
| 528 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) { | |
| 529 base::Process process = | |
| 530 Launch("CloudPrintMockService_StartEnabledWaitForQuit"); | |
| 531 | |
| 532 // Setup the Browser Process with a full IOThread::Globals. | |
| 533 TestingBrowserProcess* browser_process = | |
| 534 TestingBrowserProcess::GetGlobal(); | |
| 535 | |
| 536 TestingProfileManager profile_manager(browser_process); | |
| 537 ASSERT_TRUE(profile_manager.SetUp()); | |
| 538 | |
| 539 // Must be created after the TestingProfileManager since that creates the | |
| 540 // LocalState for the BrowserProcess. Must be created before profiles are | |
| 541 // constructed. | |
| 542 chrome::TestingIOThreadState testing_io_thread_state; | |
| 543 | |
| 544 TestingProfile* profile = | |
| 545 profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy"); | |
| 546 CloudPrintProxyServiceFactory::GetInstance()-> | |
| 547 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | |
| 548 | |
| 549 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | |
| 550 prefs->SetUserPref( | |
| 551 prefs::kCloudPrintEmail, | |
| 552 new base::StringValue(MockServiceIPCServer::EnabledUserId())); | |
| 553 | |
| 554 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
| 555 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | |
| 556 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | |
| 557 | |
| 558 WaitForConnect(); | |
| 559 base::RunLoop run_loop; | |
| 560 base::MessageLoop::current()->PostDelayedTask( | |
| 561 FROM_HERE, | |
| 562 run_loop.QuitClosure(), | |
| 563 TestTimeouts::action_timeout()); | |
| 564 | |
| 565 bool should_run_loop = LaunchBrowser(command_line, profile); | |
| 566 EXPECT_FALSE(should_run_loop); | |
| 567 if (should_run_loop) | |
| 568 run_loop.Run(); | |
| 569 | |
| 570 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), | |
| 571 prefs->GetString(prefs::kCloudPrintEmail)); | |
| 572 | |
| 573 ShutdownAndWaitForExitWithTimeout(process.Pass()); | |
| 574 content::RunAllPendingInMessageLoop(); | |
| 575 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); | |
| 576 } | |
| 577 | |
| 578 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { | |
| 579 base::Process process = | |
| 580 Launch("CloudPrintMockService_StartEnabledExpectDisabled"); | |
| 581 | |
| 582 TestingBrowserProcess* browser_process = | |
| 583 TestingBrowserProcess::GetGlobal(); | |
| 584 TestingProfileManager profile_manager(browser_process); | |
| 585 ASSERT_TRUE(profile_manager.SetUp()); | |
| 586 | |
| 587 // Must be created after the TestingProfileManager since that creates the | |
| 588 // LocalState for the BrowserProcess. Must be created before profiles are | |
| 589 // constructed. | |
| 590 chrome::TestingIOThreadState testing_io_thread_state; | |
| 591 | |
| 592 TestingProfile* profile = | |
| 593 profile_manager.CreateTestingProfile("StartBrowserWithPolicy"); | |
| 594 CloudPrintProxyServiceFactory::GetInstance()-> | |
| 595 SetTestingFactory(profile, CloudPrintProxyServiceFactoryForPolicyTest); | |
| 596 | |
| 597 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); | |
| 598 prefs->SetUserPref( | |
| 599 prefs::kCloudPrintEmail, | |
| 600 new base::StringValue(MockServiceIPCServer::EnabledUserId())); | |
| 601 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | |
| 602 new base::FundamentalValue(false)); | |
| 603 | |
| 604 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
| 605 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | |
| 606 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); | |
| 607 | |
| 608 WaitForConnect(); | |
| 609 base::RunLoop run_loop; | |
| 610 base::MessageLoop::current()->PostDelayedTask( | |
| 611 FROM_HERE, | |
| 612 run_loop.QuitClosure(), | |
| 613 TestTimeouts::action_timeout()); | |
| 614 | |
| 615 bool should_run_loop = LaunchBrowser(command_line, profile); | |
| 616 | |
| 617 // No expectations on run_loop being true here; that would be a race | |
| 618 // condition. | |
| 619 if (should_run_loop) | |
| 620 run_loop.Run(); | |
| 621 | |
| 622 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); | |
| 623 | |
| 624 ShutdownAndWaitForExitWithTimeout(process.Pass()); | |
| 625 content::RunAllPendingInMessageLoop(); | |
| 626 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); | |
| 627 } | |
| OLD | NEW |