| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/after_startup_task_utils.h" | 5 #include "chrome/browser/after_startup_task_utils.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 TestBrowserThreadBundle browser_thread_bundle_; | 132 TestBrowserThreadBundle browser_thread_bundle_; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 TEST_F(AfterStartupTaskTest, IsStartupComplete) { | 135 TEST_F(AfterStartupTaskTest, IsStartupComplete) { |
| 136 // Check IsBrowserStartupComplete on a background thread first to | 136 // Check IsBrowserStartupComplete on a background thread first to |
| 137 // verify that it does not allocate the underlying flag on that thread. | 137 // verify that it does not allocate the underlying flag on that thread. |
| 138 // That allocation thread correctness part of this test relies on | 138 // That allocation thread correctness part of this test relies on |
| 139 // the DCHECK in CancellationFlag::Set(). | 139 // the DCHECK in CancellationFlag::Set(). |
| 140 EXPECT_FALSE(GetIsBrowserStartupCompleteFromDBThread()); | 140 EXPECT_FALSE(GetIsBrowserStartupCompleteFromDBThread()); |
| 141 EXPECT_FALSE(AfterStartupTaskUtils::IsBrowserStartupComplete()); | 141 EXPECT_FALSE(AfterStartupTaskUtils::IsBrowserStartupComplete()); |
| 142 AfterStartupTaskUtils::SetBrowserStartupIsComplete(); | 142 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 143 EXPECT_TRUE(AfterStartupTaskUtils::IsBrowserStartupComplete()); | 143 EXPECT_TRUE(AfterStartupTaskUtils::IsBrowserStartupComplete()); |
| 144 EXPECT_TRUE(GetIsBrowserStartupCompleteFromDBThread()); | 144 EXPECT_TRUE(GetIsBrowserStartupCompleteFromDBThread()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 TEST_F(AfterStartupTaskTest, PostTask) { | 147 TEST_F(AfterStartupTaskTest, PostTask) { |
| 148 // Nothing should be posted prior to startup completion. | 148 // Nothing should be posted prior to startup completion. |
| 149 EXPECT_FALSE(AfterStartupTaskUtils::IsBrowserStartupComplete()); | 149 EXPECT_FALSE(AfterStartupTaskUtils::IsBrowserStartupComplete()); |
| 150 AfterStartupTaskUtils::PostTask( | 150 AfterStartupTaskUtils::PostTask( |
| 151 FROM_HERE, ui_thread_, | 151 FROM_HERE, ui_thread_, |
| 152 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, | 152 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, |
| 153 BrowserThread::UI)); | 153 BrowserThread::UI)); |
| 154 AfterStartupTaskUtils::PostTask( | 154 AfterStartupTaskUtils::PostTask( |
| 155 FROM_HERE, db_thread_, | 155 FROM_HERE, db_thread_, |
| 156 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, | 156 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, |
| 157 BrowserThread::DB)); | 157 BrowserThread::DB)); |
| 158 PostAfterStartupTaskFromDBThread( | 158 PostAfterStartupTaskFromDBThread( |
| 159 FROM_HERE, ui_thread_, | 159 FROM_HERE, ui_thread_, |
| 160 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, | 160 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, |
| 161 BrowserThread::UI)); | 161 BrowserThread::UI)); |
| 162 PostAfterStartupTaskFromDBThread( | 162 PostAfterStartupTaskFromDBThread( |
| 163 FROM_HERE, db_thread_, | 163 FROM_HERE, db_thread_, |
| 164 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, | 164 base::Bind(&AfterStartupTaskTest::VerifyExpectedThread, |
| 165 BrowserThread::DB)); | 165 BrowserThread::DB)); |
| 166 RunLoop().RunUntilIdle(); | 166 RunLoop().RunUntilIdle(); |
| 167 EXPECT_EQ(0, db_thread_->total_task_count() + ui_thread_->total_task_count()); | 167 EXPECT_EQ(0, db_thread_->total_task_count() + ui_thread_->total_task_count()); |
| 168 | 168 |
| 169 // Queued tasks should be posted upon setting the flag. | 169 // Queued tasks should be posted upon setting the flag. |
| 170 AfterStartupTaskUtils::SetBrowserStartupIsComplete(); | 170 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 171 EXPECT_EQ(2, db_thread_->posted_task_count()); | 171 EXPECT_EQ(2, db_thread_->posted_task_count()); |
| 172 EXPECT_EQ(2, ui_thread_->posted_task_count()); | 172 EXPECT_EQ(2, ui_thread_->posted_task_count()); |
| 173 FlushDBThread(); | 173 FlushDBThread(); |
| 174 RunLoop().RunUntilIdle(); | 174 RunLoop().RunUntilIdle(); |
| 175 EXPECT_EQ(2, db_thread_->ran_task_count()); | 175 EXPECT_EQ(2, db_thread_->ran_task_count()); |
| 176 EXPECT_EQ(2, ui_thread_->ran_task_count()); | 176 EXPECT_EQ(2, ui_thread_->ran_task_count()); |
| 177 | 177 |
| 178 db_thread_->reset_task_counts(); | 178 db_thread_->reset_task_counts(); |
| 179 ui_thread_->reset_task_counts(); | 179 ui_thread_->reset_task_counts(); |
| 180 EXPECT_EQ(0, db_thread_->total_task_count() + ui_thread_->total_task_count()); | 180 EXPECT_EQ(0, db_thread_->total_task_count() + ui_thread_->total_task_count()); |
| 181 | 181 |
| 182 // Tasks posted after startup should get posted immediately. | 182 // Tasks posted after startup should get posted immediately. |
| 183 AfterStartupTaskUtils::PostTask(FROM_HERE, ui_thread_, | 183 AfterStartupTaskUtils::PostTask(FROM_HERE, ui_thread_, |
| 184 base::Bind(&base::DoNothing)); | 184 base::Bind(&base::DoNothing)); |
| 185 AfterStartupTaskUtils::PostTask(FROM_HERE, db_thread_, | 185 AfterStartupTaskUtils::PostTask(FROM_HERE, db_thread_, |
| 186 base::Bind(&base::DoNothing)); | 186 base::Bind(&base::DoNothing)); |
| 187 EXPECT_EQ(1, db_thread_->posted_task_count()); | 187 EXPECT_EQ(1, db_thread_->posted_task_count()); |
| 188 EXPECT_EQ(1, ui_thread_->posted_task_count()); | 188 EXPECT_EQ(1, ui_thread_->posted_task_count()); |
| 189 PostAfterStartupTaskFromDBThread(FROM_HERE, ui_thread_, | 189 PostAfterStartupTaskFromDBThread(FROM_HERE, ui_thread_, |
| 190 base::Bind(&base::DoNothing)); | 190 base::Bind(&base::DoNothing)); |
| 191 PostAfterStartupTaskFromDBThread(FROM_HERE, db_thread_, | 191 PostAfterStartupTaskFromDBThread(FROM_HERE, db_thread_, |
| 192 base::Bind(&base::DoNothing)); | 192 base::Bind(&base::DoNothing)); |
| 193 EXPECT_EQ(2, db_thread_->posted_task_count()); | 193 EXPECT_EQ(2, db_thread_->posted_task_count()); |
| 194 EXPECT_EQ(2, ui_thread_->posted_task_count()); | 194 EXPECT_EQ(2, ui_thread_->posted_task_count()); |
| 195 FlushDBThread(); | 195 FlushDBThread(); |
| 196 RunLoop().RunUntilIdle(); | 196 RunLoop().RunUntilIdle(); |
| 197 EXPECT_EQ(2, db_thread_->ran_task_count()); | 197 EXPECT_EQ(2, db_thread_->ran_task_count()); |
| 198 EXPECT_EQ(2, ui_thread_->ran_task_count()); | 198 EXPECT_EQ(2, ui_thread_->ran_task_count()); |
| 199 } | 199 } |
| OLD | NEW |