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

Unified Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/JavaScriptUtils.java

Issue 11085008: [Android] Upstream content detection and ChromeBrowserProvider tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean-up for review. Created 8 years, 2 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: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/JavaScriptUtils.java
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/JavaScriptUtils.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/JavaScriptUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..49e8c184ebdead5b5032dc0d8d24009b8e54e3cf
--- /dev/null
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/JavaScriptUtils.java
@@ -0,0 +1,53 @@
+// Copyright (c) 2012 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.content.browser.test.util;
+
+import android.test.InstrumentationTestCase;
+
+import junit.framework.Assert;
+
+import org.chromium.content.browser.ContentView;
+
+/**
+ * Collection of JavaScript utilities.
+ */
+public class JavaScriptUtils {
+ private static int mRequestId;
+
+ /**
+ * Executes the given snippet of JavaScript code within the given ContentView. Returns the
+ * result of its execution in JSON format.
+ */
+ public static String executeJavaScriptAndWaitForResult(InstrumentationTestCase test,
+ final ContentView view, TestCallbackHelperContainer viewClient, final String code)
Yaron 2012/10/09 02:12:45 We should probably make this operate on a ContentV
Leandro GraciĆ” Gil 2012/10/10 00:35:54 Deferring this to later patches / follow-ups as su
+ throws Throwable {
+ TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper
+ onEvaluateJavaScriptResultHelper = viewClient.getOnEvaluateJavaScriptResultHelper();
+ int currentCallCount = onEvaluateJavaScriptResultHelper.getCallCount();
+ test.runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mRequestId = view.evaluateJavaScript(code);
+ }
+ });
+ onEvaluateJavaScriptResultHelper.waitForCallback(currentCallCount);
+ Assert.assertEquals("Response ID mismatch when evaluating JavaScript.",
+ mRequestId, onEvaluateJavaScriptResultHelper.getId());
+ return onEvaluateJavaScriptResultHelper.getJsonResult();
+ }
+
+ /**
+ * Executes the given snippet of JavaScript code but does not wait for the result.
+ */
+ public static void executeJavaScript(InstrumentationTestCase test, final ContentView view,
+ final String code) throws Throwable {
+ test.runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ view.evaluateJavaScript(code);
+ }
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698