OLD | NEW |
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 static org.junit.Assert.assertArrayEquals; | 7 import static org.junit.Assert.assertArrayEquals; |
8 | 8 |
9 import android.os.ParcelFileDescriptor; | 9 import android.os.ParcelFileDescriptor; |
10 import android.support.test.filters.MediumTest; | 10 import android.support.test.filters.MediumTest; |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!file.delete()) { | 467 if (!file.delete()) { |
468 throw new RuntimeException( | 468 throw new RuntimeException( |
469 "Couldn't delete file " + file.getAbsolutePath()
); | 469 "Couldn't delete file " + file.getAbsolutePath()
); |
470 } | 470 } |
471 } | 471 } |
472 } | 472 } |
473 } | 473 } |
474 } | 474 } |
475 | 475 |
476 private void testMinidumpStorageRestrictions(boolean perUid) throws IOExcept
ion { | 476 private void testMinidumpStorageRestrictions(boolean perUid) throws IOExcept
ion { |
477 CrashFileManager fileManager = new CrashFileManager(mCacheDir); | 477 CrashFileManager fileManager = |
| 478 new CrashFileManager(getInstrumentation().getTargetContext().get
CacheDir()); |
478 // Delete existing minidumps to ensure they don't interfere with this te
st. | 479 // Delete existing minidumps to ensure they don't interfere with this te
st. |
479 deleteFilesInDirIfExists(fileManager.getCrashDirectory()); | 480 deleteFilesInDirIfExists(fileManager.getCrashDirectory()); |
480 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); | 481 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); |
481 File tmpCopyDir = new File(getExistingCacheDir(), "tmpDir"); | 482 File tmpCopyDir = new File(getInstrumentation().getTargetContext().getCa
cheDir(), "tmpDir"); |
482 | 483 |
483 // Note that these minidump files are set up directly in the cache dir -
not in the crash | 484 // Note that these minidump files are set up directly in the cache dir -
not in the crash |
484 // dir. This is to ensure the CrashFileManager doesn't see these minidum
ps without us first | 485 // dir. This is to ensure the CrashFileManager doesn't see these minidum
ps without us first |
485 // copying them. | 486 // copying them. |
486 File minidumpToCopy = new File(getExistingCacheDir(), "toCopy.dmp"); | 487 File minidumpToCopy = |
| 488 new File(getInstrumentation().getTargetContext().getCacheDir(),
"toCopy.dmp"); |
487 setUpMinidumpFile(minidumpToCopy, "BOUNDARY"); | 489 setUpMinidumpFile(minidumpToCopy, "BOUNDARY"); |
488 // Ensure we didn't add any new minidumps to the crash directory. | 490 // Ensure we didn't add any new minidumps to the crash directory. |
489 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); | 491 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); |
490 | 492 |
491 int minidumpLimit = perUid ? CrashFileManager.MAX_CRASH_REPORTS_TO_UPLOA
D_PER_UID | 493 int minidumpLimit = perUid ? CrashFileManager.MAX_CRASH_REPORTS_TO_UPLOA
D_PER_UID |
492 : CrashFileManager.MAX_CRASH_REPORTS_TO_UPLOA
D; | 494 : CrashFileManager.MAX_CRASH_REPORTS_TO_UPLOA
D; |
493 for (int n = 0; n < minidumpLimit; n++) { | 495 for (int n = 0; n < minidumpLimit; n++) { |
494 // If we are testing the app-throttling we want to use the same uid
for each | 496 // If we are testing the app-throttling we want to use the same uid
for each |
495 // minidump, otherwise use a different one for each minidump. | 497 // minidump, otherwise use a different one for each minidump. |
496 createFdForandCopyFile(fileManager, minidumpToCopy, tmpCopyDir, | 498 createFdForandCopyFile(fileManager, minidumpToCopy, tmpCopyDir, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 558 } |
557 return oldestFile; | 559 return oldestFile; |
558 } | 560 } |
559 | 561 |
560 /** | 562 /** |
561 * Ensure that we won't copy minidumps that are too large. | 563 * Ensure that we won't copy minidumps that are too large. |
562 */ | 564 */ |
563 @MediumTest | 565 @MediumTest |
564 @Feature({"Android-AppBase"}) | 566 @Feature({"Android-AppBase"}) |
565 public void testCantCopyLargeFile() throws IOException { | 567 public void testCantCopyLargeFile() throws IOException { |
566 CrashFileManager fileManager = new CrashFileManager(mCacheDir); | 568 CrashFileManager fileManager = |
| 569 new CrashFileManager(getInstrumentation().getTargetContext().get
CacheDir()); |
567 // Delete existing minidumps to ensure they don't interfere with this te
st. | 570 // Delete existing minidumps to ensure they don't interfere with this te
st. |
568 deleteFilesInDirIfExists(fileManager.getCrashDirectory()); | 571 deleteFilesInDirIfExists(fileManager.getCrashDirectory()); |
569 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); | 572 assertEquals(0, fileManager.getAllMinidumpFiles(10000 /* maxTries */).le
ngth); |
570 File tmpCopyDir = new File(getExistingCacheDir(), "tmpDir"); | 573 File tmpCopyDir = new File(getInstrumentation().getTargetContext().getCa
cheDir(), "tmpDir"); |
571 | 574 |
572 // Note that these minidump files are set up directly in the cache dir -
not in the crash | 575 // Note that these minidump files are set up directly in the cache dir -
not in the crash |
573 // dir. This is to ensure the CrashFileManager doesn't see these minidum
ps without us first | 576 // dir. This is to ensure the CrashFileManager doesn't see these minidum
ps without us first |
574 // copying them. | 577 // copying them. |
575 File minidumpToCopy = new File(getExistingCacheDir(), "toCopy.dmp"); | 578 File minidumpToCopy = |
| 579 new File(getInstrumentation().getTargetContext().getCacheDir(),
"toCopy.dmp"); |
576 setUpMinidumpFile(minidumpToCopy, "BOUNDARY"); | 580 setUpMinidumpFile(minidumpToCopy, "BOUNDARY"); |
577 // Write ~1MB data into the minidump file. | 581 // Write ~1MB data into the minidump file. |
578 final int kilo = 1024; | 582 final int kilo = 1024; |
579 byte[] kiloByteArray = new byte[kilo]; | 583 byte[] kiloByteArray = new byte[kilo]; |
580 FileOutputStream minidumpOutputStream = | 584 FileOutputStream minidumpOutputStream = |
581 new FileOutputStream(minidumpToCopy, true /* append */); | 585 new FileOutputStream(minidumpToCopy, true /* append */); |
582 try { | 586 try { |
583 for (int n = 0; n < kilo; n++) { | 587 for (int n = 0; n < kilo; n++) { |
584 minidumpOutputStream.write(kiloByteArray); | 588 minidumpOutputStream.write(kiloByteArray); |
585 } | 589 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 assertFalse(mMultiDigitMaxTriesFile.exists()); | 681 assertFalse(mMultiDigitMaxTriesFile.exists()); |
678 assertFalse(mUpFile1.exists()); | 682 assertFalse(mUpFile1.exists()); |
679 assertFalse(mUpFile2.exists()); | 683 assertFalse(mUpFile2.exists()); |
680 assertFalse(temp1.exists()); | 684 assertFalse(temp1.exists()); |
681 assertFalse(temp2.exists()); | 685 assertFalse(temp2.exists()); |
682 assertFalse(success1.exists()); | 686 assertFalse(success1.exists()); |
683 assertFalse(success2.exists()); | 687 assertFalse(success2.exists()); |
684 assertFalse(success3.exists()); | 688 assertFalse(success3.exists()); |
685 } | 689 } |
686 } | 690 } |
OLD | NEW |