| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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.document; | |
| 6 | |
| 7 import android.app.Instrumentation; | |
| 8 import android.content.Intent; | |
| 9 import android.net.Uri; | |
| 10 import android.os.Build; | |
| 11 import android.provider.Browser; | |
| 12 import android.test.suitebuilder.annotation.MediumTest; | |
| 13 | |
| 14 import org.chromium.base.test.util.DisabledTest; | |
| 15 import org.chromium.base.test.util.MinAndroidSdkLevel; | |
| 16 import org.chromium.chrome.browser.ChromeApplication; | |
| 17 import org.chromium.chrome.browser.IntentHandler; | |
| 18 import org.chromium.chrome.browser.tab.Tab; | |
| 19 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; | |
| 20 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector; | |
| 21 import org.chromium.chrome.test.util.ApplicationTestUtils; | |
| 22 import org.chromium.content.browser.test.util.Criteria; | |
| 23 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 24 import org.chromium.content_public.browser.LoadUrlParams; | |
| 25 | |
| 26 import java.util.concurrent.Callable; | |
| 27 | |
| 28 /** | |
| 29 * Tests that Document mode handles referrers correctly. | |
| 30 */ | |
| 31 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) | |
| 32 @DisabledTest | |
| 33 public class DocumentModeReferrerTest extends DocumentModeTestBase { | |
| 34 private static final int ACTIVITY_START_TIMEOUT = 1000; | |
| 35 | |
| 36 private String mUrl; | |
| 37 private String mReferrer; | |
| 38 private TabModelSelectorTabObserver mObserver; | |
| 39 | |
| 40 @Override | |
| 41 public void tearDown() throws Exception { | |
| 42 super.tearDown(); | |
| 43 if (mObserver != null) { | |
| 44 mObserver.destroy(); | |
| 45 mObserver = null; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 @MediumTest | |
| 50 public void testReferrerExtra() throws Exception { | |
| 51 Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonito
r( | |
| 52 DocumentActivity.class.getName(), null, false); | |
| 53 ApplicationTestUtils.launchChrome(mContext); | |
| 54 | |
| 55 // Wait for tab model to become initialized. | |
| 56 CriteriaHelper.pollInstrumentationThread(new Criteria() { | |
| 57 @Override | |
| 58 public boolean isSatisfied() { | |
| 59 return ChromeApplication.isDocumentTabModelSelectorInitializedFo
rTests(); | |
| 60 } | |
| 61 }); | |
| 62 | |
| 63 DocumentTabModelSelector selector = ChromeApplication.getDocumentTabMode
lSelector(); | |
| 64 mObserver = new TabModelSelectorTabObserver(selector) { | |
| 65 @Override | |
| 66 public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) { | |
| 67 mUrl = params.getUrl(); | |
| 68 if (params.getReferrer() != null) { | |
| 69 mReferrer = params.getReferrer().getUrl(); | |
| 70 } | |
| 71 } | |
| 72 }; | |
| 73 | |
| 74 // Wait for document activity from the main intent to launch before firi
ng the next | |
| 75 // intent. | |
| 76 DocumentActivity doc = (DocumentActivity) monitor.waitForActivityWithTim
eout( | |
| 77 ACTIVITY_START_TIMEOUT); | |
| 78 assertNotNull("DocumentActivity did not start", doc); | |
| 79 | |
| 80 mUrl = null; | |
| 81 mReferrer = null; | |
| 82 | |
| 83 // Fire the Intent with EXTRA_REFERRER. | |
| 84 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_1)); | |
| 85 intent.setClassName(mContext.getPackageName(), ChromeLauncherActivity.cl
ass.getName()); | |
| 86 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 87 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(URL_2)); | |
| 88 IntentHandler.addTrustedIntentExtras(intent, mContext); | |
| 89 mContext.startActivity(intent); | |
| 90 | |
| 91 CriteriaHelper.pollUiThread(Criteria.equals(URL_1, new Callable<String>(
) { | |
| 92 @Override | |
| 93 public String call() { | |
| 94 return mUrl; | |
| 95 } | |
| 96 })); | |
| 97 | |
| 98 assertEquals(URL_2, mReferrer); | |
| 99 } | |
| 100 | |
| 101 @MediumTest | |
| 102 public void testReferrerExtraAndroidApp() throws Exception { | |
| 103 Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonito
r( | |
| 104 DocumentActivity.class.getName(), null, false); | |
| 105 ApplicationTestUtils.launchChrome(mContext); | |
| 106 | |
| 107 // Wait for tab model to become initialized. | |
| 108 CriteriaHelper.pollInstrumentationThread(new Criteria() { | |
| 109 @Override | |
| 110 public boolean isSatisfied() { | |
| 111 return ChromeApplication.isDocumentTabModelSelectorInitializedFo
rTests(); | |
| 112 } | |
| 113 }); | |
| 114 | |
| 115 DocumentTabModelSelector selector = ChromeApplication.getDocumentTabMode
lSelector(); | |
| 116 mObserver = new TabModelSelectorTabObserver(selector) { | |
| 117 @Override | |
| 118 public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) { | |
| 119 mUrl = params.getUrl(); | |
| 120 if (params.getReferrer() != null) { | |
| 121 mReferrer = params.getReferrer().getUrl(); | |
| 122 } | |
| 123 } | |
| 124 }; | |
| 125 | |
| 126 // Wait for document activity from the main intent to launch before firi
ng the next | |
| 127 // intent. | |
| 128 DocumentActivity doc = (DocumentActivity) monitor.waitForActivityWithTim
eout( | |
| 129 ACTIVITY_START_TIMEOUT); | |
| 130 assertNotNull("DocumentActivity did not start", doc); | |
| 131 | |
| 132 mUrl = null; | |
| 133 mReferrer = null; | |
| 134 | |
| 135 // Fire the Intent with EXTRA_REFERRER using android-app scheme. | |
| 136 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_1)); | |
| 137 intent.setClassName(mContext.getPackageName(), ChromeLauncherActivity.cl
ass.getName()); | |
| 138 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 139 final String androidAppReferrer = "android-app://com.imdb.mobile/http/ww
w.imdb.com"; | |
| 140 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(androidAppReferrer)); | |
| 141 mContext.startActivity(intent); | |
| 142 | |
| 143 CriteriaHelper.pollUiThread(Criteria.equals(URL_1, new Callable<String>(
) { | |
| 144 @Override | |
| 145 public String call() { | |
| 146 return mUrl; | |
| 147 } | |
| 148 })); | |
| 149 | |
| 150 assertEquals(androidAppReferrer, mReferrer); | |
| 151 } | |
| 152 | |
| 153 @MediumTest | |
| 154 public void testReferrerExtraNotAndroidApp() throws Exception { | |
| 155 Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonito
r( | |
| 156 DocumentActivity.class.getName(), null, false); | |
| 157 ApplicationTestUtils.launchChrome(mContext); | |
| 158 | |
| 159 // Wait for tab model to become initialized. | |
| 160 CriteriaHelper.pollInstrumentationThread(new Criteria() { | |
| 161 @Override | |
| 162 public boolean isSatisfied() { | |
| 163 return ChromeApplication.isDocumentTabModelSelectorInitializedFo
rTests(); | |
| 164 } | |
| 165 }); | |
| 166 | |
| 167 DocumentTabModelSelector selector = ChromeApplication.getDocumentTabMode
lSelector(); | |
| 168 mObserver = new TabModelSelectorTabObserver(selector) { | |
| 169 @Override | |
| 170 public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) { | |
| 171 mUrl = params.getUrl(); | |
| 172 if (params.getReferrer() != null) { | |
| 173 mReferrer = params.getReferrer().getUrl(); | |
| 174 } | |
| 175 } | |
| 176 }; | |
| 177 | |
| 178 // Wait for document activity from the main intent to launch before firi
ng the next | |
| 179 // intent. | |
| 180 DocumentActivity doc = (DocumentActivity) monitor.waitForActivityWithTim
eout( | |
| 181 ACTIVITY_START_TIMEOUT); | |
| 182 assertNotNull("DocumentActivity did not start", doc); | |
| 183 | |
| 184 mUrl = null; | |
| 185 mReferrer = null; | |
| 186 | |
| 187 // Fire the third-party Intent with EXTRA_REFERRER using a regular URL. | |
| 188 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_1)); | |
| 189 intent.setClassName(mContext.getPackageName(), ChromeLauncherActivity.cl
ass.getName()); | |
| 190 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 191 final String nonAppExtra = "http://www.imdb.com"; | |
| 192 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(nonAppExtra)); | |
| 193 mContext.startActivity(intent); | |
| 194 | |
| 195 CriteriaHelper.pollUiThread(Criteria.equals(URL_1, new Callable<String>(
) { | |
| 196 @Override | |
| 197 public String call() { | |
| 198 return mUrl; | |
| 199 } | |
| 200 })); | |
| 201 | |
| 202 // Check that referrer is not carried over | |
| 203 assertNull(mReferrer); | |
| 204 } | |
| 205 | |
| 206 @MediumTest | |
| 207 public void testReferrerExtraFromExternalIntent() throws Exception { | |
| 208 Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonito
r( | |
| 209 DocumentActivity.class.getName(), null, false); | |
| 210 ApplicationTestUtils.launchChrome(mContext); | |
| 211 | |
| 212 // Wait for tab model to become initialized. | |
| 213 CriteriaHelper.pollInstrumentationThread(new Criteria() { | |
| 214 @Override | |
| 215 public boolean isSatisfied() { | |
| 216 return ChromeApplication.isDocumentTabModelSelectorInitializedFo
rTests(); | |
| 217 } | |
| 218 }); | |
| 219 | |
| 220 DocumentTabModelSelector selector = ChromeApplication.getDocumentTabMode
lSelector(); | |
| 221 mObserver = new TabModelSelectorTabObserver(selector) { | |
| 222 @Override | |
| 223 public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) { | |
| 224 mUrl = params.getUrl(); | |
| 225 if (params.getReferrer() != null) { | |
| 226 mReferrer = params.getReferrer().getUrl(); | |
| 227 } | |
| 228 } | |
| 229 }; | |
| 230 | |
| 231 // Wait for document activity from the main intent to launch before firi
ng the next | |
| 232 // intent. | |
| 233 DocumentActivity doc = (DocumentActivity) monitor.waitForActivityWithTim
eout( | |
| 234 ACTIVITY_START_TIMEOUT); | |
| 235 assertNotNull("DocumentActivity did not start", doc); | |
| 236 | |
| 237 mUrl = null; | |
| 238 mReferrer = null; | |
| 239 | |
| 240 // Simulate a link click inside the application that goes through extern
al navigation | |
| 241 // handler and then goes back to Chrome. | |
| 242 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_1)); | |
| 243 intent.setClassName(mContext.getPackageName(), ChromeLauncherActivity.cl
ass.getName()); | |
| 244 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 245 intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName())
; | |
| 246 IntentHandler.setPendingReferrer(intent, "http://www.google.com"); | |
| 247 mContext.startActivity(intent); | |
| 248 | |
| 249 CriteriaHelper.pollUiThread(Criteria.equals(URL_1, new Callable<String>(
) { | |
| 250 @Override | |
| 251 public String call() { | |
| 252 return mUrl; | |
| 253 } | |
| 254 })); | |
| 255 | |
| 256 // Check that referrer is not carried over | |
| 257 assertEquals("http://www.google.com", mReferrer); | |
| 258 } | |
| 259 } | |
| OLD | NEW |