Skip to content

Commit

Permalink
Revert of Add custom tabs tests using intents with non-null sessions …
Browse files Browse the repository at this point in the history
…(patchset #3 id:40001 of https://codereview.chromium.org/1267243003/ )

Reason for revert:
Test flaking on dowsntream ToT due to deferred startup not finishing.

Original issue's description:
> Add custom tabs tests using intents with non-null sessions
>
> All current tests either test the service side session creation without
> launching intents or the UI customization with no sessions. This change
> add a trivial test that uses a valid session to launch an intent and also
> another more complex test that reloads a new URL in the same tab when the
> same session is used inside the intent.
>
> Note that the service side is interfaced directly through CustomTabConnection
> and this doesn't exactly replicate the actual scenario since all calls come
> from the same process.
>
> Committed: https://crrev.com/a69c3f7ba69a30aef2143945b8b2bbf8e6421080
> Cr-Commit-Position: refs/heads/master@{#342131}

[email protected]
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1276993002

Cr-Commit-Position: refs/heads/master@{#342169}
  • Loading branch information
yusufo authored and Anton Obzhirov committed Aug 7, 2015
1 parent 99516c8 commit eb5f9dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.chromium.chrome.browser.customtabs;

import android.app.Application;
import android.app.Instrumentation;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
Expand All @@ -16,9 +15,7 @@
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;
Expand All @@ -40,7 +37,6 @@
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;

Expand Down Expand Up @@ -72,8 +68,6 @@ public void onReceive(Context context, Intent intent) {
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;
Expand All @@ -85,11 +79,10 @@ protected void startActivityCompletely(Intent intent) {
}

/**
* @see CustomTabsTestUtils#createMinimalCustomTabIntent(Context, String, IBinder).
* @see CustomTabActivityTestBase#createMinimalCustomTabIntent(String)
*/
private Intent createMinimalCustomTabIntent() {
return CustomTabsTestUtils.createMinimalCustomTabIntent(
getInstrumentation().getTargetContext(), TEST_PAGE, null);
return createMinimalCustomTabIntent(TEST_PAGE);
}

/**
Expand Down Expand Up @@ -375,61 +368,6 @@ public void testActionButtonBadRatio() throws InterruptedException {
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}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

import android.app.Activity;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;

import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
Expand Down Expand Up @@ -62,9 +67,22 @@ public boolean isSatisfied() {
public boolean isSatisfied() {
return DeferredStartupHandler.getInstance().isDeferredStartupComplete();
}
}, 5000, 200));
}));

assertNotNull(tab);
assertNotNull(tab.getView());
}

/**
* Creates the simplest intent that is sufficient to let {@link ChromeLauncherActivity} launch
* the {@link CustomTabActivity}.
*/
protected Intent createMinimalCustomTabIntent(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(getInstrumentation().getTargetContext(),
ChromeLauncherActivity.class));
IntentUtils.safePutBinderExtra(intent, CustomTabsIntent.EXTRA_SESSION, null);
return intent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void startMainActivity() throws InterruptedException {
super.startMainActivity();
startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent(
getInstrumentation().getTargetContext(), TEST_URL, null));
startCustomTabActivityWithIntent(createMinimalCustomTabIntent(TEST_URL));
Tab tab = getActivity().getActivityTab();
assertTrue("A custom tab is not present in the activity.", tab instanceof CustomTab);
CustomTab customTab = (CustomTab) tab;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.app.Application;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.support.customtabs.ICustomTabsCallback;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
Expand All @@ -31,14 +33,25 @@ protected void tearDown() throws Exception {
mCustomTabsConnection.cleanupAll();
}

private ICustomTabsCallback newDummyCallback() {
return new ICustomTabsCallback.Stub() {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {}
@Override
public IBinder asBinder() {
return this;
}
};
}

/**
* Tests that we can create a new session. Registering with a null callback
* fails, as well as multiple sessions with the same callback.
*/
@SmallTest
public void testNewSession() {
assertEquals(false, mCustomTabsConnection.newSession(null));
ICustomTabsCallback cb = CustomTabsTestUtils.newDummyCallback();
ICustomTabsCallback cb = newDummyCallback();
assertEquals(true, mCustomTabsConnection.newSession(cb));
assertEquals(false, mCustomTabsConnection.newSession(cb));
}
Expand All @@ -61,7 +74,7 @@ private ICustomTabsCallback assertWarmupAndMayLaunchUrl(
ICustomTabsCallback cb, String url, boolean shouldSucceed) {
mCustomTabsConnection.warmup(0);
if (cb == null) {
cb = CustomTabsTestUtils.newDummyCallback();
cb = newDummyCallback();
mCustomTabsConnection.newSession(cb);
}
boolean succeeded = mCustomTabsConnection.mayLaunchUrl(cb, Uri.parse(url), null, null);
Expand All @@ -71,13 +84,12 @@ private ICustomTabsCallback assertWarmupAndMayLaunchUrl(

/**
* Tests that
* {@link CustomTabsConnection#mayLaunchUrl(
* ICustomTabsCallback, Uri, android.os.Bundle, java.util.List)}
* {@link CustomTabsConnection#mayLaunchUrl(long, String, Bundle, List<Bundle>)}
* returns an error when called with an invalid session ID.
*/
@SmallTest
public void testNoMayLaunchUrlWithInvalidSessionId() {
assertWarmupAndMayLaunchUrl(CustomTabsTestUtils.newDummyCallback(), URL, false);
assertWarmupAndMayLaunchUrl(newDummyCallback(), URL, false);
}

/**
Expand Down

This file was deleted.

0 comments on commit eb5f9dd

Please sign in to comment.