Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 }; 86 };
87 87
88 } // namespace 88 } // namespace
89 89
90 class TestServiceProcess : public ServiceProcess { 90 class TestServiceProcess : public ServiceProcess {
91 public: 91 public:
92 TestServiceProcess() { } 92 TestServiceProcess() { }
93 virtual ~TestServiceProcess() { } 93 virtual ~TestServiceProcess() { }
94 94
95 bool Initialize(MessageLoopForUI* message_loop, ServiceProcessState* state); 95 bool Initialize(base::MessageLoopForUI* message_loop,
96 ServiceProcessState* state);
96 97
97 base::MessageLoopProxy* IOMessageLoopProxy() { 98 base::MessageLoopProxy* IOMessageLoopProxy() {
98 return io_thread_->message_loop_proxy(); 99 return io_thread_->message_loop_proxy();
99 } 100 }
100 }; 101 };
101 102
102 bool TestServiceProcess::Initialize(MessageLoopForUI* message_loop, 103 bool TestServiceProcess::Initialize(base::MessageLoopForUI* message_loop,
103 ServiceProcessState* state) { 104 ServiceProcessState* state) {
104 main_message_loop_ = message_loop; 105 main_message_loop_ = message_loop;
105 106
106 service_process_state_.reset(state); 107 service_process_state_.reset(state);
107 108
108 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 109 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
109 io_thread_.reset(new base::Thread("TestServiceProcess_IO")); 110 io_thread_.reset(new base::Thread("TestServiceProcess_IO"));
110 return io_thread_->StartWithOptions(options); 111 return io_thread_->StartWithOptions(options);
111 } 112 }
112 113
113 // This mocks the service side IPC message handler, allowing us to have a 114 // This mocks the service side IPC message handler, allowing us to have a
114 // minimal service process. 115 // minimal service process.
115 class MockServiceIPCServer : public ServiceIPCServer { 116 class MockServiceIPCServer : public ServiceIPCServer {
116 public: 117 public:
117 static std::string EnabledUserId(); 118 static std::string EnabledUserId();
118 119
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return true; 196 return true;
196 } 197 }
197 198
198 typedef base::Callback<void(MockServiceIPCServer* server)> 199 typedef base::Callback<void(MockServiceIPCServer* server)>
199 SetExpectationsCallback; 200 SetExpectationsCallback;
200 201
201 // The return value from this routine is used as the exit code for the mock 202 // The return value from this routine is used as the exit code for the mock
202 // service process. Any non-zero return value will be printed out and can help 203 // service process. Any non-zero return value will be printed out and can help
203 // determine the failure. 204 // determine the failure.
204 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { 205 int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) {
205 MessageLoopForUI main_message_loop; 206 base::MessageLoopForUI main_message_loop;
206 main_message_loop.set_thread_name("Main Thread"); 207 main_message_loop.set_thread_name("Main Thread");
207 208
208 #if defined(OS_MACOSX) 209 #if defined(OS_MACOSX)
209 CommandLine* cl = CommandLine::ForCurrentProcess(); 210 CommandLine* cl = CommandLine::ForCurrentProcess();
210 if (!cl->HasSwitch(kTestExecutablePath)) 211 if (!cl->HasSwitch(kTestExecutablePath))
211 return kMissingSwitch; 212 return kMissingSwitch;
212 base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath); 213 base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath);
213 EXPECT_FALSE(executable_path.empty()); 214 EXPECT_FALSE(executable_path.empty());
214 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true); 215 MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true);
215 Launchd::ScopedInstance use_mock(&mock_launchd); 216 Launchd::ScopedInstance use_mock(&mock_launchd);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 309
309 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) { 310 bool LaunchBrowser(const CommandLine& command_line, Profile* profile) {
310 int return_code = 0; 311 int return_code = 0;
311 StartupBrowserCreator browser_creator; 312 StartupBrowserCreator browser_creator;
312 return StartupBrowserCreator::ProcessCmdLineImpl( 313 return StartupBrowserCreator::ProcessCmdLineImpl(
313 command_line, base::FilePath(), false, profile, 314 command_line, base::FilePath(), false, profile,
314 StartupBrowserCreator::Profiles(), &return_code, &browser_creator); 315 StartupBrowserCreator::Profiles(), &return_code, &browser_creator);
315 } 316 }
316 317
317 protected: 318 protected:
318 MessageLoopForUI message_loop_; 319 base::MessageLoopForUI message_loop_;
319 content::TestBrowserThread ui_thread_; 320 content::TestBrowserThread ui_thread_;
320 base::Thread io_thread_; 321 base::Thread io_thread_;
321 322
322 std::string startup_channel_id_; 323 std::string startup_channel_id_;
323 scoped_ptr<IPC::ChannelProxy> startup_channel_; 324 scoped_ptr<IPC::ChannelProxy> startup_channel_;
324 325
325 #if defined(OS_MACOSX) 326 #if defined(OS_MACOSX)
326 base::ScopedTempDir temp_dir_; 327 base::ScopedTempDir temp_dir_;
327 base::FilePath executable_path_, bundle_path_; 328 base::FilePath executable_path_, bundle_path_;
328 scoped_ptr<MockLaunchd> mock_launchd_; 329 scoped_ptr<MockLaunchd> mock_launchd_;
(...skipping 10 matching lines...) Expand all
339 void Wait() { 340 void Wait() {
340 if (seen_) 341 if (seen_)
341 return; 342 return;
342 running_ = true; 343 running_ = true;
343 content::RunMessageLoop(); 344 content::RunMessageLoop();
344 } 345 }
345 346
346 void Notify() { 347 void Notify() {
347 seen_ = true; 348 seen_ = true;
348 if (running_) 349 if (running_)
349 MessageLoopForUI::current()->Quit(); 350 base::MessageLoopForUI::current()->Quit();
350 } 351 }
351 352
352 private: 353 private:
353 bool seen_; 354 bool seen_;
354 bool running_; 355 bool running_;
355 }; 356 };
356 357
357 WindowedChannelConnectionObserver observer_; 358 WindowedChannelConnectionObserver observer_;
358 }; 359 };
359 360
360 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() 361 CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest()
361 : ui_thread_(content::BrowserThread::UI, &message_loop_), 362 : ui_thread_(content::BrowserThread::UI, &message_loop_),
362 io_thread_("CloudPrintProxyPolicyTestThread") { 363 io_thread_("CloudPrintProxyPolicyTestThread") {
363 } 364 }
364 365
365 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { 366 CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() {
366 } 367 }
367 368
368 void CloudPrintProxyPolicyStartupTest::SetUp() { 369 void CloudPrintProxyPolicyStartupTest::SetUp() {
369 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 370 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
370 ASSERT_TRUE(io_thread_.StartWithOptions(options)); 371 ASSERT_TRUE(io_thread_.StartWithOptions(options));
371 372
372 #if defined(OS_MACOSX) 373 #if defined(OS_MACOSX)
373 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 374 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
374 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(), 375 EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(),
375 "CloudPrintProxyTest", 376 "CloudPrintProxyTest",
376 &bundle_path_, 377 &bundle_path_,
377 &executable_path_)); 378 &executable_path_));
378 mock_launchd_.reset(new MockLaunchd(executable_path_, &message_loop_, 379 mock_launchd_.reset(new MockLaunchd(executable_path_, &message_loop_,
379 true, false)); 380 true, false));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService(); 480 TestingPrefServiceSyncable* prefs = profile->GetTestingPrefService();
480 prefs->SetUserPref(prefs::kCloudPrintEmail, 481 prefs->SetUserPref(prefs::kCloudPrintEmail,
481 Value::CreateStringValue( 482 Value::CreateStringValue(
482 MockServiceIPCServer::EnabledUserId())); 483 MockServiceIPCServer::EnabledUserId()));
483 484
484 CommandLine command_line(CommandLine::NO_PROGRAM); 485 CommandLine command_line(CommandLine::NO_PROGRAM);
485 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); 486 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy);
486 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); 487 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line);
487 488
488 WaitForConnect(); 489 WaitForConnect();
489 MessageLoop::current()->PostDelayedTask(FROM_HERE, 490 base::MessageLoop::current()->PostDelayedTask(
490 MessageLoop::QuitClosure(), 491 FROM_HERE,
491 TestTimeouts::action_timeout()); 492 base::MessageLoop::QuitClosure(),
493 TestTimeouts::action_timeout());
492 494
493 bool run_loop = LaunchBrowser(command_line, profile); 495 bool run_loop = LaunchBrowser(command_line, profile);
494 EXPECT_FALSE(run_loop); 496 EXPECT_FALSE(run_loop);
495 if (run_loop) 497 if (run_loop)
496 MessageLoop::current()->Run(); 498 base::MessageLoop::current()->Run();
497 499
498 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(), 500 EXPECT_EQ(MockServiceIPCServer::EnabledUserId(),
499 prefs->GetString(prefs::kCloudPrintEmail)); 501 prefs->GetString(prefs::kCloudPrintEmail));
500 502
501 ShutdownAndWaitForExitWithTimeout(handle); 503 ShutdownAndWaitForExitWithTimeout(handle);
502 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy"); 504 profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy");
503 } 505 }
504 506
505 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) { 507 TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
506 base::ProcessHandle handle = 508 base::ProcessHandle handle =
(...skipping 14 matching lines...) Expand all
521 Value::CreateStringValue( 523 Value::CreateStringValue(
522 MockServiceIPCServer::EnabledUserId())); 524 MockServiceIPCServer::EnabledUserId()));
523 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, 525 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
524 Value::CreateBooleanValue(false)); 526 Value::CreateBooleanValue(false));
525 527
526 CommandLine command_line(CommandLine::NO_PROGRAM); 528 CommandLine command_line(CommandLine::NO_PROGRAM);
527 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); 529 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy);
528 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); 530 test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line);
529 531
530 WaitForConnect(); 532 WaitForConnect();
531 MessageLoop::current()->PostDelayedTask(FROM_HERE, 533 base::MessageLoop::current()->PostDelayedTask(
532 MessageLoop::QuitClosure(), 534 FROM_HERE,
533 TestTimeouts::action_timeout()); 535 base::MessageLoop::QuitClosure(),
536 TestTimeouts::action_timeout());
534 537
535 bool run_loop = LaunchBrowser(command_line, profile); 538 bool run_loop = LaunchBrowser(command_line, profile);
536 539
537 // No expectations on run_loop being true here; that would be a race 540 // No expectations on run_loop being true here; that would be a race
538 // condition. 541 // condition.
539 if (run_loop) 542 if (run_loop)
540 MessageLoop::current()->Run(); 543 base::MessageLoop::current()->Run();
541 544
542 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail)); 545 EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail));
543 546
544 ShutdownAndWaitForExitWithTimeout(handle); 547 ShutdownAndWaitForExitWithTimeout(handle);
545 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy"); 548 profile_manager.DeleteTestingProfile("StartBrowserWithPolicy");
546 } 549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698