Make the ChromeOS chromecast system tray integration use a private API.
[chromium-blink-merge.git] / chrome / browser / diagnostics / diagnostics_model_unittest.cc
blobd8404db9d85f5114d9213f4f28a02f4ad699a8c3
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.
5 #include "chrome/browser/diagnostics/diagnostics_model.h"
7 #include "base/command_line.h"
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace diagnostics {
14 // Basic harness to acquire and release the Diagnostic model object.
15 class DiagnosticsModelTest : public testing::Test {
16 protected:
17 DiagnosticsModelTest() : cmdline_(base::CommandLine::NO_PROGRAM) {}
19 ~DiagnosticsModelTest() override {}
21 void SetUp() override {
22 model_.reset(MakeDiagnosticsModel(cmdline_));
23 ASSERT_TRUE(model_.get() != NULL);
26 void TearDown() override { model_.reset(); }
28 scoped_ptr<DiagnosticsModel> model_;
29 base::CommandLine cmdline_;
31 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelTest);
34 // The test observer is used to know if the callbacks are being called.
35 class UTObserver: public DiagnosticsModel::Observer {
36 public:
37 UTObserver()
38 : tests_done_(false),
39 recovery_done_(false),
40 num_tested_(0),
41 num_recovered_(0) {
44 void OnTestFinished(int index, DiagnosticsModel* model) override {
45 EXPECT_TRUE(model != NULL);
46 ++num_tested_;
47 EXPECT_NE(DiagnosticsModel::TEST_FAIL_STOP,
48 model->GetTest(index).GetResult())
49 << "Failed stop test: " << index;
52 void OnAllTestsDone(DiagnosticsModel* model) override {
53 EXPECT_TRUE(model != NULL);
54 tests_done_ = true;
57 void OnRecoveryFinished(int index, DiagnosticsModel* model) override {
58 EXPECT_TRUE(model != NULL);
59 ++num_recovered_;
60 EXPECT_NE(DiagnosticsModel::RECOVERY_FAIL_STOP,
61 model->GetTest(index).GetResult())
62 << "Failed stop recovery: " << index;
65 void OnAllRecoveryDone(DiagnosticsModel* model) override {
66 EXPECT_TRUE(model != NULL);
67 recovery_done_ = true;
70 bool tests_done() const { return tests_done_; }
71 bool recovery_done() const { return recovery_done_; }
73 int num_tested() const { return num_tested_;}
74 int num_recovered() const { return num_recovered_;}
76 private:
77 bool tests_done_;
78 bool recovery_done_;
79 int num_tested_;
80 int num_recovered_;
82 DISALLOW_COPY_AND_ASSIGN(UTObserver);
85 // Test that the initial state is correct.
86 TEST_F(DiagnosticsModelTest, BeforeRun) {
87 int available = model_->GetTestAvailableCount();
88 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, available);
89 EXPECT_EQ(0, model_->GetTestRunCount());
90 EXPECT_EQ(DiagnosticsModel::TEST_NOT_RUN, model_->GetTest(0).GetResult());
93 // Run all the tests, verify that the basic callbacks are run and that the
94 // final state is correct.
95 TEST_F(DiagnosticsModelTest, RunAll) {
96 UTObserver observer;
97 EXPECT_FALSE(observer.tests_done());
98 model_->RunAll(&observer);
99 EXPECT_TRUE(observer.tests_done());
100 EXPECT_FALSE(observer.recovery_done());
101 model_->RecoverAll(&observer);
102 EXPECT_TRUE(observer.recovery_done());
103 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, model_->GetTestRunCount());
104 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, observer.num_tested());
105 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, observer.num_recovered());
108 } // namespace diagnostics