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

Side by Side Diff: chrome/browser/chromeos/login/login_utils_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 #include "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 // Single task of the fake IO loop used in the test, that just waits until 129 // Single task of the fake IO loop used in the test, that just waits until
130 // it is signaled to quit or perform some work. 130 // it is signaled to quit or perform some work.
131 // |completion| is the event to wait for, and |work| is the task to invoke 131 // |completion| is the event to wait for, and |work| is the task to invoke
132 // when signaled. If the task returns false then this quits the IO loop. 132 // when signaled. If the task returns false then this quits the IO loop.
133 void BlockLoop(base::WaitableEvent* completion, base::Callback<bool()> work) { 133 void BlockLoop(base::WaitableEvent* completion, base::Callback<bool()> work) {
134 do { 134 do {
135 completion->Wait(); 135 completion->Wait();
136 } while (work.Run()); 136 } while (work.Run());
137 MessageLoop::current()->QuitNow(); 137 base::MessageLoop::current()->QuitNow();
138 } 138 }
139 139
140 void CopyLockResult(base::RunLoop* loop, 140 void CopyLockResult(base::RunLoop* loop,
141 policy::EnterpriseInstallAttributes::LockResult* out, 141 policy::EnterpriseInstallAttributes::LockResult* out,
142 policy::EnterpriseInstallAttributes::LockResult result) { 142 policy::EnterpriseInstallAttributes::LockResult result) {
143 *out = result; 143 *out = result;
144 loop->Quit(); 144 loop->Quit();
145 } 145 }
146 146
147 class LoginUtilsTest : public testing::Test, 147 class LoginUtilsTest : public testing::Test,
148 public LoginUtils::Delegate, 148 public LoginUtils::Delegate,
149 public LoginStatusConsumer { 149 public LoginStatusConsumer {
150 public: 150 public:
151 // Initialization here is important. The UI thread gets the test's 151 // Initialization here is important. The UI thread gets the test's
152 // message loop, as does the file thread (which never actually gets 152 // message loop, as does the file thread (which never actually gets
153 // started - so this is a way to fake multiple threads on a single 153 // started - so this is a way to fake multiple threads on a single
154 // test thread). The IO thread does not get the message loop set, 154 // test thread). The IO thread does not get the message loop set,
155 // and is never started. This is necessary so that we skip various 155 // and is never started. This is necessary so that we skip various
156 // bits of initialization that get posted to the IO thread. We do 156 // bits of initialization that get posted to the IO thread. We do
157 // however, at one point in the test, temporarily set the message 157 // however, at one point in the test, temporarily set the message
158 // loop for the IO thread. 158 // loop for the IO thread.
159 LoginUtilsTest() 159 LoginUtilsTest()
160 : fake_io_thread_completion_(false, false), 160 : fake_io_thread_completion_(false, false),
161 fake_io_thread_("fake_io_thread"), 161 fake_io_thread_("fake_io_thread"),
162 loop_(MessageLoop::TYPE_IO), 162 loop_(base::MessageLoop::TYPE_IO),
163 browser_process_(TestingBrowserProcess::GetGlobal()), 163 browser_process_(TestingBrowserProcess::GetGlobal()),
164 local_state_(browser_process_), 164 local_state_(browser_process_),
165 ui_thread_(BrowserThread::UI, &loop_), 165 ui_thread_(BrowserThread::UI, &loop_),
166 db_thread_(BrowserThread::DB, &loop_), 166 db_thread_(BrowserThread::DB, &loop_),
167 file_thread_(BrowserThread::FILE, &loop_), 167 file_thread_(BrowserThread::FILE, &loop_),
168 mock_input_method_manager_(NULL), 168 mock_input_method_manager_(NULL),
169 mock_async_method_caller_(NULL), 169 mock_async_method_caller_(NULL),
170 connector_(NULL), 170 connector_(NULL),
171 cryptohome_(NULL), 171 cryptohome_(NULL),
172 prepared_profile_(NULL) {} 172 prepared_profile_(NULL) {}
173 173
174 virtual void SetUp() OVERRIDE { 174 virtual void SetUp() OVERRIDE {
175 // This test is not a full blown InProcessBrowserTest, and doesn't have 175 // This test is not a full blown InProcessBrowserTest, and doesn't have
176 // all the usual threads running. However a lot of subsystems pulled from 176 // all the usual threads running. However a lot of subsystems pulled from
177 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that 177 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that
178 // those tasks were posted. Those tasks in turn depend on a lot of other 178 // those tasks were posted. Those tasks in turn depend on a lot of other
179 // components that aren't there during this test, so this kludge is used to 179 // components that aren't there during this test, so this kludge is used to
180 // have a running IO loop that doesn't really execute any tasks. 180 // have a running IO loop that doesn't really execute any tasks.
181 // 181 //
182 // See InvokeOnIO() below for a way to perform specific tasks on IO, when 182 // See InvokeOnIO() below for a way to perform specific tasks on IO, when
183 // that's necessary. 183 // that's necessary.
184 184
185 // A thread is needed to create a new MessageLoop, since there can be only 185 // A thread is needed to create a new MessageLoop, since there can be only
186 // one loop per thread. 186 // one loop per thread.
187 fake_io_thread_.StartWithOptions( 187 fake_io_thread_.StartWithOptions(
188 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 188 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
189 MessageLoop* fake_io_loop = fake_io_thread_.message_loop(); 189 base::MessageLoop* fake_io_loop = fake_io_thread_.message_loop();
190 // Make this loop enter the single task, BlockLoop(). Pass in the completion 190 // Make this loop enter the single task, BlockLoop(). Pass in the completion
191 // event and the work callback. 191 // event and the work callback.
192 fake_io_thread_.StopSoon(); 192 fake_io_thread_.StopSoon();
193 fake_io_loop->PostTask( 193 fake_io_loop->PostTask(
194 FROM_HERE, 194 FROM_HERE,
195 base::Bind( 195 base::Bind(
196 BlockLoop, 196 BlockLoop,
197 &fake_io_thread_completion_, 197 &fake_io_thread_completion_,
198 base::Bind(&LoginUtilsTest::DoIOWork, base::Unretained(this)))); 198 base::Bind(&LoginUtilsTest::DoIOWork, base::Unretained(this))));
199 // Map BrowserThread::IO to this loop. This allows posting to IO but nothing 199 // Map BrowserThread::IO to this loop. This allows posting to IO but nothing
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 356 }
357 357
358 // Helper for BlockLoop, InvokeOnIO and QuitIOLoop. 358 // Helper for BlockLoop, InvokeOnIO and QuitIOLoop.
359 bool DoIOWork() { 359 bool DoIOWork() {
360 bool has_work = !fake_io_thread_work_.is_null(); 360 bool has_work = !fake_io_thread_work_.is_null();
361 if (has_work) 361 if (has_work)
362 fake_io_thread_work_.Run(); 362 fake_io_thread_work_.Run();
363 fake_io_thread_work_.Reset(); 363 fake_io_thread_work_.Reset();
364 BrowserThread::PostTask( 364 BrowserThread::PostTask(
365 BrowserThread::UI, FROM_HERE, 365 BrowserThread::UI, FROM_HERE,
366 MessageLoop::QuitWhenIdleClosure()); 366 base::MessageLoop::QuitWhenIdleClosure());
367 // If there was work then keep waiting for more work. 367 // If there was work then keep waiting for more work.
368 // If there was no work then quit the fake IO loop. 368 // If there was no work then quit the fake IO loop.
369 return has_work; 369 return has_work;
370 } 370 }
371 371
372 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { 372 virtual void OnProfilePrepared(Profile* profile) OVERRIDE {
373 EXPECT_FALSE(prepared_profile_); 373 EXPECT_FALSE(prepared_profile_);
374 prepared_profile_ = profile; 374 prepared_profile_ = profile;
375 } 375 }
376 376
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 return PrepareDMServiceFetcher(kDMPolicyRequest, response); 496 return PrepareDMServiceFetcher(kDMPolicyRequest, response);
497 } 497 }
498 498
499 protected: 499 protected:
500 ScopedStubCrosEnabler stub_cros_enabler_; 500 ScopedStubCrosEnabler stub_cros_enabler_;
501 501
502 base::Closure fake_io_thread_work_; 502 base::Closure fake_io_thread_work_;
503 base::WaitableEvent fake_io_thread_completion_; 503 base::WaitableEvent fake_io_thread_completion_;
504 base::Thread fake_io_thread_; 504 base::Thread fake_io_thread_;
505 505
506 MessageLoop loop_; 506 base::MessageLoop loop_;
507 TestingBrowserProcess* browser_process_; 507 TestingBrowserProcess* browser_process_;
508 ScopedTestingLocalState local_state_; 508 ScopedTestingLocalState local_state_;
509 509
510 content::TestBrowserThread ui_thread_; 510 content::TestBrowserThread ui_thread_;
511 content::TestBrowserThread db_thread_; 511 content::TestBrowserThread db_thread_;
512 content::TestBrowserThread file_thread_; 512 content::TestBrowserThread file_thread_;
513 scoped_ptr<content::TestBrowserThread> io_thread_; 513 scoped_ptr<content::TestBrowserThread> io_thread_;
514 scoped_ptr<IOThread> io_thread_state_; 514 scoped_ptr<IOThread> io_thread_state_;
515 515
516 MockDBusThreadManagerWithoutGMock mock_dbus_thread_manager_; 516 MockDBusThreadManagerWithoutGMock mock_dbus_thread_manager_;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 718 }
719 719
720 INSTANTIATE_TEST_CASE_P( 720 INSTANTIATE_TEST_CASE_P(
721 LoginUtilsBlockingLoginTestInstance, 721 LoginUtilsBlockingLoginTestInstance,
722 LoginUtilsBlockingLoginTest, 722 LoginUtilsBlockingLoginTest,
723 testing::Values(0, 1, 2, 3, 4, 5)); 723 testing::Values(0, 1, 2, 3, 4, 5));
724 724
725 } // namespace 725 } // namespace
726 726
727 } 727 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_performer.cc ('k') | chrome/browser/chromeos/login/merge_session_load_page_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698