Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/crash/LogcatExtractionRunnableTest.java

Issue 2737263006: [Android Crash Reporting] Allow uploading minidumps via the JobScheduler (Closed)
Patch Set: Use shared prefs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 android.content.ComponentName; 7 import android.content.ComponentName;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.support.test.filters.MediumTest; 10 import android.support.test.filters.MediumTest;
(...skipping 11 matching lines...) Expand all
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 import java.util.List; 23 import java.util.List;
24 import java.util.concurrent.atomic.AtomicInteger; 24 import java.util.concurrent.atomic.AtomicInteger;
25 25
26 /** 26 /**
27 * Unittests for {@link LogcatExtractionRunnable}. 27 * Unittests for {@link LogcatExtractionRunnable}.
28 */ 28 */
29 public class LogcatExtractionRunnableTest extends CrashTestCase { 29 public class LogcatExtractionRunnableTest extends CrashTestCase {
30 private File mCrashDir; 30 private File mCrashDir;
31 31
32 private class TestJobScheduler extends JobScheduler {
33 private final JobScheduler mRealScheduler;
34
35 TestJobScheduler(JobScheduler realScheduler) {
36 mRealScheduler = realScheduler;
37 }
38
39 @Override
40 public void cancel(int jobId) {
41 mRealScheduler.cancel(jobId);
42 }
43 @Override
44 public void cancelAll() {
45 mRealScheduler.cancelAll();
46 }
47 @Override
48 public List<JobInfo> getAllPendingJobs() {
49 mRealScheduler.getAllPendingJobs();
50 }
51 @Override
52 public JobInfo getPendingJob() {
53 mRealScheduler.getPendingJob();
54 }
55 @Override
56 public int schedule(JobInfo job) {
57 assertEquals(MinidumpUploadJobService.MINIDUMP_UPLOADING_JOB_ID, job .getId());
58 assertEquals(ChromeMinidumpUploadJobService.class.getName(),
59 job.getService().getClassName());
60 return mRealScheduler.schedule(uploadJob);
61 }
62 };
63
32 @Override 64 @Override
33 protected void setUp() throws Exception { 65 protected void setUp() throws Exception {
34 super.setUp(); 66 super.setUp();
35 mCrashDir = new CrashFileManager(mCacheDir).getCrashDirectory(); 67 mCrashDir = new CrashFileManager(mCacheDir).getCrashDirectory();
36 } 68 }
37 69
38 @MediumTest 70 @MediumTest
39 public void testSimpleExtraction() { 71 public void testSimpleExtraction() {
40 // Set up the test. 72 // Set up the test.
41 final List<String> logcat = new ArrayList<String>(); 73 final List<String> logcat = new ArrayList<String>();
(...skipping 21 matching lines...) Expand all
63 @Override 95 @Override
64 public ComponentName startService(Intent intent) { 96 public ComponentName startService(Intent intent) {
65 assertEquals(1, numServiceStarts.incrementAndGet()); 97 assertEquals(1, numServiceStarts.incrementAndGet());
66 assertEquals(MinidumpUploadService.class.getName(), 98 assertEquals(MinidumpUploadService.class.getName(),
67 intent.getComponent().getClassName()); 99 intent.getComponent().getClassName());
68 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intent.getActi on()); 100 assertEquals(MinidumpUploadService.ACTION_UPLOAD, intent.getActi on());
69 assertEquals(new File(mCrashDir, "test.dmp.try0").getAbsolutePat h(), 101 assertEquals(new File(mCrashDir, "test.dmp.try0").getAbsolutePat h(),
70 intent.getStringExtra(MinidumpUploadService.FILE_TO_UPLO AD_KEY)); 102 intent.getStringExtra(MinidumpUploadService.FILE_TO_UPLO AD_KEY));
71 return super.startService(intent); 103 return super.startService(intent);
72 } 104 }
105
106 @Override
107 public getSystemService(String name) {
108 if (Context.JOB_SCHEDULER_SERVICE.equals(name)) {
109 return new TestJobScheduler(super.getSystemService(name));
110 }
111
112 return super.getSystemService(name);
113 }
73 }; 114 };
74 115
75 // Extract the logcat! 116 // Extract the logcat!
76 LogcatExtractionRunnable runnable = new LogcatExtractionRunnable(testCon text, minidump) { 117 LogcatExtractionRunnable runnable = new LogcatExtractionRunnable(testCon text, minidump) {
77 @Override 118 @Override
78 protected List<String> getLogcat() { 119 protected List<String> getLogcat() {
79 return logcat; 120 return logcat;
80 } 121 }
81 }; 122 };
82 runnable.run(); 123 runnable.run();
(...skipping 19 matching lines...) Expand all
102 assertEquals( 143 assertEquals(
103 "The minidump contents should follow.", minidumpContents, in put.readLine()); 144 "The minidump contents should follow.", minidumpContents, in put.readLine());
104 assertNull("There should be nothing else in the file", input.readLin e()); 145 assertNull("There should be nothing else in the file", input.readLin e());
105 } catch (IOException e) { 146 } catch (IOException e) {
106 fail(e.toString()); 147 fail(e.toString());
107 } finally { 148 } finally {
108 StreamUtil.closeQuietly(input); 149 StreamUtil.closeQuietly(input);
109 } 150 }
110 } 151 }
111 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698