Chromium Code Reviews| Index: testing/android/java/src/org/chromium/test/outstrumentation/reporter/Reporter.java |
| diff --git a/testing/android/java/src/org/chromium/test/outstrumentation/reporter/Reporter.java b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/Reporter.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d098979e6f4d43e9d03f5a027eda0fa7d1478478 |
| --- /dev/null |
| +++ b/testing/android/java/src/org/chromium/test/outstrumentation/reporter/Reporter.java |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.test.outstrumentation.reporter; |
| + |
| +import android.content.ComponentName; |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.content.ServiceConnection; |
| +import android.os.Bundle; |
| +import android.os.IBinder; |
| +import android.os.Message; |
| +import android.os.Messenger; |
| +import android.os.RemoteException; |
| +import android.util.Log; |
| + |
| +/** |
| + * Reports test status to the {@link ReportingService}. |
| + */ |
| +public class Reporter { |
| + |
| + private static final String TAG = "Reporter"; |
| + |
| + private static final String OUTSTRUMENTATION_PACKAGE = |
| + "org.chromium.test.outstrumentation"; |
| + |
| + private Messenger mService; |
| + private Object mLock = new Object(); |
| + |
| + public Reporter(Context c) { |
| + ServiceConnection connection = new ServiceConnection() { |
| + @Override |
| + public void onServiceConnected(ComponentName name, IBinder service) { |
| + Log.d(TAG, "service connected"); |
| + synchronized (mLock) { |
| + mService = new Messenger(service); |
| + mLock.notify(); |
| + } |
| + } |
| + |
| + @Override |
| + public void onServiceDisconnected(ComponentName name) { |
| + Log.d(TAG, "service disconnected"); |
| + synchronized (mLock) { |
| + mService = null; |
| + mLock.notify(); |
| + } |
| + } |
| + }; |
| + |
| + Intent i = new Intent(); |
| + i.setComponent(new ComponentName( |
| + OUTSTRUMENTATION_PACKAGE, |
| + ReportingService.class.getName())); |
| + c.bindService(i, connection, 0); |
| + } |
| + |
| + public void testStarted(String testClass, String testMethod) |
| + throws InterruptedException, RemoteException { |
| + sendMessage(testClass, testMethod, ReportingService.MSG_REPORT_TEST_STARTED); |
| + } |
| + |
| + public void testPassed(String testClass, String testMethod) |
| + throws InterruptedException, RemoteException { |
| + sendMessage(testClass, testMethod, ReportingService.MSG_REPORT_TEST_PASSED); |
| + } |
| + |
| + public void testFailed(String testClass, String testMethod) |
| + throws InterruptedException, RemoteException { |
| + sendMessage(testClass, testMethod, ReportingService.MSG_REPORT_TEST_FAILED); |
| + } |
| + |
| + private void sendMessage(String testClass, String testMethod, int messageType) |
| + throws InterruptedException, RemoteException { |
| + synchronized (mLock) { |
| + while (mService == null) { |
| + mLock.wait(); |
|
Ted C
2015/04/06 17:43:54
what happens if the service were to be disconnecte
jbudorick
2015/04/07 00:54:39
It probably would hang. It certainly hangs when ru
|
| + } |
| + |
| + Bundle msgData = new Bundle(); |
| + msgData.putString(ReportingService.MSG_DATA_TEST_CLASS, testClass); |
| + msgData.putString(ReportingService.MSG_DATA_TEST_METHOD, testMethod); |
| + |
| + Message msg = Message.obtain(); |
| + msg.what = messageType; |
| + msg.setData(msgData); |
| + mService.send(msg); |
| + } |
| + } |
| + |
| +} |