summaryrefslogtreecommitdiffstats
path: root/chrome/browser/diagnostics/diagnostics_model_unittest.cc
blob: 442db84d5e194a8f2559034c21e1617e8c3a28a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/diagnostics/diagnostics_model.h"
#include "testing/gtest/include/gtest/gtest.h"

// Basic harness to adquire and release the Diagnostic model object.
class DiagnosticsModelTest : public testing::Test {
 protected:
  DiagnosticsModelTest() : model_(NULL) { }

  virtual ~DiagnosticsModelTest() { }

  virtual void SetUp() {
    model_ = MakeDiagnosticsModel();
    ASSERT_TRUE(model_ != NULL);
  }

  virtual void TearDown() {
    delete model_;
  }

  DiagnosticsModel* model_;
};

// The test observer is used to know if the callbacks are being called.
class UTObserver: public DiagnosticsModel::Observer {
 public:
  UTObserver() : done_(false), progress_called_(0), finished_(0) {}

  virtual void OnProgress(int id, int percent, DiagnosticsModel* model) {
    EXPECT_TRUE(model != NULL);
    ++progress_called_;
  }

  virtual void OnSkipped(int id, DiagnosticsModel* model) {
    EXPECT_TRUE(model != NULL);
  }

  virtual void OnFinished(int id, DiagnosticsModel* model) {
    EXPECT_TRUE(model != NULL);
    ++finished_;
  }

  virtual void OnDoneAll(DiagnosticsModel* model) {
    done_ = true;
    EXPECT_TRUE(model != NULL);
  }

  bool done() const { return done_; }

  int progress_called() const { return progress_called_; }

  int finished() const { return finished_;}

 private:
  bool done_;
  int progress_called_;
  int finished_;
};

// Test that the initial state is correct. We only have one test
TEST_F(DiagnosticsModelTest, BeforeRun) {
  int available = model_->GetTestAvailableCount();
  EXPECT_EQ(1, available);
  EXPECT_EQ(0, model_->GetTestRunCount());
  EXPECT_EQ(DiagnosticsModel::TEST_NOT_RUN, model_->GetTest(0).GetResult());
}

// Run all the tests, verify that the basic callbacks are run and that the
// final state is correct.
TEST_F(DiagnosticsModelTest, RunAll) {
  UTObserver observer;
  EXPECT_FALSE(observer.done());
  model_->RunAll(&observer);
  EXPECT_TRUE(observer.done());
  EXPECT_GT(observer.progress_called(), 0);
  EXPECT_EQ(1, model_->GetTestRunCount());
  EXPECT_EQ(1, observer.finished());
}