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 android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
8 | 8 |
9 import org.chromium.base.annotations.SuppressFBWarnings; | 9 import org.chromium.base.annotations.SuppressFBWarnings; |
10 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
(...skipping 17 matching lines...) Expand all Loading... |
28 * Unittests for {@link MinidumpUploadCallable}. | 28 * Unittests for {@link MinidumpUploadCallable}. |
29 */ | 29 */ |
30 public class MinidumpUploadCallableTest extends CrashTestCase { | 30 public class MinidumpUploadCallableTest extends CrashTestCase { |
31 private static final String BOUNDARY = "TESTBOUNDARY"; | 31 private static final String BOUNDARY = "TESTBOUNDARY"; |
32 private static final String CRASH_ID = "IMACRASHID"; | 32 private static final String CRASH_ID = "IMACRASHID"; |
33 private static final String LOG_FILE_NAME = "chromium_renderer-123_log.dmp22
4"; | 33 private static final String LOG_FILE_NAME = "chromium_renderer-123_log.dmp22
4"; |
34 private File mTestUpload; | 34 private File mTestUpload; |
35 private File mUploadLog; | 35 private File mUploadLog; |
36 private File mExpectedFileAfterUpload; | 36 private File mExpectedFileAfterUpload; |
37 | 37 |
38 private static class TestHttpURLConnection extends HttpURLConnection { | 38 /** |
| 39 * A HttpURLConnection that performs some basic checks to ensure we are uplo
ading |
| 40 * minidumps correctly. |
| 41 */ |
| 42 public static class TestHttpURLConnection extends HttpURLConnection { |
39 private static final String EXPECTED_CONTENT_TYPE_VALUE = | 43 private static final String EXPECTED_CONTENT_TYPE_VALUE = |
40 String.format(MinidumpUploadCallable.CONTENT_TYPE_TMPL, BOUNDARY
); | 44 String.format(MinidumpUploadCallable.CONTENT_TYPE_TMPL, BOUNDARY
); |
41 | 45 |
42 /** | 46 /** |
43 * The value of the "Content-Type" property if the property has been set
. | 47 * The value of the "Content-Type" property if the property has been set
. |
44 */ | 48 */ |
45 private String mContentTypePropertyValue = ""; | 49 private String mContentTypePropertyValue = ""; |
46 | 50 |
47 TestHttpURLConnection(URL url) { | 51 public TestHttpURLConnection(URL url) { |
48 super(url); | 52 super(url); |
49 assertEquals(MinidumpUploadCallable.CRASH_URL_STRING, url.toString()
); | 53 assertEquals(MinidumpUploadCallable.CRASH_URL_STRING, url.toString()
); |
50 } | 54 } |
51 | 55 |
52 @Override | 56 @Override |
53 public void disconnect() { | 57 public void disconnect() { |
54 // Check that the "Content-Type" property has been set and the prope
rty's value. | 58 // Check that the "Content-Type" property has been set and the prope
rty's value. |
55 assertEquals(EXPECTED_CONTENT_TYPE_VALUE, mContentTypePropertyValue)
; | 59 assertEquals(EXPECTED_CONTENT_TYPE_VALUE, mContentTypePropertyValue)
; |
56 } | 60 } |
57 | 61 |
58 @Override | 62 @Override |
59 public InputStream getInputStream() { | 63 public InputStream getInputStream() { |
60 return new ByteArrayInputStream(CRASH_ID.getBytes()); | 64 return new ByteArrayInputStream(CRASH_ID.getBytes()); |
61 } | 65 } |
62 | 66 |
63 @Override | 67 @Override |
64 public OutputStream getOutputStream() { | 68 public OutputStream getOutputStream() throws IOException { |
65 return new ByteArrayOutputStream(); | 69 return new ByteArrayOutputStream(); |
66 } | 70 } |
67 | 71 |
68 @Override | 72 @Override |
69 public int getResponseCode() { | 73 public int getResponseCode() { |
70 return 200; | 74 return 200; |
71 } | 75 } |
72 | 76 |
73 @Override | 77 @Override |
74 public String getResponseMessage() { | 78 public String getResponseMessage() { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 479 |
476 // Sanity check on the time stamp (within an hour). | 480 // Sanity check on the time stamp (within an hour). |
477 // Chances are the write and the check should have less than 1 second in
between. | 481 // Chances are the write and the check should have less than 1 second in
between. |
478 assertTrue(time <= now); | 482 assertTrue(time <= now); |
479 assertTrue(time > now - 60 * 60); | 483 assertTrue(time > now - 60 * 60); |
480 | 484 |
481 String id = lastEntry.substring(seperator + 1, lastEntry.length()); | 485 String id = lastEntry.substring(seperator + 1, lastEntry.length()); |
482 assertEquals(id, CRASH_ID); | 486 assertEquals(id, CRASH_ID); |
483 } | 487 } |
484 } | 488 } |
OLD | NEW |