Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_browser_main_extra_parts_metrics_unittest.cc
blobace798f7ecf17fff1e7bb10e3b5dd61f7b457bc9
1 // Copyright 2015 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.
5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/test/histogram_tester.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/events/test/device_data_manager_test_api.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/screen.h"
15 #include "ui/gfx/test/test_screen.h"
17 namespace {
19 const char kTouchEventsEnabledHistogramName[] =
20 "Touchscreen.TouchEventsEnabled";
22 } // namespace
24 class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
25 public:
26 ChromeBrowserMainExtraPartsMetricsTest();
27 ~ChromeBrowserMainExtraPartsMetricsTest() override;
29 protected:
30 // Test API wrapping |device_data_manager_|.
31 ui::test::DeviceDataManagerTestAPI device_data_manager_test_api_;
33 private:
34 // Required by a ChromeBrowserMainExtraPartsMetrics test target.
35 base::MessageLoop message_loop_;
37 // Dummy screen required by a ChromeBrowserMainExtraPartsMetrics test target.
38 gfx::test::TestScreen test_screen_;
40 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsMetricsTest);
43 ChromeBrowserMainExtraPartsMetricsTest::ChromeBrowserMainExtraPartsMetricsTest()
44 : device_data_manager_test_api_() {
45 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &test_screen_);
48 ChromeBrowserMainExtraPartsMetricsTest::
49 ~ChromeBrowserMainExtraPartsMetricsTest() {
50 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr);
53 // Verify a TouchEventsEnabled value isn't recorded during construction.
54 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
55 VerifyTouchEventsEnabledIsNotRecordedAfterConstruction) {
56 base::HistogramTester histogram_tester;
57 ChromeBrowserMainExtraPartsMetrics test_target;
58 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 0);
61 #if defined(USE_OZONE) || defined(USE_X11)
63 // Verify a TouchEventsEnabled value isn't recorded during PostBrowserStart if
64 // the device scan hasn't completed yet.
65 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
66 VerifyTouchEventsEnabledIsNotRecordedAfterPostBrowserStart) {
67 base::HistogramTester histogram_tester;
69 ChromeBrowserMainExtraPartsMetrics test_target;
71 test_target.PostBrowserStart();
72 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 0);
75 // Verify a TouchEventsEnabled value is recorded during PostBrowserStart if the
76 // device scan has already completed.
77 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
78 VerifyTouchEventsEnabledIsRecordedAfterPostBrowserStart) {
79 base::HistogramTester histogram_tester;
81 device_data_manager_test_api_.OnDeviceListsComplete();
83 ChromeBrowserMainExtraPartsMetrics test_target;
85 test_target.PostBrowserStart();
86 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 1);
89 // Verify a TouchEventsEnabled value is recorded when an asynchronous device
90 // scan completes.
91 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
92 VerifyTouchEventsEnabledIsRecordedWhenDeviceListsComplete) {
93 base::HistogramTester histogram_tester;
94 ChromeBrowserMainExtraPartsMetrics test_target;
96 test_target.PostBrowserStart();
97 device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
98 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 1);
101 // Verify a TouchEventsEnabled value is only recorded once if multiple
102 // asynchronous device scans happen.
103 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
104 VerifyTouchEventsEnabledIsOnlyRecordedOnce) {
105 base::HistogramTester histogram_tester;
106 ChromeBrowserMainExtraPartsMetrics test_target;
108 test_target.PostBrowserStart();
109 device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
110 device_data_manager_test_api_.NotifyObserversDeviceListsComplete();
111 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 1);
114 #else
116 // Verify a TouchEventsEnabled value is recorded during PostBrowserStart.
117 TEST_F(ChromeBrowserMainExtraPartsMetricsTest,
118 VerifyTouchEventsEnabledIsRecordedAfterPostBrowserStart) {
119 base::HistogramTester histogram_tester;
120 ChromeBrowserMainExtraPartsMetrics test_target;
122 test_target.PostBrowserStart();
123 histogram_tester.ExpectTotalCount(kTouchEventsEnabledHistogramName, 1);
126 #endif // defined(USE_OZONE) || defined(USE_X11)