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