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 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/compiler_specific.h" 9 #include "chrome/browser/diagnostics/diagnostics_model.h" 10 11 namespace base { 12 class FilePath; 13 } 14 15 namespace diagnostics { 16 17 // Represents a single diagnostic test and encapsulates the common 18 // functionality across platforms as well. 19 // It also implements the TestInfo interface providing the storage 20 // for the outcome of the test. 21 // Specific tests need (minimally) only to: 22 // 1- override ExecuteImpl() to implement the test. 23 // 2- call RecordStopFailure() or RecordFailure() or RecordSuccess() 24 // at the end of the test. 25 // 3- Optionally call observer->OnProgress() if the test is long. 26 // 4- Optionally call observer->OnSkipped() if the test cannot be run. 27 class DiagnosticsTest : public DiagnosticsModel::TestInfo { 28 public: 29 // |id| is a parse-able ASCII ID string that uniquely identifies the test. It 30 // should only have letters, numbers and underscores in it (and no spaces). 31 // |title| is the human readable string that says what the objective of the 32 // test is. 33 DiagnosticsTest(const std::string& id, const std::string& title); 34 35 virtual ~DiagnosticsTest(); 36 37 // Runs the test. Returning false signals that no more tests should be run. 38 // The actual outcome of the test should be set using the RecordXX functions. 39 bool Execute(DiagnosticsModel::Observer* observer, DiagnosticsModel* model, 40 size_t index); 41 42 // Runs any recovery steps for the test. Returning false signals that no more 43 // recovery should be attempted. 44 bool Recover(DiagnosticsModel::Observer* observer, DiagnosticsModel* model, 45 size_t index); 46 47 void RecordStopFailure(int outcome_code, const std::string& additional_info) { 48 RecordOutcome( 49 outcome_code, additional_info, DiagnosticsModel::TEST_FAIL_STOP); 50 } 51 52 void RecordFailure(int outcome_code, const std::string& additional_info) { 53 RecordOutcome( 54 outcome_code, additional_info, DiagnosticsModel::TEST_FAIL_CONTINUE); 55 } 56 57 void RecordSuccess(const std::string& additional_info) { 58 RecordOutcome(0, additional_info, DiagnosticsModel::TEST_OK); 59 } 60 61 void RecordOutcome(int outcome_code, 62 const std::string& additional_info, 63 DiagnosticsModel::TestResult result); 64 65 static base::FilePath GetUserDefaultProfileDir(); 66 67 // DiagnosticsModel::TestInfo overrides 68 virtual std::string GetId() const OVERRIDE; 69 virtual std::string GetTitle() const OVERRIDE; 70 virtual DiagnosticsModel::TestResult GetResult() const OVERRIDE; 71 virtual std::string GetAdditionalInfo() const OVERRIDE; 72 virtual int GetOutcomeCode() const OVERRIDE; 73 virtual base::Time GetStartTime() const OVERRIDE; 74 virtual base::Time GetEndTime() const OVERRIDE; 75 protected: 76 // Derived classes override this method do perform the actual test. 77 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) = 0; 78 79 // Derived classes may override this method to perform a recovery, if recovery 80 // makes sense for the diagnostics test. 81 virtual bool RecoveryImpl(DiagnosticsModel::Observer* observer); 82 83 const std::string id_; 84 const std::string title_; 85 std::string additional_info_; 86 int outcome_code_; 87 DiagnosticsModel::TestResult result_; 88 base::Time start_time_; 89 base::Time end_time_; 90 }; 91 92 } // namespace diagnostics 93 #endif // CHROME_BROWSER_DIAGNOSTICS_DIAGNOSTICS_TEST_H_ 94