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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java

Issue 1267243003: Add custom tabs tests using intents with non-null sessions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added the utils class Created 5 years, 4 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 | chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTestBase.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
index 17bbb58b31c86826bfcc297449f279775ee73c14..a6726155e1c3434a4a8d636a07e5f0fe66a9592c 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.customtabs;
+import android.app.Application;
import android.app.Instrumentation;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@@ -15,7 +16,9 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
+import android.os.IBinder;
import android.support.customtabs.CustomTabsIntent;
+import android.support.customtabs.ICustomTabsCallback;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.Menu;
import android.view.MenuItem;
@@ -37,6 +40,7 @@ import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import java.util.ArrayList;
+import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -68,6 +72,8 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
TEST_ACTION = "org.chromium.chrome.browser.customtabs.TEST_PENDING_INTENT_SENT";
private static final String TEST_PAGE = TestHttpServerClient.getUrl(
"chrome/test/data/android/google.html");
+ private static final String TEST_PAGE_2 = TestHttpServerClient.getUrl(
+ "chrome/test/data/android/test.html");
private static final String TEST_MENU_TITLE = "testMenuTitle";
private CustomTabActivity mActivity;
@@ -79,10 +85,11 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
}
/**
- * @see CustomTabActivityTestBase#createMinimalCustomTabIntent(String)
+ * @see CustomTabsTestUtils#createMinimalCustomTabIntent(Context, String, IBinder).
*/
private Intent createMinimalCustomTabIntent() {
- return createMinimalCustomTabIntent(TEST_PAGE);
+ return CustomTabsTestUtils.createMinimalCustomTabIntent(
+ getInstrumentation().getTargetContext(), TEST_PAGE, null);
}
/**
@@ -368,6 +375,61 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
assertNull(dataProvider.getActionButtonPendingIntentForTest());
}
+ @SmallTest
+ public void testLaunchWithSession() throws InterruptedException {
+ IBinder session = warmUpAndLaunchUrlWithSession();
+ assertEquals(mActivity.getIntentDataProvider().getSession(), session);
+ }
+
+ @SmallTest
+ public void testLoadNewUrlWithSession() throws InterruptedException {
+ final IBinder session = warmUpAndLaunchUrlWithSession();
+ final Context context = getInstrumentation().getTargetContext();
+ assertEquals(mActivity.getIntentDataProvider().getSession(), session);
+ assertFalse("CustomTabContentHandler handled intent with wrong session",
+ ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return CustomTabActivity.handleInActiveContentIfNeeded(
+ CustomTabsTestUtils.createMinimalCustomTabIntent(context,
+ TEST_PAGE_2,
+ CustomTabsTestUtils.newDummyCallback().asBinder()));
+ }
+ }));
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mActivity.getActivityTab().getUrl().equals(TEST_PAGE);
+ }
+ }));
+ assertTrue("CustomTabContentHandler can't handle intent with same session",
+ ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return CustomTabActivity.handleInActiveContentIfNeeded(
+ CustomTabsTestUtils.createMinimalCustomTabIntent(context,
+ TEST_PAGE_2, session));
+ }
+ }));
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mActivity.getActivityTab().getUrl().equals(TEST_PAGE_2);
+ }
+ }));
+ }
+
+ private IBinder warmUpAndLaunchUrlWithSession() throws InterruptedException {
+ Context context = getInstrumentation().getTargetContext().getApplicationContext();
+ CustomTabsConnection connection = CustomTabsConnection.getInstance((Application) context);
+ ICustomTabsCallback callback = CustomTabsTestUtils.newDummyCallback();
+ connection.warmup(0);
+ connection.newSession(callback);
+ startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
+ context, TEST_PAGE, callback.asBinder()));
+ return callback.asBinder();
+ }
+
/**
* A helper class to monitor sending status of a {@link PendingIntent}.
*/
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTestBase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698