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

Side by Side Diff: ios/chrome/browser/metrics/size_class_recorder_unittest.mm

Issue 2894653002: [ObjC ARC] Converts ios/chrome/browser/metrics:unit_tests_internal to ARC. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/metrics/size_class_recorder.h" 5 #import "ios/chrome/browser/metrics/size_class_recorder.h"
6 #import "ios/chrome/browser/metrics/size_class_recorder_private.h" 6 #import "ios/chrome/browser/metrics/size_class_recorder_private.h"
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
12 #import "ios/chrome/browser/ui/ui_util.h" 11 #import "ios/chrome/browser/ui/ui_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
15 14
15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support."
17 #endif
18
16 using ios_internal::SizeClassForReporting; 19 using ios_internal::SizeClassForReporting;
17 using ios_internal::SizeClassForReportingForUIUserInterfaceSizeClass; 20 using ios_internal::SizeClassForReportingForUIUserInterfaceSizeClass;
18 21
19 namespace { 22 namespace {
20 23
21 const char kSizeClassUsedHistogramName[] = "Tab.HorizontalSizeClassUsed"; 24 const char kSizeClassUsedHistogramName[] = "Tab.HorizontalSizeClassUsed";
22 25
23 const char kPageLoadSizeClassHistogramName[] = 26 const char kPageLoadSizeClassHistogramName[] =
24 "Tab.PageLoadInHorizontalSizeClass"; 27 "Tab.PageLoadInHorizontalSizeClass";
25 28
26 class SizeClassRecorderTest : public PlatformTest { 29 class SizeClassRecorderTest : public PlatformTest {
27 protected: 30 protected:
28 void SetUp() override { 31 void SetUp() override {
29 PlatformTest::SetUp(); 32 PlatformTest::SetUp();
30 histogram_tester_.reset(new base::HistogramTester()); 33 histogram_tester_.reset(new base::HistogramTester());
31 } 34 }
32 35
33 base::scoped_nsobject<SizeClassRecorder> recorder_; 36 SizeClassRecorder* recorder_;
34 std::unique_ptr<base::HistogramTester> histogram_tester_; 37 std::unique_ptr<base::HistogramTester> histogram_tester_;
35 }; 38 };
36 39
37 TEST_F(SizeClassRecorderTest, Initialization_SizeClassUnspecified) { 40 TEST_F(SizeClassRecorderTest, Initialization_SizeClassUnspecified) {
38 // SizeClassRecoder is only available on iPad devices. 41 // SizeClassRecoder is only available on iPad devices.
39 if (!IsIPadIdiom()) 42 if (!IsIPadIdiom())
40 return; 43 return;
41 44
42 recorder_.reset([[SizeClassRecorder alloc] 45 recorder_ = [[SizeClassRecorder alloc]
43 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 46 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
44 recorder_.reset(); 47 recorder_ = nil;
45 48
46 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 49 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
47 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 50 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
48 } 51 }
49 52
50 TEST_F(SizeClassRecorderTest, Initialization_SizeClassCompact) { 53 TEST_F(SizeClassRecorderTest, Initialization_SizeClassCompact) {
51 // SizeClassRecoder is only available on iPad devices. 54 // SizeClassRecoder is only available on iPad devices.
52 if (!IsIPadIdiom()) 55 if (!IsIPadIdiom())
53 return; 56 return;
54 57
55 recorder_.reset([[SizeClassRecorder alloc] 58 recorder_ = [[SizeClassRecorder alloc]
56 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]); 59 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
57 recorder_.reset(); 60 recorder_ = nil;
58 61
59 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 62 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
60 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 63 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
61 } 64 }
62 65
63 TEST_F(SizeClassRecorderTest, Initialization_SizeClassRegular) { 66 TEST_F(SizeClassRecorderTest, Initialization_SizeClassRegular) {
64 // SizeClassRecoder is only available on iPad devices. 67 // SizeClassRecoder is only available on iPad devices.
65 if (!IsIPadIdiom()) 68 if (!IsIPadIdiom())
66 return; 69 return;
67 70
68 recorder_.reset([[SizeClassRecorder alloc] 71 recorder_ = [[SizeClassRecorder alloc]
69 initWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular]); 72 initWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
70 recorder_.reset(); 73 recorder_ = nil;
71 74
72 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 75 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
73 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 76 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
74 } 77 }
75 78
76 TEST_F(SizeClassRecorderTest, RecordInitialSizeClassOnAppBecomeActive) { 79 TEST_F(SizeClassRecorderTest, RecordInitialSizeClassOnAppBecomeActive) {
77 // SizeClassRecoder is only available on iPad devices. 80 // SizeClassRecoder is only available on iPad devices.
78 if (!IsIPadIdiom()) 81 if (!IsIPadIdiom())
79 return; 82 return;
80 83
81 recorder_.reset([[SizeClassRecorder alloc] 84 recorder_ = [[SizeClassRecorder alloc]
82 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]); 85 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
83 [[NSNotificationCenter defaultCenter] 86 [[NSNotificationCenter defaultCenter]
84 postNotificationName:UIApplicationDidBecomeActiveNotification 87 postNotificationName:UIApplicationDidBecomeActiveNotification
85 object:nil]; 88 object:nil];
86 89
87 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName, 90 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
88 SizeClassForReporting::COMPACT, 1); 91 SizeClassForReporting::COMPACT, 1);
89 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 92 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
90 } 93 }
91 94
92 TEST_F(SizeClassRecorderTest, 95 TEST_F(SizeClassRecorderTest,
93 DontRecordInitialSizeClassSubsequentAppBecomeActive) { 96 DontRecordInitialSizeClassSubsequentAppBecomeActive) {
94 // SizeClassRecoder is only available on iPad devices. 97 // SizeClassRecoder is only available on iPad devices.
95 if (!IsIPadIdiom()) 98 if (!IsIPadIdiom())
96 return; 99 return;
97 100
98 recorder_.reset([[SizeClassRecorder alloc] 101 recorder_ = [[SizeClassRecorder alloc]
99 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]); 102 initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
100 [[NSNotificationCenter defaultCenter] 103 [[NSNotificationCenter defaultCenter]
101 postNotificationName:UIApplicationDidBecomeActiveNotification 104 postNotificationName:UIApplicationDidBecomeActiveNotification
102 object:nil]; 105 object:nil];
103 [[NSNotificationCenter defaultCenter] 106 [[NSNotificationCenter defaultCenter]
104 postNotificationName:UIApplicationDidBecomeActiveNotification 107 postNotificationName:UIApplicationDidBecomeActiveNotification
105 object:nil]; 108 object:nil];
106 109
107 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName, 110 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
108 SizeClassForReporting::COMPACT, 1); 111 SizeClassForReporting::COMPACT, 1);
109 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 112 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
110 } 113 }
111 114
112 TEST_F(SizeClassRecorderTest, RecordSizeClassChangeInForeground) { 115 TEST_F(SizeClassRecorderTest, RecordSizeClassChangeInForeground) {
113 // SizeClassRecoder is only available on iPad devices. 116 // SizeClassRecoder is only available on iPad devices.
114 if (!IsIPadIdiom()) 117 if (!IsIPadIdiom())
115 return; 118 return;
116 119
117 recorder_.reset([[SizeClassRecorder alloc] 120 recorder_ = [[SizeClassRecorder alloc]
118 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 121 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
119 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular]; 122 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular];
120 123
121 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName, 124 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
122 SizeClassForReporting::REGULAR, 1); 125 SizeClassForReporting::REGULAR, 1);
123 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 126 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
124 } 127 }
125 128
126 TEST_F(SizeClassRecorderTest, DontRecordSizeClassChangeInBackground) { 129 TEST_F(SizeClassRecorderTest, DontRecordSizeClassChangeInBackground) {
127 // SizeClassRecoder is only available on iPad devices. 130 // SizeClassRecoder is only available on iPad devices.
128 if (!IsIPadIdiom()) 131 if (!IsIPadIdiom())
129 return; 132 return;
130 133
131 recorder_.reset([[SizeClassRecorder alloc] 134 recorder_ = [[SizeClassRecorder alloc]
132 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 135 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
133 [[NSNotificationCenter defaultCenter] 136 [[NSNotificationCenter defaultCenter]
134 postNotificationName:UIApplicationDidEnterBackgroundNotification 137 postNotificationName:UIApplicationDidEnterBackgroundNotification
135 object:nil]; 138 object:nil];
136 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular]; 139 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular];
137 140
138 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 141 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
139 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 142 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
140 } 143 }
141 144
142 TEST_F(SizeClassRecorderTest, 145 TEST_F(SizeClassRecorderTest,
143 RecordSizeClassChangeInForegroundAfterBackground) { 146 RecordSizeClassChangeInForegroundAfterBackground) {
144 // SizeClassRecoder is only available on iPad devices. 147 // SizeClassRecoder is only available on iPad devices.
145 if (!IsIPadIdiom()) 148 if (!IsIPadIdiom())
146 return; 149 return;
147 150
148 recorder_.reset([[SizeClassRecorder alloc] 151 recorder_ = [[SizeClassRecorder alloc]
149 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 152 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
150 [[NSNotificationCenter defaultCenter] 153 [[NSNotificationCenter defaultCenter]
151 postNotificationName:UIApplicationDidEnterBackgroundNotification 154 postNotificationName:UIApplicationDidEnterBackgroundNotification
152 object:nil]; 155 object:nil];
153 [[NSNotificationCenter defaultCenter] 156 [[NSNotificationCenter defaultCenter]
154 postNotificationName:UIApplicationWillEnterForegroundNotification 157 postNotificationName:UIApplicationWillEnterForegroundNotification
155 object:nil]; 158 object:nil];
156 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassCompact]; 159 [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassCompact];
157 160
158 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName, 161 histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
159 SizeClassForReporting::COMPACT, 1); 162 SizeClassForReporting::COMPACT, 1);
160 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0); 163 histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
161 } 164 }
162 165
163 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Unspecified) { 166 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Unspecified) {
164 // SizeClassRecoder is only available on iPad devices. 167 // SizeClassRecoder is only available on iPad devices.
165 if (!IsIPadIdiom()) 168 if (!IsIPadIdiom())
166 return; 169 return;
167 170
168 recorder_.reset([[SizeClassRecorder alloc] 171 recorder_ = [[SizeClassRecorder alloc]
169 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 172 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
170 [recorder_ 173 [recorder_
171 pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]; 174 pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
172 175
173 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 176 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
174 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName, 177 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
175 SizeClassForReporting::UNSPECIFIED, 1); 178 SizeClassForReporting::UNSPECIFIED, 1);
176 } 179 }
177 180
178 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Compact) { 181 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Compact) {
179 // SizeClassRecoder is only available on iPad devices. 182 // SizeClassRecoder is only available on iPad devices.
180 if (!IsIPadIdiom()) 183 if (!IsIPadIdiom())
181 return; 184 return;
182 185
183 recorder_.reset([[SizeClassRecorder alloc] 186 recorder_ = [[SizeClassRecorder alloc]
184 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 187 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
185 [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]; 188 [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
186 189
187 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 190 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
188 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName, 191 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
189 SizeClassForReporting::COMPACT, 1); 192 SizeClassForReporting::COMPACT, 1);
190 } 193 }
191 194
192 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Regular) { 195 TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Regular) {
193 // SizeClassRecoder is only available on iPad devices. 196 // SizeClassRecoder is only available on iPad devices.
194 if (!IsIPadIdiom()) 197 if (!IsIPadIdiom())
195 return; 198 return;
196 199
197 recorder_.reset([[SizeClassRecorder alloc] 200 recorder_ = [[SizeClassRecorder alloc]
198 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]); 201 initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
199 [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular]; 202 [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
200 203
201 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0); 204 histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
202 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName, 205 histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
203 SizeClassForReporting::REGULAR, 1); 206 SizeClassForReporting::REGULAR, 1);
204 } 207 }
205 208
206 } // namespace 209 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/metrics/BUILD.gn ('k') | ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698