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

Side by Side 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: Rename test function. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8
9 import org.chromium.base.test.util.UrlUtils;
10 import org.chromium.content.browser.ContentViewCore.NavigationTransitionDelegate ;
11 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
12 import org.chromium.content_shell_apk.ContentShellActivity;
13 import org.chromium.content_shell_apk.ContentShellTestBase;
14
15 /**
16 * Test suite for navigation transition listeners.
17 */
18 public class TransitionTest extends ContentShellTestBase {
19 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>");
20
21 class TestNavigationTransitionDelegate implements NavigationTransitionDelega te {
22 private boolean mDidCallDefer = false;
23 private boolean mDidCallWillHandleDefer = false;
24 private boolean mHandleDefer = false;
25 private ContentViewCore mContentViewCore;
26
27 TestNavigationTransitionDelegate(ContentViewCore contentViewCore, boolea n handleDefer) {
28 mContentViewCore = contentViewCore;
29 mHandleDefer = handleDefer;
30 }
31
32 @Override
33 public void didDeferAfterResponseStarted() {
34 mDidCallDefer = true;
35 mContentViewCore.resumeResponseDeferredAtStart();
36 }
37
38 @Override
39 public boolean willHandleDeferAfterResponseStarted() {
40 return mHandleDefer;
41 }
42
43 public boolean getDidCallDefer() {
44 return mDidCallDefer;
45 }
46
47 public boolean getDidCallWillHandlerDefer() {
48 return mDidCallWillHandleDefer;
49 }
50 };
51
52 /**
53 * Tests that the listener recieves DidDeferAfterResponseStarted if we speci fy that
54 * the transition is handled.
55 */
56 @SmallTest
57 public void testDidDeferAfterResponseStartedCalled() throws Throwable {
58 ContentShellActivity activity = launchContentShellWithUrl(URL_1);
59 waitForActiveShellToBeDoneLoading();
60 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
61 TestCallbackHelperContainer testCallbackHelperContainer =
62 new TestCallbackHelperContainer(contentViewCore);
63
64 contentViewCore.setHasPendingNavigationTransitionForTesting();
65 TestNavigationTransitionDelegate delegate = new TestNavigationTransition Delegate(
66 contentViewCore,
67 true);
68 contentViewCore.setNavigationTransitionDelegate(delegate);
69
70 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_1));
71
72 assertTrue("didDeferAfterResponseStarted called.", delegate.getDidCallDe fer());
73 }
74
75 /**
76 * Tests that the listener does not receive DidDeferAfterResponseStarted if we specify that
77 * the transition is handled.
78 */
79 @SmallTest
80 public void testDidDeferAfterResponseStartedNotCalled() throws Throwable {
81 ContentShellActivity activity = launchContentShellWithUrl(URL_1);
82 waitForActiveShellToBeDoneLoading();
83 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
84 TestCallbackHelperContainer testCallbackHelperContainer =
85 new TestCallbackHelperContainer(contentViewCore);
86
87 contentViewCore.setHasPendingNavigationTransitionForTesting();
88 TestNavigationTransitionDelegate delegate = new TestNavigationTransition Delegate(
89 contentViewCore,
90 false);
91 contentViewCore.setNavigationTransitionDelegate(delegate);
92
93 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_1));
94
95 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD efer());
96 }
97
98 /**
99 * Tests that the resource handler doesn't query the listener if no transiti on is pending.
100 */
101 @SmallTest
102 public void testWillHandleDeferAfterResponseStartedNotCalled() throws Throwa ble {
103 ContentShellActivity activity = launchContentShellWithUrl(URL_1);
104 waitForActiveShellToBeDoneLoading();
105 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
106 TestCallbackHelperContainer testCallbackHelperContainer =
107 new TestCallbackHelperContainer(contentViewCore);
108
109 TestNavigationTransitionDelegate delegate = new TestNavigationTransition Delegate(
110 contentViewCore,
111 false);
112 contentViewCore.setNavigationTransitionDelegate(delegate);
113
114 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_1));
115
116 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD efer());
117 assertFalse("willHandleDeferAfterResponseStarted called.",
118 delegate.getDidCallWillHandlerDefer());
119 }
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698