Commit ecf62378 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🛃 Make CustomTabTestUtils.bindWithCallback return both session and client.

Bug: 938836
Change-Id: I389403bd798e1712441acdba149d1941f4881da9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506079Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638187}
parent 6afa6bc9
......@@ -757,7 +757,7 @@ public class CustomTabActivityTest {
callbackTriggered.notifyCalled();
}
}
});
}).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(mTestPage));
......@@ -1302,7 +1302,7 @@ public class CustomTabActivityTest {
navigationFinishedSemaphore.release();
}
}
});
}).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(mTestPage));
intent.setComponent(new ComponentName(
......@@ -1361,7 +1361,7 @@ public class CustomTabActivityTest {
public void onNavigationEvent(int navigationEvent, Bundle extras) {
if (navigationEvent == CustomTabsCallback.NAVIGATION_FINISHED) semaphore.release();
}
});
}).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(mTestPage));
intent.setComponent(new ComponentName(
......@@ -1602,7 +1602,7 @@ public class CustomTabActivityTest {
public void onPostMessage(String message, Bundle extras) {
onPostMessageHelper.notifyCalled();
}
});
}).session;
session.requestPostMessageChannel(null);
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(url));
......@@ -1642,7 +1642,7 @@ public class CustomTabActivityTest {
public void onPostMessage(String message, Bundle extras) {
onPostMessageHelper.notifyCalled();
}
});
}).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(url));
......@@ -1719,7 +1719,7 @@ public class CustomTabActivityTest {
public void onMessageChannelReady(Bundle extras) {
messageChannelHelper.notifyCalled();
}
});
}).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
intent.setData(Uri.parse(url));
......@@ -2618,7 +2618,7 @@ public class CustomTabActivityTest {
}
};
CustomTabsSession session = CustomTabsTestUtils.bindWithCallback(cb);
CustomTabsSession session = CustomTabsTestUtils.bindWithCallback(cb).session;
Intent intent = new CustomTabsIntent.Builder(session).build().intent;
if (allowMetrics) {
......
......@@ -34,6 +34,18 @@ import java.util.concurrent.atomic.AtomicReference;
*/
public class CustomTabsTestUtils {
/** A plain old data class that holds the return value from {@link #bindWithCallback}. */
public static class ClientAndSession {
public final CustomTabsClient client;
public final CustomTabsSession session;
/** Creates and populates the class. */
public ClientAndSession(CustomTabsClient client, CustomTabsSession session) {
this.client = client;
this.session = session;
}
}
/**
* Creates the simplest intent that is sufficient to let {@link ChromeLauncherActivity} launch
* the {@link CustomTabActivity}.
......@@ -61,9 +73,10 @@ public class CustomTabsTestUtils {
ThreadUtils.runOnUiThreadBlocking(connection::cleanupAll);
}
public static CustomTabsSession bindWithCallback(final CustomTabsCallback callback)
public static ClientAndSession bindWithCallback(final CustomTabsCallback callback)
throws InterruptedException, TimeoutException {
final AtomicReference<CustomTabsSession> sessionReference = new AtomicReference<>(null);
final AtomicReference<CustomTabsSession> sessionReference = new AtomicReference<>();
final AtomicReference<CustomTabsClient> clientReference = new AtomicReference<>();
final CallbackHelper waitForConnection = new CallbackHelper();
CustomTabsClient.bindCustomTabsService(InstrumentationRegistry.getContext(),
InstrumentationRegistry.getTargetContext().getPackageName(),
......@@ -74,12 +87,13 @@ public class CustomTabsTestUtils {
@Override
public void onCustomTabsServiceConnected(
ComponentName name, CustomTabsClient client) {
clientReference.set(client);
sessionReference.set(client.newSession(callback));
waitForConnection.notifyCalled();
}
});
waitForConnection.waitForCallback(0);
return sessionReference.get();
return new ClientAndSession(clientReference.get(), sessionReference.get());
}
/** Calls warmup() and waits for all the tasks to complete. Fails the test otherwise. */
......@@ -94,7 +108,7 @@ public class CustomTabsTestUtils {
startupCallbackHelper.notifyCalled();
}
}
});
}).session;
Assert.assertTrue(connection.warmup(0));
startupCallbackHelper.waitForCallback(0);
return connection;
......
......@@ -516,7 +516,7 @@ public class DetachedResourceRequestTest {
private CustomTabsSessionToken prepareSession(Uri origin, CustomTabsCallback callback)
throws Exception {
CustomTabsSession session = CustomTabsTestUtils.bindWithCallback(callback);
CustomTabsSession session = CustomTabsTestUtils.bindWithCallback(callback).session;
Intent intent = (new CustomTabsIntent.Builder(session)).build().intent;
CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
Assert.assertTrue(mConnection.newSession(token));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment