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

Side by Side Diff: chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // CpuInfoProvider unit tests 5 // CpuInfoProvider unit tests
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" 9 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 public: 138 public:
139 CpuInfoProviderTest(); 139 CpuInfoProviderTest();
140 140
141 // A callback function to be called when CpuInfoProvider completes to sample. 141 // A callback function to be called when CpuInfoProvider completes to sample.
142 // Called on FILE thread. 142 // Called on FILE thread.
143 void OnCheckCpuSamplingFinishedForTesting(scoped_ptr<CpuUpdateInfo> info); 143 void OnCheckCpuSamplingFinishedForTesting(scoped_ptr<CpuUpdateInfo> info);
144 void CalculateExpectedResult(); 144 void CalculateExpectedResult();
145 void VerifyResult(); 145 void VerifyResult();
146 146
147 protected: 147 protected:
148 MessageLoop message_loop_; 148 base::MessageLoop message_loop_;
149 content::TestBrowserThread ui_thread_; 149 content::TestBrowserThread ui_thread_;
150 content::TestBrowserThread file_thread_; 150 content::TestBrowserThread file_thread_;
151 scoped_refptr<TestCpuInfoProvider> cpu_info_provider_; 151 scoped_refptr<TestCpuInfoProvider> cpu_info_provider_;
152 152
153 // Maintain the CpuUpdateInfo results returned by DoSample function. 153 // Maintain the CpuUpdateInfo results returned by DoSample function.
154 std::vector<TestCpuUpdateInfo> cpu_update_result_; 154 std::vector<TestCpuUpdateInfo> cpu_update_result_;
155 155
156 // Maintain the expected CpuUpdateInfo. 156 // Maintain the expected CpuUpdateInfo.
157 std::vector<TestCpuUpdateInfo> expected_cpu_update_result_; 157 std::vector<TestCpuUpdateInfo> expected_cpu_update_result_;
158 }; 158 };
159 159
160 CpuInfoProviderTest::CpuInfoProviderTest() 160 CpuInfoProviderTest::CpuInfoProviderTest()
161 : message_loop_(MessageLoop::TYPE_UI), 161 : message_loop_(base::MessageLoop::TYPE_UI),
162 ui_thread_(BrowserThread::UI, &message_loop_), 162 ui_thread_(BrowserThread::UI, &message_loop_),
163 file_thread_(BrowserThread::FILE, &message_loop_) { 163 file_thread_(BrowserThread::FILE, &message_loop_) {
164 } 164 }
165 165
166 void CpuInfoProviderTest::OnCheckCpuSamplingFinishedForTesting( 166 void CpuInfoProviderTest::OnCheckCpuSamplingFinishedForTesting(
167 scoped_ptr<CpuUpdateInfo> info) { 167 scoped_ptr<CpuUpdateInfo> info) {
168 // The cpu sampling is doing in FILE thread, so the callback function 168 // The cpu sampling is doing in FILE thread, so the callback function
169 // should be also called in FILE thread. 169 // should be also called in FILE thread.
170 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 170 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::FILE));
171 171
172 // Once the sampling completed, we need to quit the FILE thread to given 172 // Once the sampling completed, we need to quit the FILE thread to given
173 // UI thread a chance to verify results. 173 // UI thread a chance to verify results.
174 if (cpu_info_provider_->is_complete_sampling()) { 174 if (cpu_info_provider_->is_complete_sampling()) {
175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
176 MessageLoop::QuitClosure()); 176 base::MessageLoop::QuitClosure());
177 } 177 }
178 178
179 TestCpuUpdateInfo result; 179 TestCpuUpdateInfo result;
180 result.average_usage = info->average_usage; 180 result.average_usage = info->average_usage;
181 result.usage_per_processor = info->usage_per_processor; 181 result.usage_per_processor = info->usage_per_processor;
182 cpu_update_result_.push_back(result); 182 cpu_update_result_.push_back(result);
183 } 183 }
184 184
185 void CpuInfoProviderTest::CalculateExpectedResult() { 185 void CpuInfoProviderTest::CalculateExpectedResult() {
186 TestCpuInfoProvider::TestingCpuTimeDataPointer cpu_time_testing_data = 186 TestCpuInfoProvider::TestingCpuTimeDataPointer cpu_time_testing_data =
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 base::Bind(&CpuInfoProviderTest::OnCheckCpuSamplingFinishedForTesting, 273 base::Bind(&CpuInfoProviderTest::OnCheckCpuSamplingFinishedForTesting,
274 base::Unretained(this))); 274 base::Unretained(this)));
275 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 275 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
276 content::RunMessageLoop(); 276 content::RunMessageLoop();
277 cpu_info_provider_->StopSampling(); 277 cpu_info_provider_->StopSampling();
278 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 278 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
279 VerifyResult(); 279 VerifyResult();
280 } 280 }
281 281
282 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698