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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java

Issue 387703004: Navigation transitions: Parse out transition-entering-stylesheet link headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit fix Created 6 years, 5 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 | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..384d1b196efaa0a6c66784099e433cd238188a50 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 addEnteringStylesheetToTransition(String stylesheet) {
+ mDidCallAddStylesheet = true;
+ mTransitionStylesheets.add(stylesheet);
+ }
+
public boolean getDidCallDefer() {
return mDidCallDefer;
}
@@ -47,8 +67,25 @@ public class TransitionTest extends ContentShellTestBase {
public boolean getDidCallWillHandlerDefer() {
return mDidCallWillHandleDefer;
}
+
+ public boolean getDidCallAddStylesheet() {
+ return mDidCallAddStylesheet;
+ }
+
+ public ArrayList<String> getTransitionStylesheets() {
+ return mTransitionStylesheets;
+ }
};
+ 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 +154,98 @@ public class TransitionTest extends ContentShellTestBase {
assertFalse("willHandleDeferAfterResponseStarted called.",
delegate.getDidCallWillHandlerDefer());
}
+
+ /**
+ * Tests that the listener receives addStylesheetToTransition if we specify
+ * that there are entering transition stylesheet.
+ */
+ @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",
+ "<transition0.css>;rel=transition-entering-stylesheet;scope=*",
+ "link",
+ "<transition1.css>;rel=transition-entering-stylesheet;scope=*",
+ "link",
+ "<transition2.css>;rel=transition-entering-stylesheet;scope=*"
+ };
+ 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());
+ assertTrue("Three stylesheets are added",
+ delegate.getTransitionStylesheets().size() == 3);
+ } finally {
+ if (webServer != null)
+ webServer.shutdown();
+ }
+ }
+
+ /**
+ * Tests that the listener receives addStylesheetToTransition if we specify
+ * that there are no entering transition stylesheet.
+ */
+ @SmallTest
+ public void testAddStylesheetToTransitionNotCalled() 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();
+ final String url3 = webServer.setResponse(URL_3, URL_3_DATA, null);
+ LoadUrlParams url3_params = new LoadUrlParams(url3);
+ loadUrl(contentViewCore, testCallbackHelperContainer, url3_params);
+ testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallback(
+ currentCallCount,
+ 1,
+ 10000,
+ TimeUnit.MILLISECONDS);
+
+ assertFalse("addStylesheetToTransition is not called.",
+ delegate.getDidCallAddStylesheet());
+ assertTrue("No stylesheets are added",
+ delegate.getTransitionStylesheets().size() == 0);
+ } finally {
+ if (webServer != null)
+ webServer.shutdown();
+ }
+ }
}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698