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

Unified Diff: chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc

Issue 7345010: Tests for cloud policy UMA metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewed, rebased Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc
diff --git a/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc b/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cd2fcc4977b67b01d8b75cf8376a34c82046a27
--- /dev/null
+++ b/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc
@@ -0,0 +1,173 @@
+// Copyright (c) 2011 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 "base/basictypes.h"
+#include "base/logging.h"
+#include "base/metrics/histogram.h"
+#include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h"
+#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h"
+#include "chrome/browser/policy/cloud_policy_subsystem.h"
+#include "chrome/browser/policy/enterprise_metrics.h"
+#include "chrome/common/net/gaia/gaia_constants.h"
+#include "chrome/common/net/gaia/google_service_auth_error.h"
+#include "content/common/test_url_fetcher_factory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+namespace {
+
+void assert_handler(const std::string& str) {
+ LOG(INFO) << "Previous failure was expected, ignoring.";
+}
+
+} // namespace
+
+class EnterpriseMetricsEnrollmentTest : public WizardInProcessBrowserTest {
+ protected:
+ EnterpriseMetricsEnrollmentTest()
+ : WizardInProcessBrowserTest(
+ WizardController::kEnterpriseEnrollmentScreenName) {}
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ WizardInProcessBrowserTest::SetUpOnMainThread();
+
+ ASSERT_TRUE(controller() != NULL);
+
+ // Use mock URLFetchers.
+ URLFetcher::set_factory(&factory_);
+
+ screen_ = controller()->GetEnterpriseEnrollmentScreen();
+
+ ASSERT_TRUE(screen_ != NULL);
+ ASSERT_EQ(controller()->current_screen(), screen_);
+ }
+
+ virtual void CleanUpOnMainThread() OVERRIDE {
+ WizardInProcessBrowserTest::CleanUpOnMainThread();
+
+ // Check that no other counters were sampled.
+ base::Histogram::SampleSet samples;
+ GetSampleSet(&samples);
+ EXPECT_EQ(1, samples.TotalCount());
+ }
+
+ // This is used to let expected NOTREACHED paths go on instead of making
+ // the test fail. It will also let CHECKs and DCHECKs pass, but that should be
+ // tested elsewhere.
+ // The reason is that some code paths are not expected, but if they are
+ // executed we want to know about it, so there's a UMA metric for that.
+ // However, the NOTREACHED would make the test fail, so we disable it.
+ // There should be other unit tests that check the same code,
+ // but here we are just interested in the UMA samples.
+ void ExpectNOTREACHED() {
+ logging::SetLogAssertHandler(assert_handler);
+ }
+
+ void CheckSample(int sample) {
+ ASSERT_GE(sample, 0);
+ ASSERT_LT(sample, policy::kMetricEnrollmentSize);
+
+ base::Histogram::SampleSet samples;
+ GetSampleSet(&samples);
+ EXPECT_EQ(1, samples.counts(sample));
+ }
+
+ EnterpriseEnrollmentScreen* screen_;
+
+ private:
+ void GetSampleSet(base::Histogram::SampleSet* set) {
+ base::Histogram* histogram = NULL;
+ EXPECT_TRUE(base::StatisticsRecorder::FindHistogram(
+ policy::kMetricEnrollment, &histogram));
+ ASSERT_TRUE(histogram != NULL);
+ histogram->SnapshotSample(set);
+ }
+
+ TestURLFetcherFactory factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(EnterpriseMetricsEnrollmentTest);
+};
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentStart) {
+ screen_->Authenticate("", "", "", "");
+ CheckSample(policy::kMetricEnrollmentStarted);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentCancelled) {
+ screen_->CancelEnrollment();
+ CheckSample(policy::kMetricEnrollmentCancelled);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthTokenWrongService) {
+ ExpectNOTREACHED();
+ screen_->OnIssueAuthTokenSuccess(std::string(), std::string());
+ CheckSample(policy::kMetricEnrollmentOtherFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest,
+ AuthTokenCloudPolicyNotReady) {
+ ExpectNOTREACHED();
+ screen_->OnIssueAuthTokenSuccess(GaiaConstants::kDeviceManagementService,
+ std::string());
+ CheckSample(policy::kMetricEnrollmentOtherFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthTokenFailure) {
+ ExpectNOTREACHED();
+ GoogleServiceAuthError error(GoogleServiceAuthError::SERVICE_UNAVAILABLE);
+ screen_->OnIssueAuthTokenFailure(std::string(), error);
+ CheckSample(policy::kMetricEnrollmentOtherFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyBadToken) {
+ screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::BAD_GAIA_TOKEN,
+ policy::CloudPolicySubsystem::NO_DETAILS);
+ CheckSample(policy::kMetricEnrollmentPolicyFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyNetworkError) {
+ screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::NETWORK_ERROR,
+ policy::CloudPolicySubsystem::NO_DETAILS);
+ CheckSample(policy::kMetricEnrollmentPolicyFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyUnmanaged) {
+ screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::UNMANAGED,
+ policy::CloudPolicySubsystem::NO_DETAILS);
+ CheckSample(policy::kMetricEnrollmentNotSupported);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentOK) {
+ screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::SUCCESS,
+ policy::CloudPolicySubsystem::NO_DETAILS);
+ CheckSample(policy::kMetricEnrollmentOK);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorConnection) {
+ GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
+ screen_->OnClientLoginFailure(error);
+ CheckSample(policy::kMetricEnrollmentNetworkFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorLoginFailed) {
+ GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
+ screen_->OnClientLoginFailure(error);
+ CheckSample(policy::kMetricEnrollmentLoginFailed);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AccountDisabled) {
+ GoogleServiceAuthError error(GoogleServiceAuthError::ACCOUNT_DISABLED);
+ screen_->OnClientLoginFailure(error);
+ CheckSample(policy::kMetricEnrollmentNotSupported);
+}
+
+IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorUnexpected) {
+ GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
+ screen_->OnClientLoginFailure(error);
+ CheckSample(policy::kMetricEnrollmentNetworkFailed);
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/policy/enterprise_metrics_browsertest.cc ('k') | chrome/browser/policy/mock_cloud_policy_data_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698