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

Side by Side Diff: components/minidump_uploader/android/javatests/src/org/chromium/components/minidump_uploader/MinidumpUploadCallableTest.java

Issue 2756463004: [Cleanup] Remove the ability to disable Crash Reporting from the command line. (Closed)
Patch Set: Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.components.minidump_uploader; 5 package org.chromium.components.minidump_uploader;
6 6
7 import android.support.test.filters.SmallTest; 7 import android.support.test.filters.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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 @SmallTest 160 @SmallTest
161 @Feature({"Android-AppBase"}) 161 @Feature({"Android-AppBase"})
162 public void testCallWhenCurrentlyPermitted() throws Exception { 162 public void testCallWhenCurrentlyPermitted() throws Exception {
163 CrashReportingPermissionManager testPermManager = 163 CrashReportingPermissionManager testPermManager =
164 new MockCrashReportingPermissionManager() { 164 new MockCrashReportingPermissionManager() {
165 { 165 {
166 mIsInSample = true; 166 mIsInSample = true;
167 mIsPermitted = true; 167 mIsPermitted = true;
168 mIsUserPermitted = true; 168 mIsUserPermitted = true;
169 mIsCommandLineDisabled = false;
170 mIsNetworkAvailable = true; 169 mIsNetworkAvailable = true;
171 mIsEnabledForTests = false; 170 mIsEnabledForTests = false;
172 } 171 }
173 }; 172 };
174 173
175 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 174 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
176 175
177 MinidumpUploadCallable minidumpUploadCallable = 176 MinidumpUploadCallable minidumpUploadCallable =
178 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 177 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
179 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS, 178 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS,
180 minidumpUploadCallable.call().intValue()); 179 minidumpUploadCallable.call().intValue());
181 assertTrue(mExpectedFileAfterUpload.exists()); 180 assertTrue(mExpectedFileAfterUpload.exists());
182 assertValidUploadLogEntry(); 181 assertValidUploadLogEntry();
183 } 182 }
184 183
185 @SmallTest 184 @SmallTest
186 @Feature({"Android-AppBase"}) 185 @Feature({"Android-AppBase"})
187 public void testCallNotPermittedByUser() throws Exception { 186 public void testCallNotPermittedByUser() throws Exception {
188 CrashReportingPermissionManager testPermManager = 187 CrashReportingPermissionManager testPermManager =
189 new MockCrashReportingPermissionManager() { 188 new MockCrashReportingPermissionManager() {
190 { 189 {
191 mIsInSample = true; 190 mIsInSample = true;
192 mIsPermitted = false; 191 mIsPermitted = false;
193 mIsUserPermitted = false; 192 mIsUserPermitted = false;
194 mIsCommandLineDisabled = false;
195 mIsNetworkAvailable = true; 193 mIsNetworkAvailable = true;
196 mIsEnabledForTests = false; 194 mIsEnabledForTests = false;
197 } 195 }
198 }; 196 };
199 197
200 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory(); 198 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
201 199
202 MinidumpUploadCallable minidumpUploadCallable = 200 MinidumpUploadCallable minidumpUploadCallable =
203 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 201 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
204 assertEquals(MinidumpUploadCallable.UPLOAD_USER_DISABLED, 202 assertEquals(MinidumpUploadCallable.UPLOAD_USER_DISABLED,
205 minidumpUploadCallable.call().intValue()); 203 minidumpUploadCallable.call().intValue());
206 204
207 File expectedSkippedFileAfterUpload = 205 File expectedSkippedFileAfterUpload =
208 new File(mCrashDir, mTestUpload.getName().replace(".dmp", ".skip ped")); 206 new File(mCrashDir, mTestUpload.getName().replace(".dmp", ".skip ped"));
209 assertTrue(expectedSkippedFileAfterUpload.exists()); 207 assertTrue(expectedSkippedFileAfterUpload.exists());
210 assertFalse(mExpectedFileAfterUpload.exists()); 208 assertFalse(mExpectedFileAfterUpload.exists());
211 } 209 }
212 210
213 @SmallTest 211 @SmallTest
214 @Feature({"Android-AppBase"}) 212 @Feature({"Android-AppBase"})
215 public void testCallNotPermittedByCommandLine() throws Exception {
216 CrashReportingPermissionManager testPermManager =
217 new MockCrashReportingPermissionManager() {
218 {
219 mIsInSample = true;
220 mIsPermitted = true;
221 mIsUserPermitted = true;
222 mIsCommandLineDisabled = true;
223 mIsNetworkAvailable = true;
224 mIsEnabledForTests = false;
225 }
226 };
227
228 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
229
230 MinidumpUploadCallable minidumpUploadCallable =
231 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
232 assertEquals(MinidumpUploadCallable.UPLOAD_COMMANDLINE_DISABLED,
233 minidumpUploadCallable.call().intValue());
234 assertFalse(mExpectedFileAfterUpload.exists());
235 }
236
237 @SmallTest
238 @Feature({"Android-AppBase"})
239 public void testCallPermittedButNotInSample() throws Exception { 213 public void testCallPermittedButNotInSample() throws Exception {
240 CrashReportingPermissionManager testPermManager = 214 CrashReportingPermissionManager testPermManager =
241 new MockCrashReportingPermissionManager() { 215 new MockCrashReportingPermissionManager() {
242 { 216 {
243 mIsInSample = false; 217 mIsInSample = false;
244 mIsPermitted = true; 218 mIsPermitted = true;
245 mIsUserPermitted = true; 219 mIsUserPermitted = true;
246 mIsCommandLineDisabled = false;
247 mIsNetworkAvailable = true; 220 mIsNetworkAvailable = true;
248 mIsEnabledForTests = false; 221 mIsEnabledForTests = false;
249 } 222 }
250 }; 223 };
251 224
252 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 225 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
253 226
254 MinidumpUploadCallable minidumpUploadCallable = 227 MinidumpUploadCallable minidumpUploadCallable =
255 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 228 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
256 assertEquals(MinidumpUploadCallable.UPLOAD_DISABLED_BY_SAMPLING, 229 assertEquals(MinidumpUploadCallable.UPLOAD_DISABLED_BY_SAMPLING,
257 minidumpUploadCallable.call().intValue()); 230 minidumpUploadCallable.call().intValue());
258 231
259 File expectedSkippedFileAfterUpload = 232 File expectedSkippedFileAfterUpload =
260 new File(mCrashDir, mTestUpload.getName().replace(".dmp", ".skip ped")); 233 new File(mCrashDir, mTestUpload.getName().replace(".dmp", ".skip ped"));
261 assertTrue(expectedSkippedFileAfterUpload.exists()); 234 assertTrue(expectedSkippedFileAfterUpload.exists());
262 assertFalse(mExpectedFileAfterUpload.exists()); 235 assertFalse(mExpectedFileAfterUpload.exists());
263 } 236 }
264 237
265 @SmallTest 238 @SmallTest
266 @Feature({"Android-AppBase"}) 239 @Feature({"Android-AppBase"})
267 public void testCallPermittedButNotUnderCurrentCircumstances() throws Except ion { 240 public void testCallPermittedButNotUnderCurrentCircumstances() throws Except ion {
268 CrashReportingPermissionManager testPermManager = 241 CrashReportingPermissionManager testPermManager =
269 new MockCrashReportingPermissionManager() { 242 new MockCrashReportingPermissionManager() {
270 { 243 {
271 mIsInSample = true; 244 mIsInSample = true;
272 mIsPermitted = true; 245 mIsPermitted = true;
273 mIsUserPermitted = true; 246 mIsUserPermitted = true;
274 mIsCommandLineDisabled = false;
275 mIsNetworkAvailable = false; 247 mIsNetworkAvailable = false;
276 mIsEnabledForTests = false; 248 mIsEnabledForTests = false;
277 } 249 }
278 }; 250 };
279 251
280 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory(); 252 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
281 253
282 MinidumpUploadCallable minidumpUploadCallable = 254 MinidumpUploadCallable minidumpUploadCallable =
283 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 255 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
284 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE, 256 assertEquals(MinidumpUploadCallable.UPLOAD_FAILURE,
285 minidumpUploadCallable.call().intValue()); 257 minidumpUploadCallable.call().intValue());
286 assertFalse(mExpectedFileAfterUpload.exists()); 258 assertFalse(mExpectedFileAfterUpload.exists());
287 } 259 }
288 260
289 @SmallTest 261 @SmallTest
290 @Feature({"Android-AppBase"}) 262 @Feature({"Android-AppBase"})
291 public void testCrashUploadEnabledForTestsDespiteConstraints() throws Except ion { 263 public void testCrashUploadEnabledForTestsDespiteConstraints() throws Except ion {
292 CrashReportingPermissionManager testPermManager = 264 CrashReportingPermissionManager testPermManager =
293 new MockCrashReportingPermissionManager() { 265 new MockCrashReportingPermissionManager() {
294 { 266 {
295 mIsInSample = true; 267 mIsInSample = true;
296 mIsPermitted = false; 268 mIsPermitted = false;
297 mIsUserPermitted = false; 269 mIsUserPermitted = false;
298 mIsCommandLineDisabled = false;
299 mIsNetworkAvailable = false; 270 mIsNetworkAvailable = false;
300 mIsEnabledForTests = true; 271 mIsEnabledForTests = true;
301 } 272 }
302 }; 273 };
303 274
304 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 275 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
305 276
306 MinidumpUploadCallable minidumpUploadCallable = 277 MinidumpUploadCallable minidumpUploadCallable =
307 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 278 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
308 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS, 279 assertEquals(MinidumpUploadCallable.UPLOAD_SUCCESS,
309 minidumpUploadCallable.call().intValue()); 280 minidumpUploadCallable.call().intValue());
310 assertTrue(mExpectedFileAfterUpload.exists()); 281 assertTrue(mExpectedFileAfterUpload.exists());
311 assertValidUploadLogEntry(); 282 assertValidUploadLogEntry();
312 } 283 }
313 284
314 @SmallTest 285 @SmallTest
315 @Feature({"Android-AppBase"}) 286 @Feature({"Android-AppBase"})
316 public void testCallWhenCurrentlyPermitted_ForcedUpload() throws Exception { 287 public void testCallWhenCurrentlyPermitted_ForcedUpload() throws Exception {
317 setForcedUpload(); 288 setForcedUpload();
318 CrashReportingPermissionManager testPermManager = 289 CrashReportingPermissionManager testPermManager =
319 new MockCrashReportingPermissionManager() { 290 new MockCrashReportingPermissionManager() {
320 { 291 {
321 mIsInSample = true; 292 mIsInSample = true;
322 mIsPermitted = true; 293 mIsPermitted = true;
323 mIsUserPermitted = true; 294 mIsUserPermitted = true;
324 mIsCommandLineDisabled = false;
325 mIsNetworkAvailable = true; 295 mIsNetworkAvailable = true;
326 mIsEnabledForTests = false; 296 mIsEnabledForTests = false;
327 } 297 }
328 }; 298 };
329 299
330 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 300 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
331 301
332 MinidumpUploadCallable minidumpUploadCallable = 302 MinidumpUploadCallable minidumpUploadCallable =
333 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 303 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
334 assertEquals( 304 assertEquals(
335 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue()); 305 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue());
336 assertTrue(mExpectedFileAfterUpload.exists()); 306 assertTrue(mExpectedFileAfterUpload.exists());
337 assertValidUploadLogEntry(); 307 assertValidUploadLogEntry();
338 } 308 }
339 309
340 @SmallTest 310 @SmallTest
341 @Feature({"Android-AppBase"}) 311 @Feature({"Android-AppBase"})
342 public void testCallNotPermittedByUser_ForcedUpload() throws Exception { 312 public void testCallNotPermittedByUser_ForcedUpload() throws Exception {
343 setForcedUpload(); 313 setForcedUpload();
344 CrashReportingPermissionManager testPermManager = 314 CrashReportingPermissionManager testPermManager =
345 new MockCrashReportingPermissionManager() { 315 new MockCrashReportingPermissionManager() {
346 { 316 {
347 mIsInSample = true; 317 mIsInSample = true;
348 mIsPermitted = false; 318 mIsPermitted = false;
349 mIsUserPermitted = false; 319 mIsUserPermitted = false;
350 mIsCommandLineDisabled = false;
351 mIsNetworkAvailable = true; 320 mIsNetworkAvailable = true;
352 mIsEnabledForTests = false; 321 mIsEnabledForTests = false;
353 } 322 }
354 }; 323 };
355 324
356 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 325 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
357 326
358 MinidumpUploadCallable minidumpUploadCallable = 327 MinidumpUploadCallable minidumpUploadCallable =
359 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 328 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
360 assertEquals( 329 assertEquals(
361 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue()); 330 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue());
362 331
363 File expectedSkippedFileAfterUpload = 332 File expectedSkippedFileAfterUpload =
364 new File(mCrashDir, mTestUpload.getName().replace(".forced", ".s kipped")); 333 new File(mCrashDir, mTestUpload.getName().replace(".forced", ".s kipped"));
365 assertFalse(expectedSkippedFileAfterUpload.exists()); 334 assertFalse(expectedSkippedFileAfterUpload.exists());
366 assertTrue(mExpectedFileAfterUpload.exists()); 335 assertTrue(mExpectedFileAfterUpload.exists());
367 } 336 }
368 337
369 @SmallTest 338 @SmallTest
370 @Feature({"Android-AppBase"}) 339 @Feature({"Android-AppBase"})
371 public void testCallNotPermittedByCommandLine_ForcedUpload() throws Exceptio n {
372 setForcedUpload();
373 CrashReportingPermissionManager testPermManager =
374 new MockCrashReportingPermissionManager() {
375 {
376 mIsInSample = true;
377 mIsPermitted = true;
378 mIsUserPermitted = true;
379 mIsCommandLineDisabled = true;
380 mIsNetworkAvailable = true;
381 mIsEnabledForTests = false;
382 }
383 };
384
385 HttpURLConnectionFactory httpURLConnectionFactory = new FailHttpURLConne ctionFactory();
386
387 MinidumpUploadCallable minidumpUploadCallable =
388 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
389 assertEquals(MinidumpUploadCallable.UPLOAD_COMMANDLINE_DISABLED,
390 minidumpUploadCallable.call().intValue());
391 assertFalse(mExpectedFileAfterUpload.exists());
392 }
393
394 @SmallTest
395 @Feature({"Android-AppBase"})
396 public void testCallPermittedButNotInSample_ForcedUpload() throws Exception { 340 public void testCallPermittedButNotInSample_ForcedUpload() throws Exception {
397 setForcedUpload(); 341 setForcedUpload();
398 CrashReportingPermissionManager testPermManager = 342 CrashReportingPermissionManager testPermManager =
399 new MockCrashReportingPermissionManager() { 343 new MockCrashReportingPermissionManager() {
400 { 344 {
401 mIsInSample = false; 345 mIsInSample = false;
402 mIsPermitted = true; 346 mIsPermitted = true;
403 mIsUserPermitted = true; 347 mIsUserPermitted = true;
404 mIsCommandLineDisabled = false;
405 mIsNetworkAvailable = true; 348 mIsNetworkAvailable = true;
406 mIsEnabledForTests = false; 349 mIsEnabledForTests = false;
407 } 350 }
408 }; 351 };
409 352
410 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 353 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
411 354
412 MinidumpUploadCallable minidumpUploadCallable = 355 MinidumpUploadCallable minidumpUploadCallable =
413 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 356 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
414 assertEquals( 357 assertEquals(
415 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue()); 358 MinidumpUploadCallable.UPLOAD_SUCCESS, minidumpUploadCallable.ca ll().intValue());
416 359
417 File expectedSkippedFileAfterUpload = 360 File expectedSkippedFileAfterUpload =
418 new File(mCrashDir, mTestUpload.getName().replace(".forced", ".s kipped")); 361 new File(mCrashDir, mTestUpload.getName().replace(".forced", ".s kipped"));
419 assertFalse(expectedSkippedFileAfterUpload.exists()); 362 assertFalse(expectedSkippedFileAfterUpload.exists());
420 assertTrue(mExpectedFileAfterUpload.exists()); 363 assertTrue(mExpectedFileAfterUpload.exists());
421 } 364 }
422 365
423 @SmallTest 366 @SmallTest
424 @Feature({"Android-AppBase"}) 367 @Feature({"Android-AppBase"})
425 public void testCallPermittedButNotUnderCurrentCircumstances_ForcedUpload() throws Exception { 368 public void testCallPermittedButNotUnderCurrentCircumstances_ForcedUpload() throws Exception {
426 setForcedUpload(); 369 setForcedUpload();
427 CrashReportingPermissionManager testPermManager = 370 CrashReportingPermissionManager testPermManager =
428 new MockCrashReportingPermissionManager() { 371 new MockCrashReportingPermissionManager() {
429 { 372 {
430 mIsInSample = true; 373 mIsInSample = true;
431 mIsPermitted = true; 374 mIsPermitted = true;
432 mIsUserPermitted = true; 375 mIsUserPermitted = true;
433 mIsCommandLineDisabled = false;
434 mIsNetworkAvailable = false; 376 mIsNetworkAvailable = false;
435 mIsEnabledForTests = false; 377 mIsEnabledForTests = false;
436 } 378 }
437 }; 379 };
438 380
439 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory(); 381 HttpURLConnectionFactory httpURLConnectionFactory = new TestHttpURLConne ctionFactory();
440 382
441 MinidumpUploadCallable minidumpUploadCallable = 383 MinidumpUploadCallable minidumpUploadCallable =
442 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager); 384 new MockMinidumpUploadCallable(httpURLConnectionFactory, testPer mManager);
443 assertEquals( 385 assertEquals(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 421
480 // Sanity check on the time stamp (within an hour). 422 // Sanity check on the time stamp (within an hour).
481 // Chances are the write and the check should have less than 1 second in between. 423 // Chances are the write and the check should have less than 1 second in between.
482 assertTrue(time <= now); 424 assertTrue(time <= now);
483 assertTrue(time > now - 60 * 60); 425 assertTrue(time > now - 60 * 60);
484 426
485 String id = lastEntry.substring(seperator + 1, lastEntry.length()); 427 String id = lastEntry.substring(seperator + 1, lastEntry.length());
486 assertEquals(id, CRASH_ID); 428 assertEquals(id, CRASH_ID);
487 } 429 }
488 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698