summaryrefslogtreecommitdiffstats
path: root/chrome/browser/diagnostics/diagnostics_model_unittest.cc
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-19 04:50:58 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-19 04:50:58 +0000
commitaedc9960f80930f1c5ed1059660f822533792bb9 (patch)
treeaeff6028eefc73c5c88dd02a73f6ce821197ba66 /chrome/browser/diagnostics/diagnostics_model_unittest.cc
parent74cda952e5725e71f2294d741ecde4424e760f48 (diff)
downloadchromium_src-aedc9960f80930f1c5ed1059660f822533792bb9.zip
chromium_src-aedc9960f80930f1c5ed1059660f822533792bb9.tar.gz
chromium_src-aedc9960f80930f1c5ed1059660f822533792bb9.tar.bz2
Introducing the diagnostic model classes
Chrome diagnostics wants to be a MVC, this is the classes that compose the model part. BUG=27885 TEST=included unit tests Review URL: http://codereview.chromium.org/385144 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/diagnostics/diagnostics_model_unittest.cc')
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc76
1 files changed, 76 insertions, 0 deletions
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
new file mode 100644
index 0000000..f6a7697
--- /dev/null
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
@@ -0,0 +1,76 @@
+// 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) {}
+
+ 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);
+ }
+
+ virtual void OnDoneAll(DiagnosticsModel* model) {
+ done_ = true;
+ EXPECT_TRUE(model != NULL);
+ }
+
+ bool done() const { return done_; }
+
+ int progress_called() const { return progress_called_; }
+
+ private:
+ bool done_;
+ int progress_called_;
+};
+
+// 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());
+}