| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 #include "chrome/browser/diagnostics/diagnostics_model.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 // Basic harness to adquire and release the Diagnostic model object. |
| 9 class DiagnosticsModelTest : public testing::Test { |
| 10 protected: |
| 11 DiagnosticsModelTest() : model_(NULL) { } |
| 12 |
| 13 virtual ~DiagnosticsModelTest() { } |
| 14 |
| 15 virtual void SetUp() { |
| 16 model_ = MakeDiagnosticsModel(); |
| 17 ASSERT_TRUE(model_ != NULL); |
| 18 } |
| 19 |
| 20 virtual void TearDown() { |
| 21 delete model_; |
| 22 } |
| 23 |
| 24 DiagnosticsModel* model_; |
| 25 }; |
| 26 |
| 27 // The test observer is used to know if the callbacks are being called. |
| 28 class UTObserver: public DiagnosticsModel::Observer { |
| 29 public: |
| 30 UTObserver() : done_(false), progress_called_(0) {} |
| 31 |
| 32 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { |
| 33 EXPECT_TRUE(model != NULL); |
| 34 ++progress_called_; |
| 35 } |
| 36 |
| 37 virtual void OnSkipped(int id, DiagnosticsModel* model) { |
| 38 EXPECT_TRUE(model != NULL); |
| 39 } |
| 40 |
| 41 virtual void OnFinished(int id, DiagnosticsModel* model) { |
| 42 EXPECT_TRUE(model != NULL); |
| 43 } |
| 44 |
| 45 virtual void OnDoneAll(DiagnosticsModel* model) { |
| 46 done_ = true; |
| 47 EXPECT_TRUE(model != NULL); |
| 48 } |
| 49 |
| 50 bool done() const { return done_; } |
| 51 |
| 52 int progress_called() const { return progress_called_; } |
| 53 |
| 54 private: |
| 55 bool done_; |
| 56 int progress_called_; |
| 57 }; |
| 58 |
| 59 // Test that the initial state is correct. We only have one test |
| 60 TEST_F(DiagnosticsModelTest, BeforeRun) { |
| 61 int available = model_->GetTestAvailableCount(); |
| 62 EXPECT_EQ(1, available); |
| 63 EXPECT_EQ(0, model_->GetTestRunCount()); |
| 64 EXPECT_EQ(DiagnosticsModel::TEST_NOT_RUN, model_->GetTest(0).GetResult()); |
| 65 } |
| 66 |
| 67 // Run all the tests, verify that the basic callbacks are run and that the |
| 68 // final state is correct. |
| 69 TEST_F(DiagnosticsModelTest, RunAll) { |
| 70 UTObserver observer; |
| 71 EXPECT_FALSE(observer.done()); |
| 72 model_->RunAll(&observer); |
| 73 EXPECT_TRUE(observer.done()); |
| 74 EXPECT_GT(observer.progress_called(), 0); |
| 75 EXPECT_EQ(1, model_->GetTestRunCount()); |
| 76 } |
| OLD | NEW |