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