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"
19 const char kTouchEventsEnabledHistogramName
[] =
20 "Touchscreen.TouchEventsEnabled";
24 class ChromeBrowserMainExtraPartsMetricsTest
: public testing::Test
{
26 ChromeBrowserMainExtraPartsMetricsTest();
27 ~ChromeBrowserMainExtraPartsMetricsTest() override
;
30 // Test API wrapping |device_data_manager_|.
31 ui::test::DeviceDataManagerTestAPI device_data_manager_test_api_
;
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 device_data_manager_test_api_
.CreateDeviceDataManagerInstance();
46 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE
, &test_screen_
);
49 ChromeBrowserMainExtraPartsMetricsTest::
50 ~ChromeBrowserMainExtraPartsMetricsTest() {
51 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE
, nullptr);
54 // Verify a TouchEventsEnabled value isn't recorded during construction.
55 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
56 VerifyTouchEventsEnabledIsNotRecordedAfterConstruction
) {
57 base::HistogramTester histogram_tester
;
58 ChromeBrowserMainExtraPartsMetrics test_target
;
59 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 0);
62 #if defined(USE_OZONE) || defined(USE_X11)
64 // Verify a TouchEventsEnabled value isn't recorded during PostBrowserStart if
65 // the device scan hasn't completed yet.
66 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
67 VerifyTouchEventsEnabledIsNotRecordedAfterPostBrowserStart
) {
68 base::HistogramTester histogram_tester
;
70 ChromeBrowserMainExtraPartsMetrics test_target
;
72 test_target
.PostBrowserStart();
73 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 0);
76 // Verify a TouchEventsEnabled value is recorded during PostBrowserStart if the
77 // device scan has already completed.
78 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
79 VerifyTouchEventsEnabledIsRecordedAfterPostBrowserStart
) {
80 base::HistogramTester histogram_tester
;
82 device_data_manager_test_api_
.OnDeviceListsComplete();
84 ChromeBrowserMainExtraPartsMetrics test_target
;
86 test_target
.PostBrowserStart();
87 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 1);
90 // Verify a TouchEventsEnabled value is recorded when an asynchronous device
92 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
93 VerifyTouchEventsEnabledIsRecordedWhenDeviceListsComplete
) {
94 base::HistogramTester histogram_tester
;
95 ChromeBrowserMainExtraPartsMetrics test_target
;
97 test_target
.PostBrowserStart();
98 device_data_manager_test_api_
.NotifyObserversDeviceListsComplete();
99 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 1);
102 // Verify a TouchEventsEnabled value is only recorded once if multiple
103 // asynchronous device scans happen.
104 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
105 VerifyTouchEventsEnabledIsOnlyRecordedOnce
) {
106 base::HistogramTester histogram_tester
;
107 ChromeBrowserMainExtraPartsMetrics test_target
;
109 test_target
.PostBrowserStart();
110 device_data_manager_test_api_
.NotifyObserversDeviceListsComplete();
111 device_data_manager_test_api_
.NotifyObserversDeviceListsComplete();
112 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 1);
117 // Verify a TouchEventsEnabled value is recorded during PostBrowserStart.
118 TEST_F(ChromeBrowserMainExtraPartsMetricsTest
,
119 VerifyTouchEventsEnabledIsRecordedAfterPostBrowserStart
) {
120 base::HistogramTester histogram_tester
;
121 ChromeBrowserMainExtraPartsMetrics test_target
;
123 test_target
.PostBrowserStart();
124 histogram_tester
.ExpectTotalCount(kTouchEventsEnabledHistogramName
, 1);
127 #endif // defined(USE_OZONE) || defined(USE_X11)