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

Unified Diff: testing/android/java/src/org/chromium/test/reporter/Reporter.java

Issue 1034053002: [Android] Add an out-of-app instrumentation driver APK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: the rename Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: testing/android/java/src/org/chromium/test/reporter/Reporter.java
diff --git a/testing/android/java/src/org/chromium/test/reporter/Reporter.java b/testing/android/java/src/org/chromium/test/reporter/Reporter.java
new file mode 100644
index 0000000000000000000000000000000000000000..1fabf47dc4a7919ab9e96efe68486bec406f462e
--- /dev/null
+++ b/testing/android/java/src/org/chromium/test/reporter/Reporter.java
@@ -0,0 +1,102 @@
+// 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.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;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+/**
+ * Reports test status to the {@link ReportingService}.
+ */
+public class Reporter {
+
+ private static final String TAG = "Reporter";
+
+ private static final String DRIVER_PACKAGE = "org.chromium.test.driver";
+
+ private Messenger mService;
+ private Queue<Message> mWaitingMessages = new ArrayDeque<Message>();
+ 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);
+ try {
+ while (!mWaitingMessages.isEmpty()) {
+ mService.send(mWaitingMessages.remove());
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote error while sending delayed message.", e);
+ }
+ 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(
+ DRIVER_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 {
+ 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);
+
+ synchronized (mLock) {
+ if (mService != null) {
+ mService.send(msg);
+ } else {
+ mWaitingMessages.add(msg);
+ }
+ }
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698