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

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

Issue 297973002: Navigation transitions: Block first response until after transitions have run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from review. Created 6 years, 6 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..1d2334ff97ea2109d5304306ed14703217a0709e
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/TransitionTest.java
@@ -0,0 +1,120 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+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;
+
+/**
+ * Test suite for navigation transition listeners.
+ */
+public class TransitionTest extends ContentShellTestBase {
+ private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</html>");
+
+ class TestNavigationTransitionDelegate implements NavigationTransitionDelegate {
+ private boolean mDidCallDefer = false;
+ private boolean mDidCallWillHandleDefer = false;
+ private boolean mHandleDefer = false;
+ private ContentViewCore mContentViewCore;
+
+ TestNavigationTransitionDelegate(ContentViewCore contentViewCore, boolean handleDefer) {
+ mContentViewCore = contentViewCore;
+ mHandleDefer = handleDefer;
+ }
+
+ @Override
+ public void didDeferAfterResponseStarted() {
+ mDidCallDefer = true;
+ mContentViewCore.resumeResponseDeferredAtStart();
+ }
+
+ @Override
+ public boolean willHandleDeferAfterResponseStarted() {
+ return mHandleDefer;
+ }
+
+ public boolean getDidCallDefer() {
+ return mDidCallDefer;
+ }
+
+ public boolean getDidCallWillHandlerDefer() {
+ return mDidCallWillHandleDefer;
+ }
+ };
+
+ /**
+ * Tests that the listener recieves DidDeferAfterResponseStarted if we specify that
+ * the transition is handled.
+ */
+ @SmallTest
+ public void testDidDeferAfterResponseStartedCalled() throws Throwable {
+ ContentShellActivity activity = launchContentShellWithUrl(URL_1);
+ waitForActiveShellToBeDoneLoading();
+ ContentViewCore contentViewCore = activity.getActiveContentViewCore();
+ TestCallbackHelperContainer testCallbackHelperContainer =
+ new TestCallbackHelperContainer(contentViewCore);
+
+ contentViewCore.setHasPendingNavigationTransitionForTesting();
+ TestNavigationTransitionDelegate delegate = new TestNavigationTransitionDelegate(
+ contentViewCore,
+ true);
+ contentViewCore.setNavigationTransitionDelegate(delegate);
+
+ loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(URL_1));
+
+ assertTrue("didDeferAfterResponseStarted called.", delegate.getDidCallDefer());
+ }
+
+ /**
+ * Tests that the listener does not receive DidDeferAfterResponseStarted if we specify that
+ * the transition is handled.
+ */
+ @SmallTest
+ public void testDidDeferAfterResponseStartedNotCalled() throws Throwable {
+ ContentShellActivity activity = launchContentShellWithUrl(URL_1);
+ waitForActiveShellToBeDoneLoading();
+ ContentViewCore contentViewCore = activity.getActiveContentViewCore();
+ TestCallbackHelperContainer testCallbackHelperContainer =
+ new TestCallbackHelperContainer(contentViewCore);
+
+ contentViewCore.setHasPendingNavigationTransitionForTesting();
+ TestNavigationTransitionDelegate delegate = new TestNavigationTransitionDelegate(
+ contentViewCore,
+ false);
+ contentViewCore.setNavigationTransitionDelegate(delegate);
+
+ loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(URL_1));
+
+ assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallDefer());
+ }
+
+ /**
+ * Tests that the resource handler doesn't query the listener if no transition is pending.
+ */
+ @SmallTest
+ public void testWillHandleDeferAfterResponseStartedNotCalled() throws Throwable {
+ ContentShellActivity activity = launchContentShellWithUrl(URL_1);
+ waitForActiveShellToBeDoneLoading();
+ ContentViewCore contentViewCore = activity.getActiveContentViewCore();
+ TestCallbackHelperContainer testCallbackHelperContainer =
+ new TestCallbackHelperContainer(contentViewCore);
+
+ TestNavigationTransitionDelegate delegate = new TestNavigationTransitionDelegate(
+ contentViewCore,
+ false);
+ contentViewCore.setNavigationTransitionDelegate(delegate);
+
+ loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(URL_1));
+
+ assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallDefer());
+ assertFalse("willHandleDeferAfterResponseStarted called.",
+ delegate.getDidCallWillHandlerDefer());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698