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; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 | 12 |
13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
15 import org.chromium.base.test.util.UrlUtils; | 15 import org.chromium.base.test.util.UrlUtils; |
| 16 import org.chromium.chrome.browser.ChromeActivity; |
| 17 import org.chromium.chrome.browser.ShortcutHelper; |
16 import org.chromium.chrome.browser.tab.Tab; | 18 import org.chromium.chrome.browser.tab.Tab; |
17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
18 import org.chromium.chrome.test.util.browser.TabLoadObserver; | 20 import org.chromium.chrome.test.util.browser.TabLoadObserver; |
19 import org.chromium.content.browser.test.util.Criteria; | 21 import org.chromium.content.browser.test.util.Criteria; |
20 import org.chromium.content.browser.test.util.CriteriaHelper; | 22 import org.chromium.content.browser.test.util.CriteriaHelper; |
21 | 23 |
22 import java.util.concurrent.Callable; | 24 import java.util.concurrent.Callable; |
23 | 25 |
24 /** | 26 /** |
25 * Tests org.chromium.chrome.browser.ShortcutHelper and it's C++ counterpart. | 27 * Tests org.chromium.chrome.browser.webapps.AddToHomescreenDialogHelper and it'
s C++ counterpart. |
26 */ | 28 */ |
27 public class ShortcutHelperTest extends ChromeActivityTestCaseBase<ChromeActivit
y> { | 29 public class AddToHomescreenDialogHelperTest extends ChromeActivityTestCaseBase<
ChromeActivity> { |
28 private static final String WEBAPP_ACTION_NAME = "WEBAPP_ACTION"; | 30 private static final String WEBAPP_ACTION_NAME = "WEBAPP_ACTION"; |
29 | 31 |
30 private static final String WEBAPP_TITLE = "Webapp shortcut"; | 32 private static final String WEBAPP_TITLE = "Webapp shortcut"; |
31 private static final String WEBAPP_HTML = UrlUtils.encodeHtmlDataUri( | 33 private static final String WEBAPP_HTML = UrlUtils.encodeHtmlDataUri( |
32 "<html><head>" | 34 "<html><head>" |
33 + "<meta name=\"mobile-web-app-capable\" content=\"yes\" />" | 35 + "<meta name=\"mobile-web-app-capable\" content=\"yes\" />" |
34 + "<title>" + WEBAPP_TITLE + "</title>" | 36 + "<title>" + WEBAPP_TITLE + "</title>" |
35 + "</head><body>Webapp capable</body></html>"); | 37 + "</head><body>Webapp capable</body></html>"); |
36 private static final String EDITED_WEBAPP_TITLE = "Webapp shortcut edited"; | 38 private static final String EDITED_WEBAPP_TITLE = "Webapp shortcut edited"; |
37 | 39 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 73 } |
72 | 74 |
73 public void clearBroadcastedIntent() { | 75 public void clearBroadcastedIntent() { |
74 mBroadcastedIntent = null; | 76 mBroadcastedIntent = null; |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 private ChromeActivity mActivity; | 80 private ChromeActivity mActivity; |
79 private TestShortcutHelperDelegate mShortcutHelperDelegate; | 81 private TestShortcutHelperDelegate mShortcutHelperDelegate; |
80 | 82 |
81 public ShortcutHelperTest() { | 83 public AddToHomescreenDialogHelperTest() { |
82 super(ChromeActivity.class); | 84 super(ChromeActivity.class); |
83 } | 85 } |
84 | 86 |
85 @Override | 87 @Override |
86 public void startMainActivity() throws InterruptedException { | 88 public void startMainActivity() throws InterruptedException { |
87 startMainActivityOnBlankPage(); | 89 startMainActivityOnBlankPage(); |
88 } | 90 } |
89 | 91 |
90 @Override | 92 @Override |
91 public void setUp() throws Exception { | 93 public void setUp() throws Exception { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 public boolean isSatisfied() { | 172 public boolean isSatisfied() { |
171 // The page title is often updated over several iterations. Wai
t until the right | 173 // The page title is often updated over several iterations. Wai
t until the right |
172 // one appears. | 174 // one appears. |
173 return super.isSatisfied() | 175 return super.isSatisfied() |
174 && TextUtils.equals(activeTab.getTitle(), expectedPageTi
tle); | 176 && TextUtils.equals(activeTab.getTitle(), expectedPageTi
tle); |
175 } | 177 } |
176 }; | 178 }; |
177 assertTrue(CriteriaHelper.pollForUIThreadCriteria(observer)); | 179 assertTrue(CriteriaHelper.pollForUIThreadCriteria(observer)); |
178 | 180 |
179 // Add the shortcut. | 181 // Add the shortcut. |
180 Callable<ShortcutHelper> callable = new Callable<ShortcutHelper>() { | 182 Callable<AddToHomescreenDialogHelper> callable = |
| 183 new Callable<AddToHomescreenDialogHelper>() { |
181 @Override | 184 @Override |
182 public ShortcutHelper call() { | 185 public AddToHomescreenDialogHelper call() { |
183 final ShortcutHelper helper = new ShortcutHelper( | 186 final AddToHomescreenDialogHelper helper = new AddToHomescreenDi
alogHelper( |
184 mActivity.getApplicationContext(), mActivity.getActivity
Tab()); | 187 mActivity.getApplicationContext(), mActivity.getActivity
Tab()); |
185 // Calling initialize() isn't strictly required but it is testin
g this code path. | 188 // Calling initialize() isn't strictly required but it is testin
g this code path. |
186 helper.initialize(new ShortcutHelper.ShortcutHelperObserver() { | 189 helper.initialize(new AddToHomescreenDialogHelper.Observer() { |
187 @Override | 190 @Override |
188 public void onUserTitleAvailable(String t) { | 191 public void onUserTitleAvailable(String t) { |
189 } | 192 } |
190 | 193 |
191 @Override | 194 @Override |
192 public void onIconAvailable(Bitmap icon) { | 195 public void onIconAvailable(Bitmap icon) { |
193 helper.addShortcut(title); | 196 helper.addShortcut(title); |
194 } | 197 } |
195 }); | 198 }); |
196 return helper; | 199 return helper; |
197 } | 200 } |
198 }; | 201 }; |
199 final ShortcutHelper helper = ThreadUtils.runOnUiThreadBlockingNoExcepti
on(callable); | 202 final AddToHomescreenDialogHelper helper = |
| 203 ThreadUtils.runOnUiThreadBlockingNoException(callable); |
200 | 204 |
201 // Make sure that the shortcut was added. | 205 // Make sure that the shortcut was added. |
202 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 206 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
203 @Override | 207 @Override |
204 public boolean isSatisfied() { | 208 public boolean isSatisfied() { |
205 return mShortcutHelperDelegate.mBroadcastedIntent != null; | 209 return mShortcutHelperDelegate.mBroadcastedIntent != null; |
206 } | 210 } |
207 })); | 211 })); |
208 | 212 |
209 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 213 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
210 @Override | 214 @Override |
211 public void run() { | 215 public void run() { |
212 helper.destroy(); | 216 helper.destroy(); |
213 } | 217 } |
214 }); | 218 }); |
215 } | 219 } |
216 } | 220 } |
OLD | NEW |