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

Side by Side Diff: chrome/browser/diagnostics/diagnostics_main.cc

Issue 6098004: Integrate about:conflicts with --diagnostics... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/diagnostics/diagnostics_model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/diagnostics/diagnostics_main.h" 5 #include "chrome/browser/diagnostics/diagnostics_main.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 #endif 10 #endif
11 11
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 #endif 198 #endif
199 199
200 // This class wraps a SimpleConsole for the specific use case of 200 // This class wraps a SimpleConsole for the specific use case of
201 // writing the results of the diagnostic tests. 201 // writing the results of the diagnostic tests.
202 // TODO(cpu) figure out the localization strategy. 202 // TODO(cpu) figure out the localization strategy.
203 class TestWriter { 203 class TestWriter {
204 public: 204 public:
205 // The |console| must be valid and properly initialized. This 205 // The |console| must be valid and properly initialized. This
206 // class does not own it. 206 // class does not own it.
207 explicit TestWriter(SimpleConsole* console) : console_(console) { 207 explicit TestWriter(SimpleConsole* console)
208 : console_(console),
209 failures_(0) {
208 } 210 }
209 211
212 // How many tests reported failure.
213 int failures() { return failures_; }
214
210 // Write an informational line of text in white over black. 215 // Write an informational line of text in white over black.
211 bool WriteInfoText(const std::wstring& txt) { 216 bool WriteInfoText(const std::wstring& txt) {
212 console_->SetColor(SimpleConsole::DEFAULT); 217 console_->SetColor(SimpleConsole::DEFAULT);
213 return console_->Write(txt); 218 return console_->Write(txt);
214 } 219 }
215 220
216 // Write a result block. It consist of two lines. The first line 221 // Write a result block. It consist of two lines. The first line
217 // has [PASS] or [FAIL] with |name| and the second line has 222 // has [PASS] or [FAIL] with |name| and the second line has
218 // the text in |extra|. 223 // the text in |extra|.
219 bool WriteResult(bool success, const std::wstring& name, 224 bool WriteResult(bool success, const std::wstring& name,
220 const std::wstring& extra) { 225 const std::wstring& extra) {
221 if (success) { 226 if (success) {
222 console_->SetColor(SimpleConsole::GREEN); 227 console_->SetColor(SimpleConsole::GREEN);
223 console_->Write(L"[PASS] "); 228 console_->Write(L"[PASS] ");
224 } else { 229 } else {
225 console_->SetColor(SimpleConsole::RED); 230 console_->SetColor(SimpleConsole::RED);
226 console_->Write(L"[FAIL] "); 231 console_->Write(L"[FAIL] ");
232 failures_++;
227 } 233 }
228 WriteInfoText(name + L"\n"); 234 WriteInfoText(name + L"\n");
229 std::wstring second_line(L" "); 235 std::wstring second_line(L" ");
230 second_line.append(extra); 236 second_line.append(extra);
231 return WriteInfoText(second_line + L"\n\n"); 237 return WriteInfoText(second_line + L"\n\n");
232 } 238 }
233 239
234 private: 240 private:
235 241
236 SimpleConsole* console_; 242 SimpleConsole* console_;
237 243
244 // Keeps track of how many tests reported failure.
245 int failures_;
246
238 DISALLOW_COPY_AND_ASSIGN(TestWriter); 247 DISALLOW_COPY_AND_ASSIGN(TestWriter);
239 }; 248 };
240 249
241 std::wstring PrintableUSCurrentTime() { 250 std::wstring PrintableUSCurrentTime() {
242 base::Time::Exploded exploded = {0}; 251 base::Time::Exploded exploded = {0};
243 base::Time::Now().UTCExplode(&exploded); 252 base::Time::Now().UTCExplode(&exploded);
244 return StringPrintf(L"%d:%d:%d.%d:%d:%d", 253 return StringPrintf(L"%d:%d:%d.%d:%d:%d",
245 exploded.year, exploded.month, exploded.day_of_month, 254 exploded.year, exploded.month, exploded.day_of_month,
246 exploded.hour, exploded.minute, exploded.second); 255 exploded.hour, exploded.minute, exploded.second);
247 } 256 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 virtual void OnSkipped(int id, DiagnosticsModel* model) { 292 virtual void OnSkipped(int id, DiagnosticsModel* model) {
284 // TODO(cpu): display skipped tests. 293 // TODO(cpu): display skipped tests.
285 } 294 }
286 295
287 virtual void OnFinished(int id, DiagnosticsModel* model) { 296 virtual void OnFinished(int id, DiagnosticsModel* model) {
288 // As each test completes we output the results. 297 // As each test completes we output the results.
289 ShowResult(model->GetTest(id)); 298 ShowResult(model->GetTest(id));
290 } 299 }
291 300
292 virtual void OnDoneAll(DiagnosticsModel* model) { 301 virtual void OnDoneAll(DiagnosticsModel* model) {
293 writer_->WriteInfoText(L"DONE\n\n"); 302 if (writer_->failures() > 0) {
303 writer_->WriteInfoText(StringPrintf(L"DONE. %d failure(s)\n\n",
304 writer_->failures()));
305 } else {
306 writer_->WriteInfoText(L"DONE\n\n");
307 }
294 } 308 }
295 309
296 private: 310 private:
297 void ShowResult(DiagnosticsModel::TestInfo& test_info) { 311 void ShowResult(DiagnosticsModel::TestInfo& test_info) {
298 bool success = (DiagnosticsModel::TEST_OK == test_info.GetResult()); 312 bool success = (DiagnosticsModel::TEST_OK == test_info.GetResult());
299 writer_->WriteResult(success, UTF16ToWide(test_info.GetTitle()), 313 writer_->WriteResult(success, UTF16ToWide(test_info.GetTitle()),
300 UTF16ToWide(test_info.GetAdditionalInfo())); 314 UTF16ToWide(test_info.GetAdditionalInfo()));
301 } 315 }
302 316
303 DiagnosticsModel* model_; 317 DiagnosticsModel* model_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // Windows. 357 // Windows.
344 #if defined(OS_WIN) 358 #if defined(OS_WIN)
345 // Block here so the user can see the results. 359 // Block here so the user can see the results.
346 writer.WriteInfoText(L"Press [enter] to continue\n"); 360 writer.WriteInfoText(L"Press [enter] to continue\n");
347 std::wstring txt; 361 std::wstring txt;
348 console->Read(&txt); 362 console->Read(&txt);
349 #endif 363 #endif
350 delete console; 364 delete console;
351 return 0; 365 return 0;
352 } 366 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/diagnostics/diagnostics_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698