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

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

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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/reporter/java/src/org/chromium/test/reporter/TestStatusReporter.java
diff --git a/testing/android/reporter/java/src/org/chromium/test/reporter/TestStatusReporter.java b/testing/android/reporter/java/src/org/chromium/test/reporter/TestStatusReporter.java
new file mode 100644
index 0000000000000000000000000000000000000000..6ac7312fad3f422a6fa6bcc1b8acf226d1ae249c
--- /dev/null
+++ b/testing/android/reporter/java/src/org/chromium/test/reporter/TestStatusReporter.java
@@ -0,0 +1,83 @@
+// 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.Context;
+import android.content.Intent;
+
+import org.chromium.base.ThreadUtils;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Broadcasts test status to any listening {@link org.chromium.test.reporter.TestStatusReceiver}.
+ */
+public class TestStatusReporter {
+
+ public static final String ACTION_HEARTBEAT =
+ "org.chromium.test.reporter.TestStatusReporter.HEARTBEAT";
+ public static final String ACTION_TEST_STARTED =
+ "org.chromium.test.reporter.TestStatusReporter.TEST_STARTED";
+ public static final String ACTION_TEST_PASSED =
+ "org.chromium.test.reporter.TestStatusReporter.TEST_PASSED";
+ public static final String ACTION_TEST_FAILED =
+ "org.chromium.test.reporter.TestStatusReporter.TEST_FAILED";
+ public static final String DATA_TYPE_HEARTBEAT = "org.chromium.test.reporter/heartbeat";
+ public static final String DATA_TYPE_RESULT = "org.chromium.test.reporter/result";
+ public static final String EXTRA_TEST_CLASS =
+ "org.chromium.test.reporter.TestStatusReporter.TEST_CLASS";
+ public static final String EXTRA_TEST_METHOD =
+ "org.chromium.test.reporter.TestStatusReporter.TEST_METHOD";
+
+ public static final int HEARTBEAT_INTERVAL_MS = 5000;
+
+ private final Context mContext;
+ private final AtomicBoolean mKeepBeating = new AtomicBoolean(false);
+
+ public TestStatusReporter(Context c) {
+ mContext = c;
+ }
+
+ public void startHeartbeat() {
+ mKeepBeating.set(true);
+ Runnable heartbeat = new Runnable() {
+ @Override
+ public void run() {
+ Intent i = new Intent(ACTION_HEARTBEAT);
+ i.setType(DATA_TYPE_HEARTBEAT);
+ mContext.sendBroadcast(i);
+ if (mKeepBeating.get()) {
+ ThreadUtils.postOnUiThreadDelayed(this, HEARTBEAT_INTERVAL_MS);
+ }
+ }
+ };
+ ThreadUtils.postOnUiThreadDelayed(heartbeat, HEARTBEAT_INTERVAL_MS);
+ }
+
+ public void testStarted(String testClass, String testMethod) {
+ sendBroadcast(testClass, testMethod, ACTION_TEST_STARTED);
+ }
+
+ public void testPassed(String testClass, String testMethod) {
+ sendBroadcast(testClass, testMethod, ACTION_TEST_PASSED);
+ }
+
+ public void testFailed(String testClass, String testMethod) {
+ sendBroadcast(testClass, testMethod, ACTION_TEST_FAILED);
+ }
+
+ public void stopHeartbeat() {
+ mKeepBeating.set(false);
+ }
+
+ private void sendBroadcast(String testClass, String testMethod, String action) {
+ Intent i = new Intent(action);
+ i.setType(DATA_TYPE_RESULT);
+ i.putExtra(EXTRA_TEST_CLASS, testClass);
+ i.putExtra(EXTRA_TEST_METHOD, testMethod);
+ mContext.sendBroadcast(i);
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698