| 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 #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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Single task of the fake IO loop used in the test, that just waits until | 130 // Single task of the fake IO loop used in the test, that just waits until |
| 131 // it is signaled to quit or perform some work. | 131 // it is signaled to quit or perform some work. |
| 132 // |completion| is the event to wait for, and |work| is the task to invoke | 132 // |completion| is the event to wait for, and |work| is the task to invoke |
| 133 // when signaled. If the task returns false then this quits the IO loop. | 133 // when signaled. If the task returns false then this quits the IO loop. |
| 134 void BlockLoop(base::WaitableEvent* completion, base::Callback<bool()> work) { | 134 void BlockLoop(base::WaitableEvent* completion, base::Callback<bool()> work) { |
| 135 do { | 135 do { |
| 136 completion->Wait(); | 136 completion->Wait(); |
| 137 } while (work.Run()); | 137 } while (work.Run()); |
| 138 MessageLoop::current()->QuitNow(); | 138 base::MessageLoop::current()->QuitNow(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 ACTION_P(MockSessionManagerClientRetrievePolicyCallback, policy) { | 141 ACTION_P(MockSessionManagerClientRetrievePolicyCallback, policy) { |
| 142 arg0.Run(*policy); | 142 arg0.Run(*policy); |
| 143 } | 143 } |
| 144 | 144 |
| 145 ACTION_P(MockSessionManagerClientStorePolicyCallback, success) { | 145 ACTION_P(MockSessionManagerClientStorePolicyCallback, success) { |
| 146 arg1.Run(success); | 146 arg1.Run(success); |
| 147 } | 147 } |
| 148 | 148 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 161 // message loop, as does the file thread (which never actually gets | 161 // message loop, as does the file thread (which never actually gets |
| 162 // started - so this is a way to fake multiple threads on a single | 162 // started - so this is a way to fake multiple threads on a single |
| 163 // test thread). The IO thread does not get the message loop set, | 163 // test thread). The IO thread does not get the message loop set, |
| 164 // and is never started. This is necessary so that we skip various | 164 // and is never started. This is necessary so that we skip various |
| 165 // bits of initialization that get posted to the IO thread. We do | 165 // bits of initialization that get posted to the IO thread. We do |
| 166 // however, at one point in the test, temporarily set the message | 166 // however, at one point in the test, temporarily set the message |
| 167 // loop for the IO thread. | 167 // loop for the IO thread. |
| 168 LoginUtilsTest() | 168 LoginUtilsTest() |
| 169 : fake_io_thread_completion_(false, false), | 169 : fake_io_thread_completion_(false, false), |
| 170 fake_io_thread_("fake_io_thread"), | 170 fake_io_thread_("fake_io_thread"), |
| 171 loop_(MessageLoop::TYPE_IO), | 171 loop_(base::MessageLoop::TYPE_IO), |
| 172 browser_process_(TestingBrowserProcess::GetGlobal()), | 172 browser_process_(TestingBrowserProcess::GetGlobal()), |
| 173 local_state_(browser_process_), | 173 local_state_(browser_process_), |
| 174 ui_thread_(BrowserThread::UI, &loop_), | 174 ui_thread_(BrowserThread::UI, &loop_), |
| 175 db_thread_(BrowserThread::DB, &loop_), | 175 db_thread_(BrowserThread::DB, &loop_), |
| 176 file_thread_(BrowserThread::FILE, &loop_), | 176 file_thread_(BrowserThread::FILE, &loop_), |
| 177 mock_input_method_manager_(NULL), | 177 mock_input_method_manager_(NULL), |
| 178 mock_async_method_caller_(NULL), | 178 mock_async_method_caller_(NULL), |
| 179 connector_(NULL), | 179 connector_(NULL), |
| 180 cryptohome_(NULL), | 180 cryptohome_(NULL), |
| 181 cryptohome_client_(NULL), | 181 cryptohome_client_(NULL), |
| 182 prepared_profile_(NULL) {} | 182 prepared_profile_(NULL) {} |
| 183 | 183 |
| 184 virtual void SetUp() OVERRIDE { | 184 virtual void SetUp() OVERRIDE { |
| 185 // This test is not a full blown InProcessBrowserTest, and doesn't have | 185 // This test is not a full blown InProcessBrowserTest, and doesn't have |
| 186 // all the usual threads running. However a lot of subsystems pulled from | 186 // all the usual threads running. However a lot of subsystems pulled from |
| 187 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that | 187 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that |
| 188 // those tasks were posted. Those tasks in turn depend on a lot of other | 188 // those tasks were posted. Those tasks in turn depend on a lot of other |
| 189 // components that aren't there during this test, so this kludge is used to | 189 // components that aren't there during this test, so this kludge is used to |
| 190 // have a running IO loop that doesn't really execute any tasks. | 190 // have a running IO loop that doesn't really execute any tasks. |
| 191 // | 191 // |
| 192 // See InvokeOnIO() below for a way to perform specific tasks on IO, when | 192 // See InvokeOnIO() below for a way to perform specific tasks on IO, when |
| 193 // that's necessary. | 193 // that's necessary. |
| 194 | 194 |
| 195 // A thread is needed to create a new MessageLoop, since there can be only | 195 // A thread is needed to create a new MessageLoop, since there can be only |
| 196 // one loop per thread. | 196 // one loop per thread. |
| 197 fake_io_thread_.StartWithOptions( | 197 fake_io_thread_.StartWithOptions( |
| 198 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 198 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 199 MessageLoop* fake_io_loop = fake_io_thread_.message_loop(); | 199 base::MessageLoop* fake_io_loop = fake_io_thread_.message_loop(); |
| 200 // Make this loop enter the single task, BlockLoop(). Pass in the completion | 200 // Make this loop enter the single task, BlockLoop(). Pass in the completion |
| 201 // event and the work callback. | 201 // event and the work callback. |
| 202 fake_io_thread_.StopSoon(); | 202 fake_io_thread_.StopSoon(); |
| 203 fake_io_loop->PostTask( | 203 fake_io_loop->PostTask( |
| 204 FROM_HERE, | 204 FROM_HERE, |
| 205 base::Bind( | 205 base::Bind( |
| 206 BlockLoop, | 206 BlockLoop, |
| 207 &fake_io_thread_completion_, | 207 &fake_io_thread_completion_, |
| 208 base::Bind(&LoginUtilsTest::DoIOWork, base::Unretained(this)))); | 208 base::Bind(&LoginUtilsTest::DoIOWork, base::Unretained(this)))); |
| 209 // Map BrowserThread::IO to this loop. This allows posting to IO but nothing | 209 // Map BrowserThread::IO to this loop. This allows posting to IO but nothing |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 content::RunMessageLoop(); | 383 content::RunMessageLoop(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // Helper for BlockLoop, InvokeOnIO and QuitIOLoop. | 386 // Helper for BlockLoop, InvokeOnIO and QuitIOLoop. |
| 387 bool DoIOWork() { | 387 bool DoIOWork() { |
| 388 bool has_work = !fake_io_thread_work_.is_null(); | 388 bool has_work = !fake_io_thread_work_.is_null(); |
| 389 if (has_work) | 389 if (has_work) |
| 390 fake_io_thread_work_.Run(); | 390 fake_io_thread_work_.Run(); |
| 391 fake_io_thread_work_.Reset(); | 391 fake_io_thread_work_.Reset(); |
| 392 BrowserThread::PostTask( | 392 BrowserThread::PostTask( |
| 393 BrowserThread::UI, FROM_HERE, | 393 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 394 MessageLoop::QuitWhenIdleClosure()); | |
| 395 // If there was work then keep waiting for more work. | 394 // If there was work then keep waiting for more work. |
| 396 // If there was no work then quit the fake IO loop. | 395 // If there was no work then quit the fake IO loop. |
| 397 return has_work; | 396 return has_work; |
| 398 } | 397 } |
| 399 | 398 |
| 400 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { | 399 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { |
| 401 EXPECT_FALSE(prepared_profile_); | 400 EXPECT_FALSE(prepared_profile_); |
| 402 prepared_profile_ = profile; | 401 prepared_profile_ = profile; |
| 403 } | 402 } |
| 404 | 403 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 return PrepareDMServiceFetcher(kDMPolicyRequest, response); | 520 return PrepareDMServiceFetcher(kDMPolicyRequest, response); |
| 522 } | 521 } |
| 523 | 522 |
| 524 protected: | 523 protected: |
| 525 ScopedStubCrosEnabler stub_cros_enabler_; | 524 ScopedStubCrosEnabler stub_cros_enabler_; |
| 526 | 525 |
| 527 base::Closure fake_io_thread_work_; | 526 base::Closure fake_io_thread_work_; |
| 528 base::WaitableEvent fake_io_thread_completion_; | 527 base::WaitableEvent fake_io_thread_completion_; |
| 529 base::Thread fake_io_thread_; | 528 base::Thread fake_io_thread_; |
| 530 | 529 |
| 531 MessageLoop loop_; | 530 base::MessageLoop loop_; |
| 532 TestingBrowserProcess* browser_process_; | 531 TestingBrowserProcess* browser_process_; |
| 533 ScopedTestingLocalState local_state_; | 532 ScopedTestingLocalState local_state_; |
| 534 | 533 |
| 535 content::TestBrowserThread ui_thread_; | 534 content::TestBrowserThread ui_thread_; |
| 536 content::TestBrowserThread db_thread_; | 535 content::TestBrowserThread db_thread_; |
| 537 content::TestBrowserThread file_thread_; | 536 content::TestBrowserThread file_thread_; |
| 538 scoped_ptr<content::TestBrowserThread> io_thread_; | 537 scoped_ptr<content::TestBrowserThread> io_thread_; |
| 539 scoped_ptr<IOThread> io_thread_state_; | 538 scoped_ptr<IOThread> io_thread_state_; |
| 540 | 539 |
| 541 MockDBusThreadManager mock_dbus_thread_manager_; | 540 MockDBusThreadManager mock_dbus_thread_manager_; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 746 } |
| 748 | 747 |
| 749 INSTANTIATE_TEST_CASE_P( | 748 INSTANTIATE_TEST_CASE_P( |
| 750 LoginUtilsBlockingLoginTestInstance, | 749 LoginUtilsBlockingLoginTestInstance, |
| 751 LoginUtilsBlockingLoginTest, | 750 LoginUtilsBlockingLoginTest, |
| 752 testing::Values(0, 1, 2, 3, 4, 5)); | 751 testing::Values(0, 1, 2, 3, 4, 5)); |
| 753 | 752 |
| 754 } // namespace | 753 } // namespace |
| 755 | 754 |
| 756 } | 755 } |
| OLD | NEW |