| 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/diagnostics/diagnostics_main.h" | 5 #include "chrome/browser/diagnostics/diagnostics_main.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 SimpleConsole* SimpleConsole::Create() { | 132 SimpleConsole* SimpleConsole::Create() { |
| 133 return new WinConsole(); | 133 return new WinConsole(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 #elif defined(OS_POSIX) | 136 #elif defined(OS_POSIX) |
| 137 | 137 |
| 138 class PosixConsole : public SimpleConsole { | 138 class PosixConsole : public SimpleConsole { |
| 139 public: | 139 public: |
| 140 PosixConsole() : use_color_(false) { } | 140 PosixConsole() : use_color_(false) { } |
| 141 | 141 |
| 142 virtual bool Init() { | 142 virtual bool Init() OVERRIDE { |
| 143 // Technically, we should also check the terminal capabilities before using | 143 // Technically, we should also check the terminal capabilities before using |
| 144 // color, but in practice this is unlikely to be an issue. | 144 // color, but in practice this is unlikely to be an issue. |
| 145 use_color_ = isatty(STDOUT_FILENO); | 145 use_color_ = isatty(STDOUT_FILENO); |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 virtual bool Write(const std::wstring& text) { | 149 virtual bool Write(const std::wstring& text) OVERRIDE { |
| 150 printf("%s", base::SysWideToNativeMB(text).c_str()); | 150 printf("%s", base::SysWideToNativeMB(text).c_str()); |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 virtual void OnQuit() { | 154 virtual void OnQuit() OVERRIDE { |
| 155 // The "press enter to continue" prompt isn't very unixy, so only do that on | 155 // The "press enter to continue" prompt isn't very unixy, so only do that on |
| 156 // Windows. | 156 // Windows. |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual bool SetColor(Color color) { | 159 virtual bool SetColor(Color color) OVERRIDE { |
| 160 if (!use_color_) | 160 if (!use_color_) |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 const char* code = "\033[m"; | 163 const char* code = "\033[m"; |
| 164 switch (color) { | 164 switch (color) { |
| 165 case RED: | 165 case RED: |
| 166 code = "\033[1;31m"; | 166 code = "\033[1;31m"; |
| 167 break; | 167 break; |
| 168 case GREEN: | 168 case GREEN: |
| 169 code = "\033[1;32m"; | 169 code = "\033[1;32m"; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); | 287 ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); |
| 288 int count = model->GetTestAvailableCount(); | 288 int count = model->GetTestAvailableCount(); |
| 289 writer_->WriteInfoText(base::StringPrintf( | 289 writer_->WriteInfoText(base::StringPrintf( |
| 290 "%d available test(s)\n\n", count)); | 290 "%d available test(s)\n\n", count)); |
| 291 model->RunAll(this); | 291 model->RunAll(this); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Next four are overridden from DiagnosticsModel::Observer. | 294 // Next four are overridden from DiagnosticsModel::Observer. |
| 295 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { | 295 virtual void OnProgress(int id, |
| 296 int percent, |
| 297 DiagnosticsModel* model) OVERRIDE { |
| 296 } | 298 } |
| 297 | 299 |
| 298 virtual void OnSkipped(int id, DiagnosticsModel* model) { | 300 virtual void OnSkipped(int id, DiagnosticsModel* model) OVERRIDE { |
| 299 // TODO(cpu): display skipped tests. | 301 // TODO(cpu): display skipped tests. |
| 300 } | 302 } |
| 301 | 303 |
| 302 virtual void OnFinished(int id, DiagnosticsModel* model) { | 304 virtual void OnFinished(int id, DiagnosticsModel* model) OVERRIDE { |
| 303 // As each test completes we output the results. | 305 // As each test completes we output the results. |
| 304 ShowResult(&model->GetTest(id)); | 306 ShowResult(&model->GetTest(id)); |
| 305 } | 307 } |
| 306 | 308 |
| 307 virtual void OnDoneAll(DiagnosticsModel* model) { | 309 virtual void OnDoneAll(DiagnosticsModel* model) OVERRIDE { |
| 308 if (writer_->failures() > 0) { | 310 if (writer_->failures() > 0) { |
| 309 writer_->WriteInfoText(base::StringPrintf( | 311 writer_->WriteInfoText(base::StringPrintf( |
| 310 "DONE. %d failure(s)\n\n", writer_->failures())); | 312 "DONE. %d failure(s)\n\n", writer_->failures())); |
| 311 } else { | 313 } else { |
| 312 writer_->WriteInfoText(L"DONE\n\n"); | 314 writer_->WriteInfoText(L"DONE\n\n"); |
| 313 } | 315 } |
| 314 } | 316 } |
| 315 | 317 |
| 316 private: | 318 private: |
| 317 void ShowResult(DiagnosticsModel::TestInfo* test_info) { | 319 void ShowResult(DiagnosticsModel::TestInfo* test_info) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 TestController controller(&writer); | 358 TestController controller(&writer); |
| 357 | 359 |
| 358 // Run all the diagnostic tests. | 360 // Run all the diagnostic tests. |
| 359 controller.Run(model); | 361 controller.Run(model); |
| 360 delete model; | 362 delete model; |
| 361 | 363 |
| 362 console->OnQuit(); | 364 console->OnQuit(); |
| 363 delete console; | 365 delete console; |
| 364 return 0; | 366 return 0; |
| 365 } | 367 } |
| OLD | NEW |