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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabFromChromeExternalNavigationTest.java

Issue 2405343002: Add tests for native app redirects in herb. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.chrome.browser.customtabs;
6
7 import android.app.Activity;
8 import android.content.Intent;
9 import android.net.Uri;
10 import android.os.Environment;
11 import android.test.suitebuilder.annotation.LargeTest;
12 import android.test.suitebuilder.annotation.MediumTest;
13 import android.util.Base64;
14
15 import org.chromium.base.ActivityState;
16 import org.chromium.base.ApplicationStatus;
17 import org.chromium.base.ApplicationStatus.ActivityStateListener;
18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.util.CommandLineFlags;
20 import org.chromium.base.test.util.Feature;
21 import org.chromium.chrome.browser.ChromeSwitches;
22 import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory.CustomTab NavigationDelegate;
23 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
24 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult;
25 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
26 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl;
27 import org.chromium.chrome.browser.tab.Tab;
28 import org.chromium.chrome.browser.tab.TabDelegateFactory;
29 import org.chromium.content.browser.test.util.Criteria;
30 import org.chromium.content.browser.test.util.CriteriaHelper;
31 import org.chromium.net.test.EmbeddedTestServer;
32
33 import java.util.concurrent.Callable;
34 import java.util.concurrent.atomic.AtomicReference;
35
36 /**
37 * Tests for external navigation handling of Custom Tabs generated by Chrome.
38 */
39 @CommandLineFlags.Add(ChromeSwitches.HERB_FLAVOR_ELDERBERRY_SWITCH)
40 public class CustomTabFromChromeExternalNavigationTest extends CustomTabActivity TestBase {
41
42 private EmbeddedTestServer mTestServer;
43
44 @Override
45 public void setUp() throws Exception {
46 mTestServer = EmbeddedTestServer.createAndStartFileServer(
47 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory());
48 super.setUp();
49
50 ChromePreferenceManager.getInstance(getInstrumentation().getTargetContex t())
51 .setCachedHerbFlavor(ChromeSwitches.HERB_FLAVOR_ELDERBERRY);
52 }
53
54 @Override
55 public void tearDown() throws Exception {
56 mTestServer.stopAndDestroyServer();
57 super.tearDown();
58 }
59
60 @Override
61 protected void startActivityCompletely(Intent intent) {
62 final AtomicReference<CustomTabActivity> createdCct = new AtomicReferenc e<>();
63 ActivityStateListener stateListener = new ActivityStateListener() {
64 @Override
65 public void onActivityStateChange(Activity activity, int newState) {
66 if (newState != ActivityState.CREATED) return;
67 if (activity instanceof SeparateTaskCustomTabActivity) {
68 createdCct.set((CustomTabActivity) activity);
69 }
70 }
71 };
72 ApplicationStatus.registerStateListenerForAllActivities(stateListener);
73 Activity activity = getInstrumentation().startActivitySync(intent);
74 assertNotNull("Main activity did not start", activity);
75 try {
76 CriteriaHelper.pollUiThread(new Criteria() {
Maria 2016/10/11 21:48:16 why do we need to poll UI thread for this? I thoug
Ted C 2016/10/11 23:38:58 Very true. I copied this from other places that e
77 @Override
78 public boolean isSatisfied() {
79 return createdCct.get() != null;
80 }
81 });
82 } catch (InterruptedException e) {
83 fail(e.getMessage());
84 } finally {
85 ApplicationStatus.unregisterActivityStateListener(stateListener);
86 }
87 setActivity(createdCct.get());
88 }
89
90 private Intent getCustomTabFromChromeIntent(final String url) {
91 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Intent> () {
92 @Override
93 public Intent call() throws Exception {
94 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
95 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
96 return ChromeLauncherActivity.createCustomTabActivityIntent(
97 getInstrumentation().getTargetContext(), intent, true);
98 }
99 });
100
101 }
102
103 private void startCustomTabFromChrome(String url) throws InterruptedExceptio n {
104 startCustomTabActivityWithIntent(getCustomTabFromChromeIntent(url));
105 }
106
107 @Feature("CustomTabFromChrome")
108 @MediumTest
109 public void testUsingStandardExternalNavigationHandler() throws Exception {
110 startCustomTabFromChrome("about:blank");
111
112 Tab tab = getActivity().getActivityTab();
113 TabDelegateFactory delegateFactory = tab.getDelegateFactory();
114 assertTrue(delegateFactory instanceof CustomTabDelegateFactory);
115 CustomTabDelegateFactory customTabDelegateFactory =
116 ((CustomTabDelegateFactory) delegateFactory);
117 assertFalse(customTabDelegateFactory.getExternalNavigationDelegate()
118 instanceof CustomTabNavigationDelegate);
119 }
120
121 @Feature("CustomTabFromChrome")
122 @LargeTest
123 public void testIntentWithRedirectToApp() throws Exception {
124 final String redirectUrl = "https://maps.google.com/maps?q=1600+amphithe atre+parkway";
125 final String initialUrl = mTestServer.getURL(
126 "/chrome/test/data/android/redirect/js_redirect.html"
127 + "?replace_text="
128 + Base64.encodeToString("PARAM_URL".getBytes("utf-8"), Base64.UR L_SAFE) + ":"
129 + Base64.encodeToString(redirectUrl.getBytes("utf-8"), Base64.UR L_SAFE));
130
131 startActivityCompletely(getCustomTabFromChromeIntent(initialUrl));
132
133 final AtomicReference<InterceptNavigationDelegateImpl> navigationDelegat e =
134 new AtomicReference<>();
135 CriteriaHelper.pollUiThread(new Criteria("Tab never selected/initialized .") {
136 @Override
137 public boolean isSatisfied() {
138 Tab tab = getActivity().getActivityTab();
139 if (tab == null || tab.getInterceptNavigationDelegate() == null) return false;
140 navigationDelegate.set(tab.getInterceptNavigationDelegate());
141 return true;
142 }
143 });
144
145 Criteria.equals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
146 new Callable<OverrideUrlLoadingResult>() {
147 @Override
148 public OverrideUrlLoadingResult call() throws Exception {
149 return navigationDelegate.get().getLastOverrideUrlLoadin gResultForTests();
150 }
151 });
152
153 CriteriaHelper.pollUiThread(new Criteria() {
154 @Override
155 public boolean isSatisfied() {
Maria 2016/10/11 21:48:16 Hmm, do we restart everything on per-testcase or p
Ted C 2016/10/11 23:38:58 Switched the ordering and it ran (tried both the r
156 int activityState = ApplicationStatus.getStateForActivity(getAct ivity());
157 return activityState == ActivityState.STOPPED
158 || activityState == ActivityState.DESTROYED;
159 }
160 });
161 }
162 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698