| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/diagnostics/diagnostics_model.h" | 5 #include "chrome/browser/diagnostics/diagnostics_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 // Basic harness to adquire and release the Diagnostic model object. | 11 // Basic harness to adquire and release the Diagnostic model object. |
| 11 class DiagnosticsModelTest : public testing::Test { | 12 class DiagnosticsModelTest : public testing::Test { |
| 12 protected: | 13 protected: |
| 13 DiagnosticsModelTest() | 14 DiagnosticsModelTest() |
| 14 : model_(NULL), | 15 : model_(NULL), |
| 15 cmdline_(CommandLine::NO_PROGRAM) { | 16 cmdline_(CommandLine::NO_PROGRAM) { |
| 16 } | 17 } |
| 17 | 18 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 // The test observer is used to know if the callbacks are being called. | 34 // The test observer is used to know if the callbacks are being called. |
| 34 class UTObserver: public DiagnosticsModel::Observer { | 35 class UTObserver: public DiagnosticsModel::Observer { |
| 35 public: | 36 public: |
| 36 UTObserver() | 37 UTObserver() |
| 37 : done_(false), | 38 : done_(false), |
| 38 progress_called_(0), | 39 progress_called_(0), |
| 39 finished_(0), | 40 finished_(0), |
| 40 id_of_failed_stop_test(-1) { | 41 id_of_failed_stop_test(-1) { |
| 41 } | 42 } |
| 42 | 43 |
| 43 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { | 44 virtual void OnProgress(int id, |
| 45 int percent, |
| 46 DiagnosticsModel* model) OVERRIDE { |
| 44 EXPECT_TRUE(model != NULL); | 47 EXPECT_TRUE(model != NULL); |
| 45 ++progress_called_; | 48 ++progress_called_; |
| 46 } | 49 } |
| 47 | 50 |
| 48 virtual void OnSkipped(int id, DiagnosticsModel* model) { | 51 virtual void OnSkipped(int id, DiagnosticsModel* model) OVERRIDE { |
| 49 EXPECT_TRUE(model != NULL); | 52 EXPECT_TRUE(model != NULL); |
| 50 } | 53 } |
| 51 | 54 |
| 52 virtual void OnFinished(int id, DiagnosticsModel* model) { | 55 virtual void OnFinished(int id, DiagnosticsModel* model) OVERRIDE { |
| 53 EXPECT_TRUE(model != NULL); | 56 EXPECT_TRUE(model != NULL); |
| 54 ++finished_; | 57 ++finished_; |
| 55 if (model->GetTest(id).GetResult() == DiagnosticsModel::TEST_FAIL_STOP) { | 58 if (model->GetTest(id).GetResult() == DiagnosticsModel::TEST_FAIL_STOP) { |
| 56 id_of_failed_stop_test = id; | 59 id_of_failed_stop_test = id; |
| 57 ASSERT_TRUE(false); | 60 ASSERT_TRUE(false); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 | 63 |
| 61 virtual void OnDoneAll(DiagnosticsModel* model) { | 64 virtual void OnDoneAll(DiagnosticsModel* model) OVERRIDE { |
| 62 done_ = true; | 65 done_ = true; |
| 63 EXPECT_TRUE(model != NULL); | 66 EXPECT_TRUE(model != NULL); |
| 64 } | 67 } |
| 65 | 68 |
| 66 bool done() const { return done_; } | 69 bool done() const { return done_; } |
| 67 | 70 |
| 68 int progress_called() const { return progress_called_; } | 71 int progress_called() const { return progress_called_; } |
| 69 | 72 |
| 70 int finished() const { return finished_;} | 73 int finished() const { return finished_;} |
| 71 | 74 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 97 // final state is correct. | 100 // final state is correct. |
| 98 TEST_F(DiagnosticsModelTest, RunAll) { | 101 TEST_F(DiagnosticsModelTest, RunAll) { |
| 99 UTObserver observer; | 102 UTObserver observer; |
| 100 EXPECT_FALSE(observer.done()); | 103 EXPECT_FALSE(observer.done()); |
| 101 model_->RunAll(&observer); | 104 model_->RunAll(&observer); |
| 102 EXPECT_TRUE(observer.done()); | 105 EXPECT_TRUE(observer.done()); |
| 103 EXPECT_GT(observer.progress_called(), 0); | 106 EXPECT_GT(observer.progress_called(), 0); |
| 104 EXPECT_EQ(kDiagnosticsTestCount, model_->GetTestRunCount()); | 107 EXPECT_EQ(kDiagnosticsTestCount, model_->GetTestRunCount()); |
| 105 EXPECT_EQ(kDiagnosticsTestCount, observer.finished()); | 108 EXPECT_EQ(kDiagnosticsTestCount, observer.finished()); |
| 106 } | 109 } |
| OLD | NEW |