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

Unified Diff: content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java

Issue 10911131: Upstream JavaBridge tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update ContentShellTestBase Created 8 years, 3 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
« no previous file with comments | « no previous file | content/shell/android/javatests/src/org/chromium/content_shell/JavaBridgeArrayCoercionTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java
diff --git a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java
index 59a6f7de77f2aa3e3706a1cba51c6b2734ff0910..2e3ee96f0089b9df891b6cbec750c91d3ce8419c 100644
--- a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java
+++ b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellTestBase.java
@@ -9,10 +9,23 @@ import android.content.Intent;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
+import org.chromium.content.browser.ContentView;
+import org.chromium.content.browser.ContentViewClient;
+import org.chromium.content.browser.LoadUrlParams;
+import org.chromium.content.browser.test.TestContentViewClient;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
/**
* Base test class for all ContentShell based tests.
*/
public class ContentShellTestBase extends ActivityInstrumentationTestCase2<ContentShellActivity> {
+ private Map<ContentView, TestContentViewClient> mTestContentViewClients
+ = new HashMap<ContentView, TestContentViewClient>();
klundberg 2012/09/07 16:15:29 I don't think you should add this to ContentShellT
Ramya 2012/09/19 21:31:57 Done.
+
+ protected static int WAIT_TIMEOUT_SECONDS = 15;
public ContentShellTestBase() {
super(ContentShellActivity.class);
@@ -28,6 +41,72 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
intent.setData(Uri.parse(url));
intent.setComponent(new ComponentName(getInstrumentation().getTargetContext(),
ContentShellActivity.class));
- return (ContentShellActivity) getInstrumentation().startActivitySync(intent);
+ setActivityIntent(intent);
+ return getActivity();
+ }
+
+ /**
+ * Sets the {@link TestContentViewClient} associated with the specified
+ * {@link ContentView}.
+ *
+ * Must be called on the UI thread.
+ */
+ public void setTestContentViewClient(
+ final ContentView contentView, final TestContentViewClient client) {
+ contentView.setContentViewClient(client);
+ mTestContentViewClients.put(contentView, client);
+ }
+
+ /**
+ * Gets the {@link TestContentViewClient} associated with the specified
+ * {@link ContentView}.
+ *
+ * This will not work correctly if the test code invokes
+ * {link {@link ContentView#setContentViewClient(ContentViewClient)} directly.
+ *
+ * @return {@link TestContentViewClient}
+ */
+ public TestContentViewClient getTestContentViewClient(ContentView contentView) {
+ return mTestContentViewClients.get(contentView);
+ }
+
+ /**
+ * Loads data on the UI thread and blocks until onPageFinished is called.
+ */
+ @Deprecated
+ protected void loadDataSync(final ContentView chromeView, final String data,
+ final String mimeType, final boolean isBase64Encoded)
+ throws Throwable {
+ TestContentViewClient.OnPageFinishedHelper onPageFinishedHelper =
+ getTestContentViewClient(chromeView).getOnPageFinishedHelper();
+ int currentCallCount = onPageFinishedHelper.getCallCount();
+ loadDataAsync(chromeView, data, mimeType, isBase64Encoded);
+ onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
+ TimeUnit.SECONDS);
klundberg 2012/09/07 16:15:30 This should be in a utility class, not in a test b
Ramya 2012/09/19 21:31:57 As discussed, leaving it here till the Util files
+ }
+
+ /**
+ * Loads data on the UI thread but does not block.
+ */
+ @Deprecated
+ protected void loadDataAsync(final ContentView chromeView, final String data,
+ final String mimeType, final boolean isBase64Encoded)
+ throws Throwable {
klundberg 2012/09/07 16:15:30 Same comment as above.
Ramya 2012/09/19 21:31:57 See comment above.
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ chromeView.loadUrl(LoadUrlParams.createLoadDataParams(
+ data, mimeType, isBase64Encoded));
+ }
+ });
+ }
+
+ /**
+ * Allows access to the {@link ContentView}.
+ *
+ * @return The first {@link ContentView}
+ */
+ public ContentView getContentView() {
+ return getActivity().getActiveContentView();
}
}
« no previous file with comments | « no previous file | content/shell/android/javatests/src/org/chromium/content_shell/JavaBridgeArrayCoercionTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698