OLD | NEW |
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 static android.support.test.InstrumentationRegistry.getInstrumentation; | |
8 | |
9 import static org.chromium.chrome.browser.crash.MinidumpUploadService.BROWSER; | 7 import static org.chromium.chrome.browser.crash.MinidumpUploadService.BROWSER; |
10 import static org.chromium.chrome.browser.crash.MinidumpUploadService.GPU; | 8 import static org.chromium.chrome.browser.crash.MinidumpUploadService.GPU; |
11 import static org.chromium.chrome.browser.crash.MinidumpUploadService.OTHER; | 9 import static org.chromium.chrome.browser.crash.MinidumpUploadService.OTHER; |
12 import static org.chromium.chrome.browser.crash.MinidumpUploadService.RENDERER; | 10 import static org.chromium.chrome.browser.crash.MinidumpUploadService.RENDERER; |
13 | 11 |
14 import android.annotation.TargetApi; | 12 import android.annotation.TargetApi; |
15 import android.app.job.JobInfo; | 13 import android.app.job.JobInfo; |
16 import android.app.job.JobScheduler; | 14 import android.app.job.JobScheduler; |
17 import android.content.ComponentName; | 15 import android.content.ComponentName; |
18 import android.content.Context; | 16 import android.content.Context; |
19 import android.content.Intent; | 17 import android.content.Intent; |
20 import android.os.Build; | 18 import android.os.Build; |
21 import android.os.Handler; | 19 import android.os.Handler; |
22 import android.os.HandlerThread; | 20 import android.os.HandlerThread; |
23 import android.support.test.filters.SmallTest; | 21 import android.support.test.filters.SmallTest; |
24 | 22 |
25 import org.chromium.base.ContextUtils; | |
26 import org.chromium.base.annotations.SuppressFBWarnings; | 23 import org.chromium.base.annotations.SuppressFBWarnings; |
27 import org.chromium.base.test.util.AdvancedMockContext; | 24 import org.chromium.base.test.util.AdvancedMockContext; |
28 import org.chromium.base.test.util.Feature; | 25 import org.chromium.base.test.util.Feature; |
29 import org.chromium.components.background_task_scheduler.TaskIds; | 26 import org.chromium.components.background_task_scheduler.TaskIds; |
30 import org.chromium.components.minidump_uploader.CrashTestCase; | 27 import org.chromium.components.minidump_uploader.CrashTestCase; |
31 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; | 28 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; |
32 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; | 29 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
33 import org.chromium.content.browser.test.util.Criteria; | 30 import org.chromium.content.browser.test.util.Criteria; |
34 import org.chromium.content.browser.test.util.CriteriaHelper; | 31 import org.chromium.content.browser.test.util.CriteriaHelper; |
35 import org.chromium.net.NetworkChangeNotifier; | 32 import org.chromium.net.NetworkChangeNotifier; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; | 83 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
87 | 84 |
88 // Setup prerequisites. | 85 // Setup prerequisites. |
89 final AtomicInteger numServiceStarts = new AtomicInteger(0); | 86 final AtomicInteger numServiceStarts = new AtomicInteger(0); |
90 final File[] minidumpFiles = { | 87 final File[] minidumpFiles = { |
91 new File(mCrashDir, "chromium_renderer-111.dmp1"), | 88 new File(mCrashDir, "chromium_renderer-111.dmp1"), |
92 new File(mCrashDir, "chromium_renderer-222.dmp2"), | 89 new File(mCrashDir, "chromium_renderer-222.dmp2"), |
93 new File(mCrashDir, "chromium_renderer-333.dmp3"), | 90 new File(mCrashDir, "chromium_renderer-333.dmp3"), |
94 }; | 91 }; |
95 MinidumpPreparationContext context = new MinidumpPreparationContext( | 92 MinidumpPreparationContext context = new MinidumpPreparationContext( |
96 getInstrumentation().getTargetContext().getApplicationContext())
{ | 93 getInstrumentation().getTargetContext()) { |
97 @Override | 94 @Override |
98 public ComponentName startService(Intent intentToCheck) { | 95 public ComponentName startService(Intent intentToCheck) { |
99 String filePath = | 96 String filePath = |
100 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); | 97 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); |
101 // Assuming numServicesStart value corresponds to minidumpFiles
index. | 98 // Assuming numServicesStart value corresponds to minidumpFiles
index. |
102 assertEquals("Action should be correct", MinidumpUploadService.A
CTION_UPLOAD, | 99 assertEquals("Action should be correct", MinidumpUploadService.A
CTION_UPLOAD, |
103 intentToCheck.getAction()); | 100 intentToCheck.getAction()); |
104 assertTrue("Should not call service more than number of files", | 101 assertTrue("Should not call service more than number of files", |
105 numServiceStarts.incrementAndGet() <= minidumpFiles.leng
th); | 102 numServiceStarts.incrementAndGet() <= minidumpFiles.leng
th); |
106 assertEquals("Minidump path should be the absolute path", | 103 assertEquals("Minidump path should be the absolute path", |
107 minidumpFiles[numServiceStarts.intValue() - 1].getAbsolu
tePath(), filePath); | 104 minidumpFiles[numServiceStarts.intValue() - 1].getAbsolu
tePath(), filePath); |
108 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 105 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
109 } | 106 } |
110 | 107 |
111 }; | 108 }; |
112 MinidumpUploadService service = new TestMinidumpUploadService(context); | 109 MinidumpUploadService service = new TestMinidumpUploadService(context); |
113 for (File minidumpFile : minidumpFiles) { | 110 for (File minidumpFile : minidumpFiles) { |
114 setUpMinidumpFile(minidumpFile, BOUNDARY); | 111 setUpMinidumpFile(minidumpFile, BOUNDARY); |
115 } | 112 } |
116 | 113 |
117 // Run test. | 114 // Run test. |
118 service.onCreate(); | 115 service.onCreate(); |
119 ContextUtils.initApplicationContextForTests(context); | 116 MinidumpUploadService.tryUploadAllCrashDumps(context); |
120 MinidumpUploadService.tryUploadAllCrashDumps(); | |
121 | 117 |
122 // Verify. | 118 // Verify. |
123 for (File minidumpFile : minidumpFiles) { | 119 for (File minidumpFile : minidumpFiles) { |
124 assertTrue("Minidump file should exist: " + minidumpFile, minidumpFi
le.isFile()); | 120 assertTrue("Minidump file should exist: " + minidumpFile, minidumpFi
le.isFile()); |
125 } | 121 } |
126 assertEquals("Should have called startService() same number of times as
there are files", | 122 assertEquals("Should have called startService() same number of times as
there are files", |
127 minidumpFiles.length, numServiceStarts.intValue()); | 123 minidumpFiles.length, numServiceStarts.intValue()); |
128 } | 124 } |
129 | 125 |
130 @SmallTest | 126 @SmallTest |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 t.printStackTrace(); | 233 t.printStackTrace(); |
238 fail("Failed to trigger NetworkChangeNotifier"); | 234 fail("Failed to trigger NetworkChangeNotifier"); |
239 } | 235 } |
240 } | 236 } |
241 } | 237 } |
242 }; | 238 }; |
243 // Create a context that supports call to startService(...), where it ru
ns the new service | 239 // Create a context that supports call to startService(...), where it ru
ns the new service |
244 // calls on a handler thread. We pass in the MinidumpUploadService as an
argument so we | 240 // calls on a handler thread. We pass in the MinidumpUploadService as an
argument so we |
245 // can call it directly without going through the Android framework. | 241 // can call it directly without going through the Android framework. |
246 final MinidumpPreparationContext context = new MinidumpPreparationContex
t( | 242 final MinidumpPreparationContext context = new MinidumpPreparationContex
t( |
247 getInstrumentation().getTargetContext().getApplicationContext(),
service) { | 243 getInstrumentation().getTargetContext(), service) { |
248 Handler mHandler; | 244 Handler mHandler; |
249 { | 245 { |
250 HandlerThread handlerThread = | 246 HandlerThread handlerThread = |
251 new HandlerThread("MinidumpUploadServiceTest Handler Thr
ead"); | 247 new HandlerThread("MinidumpUploadServiceTest Handler Thr
ead"); |
252 handlerThread.start(); | 248 handlerThread.start(); |
253 mHandler = new Handler(handlerThread.getLooper()); | 249 mHandler = new Handler(handlerThread.getLooper()); |
254 } | 250 } |
255 | 251 |
256 @Override | 252 @Override |
257 public ComponentName startService(final Intent intentToCheck) { | 253 public ComponentName startService(final Intent intentToCheck) { |
(...skipping 12 matching lines...) Expand all Loading... |
270 // We need the context before we can attach it to the service, so since
Context is | 266 // We need the context before we can attach it to the service, so since
Context is |
271 // dependent on the service, we do this after context creation. | 267 // dependent on the service, we do this after context creation. |
272 service.attachBaseContextLate(context); | 268 service.attachBaseContextLate(context); |
273 // Create the file used for uploading. | 269 // Create the file used for uploading. |
274 File minidumpFile = new File(mCrashDir, "chromium_renderer-111.dmp1"); | 270 File minidumpFile = new File(mCrashDir, "chromium_renderer-111.dmp1"); |
275 minidumpFile.createNewFile(); | 271 minidumpFile.createNewFile(); |
276 setUpMinidumpFile(minidumpFile, BOUNDARY); | 272 setUpMinidumpFile(minidumpFile, BOUNDARY); |
277 | 273 |
278 // Run test. | 274 // Run test. |
279 service.onCreate(); | 275 service.onCreate(); |
280 ContextUtils.initApplicationContextForTests(context); | 276 MinidumpUploadService.tryUploadCrashDump(context, minidumpFile); |
281 MinidumpUploadService.tryUploadCrashDump(minidumpFile); | |
282 | 277 |
283 // Verify asynchronously. | 278 // Verify asynchronously. |
284 CriteriaHelper.pollInstrumentationThread( | 279 CriteriaHelper.pollInstrumentationThread( |
285 new Criteria("All callables should have a call-count of 1") { | 280 new Criteria("All callables should have a call-count of 1") { |
286 @Override | 281 @Override |
287 public boolean isSatisfied() { | 282 public boolean isSatisfied() { |
288 for (CountedMinidumpUploadCallable callable : callables)
{ | 283 for (CountedMinidumpUploadCallable callable : callables)
{ |
289 if (callable.mCalledCount != 1) { | 284 if (callable.mCalledCount != 1) { |
290 return false; | 285 return false; |
291 } | 286 } |
(...skipping 12 matching lines...) Expand all Loading... |
304 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; | 299 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
305 | 300 |
306 // Set up prerequisites. | 301 // Set up prerequisites. |
307 File minidumpFile = | 302 File minidumpFile = |
308 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"); | 303 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"); |
309 final File expectedRenamedMinidumpFile = | 304 final File expectedRenamedMinidumpFile = |
310 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 305 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
311 setUpMinidumpFile(minidumpFile, BOUNDARY); | 306 setUpMinidumpFile(minidumpFile, BOUNDARY); |
312 final String startServiceFlag = "startServiceFlag"; | 307 final String startServiceFlag = "startServiceFlag"; |
313 MinidumpPreparationContext context = new MinidumpPreparationContext( | 308 MinidumpPreparationContext context = new MinidumpPreparationContext( |
314 getInstrumentation().getTargetContext().getApplicationContext())
{ | 309 getInstrumentation().getTargetContext()) { |
315 @Override | 310 @Override |
316 public ComponentName startService(Intent intentToCheck) { | 311 public ComponentName startService(Intent intentToCheck) { |
317 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intentToCheck.
getAction()); | 312 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intentToCheck.
getAction()); |
318 String filePath = | 313 String filePath = |
319 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); | 314 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); |
320 assertEquals("Minidump path should be for a fresh upload", | 315 assertEquals("Minidump path should be for a fresh upload", |
321 expectedRenamedMinidumpFile.getAbsolutePath(), filePath)
; | 316 expectedRenamedMinidumpFile.getAbsolutePath(), filePath)
; |
322 setFlag(startServiceFlag); | 317 setFlag(startServiceFlag); |
323 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 318 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
324 } | 319 } |
325 }; | 320 }; |
326 | 321 |
327 // Run test. | 322 // Run test. |
328 ContextUtils.initApplicationContextForTests(context); | 323 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
329 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | |
330 | 324 |
331 // Verify. | 325 // Verify. |
332 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); | 326 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); |
333 } | 327 } |
334 | 328 |
335 @SmallTest | 329 @SmallTest |
336 @Feature({"Android-AppBase"}) | 330 @Feature({"Android-AppBase"}) |
337 public void testHandleForceUploadCrash_MinidumpFileExists_WithJobScheduler() | 331 public void testHandleForceUploadCrash_MinidumpFileExists_WithJobScheduler() |
338 throws IOException { | 332 throws IOException { |
339 // The JobScheduler API is only available as of Android M+. | 333 // The JobScheduler API is only available as of Android M+. |
340 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 334 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
341 | 335 |
342 // Set up prerequisites. | 336 // Set up prerequisites. |
343 setUpMinidumpFile( | 337 setUpMinidumpFile( |
344 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"), | 338 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"), |
345 BOUNDARY); | 339 BOUNDARY); |
346 AdvancedMockContext context = new MinidumpPreparationContext( | 340 AdvancedMockContext context = |
347 getInstrumentation().getTargetContext().getApplicationContext())
; | 341 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
348 | 342 |
349 // Run test. | 343 // Run test. |
350 ContextUtils.initApplicationContextForTests(context); | 344 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
351 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | |
352 | 345 |
353 // Verify. | 346 // Verify. |
354 final File expectedRenamedMinidumpFile = | 347 final File expectedRenamedMinidumpFile = |
355 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 348 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
356 assertTrue("Should have renamed the minidump file for forced upload", | 349 assertTrue("Should have renamed the minidump file for forced upload", |
357 expectedRenamedMinidumpFile.exists()); | 350 expectedRenamedMinidumpFile.exists()); |
358 assertTrue("Should have tried to schedule an upload job", | 351 assertTrue("Should have tried to schedule an upload job", |
359 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 352 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
360 } | 353 } |
361 | 354 |
362 @SmallTest | 355 @SmallTest |
363 @Feature({"Android-AppBase"}) | 356 @Feature({"Android-AppBase"}) |
364 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_SansJobSche
duler() | 357 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_SansJobSche
duler() |
365 throws IOException { | 358 throws IOException { |
366 // The JobScheduler API is used on Android M+. | 359 // The JobScheduler API is used on Android M+. |
367 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; | 360 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
368 | 361 |
369 // Set up prerequisites. | 362 // Set up prerequisites. |
370 File minidumpFile = | 363 File minidumpFile = |
371 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try0"); | 364 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try0"); |
372 final File expectedRenamedMinidumpFile = | 365 final File expectedRenamedMinidumpFile = |
373 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 366 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
374 setUpMinidumpFile(minidumpFile, BOUNDARY); | 367 setUpMinidumpFile(minidumpFile, BOUNDARY); |
375 final String startServiceFlag = "startServiceFlag"; | 368 final String startServiceFlag = "startServiceFlag"; |
376 MinidumpPreparationContext context = new MinidumpPreparationContext( | 369 MinidumpPreparationContext context = new MinidumpPreparationContext( |
377 getInstrumentation().getTargetContext().getApplicationContext())
{ | 370 getInstrumentation().getTargetContext()) { |
378 @Override | 371 @Override |
379 public ComponentName startService(Intent intentToCheck) { | 372 public ComponentName startService(Intent intentToCheck) { |
380 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intentToCheck.
getAction()); | 373 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intentToCheck.
getAction()); |
381 String filePath = | 374 String filePath = |
382 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); | 375 intentToCheck.getStringExtra(MinidumpUploadService.FILE_
TO_UPLOAD_KEY); |
383 assertEquals("Minidump path should be for a fresh upload", | 376 assertEquals("Minidump path should be for a fresh upload", |
384 expectedRenamedMinidumpFile.getAbsolutePath(), filePath)
; | 377 expectedRenamedMinidumpFile.getAbsolutePath(), filePath)
; |
385 setFlag(startServiceFlag); | 378 setFlag(startServiceFlag); |
386 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 379 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
387 } | 380 } |
388 }; | 381 }; |
389 | 382 |
390 // Run test. | 383 // Run test. |
391 ContextUtils.initApplicationContextForTests(context); | 384 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
392 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | |
393 | 385 |
394 // Verify. | 386 // Verify. |
395 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); | 387 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); |
396 } | 388 } |
397 | 389 |
398 @SmallTest | 390 @SmallTest |
399 @Feature({"Android-AppBase"}) | 391 @Feature({"Android-AppBase"}) |
400 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_WithJobSche
duler() | 392 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_WithJobSche
duler() |
401 throws IOException { | 393 throws IOException { |
402 // The JobScheduler API is only available as of Android M. | 394 // The JobScheduler API is only available as of Android M. |
403 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 395 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
404 | 396 |
405 // Set up prerequisites. | 397 // Set up prerequisites. |
406 setUpMinidumpFile( | 398 setUpMinidumpFile( |
407 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try3"), | 399 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try3"), |
408 BOUNDARY); | 400 BOUNDARY); |
409 AdvancedMockContext context = new MinidumpPreparationContext( | 401 AdvancedMockContext context = |
410 getInstrumentation().getTargetContext().getApplicationContext())
; | 402 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
411 | 403 |
412 // Run test. | 404 // Run test. |
413 ContextUtils.initApplicationContextForTests(context); | 405 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
414 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | |
415 | 406 |
416 // Verify. | 407 // Verify. |
417 final File expectedRenamedMinidumpFile = | 408 final File expectedRenamedMinidumpFile = |
418 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 409 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
419 assertTrue("Should have renamed the minidump file for forced upload", | 410 assertTrue("Should have renamed the minidump file for forced upload", |
420 expectedRenamedMinidumpFile.exists()); | 411 expectedRenamedMinidumpFile.exists()); |
421 assertTrue("Should have tried to schedule an upload job", | 412 assertTrue("Should have tried to schedule an upload job", |
422 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 413 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
423 } | 414 } |
424 | 415 |
425 @SmallTest | 416 @SmallTest |
426 @Feature({"Android-AppBase"}) | 417 @Feature({"Android-AppBase"}) |
427 public void testHandleForceUploadCrash_FileDoesntExist_SansJobScheduler() { | 418 public void testHandleForceUploadCrash_FileDoesntExist_SansJobScheduler() { |
428 // The JobScheduler API is used on Android M+. | 419 // The JobScheduler API is used on Android M+. |
429 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; | 420 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
430 | 421 |
431 // Set up prerequisites. | 422 // Set up prerequisites. |
432 final String startServiceFlag = "startServiceFlag"; | 423 final String startServiceFlag = "startServiceFlag"; |
433 MinidumpPreparationContext context = new MinidumpPreparationContext( | 424 MinidumpPreparationContext context = new MinidumpPreparationContext( |
434 getInstrumentation().getTargetContext().getApplicationContext())
{ | 425 getInstrumentation().getTargetContext()) { |
435 @Override | 426 @Override |
436 public ComponentName startService(Intent unused) { | 427 public ComponentName startService(Intent unused) { |
437 setFlag(startServiceFlag); | 428 setFlag(startServiceFlag); |
438 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 429 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
439 } | 430 } |
440 }; | 431 }; |
441 | 432 |
442 // Run test. | 433 // Run test. |
443 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | 434 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
444 | 435 |
445 // Verify. | 436 // Verify. |
446 assertFalse( | 437 assertFalse( |
447 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); | 438 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); |
448 } | 439 } |
449 | 440 |
450 @SmallTest | 441 @SmallTest |
451 @Feature({"Android-AppBase"}) | 442 @Feature({"Android-AppBase"}) |
452 public void testHandleForceUploadCrash_FileDoesntExist_WithJobScheduler() th
rows IOException { | 443 public void testHandleForceUploadCrash_FileDoesntExist_WithJobScheduler() th
rows IOException { |
453 // The JobScheduler API is only available as of Android M. | 444 // The JobScheduler API is only available as of Android M. |
454 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 445 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
455 | 446 |
456 // Set up prerequisites. | 447 // Set up prerequisites. |
457 AdvancedMockContext context = new MinidumpPreparationContext( | 448 AdvancedMockContext context = |
458 getInstrumentation().getTargetContext().getApplicationContext())
; | 449 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
459 | 450 |
460 // Run test. | 451 // Run test. |
461 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | 452 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
462 | 453 |
463 // Verify. | 454 // Verify. |
464 assertFalse("Should not have tried to schedule an upload job", | 455 assertFalse("Should not have tried to schedule an upload job", |
465 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 456 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
466 } | 457 } |
467 | 458 |
468 @SmallTest | 459 @SmallTest |
469 @Feature({"Android-AppBase"}) | 460 @Feature({"Android-AppBase"}) |
470 public void testHandleForceUploadCrash_FileAlreadyUploaded_SansJobScheduler(
) | 461 public void testHandleForceUploadCrash_FileAlreadyUploaded_SansJobScheduler(
) |
471 throws IOException { | 462 throws IOException { |
472 // The JobScheduler API is used on Android M+. | 463 // The JobScheduler API is used on Android M+. |
473 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; | 464 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
474 | 465 |
475 // Set up prerequisites. | 466 // Set up prerequisites. |
476 setUpMinidumpFile( | 467 setUpMinidumpFile( |
477 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), | 468 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), |
478 BOUNDARY); | 469 BOUNDARY); |
479 final String startServiceFlag = "startServiceFlag"; | 470 final String startServiceFlag = "startServiceFlag"; |
480 MinidumpPreparationContext context = new MinidumpPreparationContext( | 471 MinidumpPreparationContext context = new MinidumpPreparationContext( |
481 getInstrumentation().getTargetContext().getApplicationContext())
{ | 472 getInstrumentation().getTargetContext()) { |
482 @Override | 473 @Override |
483 public ComponentName startService(Intent unused) { | 474 public ComponentName startService(Intent unused) { |
484 setFlag(startServiceFlag); | 475 setFlag(startServiceFlag); |
485 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 476 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
486 } | 477 } |
487 }; | 478 }; |
488 | 479 |
489 // Run test. | 480 // Run test. |
490 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | 481 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
491 | 482 |
492 // Verify. | 483 // Verify. |
493 assertFalse( | 484 assertFalse( |
494 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); | 485 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); |
495 } | 486 } |
496 | 487 |
497 @SmallTest | 488 @SmallTest |
498 @Feature({"Android-AppBase"}) | 489 @Feature({"Android-AppBase"}) |
499 public void testHandleForceUploadCrash_FileAlreadyUploaded_WithJobScheduler(
) | 490 public void testHandleForceUploadCrash_FileAlreadyUploaded_WithJobScheduler(
) |
500 throws IOException { | 491 throws IOException { |
501 // The JobScheduler API is only available as of Android M. | 492 // The JobScheduler API is only available as of Android M. |
502 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 493 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
503 | 494 |
504 // Set up prerequisites. | 495 // Set up prerequisites. |
505 setUpMinidumpFile( | 496 setUpMinidumpFile( |
506 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), | 497 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), |
507 BOUNDARY); | 498 BOUNDARY); |
508 AdvancedMockContext context = new MinidumpPreparationContext( | 499 AdvancedMockContext context = |
509 getInstrumentation().getTargetContext().getApplicationContext())
; | 500 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
510 | 501 |
511 // Run test. | 502 // Run test. |
512 MinidumpUploadService.tryUploadCrashDumpWithLocalId("f297dbcba7a2d0bb"); | 503 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
513 | 504 |
514 // Verify. | 505 // Verify. |
515 assertFalse("Should not have tried to schedule an upload job", | 506 assertFalse("Should not have tried to schedule an upload job", |
516 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 507 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
517 } | 508 } |
518 | 509 |
519 @SmallTest | 510 @SmallTest |
520 @Feature({"Android-AppBase"}) | 511 @Feature({"Android-AppBase"}) |
521 public void testGetCrashType1() throws IOException { | 512 public void testGetCrashType1() throws IOException { |
522 final File minidumpFile = new File(mCrashDir, "chromium_renderer-123.dmp
"); | 513 final File minidumpFile = new File(mCrashDir, "chromium_renderer-123.dmp
"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 public MinidumpPreparationContext(Context targetContext) { | 548 public MinidumpPreparationContext(Context targetContext) { |
558 this(targetContext, null); | 549 this(targetContext, null); |
559 } | 550 } |
560 | 551 |
561 public MinidumpPreparationContext(Context targetContext, MinidumpUploadS
ervice service) { | 552 public MinidumpPreparationContext(Context targetContext, MinidumpUploadS
ervice service) { |
562 super(targetContext); | 553 super(targetContext); |
563 mService = service; | 554 mService = service; |
564 } | 555 } |
565 | 556 |
566 @Override | 557 @Override |
| 558 public File getCacheDir() { |
| 559 return mCacheDir; |
| 560 } |
| 561 |
| 562 @Override |
567 public Object getSystemService(String name) { | 563 public Object getSystemService(String name) { |
568 if (Context.JOB_SCHEDULER_SERVICE.equals(name)) { | 564 if (Context.JOB_SCHEDULER_SERVICE.equals(name)) { |
569 return new TestJobScheduler(this); | 565 return new TestJobScheduler(this); |
570 } | 566 } |
571 | 567 |
572 return super.getSystemService(name); | 568 return super.getSystemService(name); |
573 } | 569 } |
574 } | 570 } |
575 | 571 |
576 /** | 572 /** |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 this.mTriggerNetworkChange = networkChange; | 631 this.mTriggerNetworkChange = networkChange; |
636 } | 632 } |
637 | 633 |
638 @Override | 634 @Override |
639 public Integer call() { | 635 public Integer call() { |
640 ++mCalledCount; | 636 ++mCalledCount; |
641 return mResult; | 637 return mResult; |
642 } | 638 } |
643 } | 639 } |
644 } | 640 } |
OLD | NEW |