| Index: content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java b/content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java
|
| index c5ebef2c264a663b0555feac4aaa661853937c04..cb537c6d296cb474425b7187187dce97c9a61927 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java
|
| @@ -5,28 +5,42 @@
|
| package org.chromium.content.browser;
|
|
|
| import android.test.suitebuilder.annotation.SmallTest;
|
| +import android.util.Pair;
|
|
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.content.browser.ContentViewCore.NavigationTransitionDelegate;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
|
| import org.chromium.content_shell_apk.ContentShellActivity;
|
| import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.net.test.util.TestWebServer;
|
| +
|
| +import java.util.ArrayList;
|
| +import java.util.List;
|
| +import java.util.concurrent.TimeUnit;
|
|
|
| /**
|
| * Test suite for navigation transition listeners.
|
| */
|
| public class TransitionTest extends ContentShellTestBase {
|
| +
|
| private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</html>");
|
| + private static final String URL_2 = "/2.html";
|
| + private static final String URL_2_DATA = "<html>2</html>";
|
| + private static final String URL_3 = "/3.html";
|
| + private static final String URL_3_DATA = "<html>3</html>";
|
|
|
| static class TestNavigationTransitionDelegate implements NavigationTransitionDelegate {
|
| private boolean mDidCallDefer = false;
|
| private boolean mDidCallWillHandleDefer = false;
|
| + private boolean mDidCallAddStylesheet = false;
|
| private boolean mHandleDefer = false;
|
| + private ArrayList<String> mTransitionStylesheets;
|
| private ContentViewCore mContentViewCore;
|
|
|
| TestNavigationTransitionDelegate(ContentViewCore contentViewCore, boolean handleDefer) {
|
| mContentViewCore = contentViewCore;
|
| mHandleDefer = handleDefer;
|
| + mTransitionStylesheets = new ArrayList<String>();
|
| }
|
|
|
| @Override
|
| @@ -40,6 +54,12 @@ public class TransitionTest extends ContentShellTestBase {
|
| return mHandleDefer;
|
| }
|
|
|
| + @Override
|
| + public void addStylesheetToTransition(String stylesheet) {
|
| + mDidCallAddStylesheet = true;
|
| + mTransitionStylesheets.add(stylesheet);
|
| + }
|
| +
|
| public boolean getDidCallDefer() {
|
| return mDidCallDefer;
|
| }
|
| @@ -47,8 +67,21 @@ public class TransitionTest extends ContentShellTestBase {
|
| public boolean getDidCallWillHandlerDefer() {
|
| return mDidCallWillHandleDefer;
|
| }
|
| +
|
| + public boolean getDidCallAddStylesheet() {
|
| + return mDidCallAddStylesheet;
|
| + }
|
| };
|
|
|
| + private static List<Pair<String, String>> createHeadersList(
|
| + String[] namesAndValues) {
|
| + List<Pair<String, String>> result =
|
| + new ArrayList<Pair<String, String>>();
|
| + for (int i = 0; i < namesAndValues.length; i += 2)
|
| + result.add(Pair.create(namesAndValues[i], namesAndValues[i + 1]));
|
| + return result;
|
| + }
|
| +
|
| /**
|
| * Tests that the listener recieves DidDeferAfterResponseStarted if we specify that
|
| * the transition is handled.
|
| @@ -117,4 +150,50 @@ public class TransitionTest extends ContentShellTestBase {
|
| assertFalse("willHandleDeferAfterResponseStarted called.",
|
| delegate.getDidCallWillHandlerDefer());
|
| }
|
| +
|
| + /**
|
| + * Tests that the listener receives addStylesheetToTransition if we specify
|
| + * that the transition is handled.
|
| + */
|
| + @SmallTest
|
| + public void testAddStylesheetToTransitionCalled() throws Throwable {
|
| + TestWebServer webServer = null;
|
| + try {
|
| + webServer = new TestWebServer(false);
|
| +
|
| + final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null);
|
| + ContentShellActivity activity = launchContentShellWithUrl(url2);
|
| + waitForActiveShellToBeDoneLoading();
|
| + ContentViewCore contentViewCore = activity.getActiveContentViewCore();
|
| + TestCallbackHelperContainer testCallbackHelperContainer =
|
| + new TestCallbackHelperContainer(contentViewCore);
|
| + contentViewCore.setHasPendingNavigationTransitionForTesting();
|
| + TestNavigationTransitionDelegate delegate =
|
| + new TestNavigationTransitionDelegate(contentViewCore, true);
|
| + contentViewCore.setNavigationTransitionDelegate(delegate);
|
| +
|
| + int currentCallCount = testCallbackHelperContainer
|
| + .getOnPageFinishedHelper().getCallCount();
|
| + String[] headers = {
|
| + "link",
|
| + "<transition.css>; rel=\"transition-entering-stylesheet\";"
|
| + };
|
| + final String url3 = webServer.setResponse(URL_3,
|
| + URL_3_DATA,
|
| + createHeadersList(headers));
|
| + LoadUrlParams url3_params = new LoadUrlParams(url3);
|
| + loadUrl(contentViewCore, testCallbackHelperContainer, url3_params);
|
| + testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallback(
|
| + currentCallCount,
|
| + 1,
|
| + 10000,
|
| + TimeUnit.MILLISECONDS);
|
| +
|
| + assertTrue("addStylesheetToTransition called.",
|
| + delegate.getDidCallAddStylesheet());
|
| + } finally {
|
| + if (webServer != null)
|
| + webServer.shutdown();
|
| + }
|
| + }
|
| }
|
|
|