OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.tab; | 5 package org.chromium.chrome.browser.tab; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.content.pm.ActivityInfo; | 8 import android.content.pm.ActivityInfo; |
9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
10 import android.content.pm.ResolveInfo; | 10 import android.content.pm.ResolveInfo; |
11 import android.os.SystemClock; | 11 import android.os.SystemClock; |
12 import android.provider.Browser; | 12 import android.provider.Browser; |
13 import android.support.test.filters.SmallTest; | 13 import android.support.test.filters.SmallTest; |
14 import android.test.InstrumentationTestCase; | |
15 import android.test.mock.MockContext; | 14 import android.test.mock.MockContext; |
16 import android.test.mock.MockPackageManager; | 15 import android.test.mock.MockPackageManager; |
17 | 16 |
| 17 import org.junit.Assert; |
| 18 import org.junit.Before; |
| 19 import org.junit.Test; |
| 20 import org.junit.runner.RunWith; |
| 21 |
18 import org.chromium.base.CommandLine; | 22 import org.chromium.base.CommandLine; |
19 import org.chromium.base.test.util.Feature; | 23 import org.chromium.base.test.util.Feature; |
20 import org.chromium.base.test.util.RetryOnFailure; | 24 import org.chromium.base.test.util.RetryOnFailure; |
| 25 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
21 import org.chromium.ui.base.PageTransition; | 26 import org.chromium.ui.base.PageTransition; |
22 | 27 |
23 import java.net.URISyntaxException; | 28 import java.net.URISyntaxException; |
24 import java.util.ArrayList; | 29 import java.util.ArrayList; |
25 import java.util.List; | 30 import java.util.List; |
26 | 31 |
27 /** | 32 /** |
28 * Unittests for tab redirect handler. | 33 * Unittests for tab redirect handler. |
29 */ | 34 */ |
30 public class TabRedirectHandlerTest extends InstrumentationTestCase { | 35 @RunWith(ChromeJUnit4ClassRunner.class) |
| 36 public class TabRedirectHandlerTest { |
31 private static final int TRANS_TYPE_OF_LINK_FROM_INTENT = | 37 private static final int TRANS_TYPE_OF_LINK_FROM_INTENT = |
32 PageTransition.LINK | PageTransition.FROM_API; | 38 PageTransition.LINK | PageTransition.FROM_API; |
33 private static final String TEST_PACKAGE_NAME = "test.package.name"; | 39 private static final String TEST_PACKAGE_NAME = "test.package.name"; |
34 private static Intent sYtIntent; | 40 private static Intent sYtIntent; |
35 private static Intent sMoblieYtIntent; | 41 private static Intent sMoblieYtIntent; |
36 private static Intent sFooIntent; | 42 private static Intent sFooIntent; |
37 private MockContext mContext; | 43 private MockContext mContext; |
38 | 44 |
39 static { | 45 static { |
40 try { | 46 try { |
41 sYtIntent = Intent.parseUri("http://youtube.com/", Intent.URI_INTENT
_SCHEME); | 47 sYtIntent = Intent.parseUri("http://youtube.com/", Intent.URI_INTENT
_SCHEME); |
42 sMoblieYtIntent = Intent.parseUri("http://m.youtube.com/", Intent.UR
I_INTENT_SCHEME); | 48 sMoblieYtIntent = Intent.parseUri("http://m.youtube.com/", Intent.UR
I_INTENT_SCHEME); |
43 sFooIntent = Intent.parseUri("http://foo.com/", Intent.URI_INTENT_SC
HEME); | 49 sFooIntent = Intent.parseUri("http://foo.com/", Intent.URI_INTENT_SC
HEME); |
44 } catch (URISyntaxException ue) { | 50 } catch (URISyntaxException ue) { |
45 // Ignore exception. | 51 // Ignore exception. |
46 } | 52 } |
47 } | 53 } |
48 | 54 |
49 @Override | 55 @Before |
50 protected void setUp() throws Exception { | 56 public void setUp() throws Exception { |
51 super.setUp(); | |
52 CommandLine.init(new String[0]); | 57 CommandLine.init(new String[0]); |
53 mContext = new TestContext(); | 58 mContext = new TestContext(); |
54 } | 59 } |
55 | 60 |
| 61 @Test |
56 @SmallTest | 62 @SmallTest |
57 @Feature({"IntentHandling"}) | 63 @Feature({"IntentHandling"}) |
58 public void testRealIntentRedirect() { | 64 public void testRealIntentRedirect() { |
59 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 65 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
60 handler.updateIntent(sYtIntent); | 66 handler.updateIntent(sYtIntent); |
61 assertFalse(handler.isOnNavigation()); | 67 Assert.assertFalse(handler.isOnNavigation()); |
62 | 68 |
63 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 69 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
64 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 70 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
65 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); | 71 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); |
66 assertTrue(handler.isOnEffectiveIntentRedirectChain()); | 72 Assert.assertTrue(handler.isOnEffectiveIntentRedirectChain()); |
67 assertFalse(handler.hasNewResolver(sMoblieYtIntent)); | 73 Assert.assertFalse(handler.hasNewResolver(sMoblieYtIntent)); |
68 assertTrue(handler.hasNewResolver(sFooIntent)); | 74 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
69 assertFalse(handler.hasNewResolver(null)); | 75 Assert.assertFalse(handler.hasNewResolver(null)); |
70 | 76 |
71 assertTrue(handler.isOnNavigation()); | 77 Assert.assertTrue(handler.isOnNavigation()); |
72 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 78 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
73 } | 79 } |
74 | 80 |
| 81 @Test |
75 @SmallTest | 82 @SmallTest |
76 @Feature({"IntentHandling"}) | 83 @Feature({"IntentHandling"}) |
77 public void testEffectiveIntentRedirect() { | 84 public void testEffectiveIntentRedirect() { |
78 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 85 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
79 handler.updateIntent(sYtIntent); | 86 handler.updateIntent(sYtIntent); |
80 assertFalse(handler.isOnNavigation()); | 87 Assert.assertFalse(handler.isOnNavigation()); |
81 | 88 |
82 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 89 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
83 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 90 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
84 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 91 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
85 assertTrue(handler.isOnEffectiveIntentRedirectChain()); | 92 Assert.assertTrue(handler.isOnEffectiveIntentRedirectChain()); |
86 assertFalse(handler.hasNewResolver(sMoblieYtIntent)); | 93 Assert.assertFalse(handler.hasNewResolver(sMoblieYtIntent)); |
87 assertTrue(handler.hasNewResolver(sFooIntent)); | 94 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
88 assertFalse(handler.hasNewResolver(null)); | 95 Assert.assertFalse(handler.hasNewResolver(null)); |
89 | 96 |
90 assertTrue(handler.isOnNavigation()); | 97 Assert.assertTrue(handler.isOnNavigation()); |
91 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 98 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
92 } | 99 } |
93 | 100 |
| 101 @Test |
94 @SmallTest | 102 @SmallTest |
95 @Feature({"IntentHandling"}) | 103 @Feature({"IntentHandling"}) |
96 public void testNoIntent() { | 104 public void testNoIntent() { |
97 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 105 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
98 handler.updateIntent(null); | 106 handler.updateIntent(null); |
99 assertFalse(handler.isOnNavigation()); | 107 Assert.assertFalse(handler.isOnNavigation()); |
100 | 108 |
101 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 109 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
102 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 110 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
103 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); | 111 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); |
104 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 112 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
105 assertTrue(handler.hasNewResolver(sMoblieYtIntent)); | 113 Assert.assertTrue(handler.hasNewResolver(sMoblieYtIntent)); |
106 assertTrue(handler.hasNewResolver(sFooIntent)); | 114 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
107 assertFalse(handler.hasNewResolver(null)); | 115 Assert.assertFalse(handler.hasNewResolver(null)); |
108 | 116 |
109 assertTrue(handler.isOnNavigation()); | 117 Assert.assertTrue(handler.isOnNavigation()); |
110 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 118 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
111 } | 119 } |
112 | 120 |
| 121 @Test |
113 @SmallTest | 122 @SmallTest |
114 @Feature({"IntentHandling"}) | 123 @Feature({"IntentHandling"}) |
115 public void testClear() { | 124 public void testClear() { |
116 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 125 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
117 handler.updateIntent(sYtIntent); | 126 handler.updateIntent(sYtIntent); |
118 assertFalse(handler.isOnNavigation()); | 127 Assert.assertFalse(handler.isOnNavigation()); |
119 | 128 |
120 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 129 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
121 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 130 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
122 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); | 131 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); |
123 assertTrue(handler.isOnEffectiveIntentRedirectChain()); | 132 Assert.assertTrue(handler.isOnEffectiveIntentRedirectChain()); |
124 assertFalse(handler.hasNewResolver(sMoblieYtIntent)); | 133 Assert.assertFalse(handler.hasNewResolver(sMoblieYtIntent)); |
125 | 134 |
126 assertTrue(handler.isOnNavigation()); | 135 Assert.assertTrue(handler.isOnNavigation()); |
127 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 136 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
128 | 137 |
129 handler.clear(); | 138 handler.clear(); |
130 assertFalse(handler.isOnNavigation()); | 139 Assert.assertFalse(handler.isOnNavigation()); |
131 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 140 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
132 assertTrue(handler.hasNewResolver(sMoblieYtIntent)); | 141 Assert.assertTrue(handler.hasNewResolver(sMoblieYtIntent)); |
133 assertTrue(handler.hasNewResolver(sFooIntent)); | 142 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
134 assertFalse(handler.hasNewResolver(null)); | 143 Assert.assertFalse(handler.hasNewResolver(null)); |
135 } | 144 } |
136 | 145 |
| 146 @Test |
137 @SmallTest | 147 @SmallTest |
138 @Feature({"IntentHandling"}) | 148 @Feature({"IntentHandling"}) |
139 public void testNonLinkFromIntent() { | 149 public void testNonLinkFromIntent() { |
140 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 150 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
141 handler.updateIntent(sYtIntent); | 151 handler.updateIntent(sYtIntent); |
142 assertFalse(handler.isOnNavigation()); | 152 Assert.assertFalse(handler.isOnNavigation()); |
143 | 153 |
144 handler.updateNewUrlLoading(PageTransition.FORM_SUBMIT, false, false, 0,
0); | 154 handler.updateNewUrlLoading(PageTransition.FORM_SUBMIT, false, false, 0,
0); |
145 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 155 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
146 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 156 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
147 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 157 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
148 assertTrue(handler.hasNewResolver(sMoblieYtIntent)); | 158 Assert.assertTrue(handler.hasNewResolver(sMoblieYtIntent)); |
149 assertTrue(handler.hasNewResolver(sFooIntent)); | 159 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
150 assertFalse(handler.hasNewResolver(null)); | 160 Assert.assertFalse(handler.hasNewResolver(null)); |
151 | 161 |
152 assertTrue(handler.isOnNavigation()); | 162 Assert.assertTrue(handler.isOnNavigation()); |
153 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 163 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
154 } | 164 } |
155 | 165 |
| 166 @Test |
156 @SmallTest | 167 @SmallTest |
157 @Feature({"IntentHandling"}) | 168 @Feature({"IntentHandling"}) |
158 public void testUserInteraction() { | 169 public void testUserInteraction() { |
159 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 170 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
160 handler.updateIntent(sYtIntent); | 171 handler.updateIntent(sYtIntent); |
161 assertFalse(handler.isOnNavigation()); | 172 Assert.assertFalse(handler.isOnNavigation()); |
162 | 173 |
163 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 174 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
164 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 175 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
165 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); | 176 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, true, false,
0, 0); |
166 assertTrue(handler.isOnEffectiveIntentRedirectChain()); | 177 Assert.assertTrue(handler.isOnEffectiveIntentRedirectChain()); |
167 assertFalse(handler.hasNewResolver(sMoblieYtIntent)); | 178 Assert.assertFalse(handler.hasNewResolver(sMoblieYtIntent)); |
168 | 179 |
169 assertTrue(handler.isOnNavigation()); | 180 Assert.assertTrue(handler.isOnNavigation()); |
170 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 181 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
171 | 182 |
172 SystemClock.sleep(1); | 183 SystemClock.sleep(1); |
173 handler.updateNewUrlLoading( | 184 handler.updateNewUrlLoading( |
174 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
1); | 185 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
1); |
175 assertFalse(handler.isOnEffectiveIntentRedirectChain()); | 186 Assert.assertFalse(handler.isOnEffectiveIntentRedirectChain()); |
176 assertTrue(handler.hasNewResolver(sMoblieYtIntent)); | 187 Assert.assertTrue(handler.hasNewResolver(sMoblieYtIntent)); |
177 assertTrue(handler.hasNewResolver(sFooIntent)); | 188 Assert.assertTrue(handler.hasNewResolver(sFooIntent)); |
178 assertFalse(handler.hasNewResolver(null)); | 189 Assert.assertFalse(handler.hasNewResolver(null)); |
179 | 190 |
180 assertTrue(handler.isOnNavigation()); | 191 Assert.assertTrue(handler.isOnNavigation()); |
181 assertEquals(1, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 192 Assert.assertEquals(1, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
182 } | 193 } |
183 | 194 |
| 195 @Test |
184 @SmallTest | 196 @SmallTest |
185 @Feature({"IntentHandling"}) | 197 @Feature({"IntentHandling"}) |
186 public void testIntentFromChrome() { | 198 public void testIntentFromChrome() { |
187 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 199 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
188 Intent fooIntent = new Intent(sFooIntent); | 200 Intent fooIntent = new Intent(sFooIntent); |
189 fooIntent.putExtra(Browser.EXTRA_APPLICATION_ID, TEST_PACKAGE_NAME); | 201 fooIntent.putExtra(Browser.EXTRA_APPLICATION_ID, TEST_PACKAGE_NAME); |
190 handler.updateIntent(fooIntent); | 202 handler.updateIntent(fooIntent); |
191 assertFalse(handler.isOnNavigation()); | 203 Assert.assertFalse(handler.isOnNavigation()); |
192 assertTrue(handler.shouldStayInChrome(false)); | 204 Assert.assertTrue(handler.shouldStayInChrome(false)); |
193 assertFalse(handler.shouldStayInChrome(true)); | 205 Assert.assertFalse(handler.shouldStayInChrome(true)); |
194 | 206 |
195 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 207 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
196 assertTrue(handler.shouldStayInChrome(false)); | 208 Assert.assertTrue(handler.shouldStayInChrome(false)); |
197 assertFalse(handler.shouldStayInChrome(true)); | 209 Assert.assertFalse(handler.shouldStayInChrome(true)); |
198 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 210 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
199 assertTrue(handler.shouldStayInChrome(false)); | 211 Assert.assertTrue(handler.shouldStayInChrome(false)); |
200 assertFalse(handler.shouldStayInChrome(true)); | 212 Assert.assertFalse(handler.shouldStayInChrome(true)); |
201 | 213 |
202 assertTrue(handler.isOnNavigation()); | 214 Assert.assertTrue(handler.isOnNavigation()); |
203 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 215 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
204 | 216 |
205 SystemClock.sleep(1); | 217 SystemClock.sleep(1); |
206 handler.updateNewUrlLoading( | 218 handler.updateNewUrlLoading( |
207 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 219 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
208 assertFalse(handler.shouldStayInChrome(false)); | 220 Assert.assertFalse(handler.shouldStayInChrome(false)); |
209 assertFalse(handler.shouldStayInChrome(true)); | 221 Assert.assertFalse(handler.shouldStayInChrome(true)); |
210 | 222 |
211 assertTrue(handler.isOnNavigation()); | 223 Assert.assertTrue(handler.isOnNavigation()); |
212 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 224 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
213 } | 225 } |
214 | 226 |
| 227 @Test |
215 @SmallTest | 228 @SmallTest |
216 @Feature({"IntentHandling"}) | 229 @Feature({"IntentHandling"}) |
217 public void testNavigationFromUserTyping() { | 230 public void testNavigationFromUserTyping() { |
218 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 231 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
219 handler.updateIntent(sYtIntent); | 232 handler.updateIntent(sYtIntent); |
220 assertFalse(handler.isOnNavigation()); | 233 Assert.assertFalse(handler.isOnNavigation()); |
221 assertFalse(handler.isNavigationFromUserTyping()); | 234 Assert.assertFalse(handler.isNavigationFromUserTyping()); |
222 | 235 |
223 handler.updateNewUrlLoading(PageTransition.TYPED, false, false, 0, 0); | 236 handler.updateNewUrlLoading(PageTransition.TYPED, false, false, 0, 0); |
224 assertTrue(handler.isNavigationFromUserTyping()); | 237 Assert.assertTrue(handler.isNavigationFromUserTyping()); |
225 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 238 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
226 assertTrue(handler.isNavigationFromUserTyping()); | 239 Assert.assertTrue(handler.isNavigationFromUserTyping()); |
227 | 240 |
228 assertTrue(handler.isOnNavigation()); | 241 Assert.assertTrue(handler.isOnNavigation()); |
229 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 242 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
230 | 243 |
231 SystemClock.sleep(1); | 244 SystemClock.sleep(1); |
232 handler.updateNewUrlLoading( | 245 handler.updateNewUrlLoading( |
233 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 246 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
234 assertFalse(handler.isNavigationFromUserTyping()); | 247 Assert.assertFalse(handler.isNavigationFromUserTyping()); |
235 | 248 |
236 assertTrue(handler.isOnNavigation()); | 249 Assert.assertTrue(handler.isOnNavigation()); |
237 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 250 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
238 } | 251 } |
239 | 252 |
| 253 @Test |
240 @SmallTest | 254 @SmallTest |
241 @Feature({"IntentHandling"}) | 255 @Feature({"IntentHandling"}) |
242 public void testIntentHavingChromePackageName() { | 256 public void testIntentHavingChromePackageName() { |
243 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 257 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
244 Intent fooIntent = new Intent(sFooIntent); | 258 Intent fooIntent = new Intent(sFooIntent); |
245 fooIntent.setPackage(TEST_PACKAGE_NAME); | 259 fooIntent.setPackage(TEST_PACKAGE_NAME); |
246 handler.updateIntent(fooIntent); | 260 handler.updateIntent(fooIntent); |
247 assertFalse(handler.isOnNavigation()); | 261 Assert.assertFalse(handler.isOnNavigation()); |
248 assertTrue(handler.shouldStayInChrome(false)); | 262 Assert.assertTrue(handler.shouldStayInChrome(false)); |
249 assertFalse(handler.shouldStayInChrome(true)); | 263 Assert.assertFalse(handler.shouldStayInChrome(true)); |
250 | 264 |
251 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); | 265 handler.updateNewUrlLoading(TRANS_TYPE_OF_LINK_FROM_INTENT, false, false
, 0, 0); |
252 assertTrue(handler.shouldStayInChrome(false)); | 266 Assert.assertTrue(handler.shouldStayInChrome(false)); |
253 assertFalse(handler.shouldStayInChrome(true)); | 267 Assert.assertFalse(handler.shouldStayInChrome(true)); |
254 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 268 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
255 assertTrue(handler.shouldStayInChrome(false)); | 269 Assert.assertTrue(handler.shouldStayInChrome(false)); |
256 assertFalse(handler.shouldStayInChrome(true)); | 270 Assert.assertFalse(handler.shouldStayInChrome(true)); |
257 | 271 |
258 assertTrue(handler.isOnNavigation()); | 272 Assert.assertTrue(handler.isOnNavigation()); |
259 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 273 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
260 | 274 |
261 SystemClock.sleep(1); | 275 SystemClock.sleep(1); |
262 handler.updateNewUrlLoading( | 276 handler.updateNewUrlLoading( |
263 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 277 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
264 assertFalse(handler.shouldStayInChrome(false)); | 278 Assert.assertFalse(handler.shouldStayInChrome(false)); |
265 assertFalse(handler.shouldStayInChrome(true)); | 279 Assert.assertFalse(handler.shouldStayInChrome(true)); |
266 | 280 |
267 assertTrue(handler.isOnNavigation()); | 281 Assert.assertTrue(handler.isOnNavigation()); |
268 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 282 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
269 } | 283 } |
270 | 284 |
| 285 @Test |
271 @SmallTest | 286 @SmallTest |
272 @Feature({"IntentHandling"}) | 287 @Feature({"IntentHandling"}) |
273 public void testRedirectFromCurrentNavigationShouldNotOverrideUrlLoading() { | 288 public void testRedirectFromCurrentNavigationShouldNotOverrideUrlLoading() { |
274 ///////////////////////////////////////////////////// | 289 ///////////////////////////////////////////////////// |
275 // 1. 3XX redirection should not override URL loading. | 290 // 1. 3XX redirection should not override URL loading. |
276 ///////////////////////////////////////////////////// | 291 ///////////////////////////////////////////////////// |
277 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 292 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
278 handler.updateIntent(sYtIntent); | 293 handler.updateIntent(sYtIntent); |
279 assertFalse(handler.shouldNotOverrideUrlLoading()); | 294 Assert.assertFalse(handler.shouldNotOverrideUrlLoading()); |
280 | 295 |
281 handler.updateNewUrlLoading(PageTransition.LINK, false, true, 0, 0); | 296 handler.updateNewUrlLoading(PageTransition.LINK, false, true, 0, 0); |
282 handler.setShouldNotOverrideUrlLoadingUntilNewUrlLoading(); | 297 handler.setShouldNotOverrideUrlLoadingUntilNewUrlLoading(); |
283 | 298 |
284 handler.updateNewUrlLoading(PageTransition.LINK, true, false, 0, 0); | 299 handler.updateNewUrlLoading(PageTransition.LINK, true, false, 0, 0); |
285 assertTrue(handler.shouldNotOverrideUrlLoading()); | 300 Assert.assertTrue(handler.shouldNotOverrideUrlLoading()); |
286 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 301 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
287 | 302 |
288 ///////////////////////////////////////////////////// | 303 ///////////////////////////////////////////////////// |
289 // 2. Effective redirection should not override URL loading. | 304 // 2. Effective redirection should not override URL loading. |
290 ///////////////////////////////////////////////////// | 305 ///////////////////////////////////////////////////// |
291 handler = new TabRedirectHandler(mContext); | 306 handler = new TabRedirectHandler(mContext); |
292 handler.updateIntent(sYtIntent); | 307 handler.updateIntent(sYtIntent); |
293 assertFalse(handler.shouldNotOverrideUrlLoading()); | 308 Assert.assertFalse(handler.shouldNotOverrideUrlLoading()); |
294 | 309 |
295 handler.updateNewUrlLoading(PageTransition.LINK, false, true, 0, 0); | 310 handler.updateNewUrlLoading(PageTransition.LINK, false, true, 0, 0); |
296 handler.setShouldNotOverrideUrlLoadingUntilNewUrlLoading(); | 311 handler.setShouldNotOverrideUrlLoadingUntilNewUrlLoading(); |
297 | 312 |
298 // Effective redirection occurred. | 313 // Effective redirection occurred. |
299 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); | 314 handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); |
300 assertTrue(handler.shouldNotOverrideUrlLoading()); | 315 Assert.assertTrue(handler.shouldNotOverrideUrlLoading()); |
301 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 316 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
302 | 317 |
303 ///////////////////////////////////////////////////// | 318 ///////////////////////////////////////////////////// |
304 // 3. New URL loading should not be affected. | 319 // 3. New URL loading should not be affected. |
305 ///////////////////////////////////////////////////// | 320 ///////////////////////////////////////////////////// |
306 SystemClock.sleep(1); | 321 SystemClock.sleep(1); |
307 handler.updateNewUrlLoading( | 322 handler.updateNewUrlLoading( |
308 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 323 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
309 assertFalse(handler.shouldNotOverrideUrlLoading()); | 324 Assert.assertFalse(handler.shouldNotOverrideUrlLoading()); |
310 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 325 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
311 } | 326 } |
312 | 327 |
| 328 @Test |
313 @SmallTest | 329 @SmallTest |
314 @Feature({"IntentHandling"}) | 330 @Feature({"IntentHandling"}) |
315 @RetryOnFailure | 331 @RetryOnFailure |
316 public void testNavigationFromLinkWithoutUserGesture() { | 332 public void testNavigationFromLinkWithoutUserGesture() { |
317 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 333 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
318 handler.updateIntent(sYtIntent); | 334 handler.updateIntent(sYtIntent); |
319 assertFalse(handler.isOnNavigation()); | 335 Assert.assertFalse(handler.isOnNavigation()); |
320 assertFalse(handler.shouldStayInChrome(false)); | 336 Assert.assertFalse(handler.shouldStayInChrome(false)); |
321 assertFalse(handler.shouldStayInChrome(true)); | 337 Assert.assertFalse(handler.shouldStayInChrome(true)); |
322 | 338 |
323 handler.updateNewUrlLoading( | 339 handler.updateNewUrlLoading( |
324 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 0); | 340 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 0); |
325 assertTrue(handler.shouldStayInChrome(false)); | 341 Assert.assertTrue(handler.shouldStayInChrome(false)); |
326 assertTrue(handler.shouldStayInChrome(true)); | 342 Assert.assertTrue(handler.shouldStayInChrome(true)); |
327 handler.updateNewUrlLoading( | 343 handler.updateNewUrlLoading( |
328 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); | 344 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); |
329 assertTrue(handler.shouldStayInChrome(false)); | 345 Assert.assertTrue(handler.shouldStayInChrome(false)); |
330 assertTrue(handler.shouldStayInChrome(true)); | 346 Assert.assertTrue(handler.shouldStayInChrome(true)); |
331 | 347 |
332 assertTrue(handler.isOnNavigation()); | 348 Assert.assertTrue(handler.isOnNavigation()); |
333 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 349 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
334 | 350 |
335 SystemClock.sleep(1); | 351 SystemClock.sleep(1); |
336 handler.updateNewUrlLoading( | 352 handler.updateNewUrlLoading( |
337 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 353 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
338 assertFalse(handler.shouldStayInChrome(false)); | 354 Assert.assertFalse(handler.shouldStayInChrome(false)); |
339 assertFalse(handler.shouldStayInChrome(true)); | 355 Assert.assertFalse(handler.shouldStayInChrome(true)); |
340 | 356 |
341 assertTrue(handler.isOnNavigation()); | 357 Assert.assertTrue(handler.isOnNavigation()); |
342 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 358 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
343 } | 359 } |
344 | 360 |
| 361 @Test |
345 @SmallTest | 362 @SmallTest |
346 @Feature({"IntentHandling"}) | 363 @Feature({"IntentHandling"}) |
347 @RetryOnFailure | 364 @RetryOnFailure |
348 public void testNavigationFromReload() { | 365 public void testNavigationFromReload() { |
349 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 366 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
350 handler.updateIntent(sYtIntent); | 367 handler.updateIntent(sYtIntent); |
351 assertFalse(handler.isOnNavigation()); | 368 Assert.assertFalse(handler.isOnNavigation()); |
352 assertFalse(handler.shouldStayInChrome(false)); | 369 Assert.assertFalse(handler.shouldStayInChrome(false)); |
353 assertFalse(handler.shouldStayInChrome(true)); | 370 Assert.assertFalse(handler.shouldStayInChrome(true)); |
354 | 371 |
355 handler.updateNewUrlLoading( | 372 handler.updateNewUrlLoading( |
356 PageTransition.RELOAD, false, false, SystemClock.elapsedRealtime
(), 0); | 373 PageTransition.RELOAD, false, false, SystemClock.elapsedRealtime
(), 0); |
357 assertTrue(handler.shouldStayInChrome(false)); | 374 Assert.assertTrue(handler.shouldStayInChrome(false)); |
358 assertTrue(handler.shouldStayInChrome(true)); | 375 Assert.assertTrue(handler.shouldStayInChrome(true)); |
359 handler.updateNewUrlLoading( | 376 handler.updateNewUrlLoading( |
360 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); | 377 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); |
361 assertTrue(handler.shouldStayInChrome(false)); | 378 Assert.assertTrue(handler.shouldStayInChrome(false)); |
362 assertTrue(handler.shouldStayInChrome(true)); | 379 Assert.assertTrue(handler.shouldStayInChrome(true)); |
363 | 380 |
364 assertTrue(handler.isOnNavigation()); | 381 Assert.assertTrue(handler.isOnNavigation()); |
365 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 382 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
366 | 383 |
367 SystemClock.sleep(1); | 384 SystemClock.sleep(1); |
368 handler.updateNewUrlLoading( | 385 handler.updateNewUrlLoading( |
369 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 386 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
370 assertFalse(handler.shouldStayInChrome(false)); | 387 Assert.assertFalse(handler.shouldStayInChrome(false)); |
371 assertFalse(handler.shouldStayInChrome(true)); | 388 Assert.assertFalse(handler.shouldStayInChrome(true)); |
372 | 389 |
373 assertTrue(handler.isOnNavigation()); | 390 Assert.assertTrue(handler.isOnNavigation()); |
374 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 391 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
375 } | 392 } |
376 | 393 |
| 394 @Test |
377 @SmallTest | 395 @SmallTest |
378 @Feature({"IntentHandling"}) | 396 @Feature({"IntentHandling"}) |
379 @RetryOnFailure | 397 @RetryOnFailure |
380 public void testNavigationWithForwardBack() { | 398 public void testNavigationWithForwardBack() { |
381 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 399 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
382 handler.updateIntent(sYtIntent); | 400 handler.updateIntent(sYtIntent); |
383 assertFalse(handler.isOnNavigation()); | 401 Assert.assertFalse(handler.isOnNavigation()); |
384 assertFalse(handler.shouldStayInChrome(false)); | 402 Assert.assertFalse(handler.shouldStayInChrome(false)); |
385 assertFalse(handler.shouldStayInChrome(true)); | 403 Assert.assertFalse(handler.shouldStayInChrome(true)); |
386 | 404 |
387 handler.updateNewUrlLoading(PageTransition.FORM_SUBMIT | PageTransition.
FORWARD_BACK, | 405 handler.updateNewUrlLoading(PageTransition.FORM_SUBMIT | PageTransition.
FORWARD_BACK, |
388 false, true, SystemClock.elapsedRealtime(), 0); | 406 false, true, SystemClock.elapsedRealtime(), 0); |
389 assertTrue(handler.shouldStayInChrome(false)); | 407 Assert.assertTrue(handler.shouldStayInChrome(false)); |
390 assertTrue(handler.shouldStayInChrome(true)); | 408 Assert.assertTrue(handler.shouldStayInChrome(true)); |
391 handler.updateNewUrlLoading( | 409 handler.updateNewUrlLoading( |
392 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); | 410 PageTransition.LINK, false, false, SystemClock.elapsedRealtime()
, 1); |
393 assertTrue(handler.shouldStayInChrome(false)); | 411 Assert.assertTrue(handler.shouldStayInChrome(false)); |
394 assertTrue(handler.shouldStayInChrome(true)); | 412 Assert.assertTrue(handler.shouldStayInChrome(true)); |
395 | 413 |
396 assertTrue(handler.isOnNavigation()); | 414 Assert.assertTrue(handler.isOnNavigation()); |
397 assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 415 Assert.assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
398 | 416 |
399 SystemClock.sleep(1); | 417 SystemClock.sleep(1); |
400 handler.updateNewUrlLoading( | 418 handler.updateNewUrlLoading( |
401 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); | 419 PageTransition.LINK, false, true, SystemClock.elapsedRealtime(),
2); |
402 assertFalse(handler.shouldStayInChrome(false)); | 420 Assert.assertFalse(handler.shouldStayInChrome(false)); |
403 assertFalse(handler.shouldStayInChrome(true)); | 421 Assert.assertFalse(handler.shouldStayInChrome(true)); |
404 | 422 |
405 assertTrue(handler.isOnNavigation()); | 423 Assert.assertTrue(handler.isOnNavigation()); |
406 assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigati
on()); | 424 Assert.assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingN
avigation()); |
407 } | 425 } |
408 | 426 |
| 427 @Test |
409 @SmallTest | 428 @SmallTest |
410 @Feature({"IntentHandling"}) | 429 @Feature({"IntentHandling"}) |
411 public void testNavigationWithUninitializedUserInteractionTime() { | 430 public void testNavigationWithUninitializedUserInteractionTime() { |
412 // User interaction time could be uninitialized when a new document acti
vity is opened after | 431 // User interaction time could be uninitialized when a new document acti
vity is opened after |
413 // clicking a link. In that case, the value is 0. | 432 // clicking a link. In that case, the value is 0. |
414 final long uninitializedUserInteractionTime = 0; | 433 final long uninitializedUserInteractionTime = 0; |
415 TabRedirectHandler handler = new TabRedirectHandler(mContext); | 434 TabRedirectHandler handler = new TabRedirectHandler(mContext); |
416 | 435 |
417 assertFalse(handler.isOnNavigation()); | 436 Assert.assertFalse(handler.isOnNavigation()); |
418 handler.updateNewUrlLoading(PageTransition.LINK, false, true, | 437 handler.updateNewUrlLoading(PageTransition.LINK, false, true, |
419 uninitializedUserInteractionTime, TabRedirectHandler.INVALID_ENT
RY_INDEX); | 438 uninitializedUserInteractionTime, TabRedirectHandler.INVALID_ENT
RY_INDEX); |
420 assertTrue(handler.isOnNavigation()); | 439 Assert.assertTrue(handler.isOnNavigation()); |
421 assertEquals(TabRedirectHandler.INVALID_ENTRY_INDEX, | 440 Assert.assertEquals(TabRedirectHandler.INVALID_ENTRY_INDEX, |
422 handler.getLastCommittedEntryIndexBeforeStartingNavigation()); | 441 handler.getLastCommittedEntryIndexBeforeStartingNavigation()); |
423 } | 442 } |
424 | 443 |
425 private static class TestPackageManager extends MockPackageManager { | 444 private static class TestPackageManager extends MockPackageManager { |
426 @Override | 445 @Override |
427 public List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
{ | 446 public List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
{ |
428 List<ResolveInfo> resolves = new ArrayList<ResolveInfo>(); | 447 List<ResolveInfo> resolves = new ArrayList<ResolveInfo>(); |
429 if (intent.getDataString().startsWith("http://m.youtube.com") | 448 if (intent.getDataString().startsWith("http://m.youtube.com") |
430 || intent.getDataString().startsWith("http://youtube.com"))
{ | 449 || intent.getDataString().startsWith("http://youtube.com"))
{ |
431 ResolveInfo youTubeApp = new ResolveInfo(); | 450 ResolveInfo youTubeApp = new ResolveInfo(); |
(...skipping 18 matching lines...) Expand all Loading... |
450 return new TestPackageManager(); | 469 return new TestPackageManager(); |
451 } | 470 } |
452 | 471 |
453 @Override | 472 @Override |
454 public String getPackageName() { | 473 public String getPackageName() { |
455 return TEST_PACKAGE_NAME; | 474 return TEST_PACKAGE_NAME; |
456 } | 475 } |
457 | 476 |
458 } | 477 } |
459 } | 478 } |
OLD | NEW |