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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | |
9 import android.content.Intent; | 8 import android.content.Intent; |
10 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
11 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
12 | 11 |
13 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.test.util.CommandLineFlags; | 13 import org.chromium.base.test.util.CommandLineFlags; |
15 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
16 import org.chromium.base.test.util.Restriction; | 15 import org.chromium.base.test.util.Restriction; |
17 import org.chromium.base.test.util.RetryOnFailure; | 16 import org.chromium.base.test.util.RetryOnFailure; |
18 import org.chromium.base.test.util.UrlUtils; | 17 import org.chromium.base.test.util.UrlUtils; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 + "</head><body>Webapp capable</body></html>"); | 68 + "</head><body>Webapp capable</body></html>"); |
70 | 69 |
71 private static final String MANIFEST_PATH = "/chrome/test/data/banners/manif
est_test_page.html"; | 70 private static final String MANIFEST_PATH = "/chrome/test/data/banners/manif
est_test_page.html"; |
72 private static final String MANIFEST_TITLE = "Web app banner test page"; | 71 private static final String MANIFEST_TITLE = "Web app banner test page"; |
73 | 72 |
74 private static final String EVENT_WEBAPP_PATH = | 73 private static final String EVENT_WEBAPP_PATH = |
75 "/chrome/test/data/banners/appinstalled_test_page.html"; | 74 "/chrome/test/data/banners/appinstalled_test_page.html"; |
76 private static final String EVENT_WEBAPP_TITLE = "appinstalled event test pa
ge"; | 75 private static final String EVENT_WEBAPP_TITLE = "appinstalled event test pa
ge"; |
77 | 76 |
78 private static class TestShortcutHelperDelegate extends ShortcutHelper.Deleg
ate { | 77 private static class TestShortcutHelperDelegate extends ShortcutHelper.Deleg
ate { |
79 public Intent mBroadcastedIntent; | 78 public String mRequestedShortcutTitle; |
| 79 public Intent mRequestedShortcutIntent; |
80 | 80 |
81 @Override | 81 @Override |
82 public void sendBroadcast(Context context, Intent intent) { | 82 public void addShortcutToHomescreen(String title, Bitmap icon, Intent sh
ortcutIntent) { |
83 mBroadcastedIntent = intent; | 83 mRequestedShortcutTitle = title; |
| 84 mRequestedShortcutIntent = shortcutIntent; |
84 } | 85 } |
85 | 86 |
86 @Override | 87 @Override |
87 public String getFullscreenAction() { | 88 public String getFullscreenAction() { |
88 return WEBAPP_ACTION_NAME; | 89 return WEBAPP_ACTION_NAME; |
89 } | 90 } |
90 | 91 |
91 public void clearBroadcastedIntent() { | 92 public void clearRequestedShortcutData() { |
92 mBroadcastedIntent = null; | 93 mRequestedShortcutTitle = null; |
| 94 mRequestedShortcutIntent = null; |
93 } | 95 } |
94 } | 96 } |
95 | 97 |
96 private static class TestDataStorageFactory extends WebappDataStorage.Factor
y { | 98 private static class TestDataStorageFactory extends WebappDataStorage.Factor
y { |
97 public String mSplashImage; | 99 public String mSplashImage; |
98 | 100 |
99 @Override | 101 @Override |
100 public WebappDataStorage create(final String webappId) { | 102 public WebappDataStorage create(final String webappId) { |
101 return new WebappDataStorageWrapper(webappId); | 103 return new WebappDataStorageWrapper(webappId); |
102 } | 104 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 mActivity = getActivity(); | 172 mActivity = getActivity(); |
171 mTab = mActivity.getActivityTab(); | 173 mTab = mActivity.getActivityTab(); |
172 } | 174 } |
173 | 175 |
174 @SmallTest | 176 @SmallTest |
175 @Feature("{Webapp}") | 177 @Feature("{Webapp}") |
176 public void testAddWebappShortcuts() throws Exception { | 178 public void testAddWebappShortcuts() throws Exception { |
177 // Add a webapp shortcut and make sure the intent's parameters make sens
e. | 179 // Add a webapp shortcut and make sure the intent's parameters make sens
e. |
178 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); | 180 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
179 addShortcutToTab(mTab, ""); | 181 addShortcutToTab(mTab, ""); |
180 Intent firedIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 182 assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTit
le); |
181 assertEquals(WEBAPP_TITLE, firedIntent.getStringExtra(Intent.EXTRA_SHORT
CUT_NAME)); | |
182 | 183 |
183 Intent launchIntent = firedIntent.getParcelableExtra(Intent.EXTRA_SHORTC
UT_INTENT); | 184 Intent launchIntent = mShortcutHelperDelegate.mRequestedShortcutIntent; |
184 assertEquals(WEBAPP_HTML, launchIntent.getStringExtra(ShortcutHelper.EXT
RA_URL)); | 185 assertEquals(WEBAPP_HTML, launchIntent.getStringExtra(ShortcutHelper.EXT
RA_URL)); |
185 assertEquals(WEBAPP_ACTION_NAME, launchIntent.getAction()); | 186 assertEquals(WEBAPP_ACTION_NAME, launchIntent.getAction()); |
186 assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); | 187 assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
187 | 188 |
188 // Add a second shortcut and make sure it matches the second webapp's pa
rameters. | 189 // Add a second shortcut and make sure it matches the second webapp's pa
rameters. |
189 mShortcutHelperDelegate.clearBroadcastedIntent(); | 190 mShortcutHelperDelegate.clearRequestedShortcutData(); |
190 loadUrl(SECOND_WEBAPP_HTML, SECOND_WEBAPP_TITLE); | 191 loadUrl(SECOND_WEBAPP_HTML, SECOND_WEBAPP_TITLE); |
191 addShortcutToTab(mTab, ""); | 192 addShortcutToTab(mTab, ""); |
192 Intent newFiredIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 193 assertEquals(SECOND_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShor
tcutTitle); |
193 assertEquals(SECOND_WEBAPP_TITLE, | |
194 newFiredIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME)); | |
195 | 194 |
196 Intent newLaunchIntent = newFiredIntent.getParcelableExtra(Intent.EXTRA_
SHORTCUT_INTENT); | 195 Intent newLaunchIntent = mShortcutHelperDelegate.mRequestedShortcutInten
t; |
197 assertEquals(SECOND_WEBAPP_HTML, newLaunchIntent.getStringExtra(Shortcut
Helper.EXTRA_URL)); | 196 assertEquals(SECOND_WEBAPP_HTML, newLaunchIntent.getStringExtra(Shortcut
Helper.EXTRA_URL)); |
198 assertEquals(WEBAPP_ACTION_NAME, newLaunchIntent.getAction()); | 197 assertEquals(WEBAPP_ACTION_NAME, newLaunchIntent.getAction()); |
199 assertEquals(mActivity.getPackageName(), newLaunchIntent.getPackage()); | 198 assertEquals(mActivity.getPackageName(), newLaunchIntent.getPackage()); |
200 } | 199 } |
201 | 200 |
202 @SmallTest | 201 @SmallTest |
203 @Feature("{Webapp}") | 202 @Feature("{Webapp}") |
204 public void testAddBookmarkShortcut() throws Exception { | 203 public void testAddBookmarkShortcut() throws Exception { |
205 loadUrl(NORMAL_HTML, NORMAL_TITLE); | 204 loadUrl(NORMAL_HTML, NORMAL_TITLE); |
206 addShortcutToTab(mTab, ""); | 205 addShortcutToTab(mTab, ""); |
207 | 206 |
208 // Make sure the intent's parameters make sense. | 207 // Make sure the intent's parameters make sense. |
209 Intent firedIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 208 assertEquals(NORMAL_TITLE, mShortcutHelperDelegate.mRequestedShortcutTit
le); |
210 assertEquals(NORMAL_TITLE, firedIntent.getStringExtra(Intent.EXTRA_SHORT
CUT_NAME)); | |
211 | 209 |
212 Intent launchIntent = firedIntent.getParcelableExtra(Intent.EXTRA_SHORTC
UT_INTENT); | 210 Intent launchIntent = mShortcutHelperDelegate.mRequestedShortcutIntent; |
213 assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); | 211 assertEquals(mActivity.getPackageName(), launchIntent.getPackage()); |
214 assertEquals(Intent.ACTION_VIEW, launchIntent.getAction()); | 212 assertEquals(Intent.ACTION_VIEW, launchIntent.getAction()); |
215 assertEquals(NORMAL_HTML, launchIntent.getDataString()); | 213 assertEquals(NORMAL_HTML, launchIntent.getDataString()); |
216 } | 214 } |
217 | 215 |
218 @SmallTest | 216 @SmallTest |
219 @Feature("{Webapp}") | 217 @Feature("{Webapp}") |
220 public void testAddWebappShortcutsWithoutTitleEdit() throws Exception { | 218 public void testAddWebappShortcutsWithoutTitleEdit() throws Exception { |
221 // Add a webapp shortcut using the page's title. | 219 // Add a webapp shortcut using the page's title. |
222 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); | 220 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
223 addShortcutToTab(mTab, ""); | 221 addShortcutToTab(mTab, ""); |
224 Intent firedIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 222 assertEquals(WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShortcutTit
le); |
225 assertEquals(WEBAPP_TITLE, firedIntent.getStringExtra(Intent.EXTRA_SHORT
CUT_NAME)); | |
226 } | 223 } |
227 | 224 |
228 @SmallTest | 225 @SmallTest |
229 @Feature("{Webapp}") | 226 @Feature("{Webapp}") |
230 public void testAddWebappShortcutsWithTitleEdit() throws Exception { | 227 public void testAddWebappShortcutsWithTitleEdit() throws Exception { |
231 // Add a webapp shortcut with a custom title. | 228 // Add a webapp shortcut with a custom title. |
232 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); | 229 loadUrl(WEBAPP_HTML, WEBAPP_TITLE); |
233 addShortcutToTab(mTab, EDITED_WEBAPP_TITLE); | 230 addShortcutToTab(mTab, EDITED_WEBAPP_TITLE); |
234 Intent firedIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 231 assertEquals(EDITED_WEBAPP_TITLE, mShortcutHelperDelegate.mRequestedShor
tcutTitle); |
235 assertEquals(EDITED_WEBAPP_TITLE, firedIntent.getStringExtra(Intent.EXTR
A_SHORTCUT_NAME)); | |
236 } | 232 } |
237 | 233 |
238 @SmallTest | 234 @SmallTest |
239 @Feature("{Webapp}") | 235 @Feature("{Webapp}") |
240 public void testAddWebappShortcutsWithApplicationName() throws Exception { | 236 public void testAddWebappShortcutsWithApplicationName() throws Exception { |
241 loadUrl(META_APP_NAME_HTML, META_APP_NAME_PAGE_TITLE); | 237 loadUrl(META_APP_NAME_HTML, META_APP_NAME_PAGE_TITLE); |
242 addShortcutToTab(mTab, ""); | 238 addShortcutToTab(mTab, ""); |
243 Intent firedIntent = mShortcutHelperDelegate.mBroadcastedIntent; | 239 assertEquals(META_APP_NAME_TITLE, mShortcutHelperDelegate.mRequestedShor
tcutTitle); |
244 assertEquals(META_APP_NAME_TITLE, firedIntent.getStringExtra(Intent.EXTR
A_SHORTCUT_NAME)); | |
245 } | 240 } |
246 | 241 |
247 @SmallTest | 242 @SmallTest |
248 @Feature("{Webapp}") | 243 @Feature("{Webapp}") |
249 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 244 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
250 @CommandLineFlags.Add(ContentSwitches.DISABLE_POPUP_BLOCKING) | 245 @CommandLineFlags.Add(ContentSwitches.DISABLE_POPUP_BLOCKING) |
251 public void testAddWebappShortcutWithEmptyPage() throws Exception { | 246 public void testAddWebappShortcutWithEmptyPage() throws Exception { |
252 Tab spawnedPopup = spawnPopupInBackground(""); | 247 Tab spawnedPopup = spawnPopupInBackground(""); |
253 addShortcutToTab(spawnedPopup, ""); | 248 addShortcutToTab(spawnedPopup, ""); |
254 } | 249 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 302 |
308 private void addShortcutToTab(Tab tab, String title) throws Exception { | 303 private void addShortcutToTab(Tab tab, String title) throws Exception { |
309 // Add the shortcut. | 304 // Add the shortcut. |
310 TestAddToHomescreenManager manager = new TestAddToHomescreenManager(mAct
ivity, tab, title); | 305 TestAddToHomescreenManager manager = new TestAddToHomescreenManager(mAct
ivity, tab, title); |
311 startManagerOnUiThread(manager); | 306 startManagerOnUiThread(manager); |
312 | 307 |
313 // Make sure that the shortcut was added. | 308 // Make sure that the shortcut was added. |
314 CriteriaHelper.pollUiThread(new Criteria() { | 309 CriteriaHelper.pollUiThread(new Criteria() { |
315 @Override | 310 @Override |
316 public boolean isSatisfied() { | 311 public boolean isSatisfied() { |
317 return mShortcutHelperDelegate.mBroadcastedIntent != null; | 312 return mShortcutHelperDelegate.mRequestedShortcutIntent != null; |
318 } | 313 } |
319 }); | 314 }); |
320 | 315 |
321 destroyManagerOnUiThread(manager); | 316 destroyManagerOnUiThread(manager); |
322 } | 317 } |
323 | 318 |
324 private void startManagerOnUiThread(final AddToHomescreenManager manager) { | 319 private void startManagerOnUiThread(final AddToHomescreenManager manager) { |
325 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 320 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
326 @Override | 321 @Override |
327 public void run() { | 322 public void run() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 public Integer call() { | 354 public Integer call() { |
360 return getActivity().getTabModelSelector().getModel(false).getCo
unt(); | 355 return getActivity().getTabModelSelector().getModel(false).getCo
unt(); |
361 } | 356 } |
362 })); | 357 })); |
363 | 358 |
364 TabModel tabModel = getActivity().getTabModelSelector().getModel(false); | 359 TabModel tabModel = getActivity().getTabModelSelector().getModel(false); |
365 assertEquals(0, tabModel.indexOf(mTab)); | 360 assertEquals(0, tabModel.indexOf(mTab)); |
366 return getActivity().getTabModelSelector().getModel(false).getTabAt(1); | 361 return getActivity().getTabModelSelector().getModel(false).getTabAt(1); |
367 } | 362 } |
368 } | 363 } |
OLD | NEW |