| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_ |
| 6 #define CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_ |
| 7 |
| 8 #include "base/string16.h" |
| 9 #include "chrome/browser/diagnostics/diagnostics_model.h" |
| 10 |
| 11 // Represents a single diagnostic test and encapsulates the common |
| 12 // functionality across platforms as well. |
| 13 // It also Implements the TestInfo interface providing the storage |
| 14 // for the outcome of the test. |
| 15 // Specific tests need (minimally) only to: |
| 16 // 1- override ExecuteImpl() to imnplement the test. |
| 17 // 2- call RecordStopFailure() or RecordFailure() or RecordSuccess() |
| 18 // at the end of the test. |
| 19 // 3- Optionally call observer->OnProgress() if the test is long. |
| 20 // 4- Optionally call observer->OnSkipped() if the test cannot be run. |
| 21 class DiagnosticTest : public DiagnosticsModel::TestInfo { |
| 22 public: |
| 23 // |title| is the human readable, localized string that says that |
| 24 // the objective of the test is. |
| 25 explicit DiagnosticTest(const string16& title) |
| 26 : title_(title), result_(DiagnosticsModel::TEST_NOT_RUN) {} |
| 27 |
| 28 virtual ~DiagnosticTest() {} |
| 29 |
| 30 // Runs the test. Returning false signals that no more tests should be run. |
| 31 // The actual outcome of the test should be set using the RecordXX functions. |
| 32 bool Execute(DiagnosticsModel::Observer* observer, DiagnosticsModel* model) { |
| 33 result_ = DiagnosticsModel::TEST_RUNNING; |
| 34 observer->OnProgress(GetId(), 0, model); |
| 35 return ExecuteImpl(observer); |
| 36 } |
| 37 |
| 38 virtual string16 GetTitle() { |
| 39 return title_; |
| 40 } |
| 41 |
| 42 virtual DiagnosticsModel::TestResult GetResult() { |
| 43 return result_; |
| 44 } |
| 45 |
| 46 virtual string16 GetAdditionalInfo() { |
| 47 return additional_info_; |
| 48 } |
| 49 |
| 50 void RecordStopFailure(const string16& additional_info) { |
| 51 RecordOutcome(additional_info, DiagnosticsModel::TEST_FAIL_STOP); |
| 52 } |
| 53 |
| 54 void RecordFailure(const string16& additional_info) { |
| 55 RecordOutcome(additional_info, DiagnosticsModel::TEST_FAIL_CONTINUE); |
| 56 } |
| 57 |
| 58 void RecordSuccess(const string16& additional_info) { |
| 59 RecordOutcome(additional_info, DiagnosticsModel::TEST_OK); |
| 60 } |
| 61 |
| 62 void RecordOutcome(const string16& additional_info, |
| 63 DiagnosticsModel::TestResult result) { |
| 64 additional_info_ = additional_info; |
| 65 result_ = result; |
| 66 } |
| 67 |
| 68 protected: |
| 69 // The id needs to be overriden by derived classes and must uniquely |
| 70 // identify this test so other test can refer to it. |
| 71 virtual int GetId() = 0; |
| 72 // Derived classes override this method do perform the actual test. |
| 73 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) = 0; |
| 74 |
| 75 string16 title_; |
| 76 string16 additional_info_; |
| 77 DiagnosticsModel::TestResult result_; |
| 78 }; |
| 79 |
| 80 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_ |
| OLD | NEW |