| 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 org.chromium.chrome.browser.crash.MinidumpUploadService.BROWSER; | 7 import static org.chromium.chrome.browser.crash.MinidumpUploadService.BROWSER; |
| 8 import static org.chromium.chrome.browser.crash.MinidumpUploadService.GPU; | 8 import static org.chromium.chrome.browser.crash.MinidumpUploadService.GPU; |
| 9 import static org.chromium.chrome.browser.crash.MinidumpUploadService.OTHER; | 9 import static org.chromium.chrome.browser.crash.MinidumpUploadService.OTHER; |
| 10 import static org.chromium.chrome.browser.crash.MinidumpUploadService.RENDERER; | 10 import static org.chromium.chrome.browser.crash.MinidumpUploadService.RENDERER; |
| 11 | 11 |
| 12 import android.annotation.TargetApi; | 12 import android.annotation.TargetApi; |
| 13 import android.app.job.JobInfo; | 13 import android.app.job.JobInfo; |
| 14 import android.app.job.JobScheduler; | 14 import android.app.job.JobScheduler; |
| 15 import android.content.ComponentName; | 15 import android.content.ComponentName; |
| 16 import android.content.Context; | 16 import android.content.Context; |
| 17 import android.content.Intent; | 17 import android.content.Intent; |
| 18 import android.os.Build; | 18 import android.os.Build; |
| 19 import android.os.Handler; | 19 import android.os.Handler; |
| 20 import android.os.HandlerThread; | 20 import android.os.HandlerThread; |
| 21 import android.support.test.filters.SmallTest; | 21 import android.support.test.filters.SmallTest; |
| 22 | 22 |
| 23 import org.chromium.base.annotations.SuppressFBWarnings; | 23 import org.chromium.base.annotations.SuppressFBWarnings; |
| 24 import org.chromium.base.test.util.AdvancedMockContext; | 24 import org.chromium.base.test.util.AdvancedMockContext; |
| 25 import org.chromium.base.test.util.Feature; | 25 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.chrome.browser.ChromeFeatureList; | |
| 27 import org.chromium.components.background_task_scheduler.TaskIds; | 26 import org.chromium.components.background_task_scheduler.TaskIds; |
| 28 import org.chromium.components.minidump_uploader.CrashTestCase; | 27 import org.chromium.components.minidump_uploader.CrashTestCase; |
| 29 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; | 28 import org.chromium.components.minidump_uploader.MinidumpUploadCallable; |
| 30 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; | 29 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
| 31 import org.chromium.content.browser.test.util.Criteria; | 30 import org.chromium.content.browser.test.util.Criteria; |
| 32 import org.chromium.content.browser.test.util.CriteriaHelper; | 31 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 33 import org.chromium.net.NetworkChangeNotifier; | 32 import org.chromium.net.NetworkChangeNotifier; |
| 34 | 33 |
| 35 import java.io.File; | 34 import java.io.File; |
| 36 import java.io.IOException; | 35 import java.io.IOException; |
| 37 import java.util.ArrayList; | 36 import java.util.ArrayList; |
| 38 import java.util.HashMap; | |
| 39 import java.util.List; | 37 import java.util.List; |
| 40 import java.util.Map; | |
| 41 import java.util.concurrent.atomic.AtomicInteger; | 38 import java.util.concurrent.atomic.AtomicInteger; |
| 42 /** | 39 /** |
| 43 * Testcase for {@link MinidumpUploadService}. | 40 * Testcase for {@link MinidumpUploadService}. |
| 44 */ | 41 */ |
| 45 public class MinidumpUploadServiceTest extends CrashTestCase { | 42 public class MinidumpUploadServiceTest extends CrashTestCase { |
| 46 private static final int CHECK_INTERVAL_MS = 250; | 43 private static final int CHECK_INTERVAL_MS = 250; |
| 47 private static final int MAX_TIMEOUT_MS = 20000; | 44 private static final int MAX_TIMEOUT_MS = 20000; |
| 48 private static final String BOUNDARY = "TESTBOUNDARY"; | 45 private static final String BOUNDARY = "TESTBOUNDARY"; |
| 49 | 46 |
| 50 private static class TestMinidumpUploadService extends MinidumpUploadService
{ | 47 private static class TestMinidumpUploadService extends MinidumpUploadService
{ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 72 | 69 |
| 73 CrashReportingPermissionManager getCrashReportingPermissionManager() { | 70 CrashReportingPermissionManager getCrashReportingPermissionManager() { |
| 74 return mPermissionManager; | 71 return mPermissionManager; |
| 75 } | 72 } |
| 76 | 73 |
| 77 public void setIsNetworkAvailableForCrashUploads(boolean networkAvailabl
e) { | 74 public void setIsNetworkAvailableForCrashUploads(boolean networkAvailabl
e) { |
| 78 mPermissionManager.setIsNetworkAvailableForCrashUploads(networkAvail
able); | 75 mPermissionManager.setIsNetworkAvailableForCrashUploads(networkAvail
able); |
| 79 } | 76 } |
| 80 } | 77 } |
| 81 | 78 |
| 82 @Override | |
| 83 protected void tearDown() throws Exception { | |
| 84 ChromeFeatureList.setTestFeatures(null); | |
| 85 super.tearDown(); | |
| 86 } | |
| 87 | |
| 88 /** | |
| 89 * Sets whether to upload minidumps using the JobScheduler API. Minidumps ca
n either be uploaded | |
| 90 * via a JobScheduler, or via a direct Intent service. | |
| 91 * @param enable Whether to enable the JobScheduler API. | |
| 92 */ | |
| 93 private void setJobSchedulerEnabled(boolean enable) { | |
| 94 Map<String, Boolean> features = new HashMap<>(); | |
| 95 features.put(ChromeFeatureList.UPLOAD_CRASH_REPORTS_USING_JOB_SCHEDULER,
enable); | |
| 96 ChromeFeatureList.setTestFeatures(features); | |
| 97 } | |
| 98 | |
| 99 @SmallTest | 79 @SmallTest |
| 100 @Feature({"Android-AppBase"}) | 80 @Feature({"Android-AppBase"}) |
| 101 public void testTryUploadAllCrashDumps() throws IOException { | 81 public void testTryUploadAllCrashDumps() throws IOException { |
| 82 // The JobScheduler API is used on Android M+. |
| 83 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 84 |
| 102 // Setup prerequisites. | 85 // Setup prerequisites. |
| 103 setJobSchedulerEnabled(false); | |
| 104 final AtomicInteger numServiceStarts = new AtomicInteger(0); | 86 final AtomicInteger numServiceStarts = new AtomicInteger(0); |
| 105 final File[] minidumpFiles = { | 87 final File[] minidumpFiles = { |
| 106 new File(mCrashDir, "chromium_renderer-111.dmp1"), | 88 new File(mCrashDir, "chromium_renderer-111.dmp1"), |
| 107 new File(mCrashDir, "chromium_renderer-222.dmp2"), | 89 new File(mCrashDir, "chromium_renderer-222.dmp2"), |
| 108 new File(mCrashDir, "chromium_renderer-333.dmp3"), | 90 new File(mCrashDir, "chromium_renderer-333.dmp3"), |
| 109 }; | 91 }; |
| 110 MinidumpPreparationContext context = new MinidumpPreparationContext( | 92 MinidumpPreparationContext context = new MinidumpPreparationContext( |
| 111 getInstrumentation().getTargetContext()) { | 93 getInstrumentation().getTargetContext()) { |
| 112 @Override | 94 @Override |
| 113 public ComponentName startService(Intent intentToCheck) { | 95 public ComponentName startService(Intent intentToCheck) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 List<CountedMinidumpUploadCallable> callables = | 165 List<CountedMinidumpUploadCallable> callables = |
| 184 new ArrayList<CountedMinidumpUploadCallable>(); | 166 new ArrayList<CountedMinidumpUploadCallable>(); |
| 185 callables.add(new CountedMinidumpUploadCallable( | 167 callables.add(new CountedMinidumpUploadCallable( |
| 186 "chromium_renderer-111.dmp1", MinidumpUploadCallable.UPLOAD_FAIL
URE, false)); | 168 "chromium_renderer-111.dmp1", MinidumpUploadCallable.UPLOAD_FAIL
URE, false)); |
| 187 runUploadCrashTest(callables); | 169 runUploadCrashTest(callables); |
| 188 } | 170 } |
| 189 | 171 |
| 190 @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") | 172 @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") |
| 191 private void runUploadCrashTest(final List<CountedMinidumpUploadCallable> ca
llables) | 173 private void runUploadCrashTest(final List<CountedMinidumpUploadCallable> ca
llables) |
| 192 throws IOException, InterruptedException { | 174 throws IOException, InterruptedException { |
| 175 // The JobScheduler API is used on Android M+. |
| 176 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 177 |
| 193 // Setup prerequisites. | 178 // Setup prerequisites. |
| 194 // This version of the service overrides the createMinidumpUploadCallabl
e(...) to be able | 179 // This version of the service overrides the createMinidumpUploadCallabl
e(...) to be able |
| 195 // to return fake ones. It also ensures that the service never tries to
create a callable | 180 // to return fake ones. It also ensures that the service never tries to
create a callable |
| 196 // too many times. | 181 // too many times. |
| 197 setJobSchedulerEnabled(false); | |
| 198 TestMinidumpUploadService service = new TestMinidumpUploadService() { | 182 TestMinidumpUploadService service = new TestMinidumpUploadService() { |
| 199 int mIndex = 0; | 183 int mIndex = 0; |
| 200 boolean mTriggerNetworkChange = false; | 184 boolean mTriggerNetworkChange = false; |
| 201 | 185 |
| 202 @Override | 186 @Override |
| 203 MinidumpUploadCallable createMinidumpUploadCallable(File minidumpFil
e, File logfile) { | 187 MinidumpUploadCallable createMinidumpUploadCallable(File minidumpFil
e, File logfile) { |
| 204 if (mIndex >= callables.size()) { | 188 if (mIndex >= callables.size()) { |
| 205 fail("Should not create callable number " + mIndex); | 189 fail("Should not create callable number " + mIndex); |
| 206 } | 190 } |
| 207 CountedMinidumpUploadCallable callable = callables.get(mIndex++)
; | 191 CountedMinidumpUploadCallable callable = callables.get(mIndex++)
; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return true; | 288 return true; |
| 305 } | 289 } |
| 306 }, | 290 }, |
| 307 MAX_TIMEOUT_MS, CHECK_INTERVAL_MS); | 291 MAX_TIMEOUT_MS, CHECK_INTERVAL_MS); |
| 308 } | 292 } |
| 309 | 293 |
| 310 @SmallTest | 294 @SmallTest |
| 311 @Feature({"Android-AppBase"}) | 295 @Feature({"Android-AppBase"}) |
| 312 public void testHandleForceUploadCrash_MinidumpFileExists_SansJobScheduler() | 296 public void testHandleForceUploadCrash_MinidumpFileExists_SansJobScheduler() |
| 313 throws IOException { | 297 throws IOException { |
| 298 // The JobScheduler API is used on Android M+. |
| 299 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 300 |
| 314 // Set up prerequisites. | 301 // Set up prerequisites. |
| 315 setJobSchedulerEnabled(false); | |
| 316 File minidumpFile = | 302 File minidumpFile = |
| 317 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"); | 303 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"); |
| 318 final File expectedRenamedMinidumpFile = | 304 final File expectedRenamedMinidumpFile = |
| 319 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 305 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
| 320 setUpMinidumpFile(minidumpFile, BOUNDARY); | 306 setUpMinidumpFile(minidumpFile, BOUNDARY); |
| 321 final String startServiceFlag = "startServiceFlag"; | 307 final String startServiceFlag = "startServiceFlag"; |
| 322 MinidumpPreparationContext context = new MinidumpPreparationContext( | 308 MinidumpPreparationContext context = new MinidumpPreparationContext( |
| 323 getInstrumentation().getTargetContext()) { | 309 getInstrumentation().getTargetContext()) { |
| 324 @Override | 310 @Override |
| 325 public ComponentName startService(Intent intentToCheck) { | 311 public ComponentName startService(Intent intentToCheck) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 337 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 323 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 338 | 324 |
| 339 // Verify. | 325 // Verify. |
| 340 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); | 326 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); |
| 341 } | 327 } |
| 342 | 328 |
| 343 @SmallTest | 329 @SmallTest |
| 344 @Feature({"Android-AppBase"}) | 330 @Feature({"Android-AppBase"}) |
| 345 public void testHandleForceUploadCrash_MinidumpFileExists_WithJobScheduler() | 331 public void testHandleForceUploadCrash_MinidumpFileExists_WithJobScheduler() |
| 346 throws IOException { | 332 throws IOException { |
| 347 // The JobScheduler API is only available as of Android M. | 333 // The JobScheduler API is only available as of Android M+. |
| 348 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 334 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
| 349 setJobSchedulerEnabled(true); | |
| 350 | 335 |
| 351 // Set up prerequisites. | 336 // Set up prerequisites. |
| 352 setUpMinidumpFile( | 337 setUpMinidumpFile( |
| 353 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"), | 338 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.dmp0.try3"), |
| 354 BOUNDARY); | 339 BOUNDARY); |
| 355 AdvancedMockContext context = | 340 AdvancedMockContext context = |
| 356 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); | 341 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
| 357 | 342 |
| 358 // Run test. | 343 // Run test. |
| 359 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 344 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 360 | 345 |
| 361 // Verify. | 346 // Verify. |
| 362 final File expectedRenamedMinidumpFile = | 347 final File expectedRenamedMinidumpFile = |
| 363 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 348 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
| 364 assertTrue("Should have renamed the minidump file for forced upload", | 349 assertTrue("Should have renamed the minidump file for forced upload", |
| 365 expectedRenamedMinidumpFile.exists()); | 350 expectedRenamedMinidumpFile.exists()); |
| 366 assertTrue("Should have tried to schedule an upload job", | 351 assertTrue("Should have tried to schedule an upload job", |
| 367 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 352 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
| 368 } | 353 } |
| 369 | 354 |
| 370 @SmallTest | 355 @SmallTest |
| 371 @Feature({"Android-AppBase"}) | 356 @Feature({"Android-AppBase"}) |
| 372 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_SansJobSche
duler() | 357 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_SansJobSche
duler() |
| 373 throws IOException { | 358 throws IOException { |
| 359 // The JobScheduler API is used on Android M+. |
| 360 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 361 |
| 374 // Set up prerequisites. | 362 // Set up prerequisites. |
| 375 setJobSchedulerEnabled(false); | |
| 376 File minidumpFile = | 363 File minidumpFile = |
| 377 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try0"); | 364 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try0"); |
| 378 final File expectedRenamedMinidumpFile = | 365 final File expectedRenamedMinidumpFile = |
| 379 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 366 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
| 380 setUpMinidumpFile(minidumpFile, BOUNDARY); | 367 setUpMinidumpFile(minidumpFile, BOUNDARY); |
| 381 final String startServiceFlag = "startServiceFlag"; | 368 final String startServiceFlag = "startServiceFlag"; |
| 382 MinidumpPreparationContext context = new MinidumpPreparationContext( | 369 MinidumpPreparationContext context = new MinidumpPreparationContext( |
| 383 getInstrumentation().getTargetContext()) { | 370 getInstrumentation().getTargetContext()) { |
| 384 @Override | 371 @Override |
| 385 public ComponentName startService(Intent intentToCheck) { | 372 public ComponentName startService(Intent intentToCheck) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 399 // Verify. | 386 // Verify. |
| 400 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); | 387 assertTrue("Should have called startService(...)", context.isFlagSet(sta
rtServiceFlag)); |
| 401 } | 388 } |
| 402 | 389 |
| 403 @SmallTest | 390 @SmallTest |
| 404 @Feature({"Android-AppBase"}) | 391 @Feature({"Android-AppBase"}) |
| 405 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_WithJobSche
duler() | 392 public void testHandleForceUploadCrash_SkippedMinidumpFileExists_WithJobSche
duler() |
| 406 throws IOException { | 393 throws IOException { |
| 407 // The JobScheduler API is only available as of Android M. | 394 // The JobScheduler API is only available as of Android M. |
| 408 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 395 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
| 409 setJobSchedulerEnabled(true); | |
| 410 | 396 |
| 411 // Set up prerequisites. | 397 // Set up prerequisites. |
| 412 setUpMinidumpFile( | 398 setUpMinidumpFile( |
| 413 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try3"), | 399 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.skipped0.try3"), |
| 414 BOUNDARY); | 400 BOUNDARY); |
| 415 AdvancedMockContext context = | 401 AdvancedMockContext context = |
| 416 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); | 402 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
| 417 | 403 |
| 418 // Run test. | 404 // Run test. |
| 419 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 405 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 420 | 406 |
| 421 // Verify. | 407 // Verify. |
| 422 final File expectedRenamedMinidumpFile = | 408 final File expectedRenamedMinidumpFile = |
| 423 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); | 409 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.forced0.try0"); |
| 424 assertTrue("Should have renamed the minidump file for forced upload", | 410 assertTrue("Should have renamed the minidump file for forced upload", |
| 425 expectedRenamedMinidumpFile.exists()); | 411 expectedRenamedMinidumpFile.exists()); |
| 426 assertTrue("Should have tried to schedule an upload job", | 412 assertTrue("Should have tried to schedule an upload job", |
| 427 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 413 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
| 428 } | 414 } |
| 429 | 415 |
| 430 @SmallTest | 416 @SmallTest |
| 431 @Feature({"Android-AppBase"}) | 417 @Feature({"Android-AppBase"}) |
| 432 public void testHandleForceUploadCrash_FileDoesntExist_SansJobScheduler() { | 418 public void testHandleForceUploadCrash_FileDoesntExist_SansJobScheduler() { |
| 419 // The JobScheduler API is used on Android M+. |
| 420 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 421 |
| 433 // Set up prerequisites. | 422 // Set up prerequisites. |
| 434 setJobSchedulerEnabled(false); | |
| 435 final String startServiceFlag = "startServiceFlag"; | 423 final String startServiceFlag = "startServiceFlag"; |
| 436 MinidumpPreparationContext context = new MinidumpPreparationContext( | 424 MinidumpPreparationContext context = new MinidumpPreparationContext( |
| 437 getInstrumentation().getTargetContext()) { | 425 getInstrumentation().getTargetContext()) { |
| 438 @Override | 426 @Override |
| 439 public ComponentName startService(Intent unused) { | 427 public ComponentName startService(Intent unused) { |
| 440 setFlag(startServiceFlag); | 428 setFlag(startServiceFlag); |
| 441 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 429 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
| 442 } | 430 } |
| 443 }; | 431 }; |
| 444 | 432 |
| 445 // Run test. | 433 // Run test. |
| 446 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 434 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 447 | 435 |
| 448 // Verify. | 436 // Verify. |
| 449 assertFalse( | 437 assertFalse( |
| 450 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); | 438 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); |
| 451 } | 439 } |
| 452 | 440 |
| 453 @SmallTest | 441 @SmallTest |
| 454 @Feature({"Android-AppBase"}) | 442 @Feature({"Android-AppBase"}) |
| 455 public void testHandleForceUploadCrash_FileDoesntExist_WithJobScheduler() th
rows IOException { | 443 public void testHandleForceUploadCrash_FileDoesntExist_WithJobScheduler() th
rows IOException { |
| 456 // The JobScheduler API is only available as of Android M. | 444 // The JobScheduler API is only available as of Android M. |
| 457 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 445 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
| 458 setJobSchedulerEnabled(true); | |
| 459 | 446 |
| 460 // Set up prerequisites. | 447 // Set up prerequisites. |
| 461 AdvancedMockContext context = | 448 AdvancedMockContext context = |
| 462 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); | 449 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
| 463 | 450 |
| 464 // Run test. | 451 // Run test. |
| 465 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 452 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 466 | 453 |
| 467 // Verify. | 454 // Verify. |
| 468 assertFalse("Should not have tried to schedule an upload job", | 455 assertFalse("Should not have tried to schedule an upload job", |
| 469 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); | 456 context.isFlagSet(TestJobScheduler.SCHEDULE_JOB_FLAG)); |
| 470 } | 457 } |
| 471 | 458 |
| 472 @SmallTest | 459 @SmallTest |
| 473 @Feature({"Android-AppBase"}) | 460 @Feature({"Android-AppBase"}) |
| 474 public void testHandleForceUploadCrash_FileAlreadyUploaded_SansJobScheduler(
) | 461 public void testHandleForceUploadCrash_FileAlreadyUploaded_SansJobScheduler(
) |
| 475 throws IOException { | 462 throws IOException { |
| 463 // The JobScheduler API is used on Android M+. |
| 464 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return; |
| 465 |
| 476 // Set up prerequisites. | 466 // Set up prerequisites. |
| 477 setJobSchedulerEnabled(false); | |
| 478 setUpMinidumpFile( | 467 setUpMinidumpFile( |
| 479 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), | 468 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), |
| 480 BOUNDARY); | 469 BOUNDARY); |
| 481 final String startServiceFlag = "startServiceFlag"; | 470 final String startServiceFlag = "startServiceFlag"; |
| 482 MinidumpPreparationContext context = new MinidumpPreparationContext( | 471 MinidumpPreparationContext context = new MinidumpPreparationContext( |
| 483 getInstrumentation().getTargetContext()) { | 472 getInstrumentation().getTargetContext()) { |
| 484 @Override | 473 @Override |
| 485 public ComponentName startService(Intent unused) { | 474 public ComponentName startService(Intent unused) { |
| 486 setFlag(startServiceFlag); | 475 setFlag(startServiceFlag); |
| 487 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); | 476 return new ComponentName(getPackageName(), MinidumpUploadService
.class.getName()); |
| 488 } | 477 } |
| 489 }; | 478 }; |
| 490 | 479 |
| 491 // Run test. | 480 // Run test. |
| 492 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 481 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| 493 | 482 |
| 494 // Verify. | 483 // Verify. |
| 495 assertFalse( | 484 assertFalse( |
| 496 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); | 485 "Should not have called startService(...)", context.isFlagSet(st
artServiceFlag)); |
| 497 } | 486 } |
| 498 | 487 |
| 499 @SmallTest | 488 @SmallTest |
| 500 @Feature({"Android-AppBase"}) | 489 @Feature({"Android-AppBase"}) |
| 501 public void testHandleForceUploadCrash_FileAlreadyUploaded_WithJobScheduler(
) | 490 public void testHandleForceUploadCrash_FileAlreadyUploaded_WithJobScheduler(
) |
| 502 throws IOException { | 491 throws IOException { |
| 503 // The JobScheduler API is only available as of Android M. | 492 // The JobScheduler API is only available as of Android M. |
| 504 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; | 493 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; |
| 505 setJobSchedulerEnabled(true); | |
| 506 | 494 |
| 507 // Set up prerequisites. | 495 // Set up prerequisites. |
| 508 setUpMinidumpFile( | 496 setUpMinidumpFile( |
| 509 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), | 497 new File(mCrashDir, "chromium-renderer-minidump-f297dbcba7a2d0bb
.up0.try0"), |
| 510 BOUNDARY); | 498 BOUNDARY); |
| 511 AdvancedMockContext context = | 499 AdvancedMockContext context = |
| 512 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); | 500 new MinidumpPreparationContext(getInstrumentation().getTargetCon
text()); |
| 513 | 501 |
| 514 // Run test. | 502 // Run test. |
| 515 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); | 503 MinidumpUploadService.tryUploadCrashDumpWithLocalId(context, "f297dbcba7
a2d0bb"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 555 } |
| 568 | 556 |
| 569 @Override | 557 @Override |
| 570 public File getCacheDir() { | 558 public File getCacheDir() { |
| 571 return mCacheDir; | 559 return mCacheDir; |
| 572 } | 560 } |
| 573 | 561 |
| 574 @Override | 562 @Override |
| 575 public Object getSystemService(String name) { | 563 public Object getSystemService(String name) { |
| 576 if (Context.JOB_SCHEDULER_SERVICE.equals(name)) { | 564 if (Context.JOB_SCHEDULER_SERVICE.equals(name)) { |
| 577 assertTrue("Should only access the JobScheduler when it is enabl
ed.", | |
| 578 ChromeFeatureList.isEnabled( | |
| 579 ChromeFeatureList.UPLOAD_CRASH_REPORTS_USING_JOB
_SCHEDULER)); | |
| 580 return new TestJobScheduler(this); | 565 return new TestJobScheduler(this); |
| 581 } | 566 } |
| 582 | 567 |
| 583 return super.getSystemService(name); | 568 return super.getSystemService(name); |
| 584 } | 569 } |
| 585 } | 570 } |
| 586 | 571 |
| 587 /** | 572 /** |
| 588 * A JobScheduler wrapper that verifies that the expected properties are set
correctly. | 573 * A JobScheduler wrapper that verifies that the expected properties are set
correctly. |
| 589 */ | 574 */ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 this.mTriggerNetworkChange = networkChange; | 631 this.mTriggerNetworkChange = networkChange; |
| 647 } | 632 } |
| 648 | 633 |
| 649 @Override | 634 @Override |
| 650 public Integer call() { | 635 public Integer call() { |
| 651 ++mCalledCount; | 636 ++mCalledCount; |
| 652 return mResult; | 637 return mResult; |
| 653 } | 638 } |
| 654 } | 639 } |
| 655 } | 640 } |
| OLD | NEW |