Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | |
| 6 | |
| 7 #include "base/metrics/statistics_recorder.h" | |
| 8 #include "chrome/test/base/uma_histogram_helper.h" | |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace chromeos { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const char* const kHistogramsToSnapshot[] = { | |
| 17 "OOBE.NetworkErrorShown.TestScreen", | |
| 18 "OOBE.ErrorScreensTime.TestScreen.Portal"}; | |
| 19 } | |
| 20 | |
| 21 class ErrorScreensHistogramHelperTest : public testing::Test { | |
| 22 public: | |
| 23 virtual void SetUp() OVERRIDE { | |
| 24 { | |
| 25 // For histograms creation | |
| 26 ErrorScreensHistogramHelper thelp("TestScreen"); | |
| 27 thelp.OnScreenShow(); | |
| 28 thelp.OnErrorShow(ErrorScreen::ERROR_STATE_PORTAL); | |
| 29 } | |
| 30 histograms_.PrepareSnapshot(kHistogramsToSnapshot, | |
| 31 arraysize(kHistogramsToSnapshot)); | |
| 32 histograms_.Fetch(); | |
| 33 helper_.reset(new ErrorScreensHistogramHelper("TestScreen")); | |
| 34 } | |
|
ygorshenin1
2014/08/26 14:33:14
nit: could you please add a blank line after the c
Roman Sorokin (ftl)
2014/09/04 13:26:47
Done.
| |
| 35 content::TestBrowserThreadBundle thread_bundle_; | |
| 36 UMAHistogramHelper histograms_; | |
| 37 scoped_ptr<ErrorScreensHistogramHelper> helper_; | |
| 38 }; | |
| 39 | |
| 40 // No errors when screen was not shown. | |
| 41 TEST_F(ErrorScreensHistogramHelperTest, DoesNotShowScreen) { | |
| 42 helper_.reset(); | |
| 43 histograms_.ExpectTotalCount("OOBE.NetworkErrorShown.TestScreen", 0); | |
| 44 } | |
| 45 | |
| 46 // No errors when screen was shown and error was not. | |
| 47 TEST_F(ErrorScreensHistogramHelperTest, ShowScreenWithoutError) { | |
| 48 helper_->OnScreenShow(); | |
| 49 helper_.reset(); | |
| 50 histograms_.ExpectUniqueSample( | |
| 51 "OOBE.NetworkErrorShown.TestScreen", ErrorScreen::ERROR_STATE_NONE, 1); | |
| 52 } | |
| 53 | |
| 54 // Show 3 offline errors and 1 portal error. Make sure in time histograms logged | |
| 55 // portal error only. | |
| 56 TEST_F(ErrorScreensHistogramHelperTest, ShowScreenAndError) { | |
| 57 helper_->OnScreenShow(); | |
| 58 helper_->OnErrorShow(ErrorScreen::ERROR_STATE_OFFLINE); | |
| 59 helper_->OnErrorShow(ErrorScreen::ERROR_STATE_OFFLINE); | |
| 60 helper_->OnErrorHide(); | |
| 61 helper_->OnErrorShow(ErrorScreen::ERROR_STATE_OFFLINE); | |
| 62 histograms_.ExpectUniqueSample( | |
| 63 "OOBE.NetworkErrorShown.TestScreen", ErrorScreen::ERROR_STATE_OFFLINE, 3); | |
| 64 helper_->OnErrorShow(ErrorScreen::ERROR_STATE_PORTAL); | |
| 65 histograms_.ExpectBucketCount( | |
| 66 "OOBE.NetworkErrorShown.TestScreen", ErrorScreen::ERROR_STATE_PORTAL, 1); | |
| 67 histograms_.ExpectTotalCount("OOBE.ErrorScreensTime.TestScreen.Portal", 0); | |
| 68 helper_.reset(); | |
| 69 histograms_.ExpectTotalCount("OOBE.ErrorScreensTime.TestScreen.Portal", 1); | |
| 70 } | |
| 71 | |
| 72 // Show error and hide it after 1 sec. | |
| 73 TEST_F(ErrorScreensHistogramHelperTest, TestShowHideTime) { | |
| 74 helper_->OnScreenShow(); | |
| 75 base::Time now = base::Time::Now(); | |
| 76 helper_->OnErrorShowTime(ErrorScreen::ERROR_STATE_PORTAL, now); | |
| 77 now += base::TimeDelta::FromMilliseconds(1000); | |
| 78 helper_->OnErrorHideTime(now); | |
| 79 helper_.reset(); | |
| 80 histograms_.ExpectUniqueSample( | |
| 81 "OOBE.ErrorScreensTime.TestScreen.Portal", 1000, 1); | |
| 82 } | |
| 83 | |
| 84 // Show, hide, show, hide error with 1 sec interval. Make sure time logged in | |
| 85 // histogram is 2 sec. | |
| 86 TEST_F(ErrorScreensHistogramHelperTest, TestShowHideShowHideTime) { | |
| 87 helper_->OnScreenShow(); | |
| 88 base::Time now = base::Time::Now(); | |
| 89 helper_->OnErrorShowTime(ErrorScreen::ERROR_STATE_PROXY, now); | |
| 90 now += base::TimeDelta::FromMilliseconds(1000); | |
| 91 helper_->OnErrorHideTime(now); | |
| 92 now += base::TimeDelta::FromMilliseconds(1000); | |
| 93 helper_->OnErrorShowTime(ErrorScreen::ERROR_STATE_PORTAL, now); | |
| 94 now += base::TimeDelta::FromMilliseconds(1000); | |
| 95 helper_->OnErrorHideTime(now); | |
| 96 helper_.reset(); | |
| 97 histograms_.ExpectUniqueSample( | |
| 98 "OOBE.ErrorScreensTime.TestScreen.Portal", 2000, 1); | |
| 99 } | |
| 100 | |
| 101 // Show, show, hide error with 1 sec interval. Make sure time logged in | |
| 102 // histogram is 2 sec. | |
| 103 TEST_F(ErrorScreensHistogramHelperTest, TestShowShowHideTime) { | |
| 104 helper_->OnScreenShow(); | |
| 105 base::Time now = base::Time::Now(); | |
| 106 helper_->OnErrorShowTime(ErrorScreen::ERROR_STATE_PROXY, now); | |
| 107 now += base::TimeDelta::FromMilliseconds(1000); | |
| 108 helper_->OnErrorShowTime(ErrorScreen::ERROR_STATE_PORTAL, now); | |
| 109 now += base::TimeDelta::FromMilliseconds(1000); | |
| 110 helper_->OnErrorHideTime(now); | |
| 111 helper_.reset(); | |
| 112 histograms_.ExpectUniqueSample( | |
| 113 "OOBE.ErrorScreensTime.TestScreen.Portal", 2000, 1); | |
| 114 } | |
| 115 | |
| 116 } // namespace chromeos | |
| OLD | NEW |