| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 // Keeps track of how many tests reported failure. | 240 // Keeps track of how many tests reported failure. |
| 241 int failures_; | 241 int failures_; |
| 242 | 242 |
| 243 DISALLOW_COPY_AND_ASSIGN(TestWriter); | 243 DISALLOW_COPY_AND_ASSIGN(TestWriter); |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 std::wstring PrintableUSCurrentTime() { | 246 std::wstring PrintableUSCurrentTime() { |
| 247 base::Time::Exploded exploded = {0}; | 247 base::Time::Exploded exploded = {0}; |
| 248 base::Time::Now().UTCExplode(&exploded); | 248 base::Time::Now().UTCExplode(&exploded); |
| 249 return base::StringPrintf(L"%d:%d:%d.%d:%d:%d", | 249 return ASCIIToWide(base::StringPrintf("%d:%d:%d.%d:%d:%d", |
| 250 exploded.year, | 250 exploded.year, |
| 251 exploded.month, | 251 exploded.month, |
| 252 exploded.day_of_month, | 252 exploded.day_of_month, |
| 253 exploded.hour, | 253 exploded.hour, |
| 254 exploded.minute, | 254 exploded.minute, |
| 255 exploded.second); | 255 exploded.second)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 // This class is a basic test controller. In this design the view (TestWriter) | 258 // This class is a basic test controller. In this design the view (TestWriter) |
| 259 // and the model (DiagnosticsModel) do not talk to each other directly but they | 259 // and the model (DiagnosticsModel) do not talk to each other directly but they |
| 260 // are mediated by the controller. This has a name: 'passive view'. | 260 // are mediated by the controller. This has a name: 'passive view'. |
| 261 // More info at http://martinfowler.com/eaaDev/PassiveScreen.html | 261 // More info at http://martinfowler.com/eaaDev/PassiveScreen.html |
| 262 class TestController : public DiagnosticsModel::Observer { | 262 class TestController : public DiagnosticsModel::Observer { |
| 263 public: | 263 public: |
| 264 explicit TestController(TestWriter* writer) | 264 explicit TestController(TestWriter* writer) |
| 265 : model_(NULL), | 265 : model_(NULL), |
| 266 writer_(writer) { | 266 writer_(writer) { |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Run all the diagnostics of |model| and invoke the view as the model | 269 // Run all the diagnostics of |model| and invoke the view as the model |
| 270 // callbacks arrive. | 270 // callbacks arrive. |
| 271 void Run(DiagnosticsModel* model) { | 271 void Run(DiagnosticsModel* model) { |
| 272 std::wstring title(L"Chrome Diagnostics Mode ("); | 272 std::wstring title(L"Chrome Diagnostics Mode ("); |
| 273 writer_->WriteInfoText(title.append(PrintableUSCurrentTime()) + L")\n"); | 273 writer_->WriteInfoText(title.append(PrintableUSCurrentTime()) + L")\n"); |
| 274 if (!model) { | 274 if (!model) { |
| 275 writer_->WriteResult(false, L"Diagnostics start", L"model is null"); | 275 writer_->WriteResult(false, L"Diagnostics start", L"model is null"); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 bool icu_result = icu_util::Initialize(); | 278 bool icu_result = icu_util::Initialize(); |
| 279 if (!icu_result) { | 279 if (!icu_result) { |
| 280 writer_->WriteResult(false, L"Diagnostics start", L"ICU failure"); | 280 writer_->WriteResult(false, L"Diagnostics start", L"ICU failure"); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); | 283 ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); |
| 284 int count = model->GetTestAvailableCount(); | 284 int count = model->GetTestAvailableCount(); |
| 285 writer_->WriteInfoText(base::StringPrintf( | 285 writer_->WriteInfoText(ASCIIToWide(base::StringPrintf( |
| 286 L"%d available test(s)\n\n", count)); | 286 "%d available test(s)\n\n", count))); |
| 287 model->RunAll(this); | 287 model->RunAll(this); |
| 288 } | 288 } |
| 289 | 289 |
| 290 // Next four are overridden from DiagnosticsModel::Observer. | 290 // Next four are overridden from DiagnosticsModel::Observer. |
| 291 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { | 291 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { |
| 292 } | 292 } |
| 293 | 293 |
| 294 virtual void OnSkipped(int id, DiagnosticsModel* model) { | 294 virtual void OnSkipped(int id, DiagnosticsModel* model) { |
| 295 // TODO(cpu): display skipped tests. | 295 // TODO(cpu): display skipped tests. |
| 296 } | 296 } |
| 297 | 297 |
| 298 virtual void OnFinished(int id, DiagnosticsModel* model) { | 298 virtual void OnFinished(int id, DiagnosticsModel* model) { |
| 299 // As each test completes we output the results. | 299 // As each test completes we output the results. |
| 300 ShowResult(&model->GetTest(id)); | 300 ShowResult(&model->GetTest(id)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 virtual void OnDoneAll(DiagnosticsModel* model) { | 303 virtual void OnDoneAll(DiagnosticsModel* model) { |
| 304 if (writer_->failures() > 0) { | 304 if (writer_->failures() > 0) { |
| 305 writer_->WriteInfoText(base::StringPrintf( | 305 writer_->WriteInfoText(ASCIIToWide(base::StringPrintf( |
| 306 L"DONE. %d failure(s)\n\n", writer_->failures())); | 306 "DONE. %d failure(s)\n\n", writer_->failures()))); |
| 307 } else { | 307 } else { |
| 308 writer_->WriteInfoText(L"DONE\n\n"); | 308 writer_->WriteInfoText(L"DONE\n\n"); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 private: | 312 private: |
| 313 void ShowResult(DiagnosticsModel::TestInfo* test_info) { | 313 void ShowResult(DiagnosticsModel::TestInfo* test_info) { |
| 314 bool success = (DiagnosticsModel::TEST_OK == test_info->GetResult()); | 314 bool success = (DiagnosticsModel::TEST_OK == test_info->GetResult()); |
| 315 writer_->WriteResult(success, UTF16ToWide(test_info->GetTitle()), | 315 writer_->WriteResult(success, UTF16ToWide(test_info->GetTitle()), |
| 316 UTF16ToWide(test_info->GetAdditionalInfo())); | 316 UTF16ToWide(test_info->GetAdditionalInfo())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 TestController controller(&writer); | 352 TestController controller(&writer); |
| 353 | 353 |
| 354 // Run all the diagnostic tests. | 354 // Run all the diagnostic tests. |
| 355 controller.Run(model); | 355 controller.Run(model); |
| 356 delete model; | 356 delete model; |
| 357 | 357 |
| 358 console->OnQuit(); | 358 console->OnQuit(); |
| 359 delete console; | 359 delete console; |
| 360 return 0; | 360 return 0; |
| 361 } | 361 } |
| OLD | NEW |