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