• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.test.reporter;
6 
7 import android.content.Context;
8 import android.content.Intent;
9 import android.util.Log;
10 
11 import org.chromium.build.gtest_apk.TestStatusIntent;
12 
13 /**
14  * Broadcasts test status to any listening {@link org.chromium.test.reporter.TestStatusReceiver}.
15  */
16 public class TestStatusReporter {
17     private final Context mContext;
18 
TestStatusReporter(Context c)19     public TestStatusReporter(Context c) {
20         mContext = c;
21     }
22 
testRunStarted(int pid)23     public void testRunStarted(int pid) {
24         sendTestRunBroadcast(TestStatusIntent.ACTION_TEST_RUN_STARTED, pid);
25     }
26 
testRunFinished(int pid)27     public void testRunFinished(int pid) {
28         sendTestRunBroadcast(TestStatusIntent.ACTION_TEST_RUN_FINISHED, pid);
29     }
30 
sendTestRunBroadcast(String action, int pid)31     private void sendTestRunBroadcast(String action, int pid) {
32         Intent i = new Intent(action);
33         i.setType(TestStatusIntent.DATA_TYPE_RESULT);
34         i.putExtra(TestStatusIntent.EXTRA_PID, pid);
35         mContext.sendBroadcast(i);
36     }
37 
uncaughtException(int pid, Throwable ex)38     public void uncaughtException(int pid, Throwable ex) {
39         Intent i = new Intent(TestStatusIntent.ACTION_UNCAUGHT_EXCEPTION);
40         i.setType(TestStatusIntent.DATA_TYPE_RESULT);
41         i.putExtra(TestStatusIntent.EXTRA_PID, pid);
42         i.putExtra(TestStatusIntent.EXTRA_STACK_TRACE, Log.getStackTraceString(ex));
43         mContext.sendBroadcast(i);
44     }
45 }
46