Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/diagnostics/diagnostics_model_unittest.cc

Issue 16948012: This adds a recovery mode to the diagnostics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload after merge Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace diagnostics { 12 namespace diagnostics {
12 13
13 // Basic harness to acquire and release the Diagnostic model object. 14 // Basic harness to acquire and release the Diagnostic model object.
14 class DiagnosticsModelTest : public testing::Test { 15 class DiagnosticsModelTest : public testing::Test {
15 protected: 16 protected:
16 DiagnosticsModelTest() 17 DiagnosticsModelTest()
17 : model_(NULL), 18 : cmdline_(CommandLine::NO_PROGRAM) {
18 cmdline_(CommandLine::NO_PROGRAM) {
19 } 19 }
20 20
21 virtual ~DiagnosticsModelTest() { } 21 virtual ~DiagnosticsModelTest() { }
22 22
23 virtual void SetUp() { 23 virtual void SetUp() {
24 model_ = MakeDiagnosticsModel(cmdline_); 24 model_.reset(MakeDiagnosticsModel(cmdline_));
25 ASSERT_TRUE(model_ != NULL); 25 ASSERT_TRUE(model_.get() != NULL);
26 } 26 }
27 27
28 virtual void TearDown() { 28 virtual void TearDown() {
29 delete model_; 29 model_.reset();
30 } 30 }
31 31
32 DiagnosticsModel* model_; 32 scoped_ptr<DiagnosticsModel> model_;
33 CommandLine cmdline_; 33 CommandLine cmdline_;
34
35 DISALLOW_COPY_AND_ASSIGN(DiagnosticsModelTest);
34 }; 36 };
35 37
36 // The test observer is used to know if the callbacks are being called. 38 // The test observer is used to know if the callbacks are being called.
37 class UTObserver: public DiagnosticsModel::Observer { 39 class UTObserver: public DiagnosticsModel::Observer {
38 public: 40 public:
39 UTObserver() 41 UTObserver()
40 : done_(false), 42 : tests_done_(false),
41 finished_(0), 43 recovery_done_(false),
42 id_of_failed_stop_test(-1) { 44 num_tested_(0),
45 num_recovered_(0) {
43 } 46 }
44 47
45 virtual void OnFinished(int index, DiagnosticsModel* model) OVERRIDE { 48 virtual void OnTestFinished(int index, DiagnosticsModel* model) OVERRIDE {
46 EXPECT_TRUE(model != NULL); 49 EXPECT_TRUE(model != NULL);
47 ++finished_; 50 ++num_tested_;
48 if (model->GetTest(index).GetResult() == DiagnosticsModel::TEST_FAIL_STOP) { 51 EXPECT_NE(DiagnosticsModel::TEST_FAIL_STOP,
49 id_of_failed_stop_test = index; 52 model->GetTest(index).GetResult())
50 ASSERT_TRUE(false); 53 << "Failed stop test: " << index;
51 }
52 } 54 }
53 55
54 virtual void OnDoneAll(DiagnosticsModel* model) OVERRIDE { 56 virtual void OnAllTestsDone(DiagnosticsModel* model) OVERRIDE {
55 done_ = true;
56 EXPECT_TRUE(model != NULL); 57 EXPECT_TRUE(model != NULL);
58 tests_done_ = true;
57 } 59 }
58 60
59 bool done() const { return done_; } 61 virtual void OnRecoveryFinished(int index, DiagnosticsModel* model) OVERRIDE {
62 EXPECT_TRUE(model != NULL);
63 ++num_recovered_;
64 EXPECT_NE(DiagnosticsModel::RECOVERY_FAIL_STOP,
65 model->GetTest(index).GetResult())
66 << "Failed stop recovery: " << index;
67 }
60 68
61 int finished() const { return finished_;} 69 virtual void OnAllRecoveryDone(DiagnosticsModel* model) OVERRIDE {
70 EXPECT_TRUE(model != NULL);
71 recovery_done_ = true;
72 }
73
74 bool tests_done() const { return tests_done_; }
75 bool recovery_done() const { return recovery_done_; }
76
77 int num_tested() const { return num_tested_;}
78 int num_recovered() const { return num_recovered_;}
62 79
63 private: 80 private:
64 bool done_; 81 bool tests_done_;
65 int finished_; 82 bool recovery_done_;
66 int id_of_failed_stop_test; 83 int num_tested_;
84 int num_recovered_;
85
86 DISALLOW_COPY_AND_ASSIGN(UTObserver);
67 }; 87 };
68 88
69 // This is the count of tests on each platform.
70 #if defined(OS_WIN)
71 const int kDiagnosticsTestCount = 19;
72 #elif defined(OS_MACOSX)
73 const int kDiagnosticsTestCount = 16;
74 #elif defined(OS_POSIX)
75 #if defined(OS_CHROMEOS)
76 const int kDiagnosticsTestCount = 19;
77 #else
78 const int kDiagnosticsTestCount = 17;
79 #endif
80 #endif
81
82 // Test that the initial state is correct. 89 // Test that the initial state is correct.
83 TEST_F(DiagnosticsModelTest, BeforeRun) { 90 TEST_F(DiagnosticsModelTest, BeforeRun) {
84 int available = model_->GetTestAvailableCount(); 91 int available = model_->GetTestAvailableCount();
85 EXPECT_EQ(kDiagnosticsTestCount, available); 92 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, available);
86 EXPECT_EQ(0, model_->GetTestRunCount()); 93 EXPECT_EQ(0, model_->GetTestRunCount());
87 EXPECT_EQ(DiagnosticsModel::TEST_NOT_RUN, model_->GetTest(0).GetResult()); 94 EXPECT_EQ(DiagnosticsModel::TEST_NOT_RUN, model_->GetTest(0).GetResult());
88 } 95 }
89 96
90 // Run all the tests, verify that the basic callbacks are run and that the 97 // Run all the tests, verify that the basic callbacks are run and that the
91 // final state is correct. 98 // final state is correct.
92 TEST_F(DiagnosticsModelTest, RunAll) { 99 TEST_F(DiagnosticsModelTest, RunAll) {
93 UTObserver observer; 100 UTObserver observer;
94 EXPECT_FALSE(observer.done()); 101 EXPECT_FALSE(observer.tests_done());
95 model_->RunAll(&observer); 102 model_->RunAll(&observer);
96 EXPECT_TRUE(observer.done()); 103 EXPECT_TRUE(observer.tests_done());
97 EXPECT_EQ(kDiagnosticsTestCount, model_->GetTestRunCount()); 104 EXPECT_FALSE(observer.recovery_done());
98 EXPECT_EQ(kDiagnosticsTestCount, observer.finished()); 105 model_->RecoverAll(&observer);
106 EXPECT_TRUE(observer.recovery_done());
107 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, model_->GetTestRunCount());
108 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, observer.num_tested());
109 EXPECT_EQ(DiagnosticsModel::kDiagnosticsTestCount, observer.num_recovered());
99 } 110 }
100 111
101 } // namespace diagnostics 112 } // namespace diagnostics
OLDNEW
« no previous file with comments | « chrome/browser/diagnostics/diagnostics_model.cc ('k') | chrome/browser/diagnostics/diagnostics_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698