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

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java

Issue 2956283002: Expose Add/RemoveActionCallback to java (Closed)
Patch Set: Use assert instead of an exception Created 3 years, 5 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: base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java b/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java
new file mode 100644
index 0000000000000000000000000000000000000000..88e3551131f89c82b80e5941fe2ab59ba7b4d201
--- /dev/null
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java
@@ -0,0 +1,51 @@
+// Copyright 2017 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.base.test.util;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.metrics.RecordUserAction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A util class that records UserActions.
+ */
+public class UserActionTester implements RecordUserAction.UserActionCallback {
+ private List<String> mActions;
+
+ public UserActionTester() {
+ mActions = new ArrayList<>();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ RecordUserAction.setActionCallbackForTesting(UserActionTester.this);
+ }
+ });
+ }
+
+ public void tearDown() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ RecordUserAction.removeActionCallbackForTesting();
+ }
+ });
+ }
+
+ @Override
+ public void onActionRecorded(String action) {
+ mActions.add(action);
+ }
+
+ public List<String> getActions() {
+ return mActions;
+ }
+
+ @Override
+ public String toString() {
+ return "Actions: " + mActions.toString();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698