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