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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/crash/MinidumpUploadCallableTest.java

Issue 2248243002: Enabling sampling of UMA and crash reports on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enabling sampling of UMA and crash reports on Android. Created 4 years, 4 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 package org.chromium.chrome.browser.crash; 5 package org.chromium.chrome.browser.crash;
6 6
7 import android.test.suitebuilder.annotation.SmallTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 8
9 import org.chromium.base.annotations.SuppressFBWarnings; 9 import org.chromium.base.annotations.SuppressFBWarnings;
10 import org.chromium.base.test.util.Feature; 10 import org.chromium.base.test.util.Feature;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 private static class FailHttpURLConnectionFactory implements HttpURLConnecti onFactory { 106 private static class FailHttpURLConnectionFactory implements HttpURLConnecti onFactory {
107 @Override 107 @Override
108 public HttpURLConnection createHttpURLConnection(String url) { 108 public HttpURLConnection createHttpURLConnection(String url) {
109 fail(); 109 fail();
110 return null; 110 return null;
111 } 111 }
112 } 112 }
113 113
114 private static class MockCrashReportingPermissionManager 114 private static class MockCrashReportingPermissionManager
115 implements CrashReportingPermissionManager { 115 implements CrashReportingPermissionManager {
116 private final boolean mIsInSample;
116 private final boolean mIsPermitted; 117 private final boolean mIsPermitted;
117 private final boolean mIsUserPermitted; 118 private final boolean mIsUserPermitted;
118 private final boolean mIsCommandLineDisabled; 119 private final boolean mIsCommandLineDisabled;
119 private final boolean mIsLimited; 120 private final boolean mIsLimited;
120 private final boolean mIsEnabledForTests; 121 private final boolean mIsEnabledForTests;
121 122
122 MockCrashReportingPermissionManager(boolean isPermitted, boolean isUserP ermitted, 123 MockCrashReportingPermissionManager(boolean isInSample, boolean isPermit ted,
123 boolean isCommandLineDisabled, boolean isLimited, boolean isEnab ledForTests) { 124 boolean isUserPermitted, boolean isCommandLineDisabled, boolean isLimited,
125 boolean isEnabledForTests) {
126 mIsInSample = isInSample;
Alexei Svitkine (slow) 2016/08/18 06:16:39 Sigh, I really hate this mock class, as it makes i
jwd 2016/08/23 18:40:03 Done.
124 mIsPermitted = isPermitted; 127 mIsPermitted = isPermitted;
125 mIsUserPermitted = isUserPermitted; 128 mIsUserPermitted = isUserPermitted;
126 mIsCommandLineDisabled = isCommandLineDisabled; 129 mIsCommandLineDisabled = isCommandLineDisabled;
127 mIsLimited = isLimited; 130 mIsLimited = isLimited;
128 mIsEnabledForTests = isEnabledForTests; 131 mIsEnabledForTests = isEnabledForTests;
129 } 132 }
130 133
131 @Override 134 @Override
135 public boolean isClientInMetricsSample() {
136 return mIsInSample;
137 }
138
139 @Override
132 public boolean isUploadPermitted() { 140 public boolean isUploadPermitted() {
133 return mIsPermitted; 141 return mIsPermitted;
134 } 142 }
135 143
136 @Override 144 @Override
137 public boolean isUmaUploadPermitted() { 145 public boolean isUmaUploadPermitted() {
138 return mIsPermitted; 146 return mIsPermitted;
139 } 147 }
140 148
141 @Override 149 @Override
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 @Override 201 @Override
194 protected void tearDown() throws Exception { 202 protected void tearDown() throws Exception {
195 if (mTestUpload.exists()) mTestUpload.delete(); 203 if (mTestUpload.exists()) mTestUpload.delete();
196 super.tearDown(); 204 super.tearDown();
197 } 205 }
198 206
199 @SmallTest 207 @SmallTest
200 @Feature({"Android-AppBase"}) 208 @Feature({"Android-AppBase"})
201 public void testCallWhenCurrentlyPermitted() throws Exception { 209 public void testCallWhenCurrentlyPermitted() throws Exception {
202 CrashReportingPermissionManager testPermManager = 210 CrashReportingPermissionManager testPermManager =
203 new MockCrashReportingPermissionManager(true, true, false, false , false); 211 new MockCrashReportingPermissionManager(true, true, true, false, false, false);
204 212
205 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 213 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
206 214
207 MinidumpUploadCallable minidumpUploadCallable = 215 MinidumpUploadCallable minidumpUploadCallable =
208 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 216 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
209 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS, 217 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS,
210 minidumpUploadCallable.call().intValue()); 218 minidumpUploadCallable.call().intValue());
211 assertTrue(mExpectedFileAfterUpload.exists()); 219 assertTrue(mExpectedFileAfterUpload.exists());
212 assertValidUploadLogEntry(); 220 assertValidUploadLogEntry();
213 } 221 }
214 222
215 @SmallTest 223 @SmallTest
216 @Feature({"Android-AppBase"}) 224 @Feature({"Android-AppBase"})
217 public void testCallNotPermittedByUser() throws Exception { 225 public void testCallNotPermittedByUser() throws Exception {
218 CrashReportingPermissionManager testPermManager = 226 CrashReportingPermissionManager testPermManager =
219 new MockCrashReportingPermissionManager(false, false, false, fal se, false); 227 new MockCrashReportingPermissionManager(true, false, false, fals e, false, false);
220 228
221 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory(); 229 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
222 230
223 MinidumpUploadCallable minidumpUploadCallable = 231 MinidumpUploadCallable minidumpUploadCallable =
224 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 232 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
225 assertEquals(MinidumpUploadCallable.UPLOAD_USER_DISABLED, 233 assertEquals(MinidumpUploadCallable.UPLOAD_USER_DISABLED,
226 minidumpUploadCallable.call().intValue()); 234 minidumpUploadCallable.call().intValue());
227 assertTrue(mExpectedFileAfterUpload.exists()); 235 assertTrue(mExpectedFileAfterUpload.exists());
228 } 236 }
229 237
230 @SmallTest 238 @SmallTest
231 @Feature({"Android-AppBase"}) 239 @Feature({"Android-AppBase"})
232 public void testCallNotPermittedByCommandLine() throws Exception { 240 public void testCallNotPermittedByCommandLine() throws Exception {
233 CrashReportingPermissionManager testPermManager = 241 CrashReportingPermissionManager testPermManager =
234 new MockCrashReportingPermissionManager(true, true, true, false, false); 242 new MockCrashReportingPermissionManager(true, true, true, true, false, false);
235 243
236 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory(); 244 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
237 245
238 MinidumpUploadCallable minidumpUploadCallable = 246 MinidumpUploadCallable minidumpUploadCallable =
239 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 247 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
240 assertEquals(MinidumpUploadCallable.UPLOAD_COMMANDLINE_DISABLED, 248 assertEquals(MinidumpUploadCallable.UPLOAD_COMMANDLINE_DISABLED,
241 minidumpUploadCallable.call().intValue()); 249 minidumpUploadCallable.call().intValue());
242 assertFalse(mExpectedFileAfterUpload.exists()); 250 assertFalse(mExpectedFileAfterUpload.exists());
243 } 251 }
244 252
245 @SmallTest 253 @SmallTest
246 @Feature({"Android-AppBase"}) 254 @Feature({"Android-AppBase"})
255 public void testCallPermittedButNotInSample() throws Exception {
256 CrashReportingPermissionManager testPermManager =
257 new MockCrashReportingPermissionManager(false, true, true, false , false, false);
258
259 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
260
261 MinidumpUploadCallable minidumpUploadCallable =
262 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
263 assertEquals(
264 MinidumpUploadCallable.UPLOAD_FAILURE, minidumpUploadCallable.ca ll().intValue());
265 assertFalse(mExpectedFileAfterUpload.exists());
266 }
267
268 @SmallTest
269 @Feature({"Android-AppBase"})
247 public void testCallPermittedButNotUnderCurrentCircumstances() throws Except ion { 270 public void testCallPermittedButNotUnderCurrentCircumstances() throws Except ion {
248 CrashReportingPermissionManager testPermManager = 271 CrashReportingPermissionManager testPermManager =
249 new MockCrashReportingPermissionManager(false, true, false, fals e, false); 272 new MockCrashReportingPermissionManager(true, false, true, false , false, false);
250 273
251 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory(); 274 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
252 275
253 MinidumpUploadCallable minidumpUploadCallable = 276 MinidumpUploadCallable minidumpUploadCallable =
254 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 277 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
255 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE, 278 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE,
256 minidumpUploadCallable.call().intValue()); 279 minidumpUploadCallable.call().intValue());
257 assertFalse(mExpectedFileAfterUpload.exists()); 280 assertFalse(mExpectedFileAfterUpload.exists());
258 } 281 }
259 282
260 @SmallTest 283 @SmallTest
261 @Feature({"Android-AppBase"}) 284 @Feature({"Android-AppBase"})
262 public void testCrashUploadConstrainted() throws Exception { 285 public void testCrashUploadConstrainted() throws Exception {
263 CrashReportingPermissionManager testPermManager = 286 CrashReportingPermissionManager testPermManager =
264 new MockCrashReportingPermissionManager(true, true, false, true, false); 287 new MockCrashReportingPermissionManager(true, true, true, false, true, false);
265 288
266 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 289 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
267 290
268 MinidumpUploadCallable minidumpUploadCallable = 291 MinidumpUploadCallable minidumpUploadCallable =
269 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 292 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
270 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE, 293 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE,
271 minidumpUploadCallable.call().intValue()); 294 minidumpUploadCallable.call().intValue());
272 assertFalse(mExpectedFileAfterUpload.exists()); 295 assertFalse(mExpectedFileAfterUpload.exists());
273 } 296 }
274 297
275 @SmallTest 298 @SmallTest
276 @Feature({"Android-AppBase"}) 299 @Feature({"Android-AppBase"})
277 public void testCrashUploadEnabledForTestsDespiteConstraints() throws Except ion { 300 public void testCrashUploadEnabledForTestsDespiteConstraints() throws Except ion {
278 CrashReportingPermissionManager testPermManager = 301 CrashReportingPermissionManager testPermManager =
279 new MockCrashReportingPermissionManager(false, false, false, tru e, true); 302 new MockCrashReportingPermissionManager(true, false, false, fals e, true, true);
280 303
281 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 304 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
282 305
283 MinidumpUploadCallable minidumpUploadCallable = 306 MinidumpUploadCallable minidumpUploadCallable =
284 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 307 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
285 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS, 308 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS,
286 minidumpUploadCallable.call().intValue()); 309 minidumpUploadCallable.call().intValue());
287 assertTrue(mExpectedFileAfterUpload.exists()); 310 assertTrue(mExpectedFileAfterUpload.exists());
288 assertValidUploadLogEntry(); 311 assertValidUploadLogEntry();
289 } 312 }
(...skipping 28 matching lines...) Expand all
318 341
319 // Sanity check on the time stamp (within an hour). 342 // Sanity check on the time stamp (within an hour).
320 // Chances are the write and the check should have less than 1 second in between. 343 // Chances are the write and the check should have less than 1 second in between.
321 assertTrue(time <= now); 344 assertTrue(time <= now);
322 assertTrue(time > now - 60 * 60); 345 assertTrue(time > now - 60 * 60);
323 346
324 String id = lastEntry.substring(seperator + 1, lastEntry.length()); 347 String id = lastEntry.substring(seperator + 1, lastEntry.length());
325 assertEquals(id, CRASH_ID); 348 assertEquals(id, CRASH_ID);
326 } 349 }
327 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698