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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/logging.h"
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h"
9 #include "chrome/browser/chromeos/login/wizard_controller.h"
10 #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h"
11 #include "chrome/browser/policy/cloud_policy_subsystem.h"
12 #include "chrome/browser/policy/enterprise_metrics.h"
13 #include "chrome/common/net/gaia/gaia_constants.h"
14 #include "chrome/common/net/gaia/google_service_auth_error.h"
15 #include "content/common/test_url_fetcher_factory.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace chromeos {
19
20 namespace {
21
22 void assert_handler(const std::string& str) {
23 LOG(INFO) << "Previous failure was expected, ignoring.";
24 }
25
26 } // namespace
27
28 class EnterpriseMetricsEnrollmentTest : public WizardInProcessBrowserTest {
29 protected:
30 EnterpriseMetricsEnrollmentTest()
31 : WizardInProcessBrowserTest(
32 WizardController::kEnterpriseEnrollmentScreenName) {}
33
34 virtual void SetUpOnMainThread() OVERRIDE {
35 WizardInProcessBrowserTest::SetUpOnMainThread();
36
37 ASSERT_TRUE(controller() != NULL);
38
39 // Use mock URLFetchers.
40 URLFetcher::set_factory(&factory_);
41
42 screen_ = controller()->GetEnterpriseEnrollmentScreen();
43
44 ASSERT_TRUE(screen_ != NULL);
45 ASSERT_EQ(controller()->current_screen(), screen_);
46 }
47
48 virtual void CleanUpOnMainThread() OVERRIDE {
49 WizardInProcessBrowserTest::CleanUpOnMainThread();
50
51 // Check that no other counters were sampled.
52 base::Histogram::SampleSet samples;
53 GetSampleSet(&samples);
54 EXPECT_EQ(1, samples.TotalCount());
55 }
56
57 // This is used to let expected NOTREACHED paths go on instead of making
58 // the test fail. It will also let CHECKs and DCHECKs pass, but that should be
59 // tested elsewhere.
60 // The reason is that some code paths are not expected, but if they are
61 // executed we want to know about it, so there's a UMA metric for that.
62 // However, the NOTREACHED would make the test fail, so we disable it.
63 // There should be other unit tests that check the same code,
64 // but here we are just interested in the UMA samples.
65 void ExpectNOTREACHED() {
66 logging::SetLogAssertHandler(assert_handler);
67 }
68
69 void CheckSample(int sample) {
70 ASSERT_GE(sample, 0);
71 ASSERT_LT(sample, policy::kMetricEnrollmentSize);
72
73 base::Histogram::SampleSet samples;
74 GetSampleSet(&samples);
75 EXPECT_EQ(1, samples.counts(sample));
76 }
77
78 EnterpriseEnrollmentScreen* screen_;
79
80 private:
81 void GetSampleSet(base::Histogram::SampleSet* set) {
82 base::Histogram* histogram = NULL;
83 EXPECT_TRUE(base::StatisticsRecorder::FindHistogram(
84 policy::kMetricEnrollment, &histogram));
85 ASSERT_TRUE(histogram != NULL);
86 histogram->SnapshotSample(set);
87 }
88
89 TestURLFetcherFactory factory_;
90
91 DISALLOW_COPY_AND_ASSIGN(EnterpriseMetricsEnrollmentTest);
92 };
93
94 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentStart) {
95 screen_->Authenticate("", "", "", "");
96 CheckSample(policy::kMetricEnrollmentStarted);
97 }
98
99 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentCancelled) {
100 screen_->CancelEnrollment();
101 CheckSample(policy::kMetricEnrollmentCancelled);
102 }
103
104 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthTokenWrongService) {
105 ExpectNOTREACHED();
106 screen_->OnIssueAuthTokenSuccess(std::string(), std::string());
107 CheckSample(policy::kMetricEnrollmentOtherFailed);
108 }
109
110 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest,
111 AuthTokenCloudPolicyNotReady) {
112 ExpectNOTREACHED();
113 screen_->OnIssueAuthTokenSuccess(GaiaConstants::kDeviceManagementService,
114 std::string());
115 CheckSample(policy::kMetricEnrollmentOtherFailed);
116 }
117
118 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthTokenFailure) {
119 ExpectNOTREACHED();
120 GoogleServiceAuthError error(GoogleServiceAuthError::SERVICE_UNAVAILABLE);
121 screen_->OnIssueAuthTokenFailure(std::string(), error);
122 CheckSample(policy::kMetricEnrollmentOtherFailed);
123 }
124
125 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyBadToken) {
126 screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::BAD_GAIA_TOKEN,
127 policy::CloudPolicySubsystem::NO_DETAILS);
128 CheckSample(policy::kMetricEnrollmentPolicyFailed);
129 }
130
131 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyNetworkError) {
132 screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::NETWORK_ERROR,
133 policy::CloudPolicySubsystem::NO_DETAILS);
134 CheckSample(policy::kMetricEnrollmentPolicyFailed);
135 }
136
137 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, OnPolicyUnmanaged) {
138 screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::UNMANAGED,
139 policy::CloudPolicySubsystem::NO_DETAILS);
140 CheckSample(policy::kMetricEnrollmentNotSupported);
141 }
142
143 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, EnrollmentOK) {
144 screen_->OnPolicyStateChanged(policy::CloudPolicySubsystem::SUCCESS,
145 policy::CloudPolicySubsystem::NO_DETAILS);
146 CheckSample(policy::kMetricEnrollmentOK);
147 }
148
149 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorConnection) {
150 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
151 screen_->OnClientLoginFailure(error);
152 CheckSample(policy::kMetricEnrollmentNetworkFailed);
153 }
154
155 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorLoginFailed) {
156 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
157 screen_->OnClientLoginFailure(error);
158 CheckSample(policy::kMetricEnrollmentLoginFailed);
159 }
160
161 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AccountDisabled) {
162 GoogleServiceAuthError error(GoogleServiceAuthError::ACCOUNT_DISABLED);
163 screen_->OnClientLoginFailure(error);
164 CheckSample(policy::kMetricEnrollmentNotSupported);
165 }
166
167 IN_PROC_BROWSER_TEST_F(EnterpriseMetricsEnrollmentTest, AuthErrorUnexpected) {
168 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
169 screen_->OnClientLoginFailure(error);
170 CheckSample(policy::kMetricEnrollmentNetworkFailed);
171 }
172
173 } // namespace chromeos
OLDNEW
« 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