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