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 static org.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
8 import static org.junit.Assert.assertTrue; | 8 import static org.junit.Assert.assertTrue; |
9 | 9 |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.SharedPreferences; | 12 import android.content.SharedPreferences; |
13 | 13 |
14 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
15 import org.chromium.blink_public.platform.WebDisplayMode; | 15 import org.chromium.blink_public.platform.WebDisplayMode; |
16 import org.chromium.chrome.browser.ShortcutHelper; | 16 import org.chromium.chrome.browser.ShortcutHelper; |
17 import org.chromium.testing.local.BackgroundShadowAsyncTask; | 17 import org.chromium.testing.local.BackgroundShadowAsyncTask; |
18 import org.chromium.testing.local.LocalRobolectricTestRunner; | 18 import org.chromium.testing.local.LocalRobolectricTestRunner; |
19 import org.junit.Before; | 19 import org.junit.Before; |
20 import org.junit.Test; | 20 import org.junit.Test; |
21 import org.junit.runner.RunWith; | 21 import org.junit.runner.RunWith; |
22 import org.robolectric.Robolectric; | 22 import org.robolectric.RuntimeEnvironment; |
23 import org.robolectric.annotation.Config; | 23 import org.robolectric.annotation.Config; |
| 24 import org.robolectric.shadows.ShadowLooper; |
24 | 25 |
25 import java.util.Arrays; | 26 import java.util.Arrays; |
26 import java.util.Collections; | 27 import java.util.Collections; |
27 import java.util.HashSet; | 28 import java.util.HashSet; |
28 import java.util.Map; | 29 import java.util.Map; |
29 import java.util.Set; | 30 import java.util.Set; |
30 | 31 |
31 /** | 32 /** |
32 * Tests the WebappRegistry class by ensuring that it persists data to | 33 * Tests the WebappRegistry class by ensuring that it persists data to |
33 * SharedPreferences as expected. | 34 * SharedPreferences as expected. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 mCallbackCalled = true; | 126 mCallbackCalled = true; |
126 } | 127 } |
127 | 128 |
128 boolean getCallbackCalled() { | 129 boolean getCallbackCalled() { |
129 return mCallbackCalled; | 130 return mCallbackCalled; |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 @Before | 134 @Before |
134 public void setUp() throws Exception { | 135 public void setUp() throws Exception { |
135 mSharedPreferences = Robolectric.application | 136 mSharedPreferences = RuntimeEnvironment.application |
136 .getSharedPreferences(REGISTRY_FILE_NAME, Context.MODE_PRIVATE); | 137 .getSharedPreferences(REGISTRY_FILE_NAME, Context.MODE_PRIVATE); |
137 mSharedPreferences.edit().putLong(KEY_LAST_CLEANUP, INITIAL_TIME).commit
(); | 138 mSharedPreferences.edit().putLong(KEY_LAST_CLEANUP, INITIAL_TIME).commit
(); |
138 | 139 |
139 mCallbackCalled = false; | 140 mCallbackCalled = false; |
140 } | 141 } |
141 | 142 |
142 @Test | 143 @Test |
143 @Feature({"Webapp"}) | 144 @Feature({"Webapp"}) |
144 public void testBackwardCompatibility() { | 145 public void testBackwardCompatibility() { |
145 assertEquals(REGISTRY_FILE_NAME, WebappRegistry.REGISTRY_FILE_NAME); | 146 assertEquals(REGISTRY_FILE_NAME, WebappRegistry.REGISTRY_FILE_NAME); |
146 assertEquals(KEY_WEBAPP_SET, WebappRegistry.KEY_WEBAPP_SET); | 147 assertEquals(KEY_WEBAPP_SET, WebappRegistry.KEY_WEBAPP_SET); |
147 assertEquals(KEY_LAST_CLEANUP, WebappRegistry.KEY_LAST_CLEANUP); | 148 assertEquals(KEY_LAST_CLEANUP, WebappRegistry.KEY_LAST_CLEANUP); |
148 } | 149 } |
149 | 150 |
150 @Test | 151 @Test |
151 @Feature({"Webapp"}) | 152 @Feature({"Webapp"}) |
152 public void testWebappRegistrationAddsToSharedPrefs() throws Exception { | 153 public void testWebappRegistrationAddsToSharedPrefs() throws Exception { |
153 WebappRegistry.registerWebapp(Robolectric.application, "test", null); | 154 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "test", nu
ll); |
| 155 |
154 BackgroundShadowAsyncTask.runBackgroundTasks(); | 156 BackgroundShadowAsyncTask.runBackgroundTasks(); |
155 | 157 |
156 Set<String> actual = mSharedPreferences.getStringSet( | 158 Set<String> actual = mSharedPreferences.getStringSet( |
157 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 159 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
158 assertEquals(1, actual.size()); | 160 assertEquals(1, actual.size()); |
159 assertTrue(actual.contains("test")); | 161 assertTrue(actual.contains("test")); |
160 } | 162 } |
161 | 163 |
162 @Test | 164 @Test |
163 @Feature({"Webapp"}) | 165 @Feature({"Webapp"}) |
164 public void testWebappRegistrationUpdatesLastUsed() throws Exception { | 166 public void testWebappRegistrationUpdatesLastUsed() throws Exception { |
165 WebappRegistry.registerWebapp(Robolectric.application, "test", null); | 167 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "test", nu
ll); |
| 168 |
166 BackgroundShadowAsyncTask.runBackgroundTasks(); | 169 BackgroundShadowAsyncTask.runBackgroundTasks(); |
167 long after = System.currentTimeMillis(); | 170 long after = System.currentTimeMillis(); |
168 | 171 |
169 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere
nces( | 172 SharedPreferences webAppPrefs = RuntimeEnvironment.application.getShared
Preferences( |
170 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); | 173 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); |
171 long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED, | 174 long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED, |
172 WebappDataStorage.LAST_USED_INVALID); | 175 WebappDataStorage.LAST_USED_INVALID); |
173 assertTrue("Timestamp is out of range", actual <= after); | 176 assertTrue("Timestamp is out of range", actual <= after); |
174 } | 177 } |
175 | 178 |
176 @Test | 179 @Test |
177 @Feature({"Webapp"}) | 180 @Feature({"Webapp"}) |
178 public void testWebappIdsRetrieval() throws Exception { | 181 public void testWebappIdsRetrieval() throws Exception { |
179 final Set<String> expected = addWebappsToRegistry("first", "second"); | 182 final Set<String> expected = addWebappsToRegistry("first", "second"); |
180 | 183 |
181 FetchCallback callback = new FetchCallback(expected); | 184 FetchCallback callback = new FetchCallback(expected); |
182 WebappRegistry.getRegisteredWebappIds(Robolectric.application, callback)
; | 185 WebappRegistry.getRegisteredWebappIds(RuntimeEnvironment.application, ca
llback); |
| 186 |
183 BackgroundShadowAsyncTask.runBackgroundTasks(); | 187 BackgroundShadowAsyncTask.runBackgroundTasks(); |
184 Robolectric.runUiThreadTasks(); | 188 ShadowLooper.runUiThreadTasks(); |
185 | 189 |
186 assertTrue(callback.getCallbackCalled()); | 190 assertTrue(callback.getCallbackCalled()); |
187 } | 191 } |
188 | 192 |
189 @Test | 193 @Test |
190 @Feature({"Webapp"}) | 194 @Feature({"Webapp"}) |
191 public void testWebappIdsRetrievalRegisterRetrival() throws Exception { | 195 public void testWebappIdsRetrievalRegisterRetrival() throws Exception { |
192 final Set<String> expected = addWebappsToRegistry("first"); | 196 final Set<String> expected = addWebappsToRegistry("first"); |
193 | 197 |
194 FetchCallback callback = new FetchCallback(expected); | 198 FetchCallback callback = new FetchCallback(expected); |
195 WebappRegistry.getRegisteredWebappIds(Robolectric.application, callback)
; | 199 WebappRegistry.getRegisteredWebappIds(RuntimeEnvironment.application, ca
llback); |
| 200 |
196 BackgroundShadowAsyncTask.runBackgroundTasks(); | 201 BackgroundShadowAsyncTask.runBackgroundTasks(); |
197 Robolectric.runUiThreadTasks(); | 202 ShadowLooper.runUiThreadTasks(); |
198 | 203 |
199 assertTrue(callback.getCallbackCalled()); | 204 assertTrue(callback.getCallbackCalled()); |
200 | 205 |
201 WebappRegistry.registerWebapp(Robolectric.application, "second", null); | 206 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "second",
null); |
| 207 |
202 BackgroundShadowAsyncTask.runBackgroundTasks(); | 208 BackgroundShadowAsyncTask.runBackgroundTasks(); |
203 | 209 |
204 // A copy of the expected set needs to be made as the SharedPreferences
is using the copy | 210 // A copy of the expected set needs to be made as the SharedPreferences
is using the copy |
205 // that was paassed to it. | 211 // that was paassed to it. |
206 final Set<String> secondExpected = new HashSet<String>(expected); | 212 final Set<String> secondExpected = new HashSet<String>(expected); |
207 secondExpected.add("second"); | 213 secondExpected.add("second"); |
208 | 214 |
209 callback = new FetchCallback(secondExpected); | 215 callback = new FetchCallback(secondExpected); |
210 WebappRegistry.getRegisteredWebappIds(Robolectric.application, callback)
; | 216 WebappRegistry.getRegisteredWebappIds(RuntimeEnvironment.application, ca
llback); |
| 217 |
211 BackgroundShadowAsyncTask.runBackgroundTasks(); | 218 BackgroundShadowAsyncTask.runBackgroundTasks(); |
212 Robolectric.runUiThreadTasks(); | 219 ShadowLooper.runUiThreadTasks(); |
213 | 220 |
214 assertTrue(callback.getCallbackCalled()); | 221 assertTrue(callback.getCallbackCalled()); |
215 } | 222 } |
216 | 223 |
217 @Test | 224 @Test |
218 @Feature({"Webapp"}) | 225 @Feature({"Webapp"}) |
219 public void testUnregisterRunsCallback() throws Exception { | 226 public void testUnregisterRunsCallback() throws Exception { |
220 CallbackRunner callback = new CallbackRunner(); | 227 CallbackRunner callback = new CallbackRunner(); |
221 WebappRegistry.unregisterAllWebapps(Robolectric.application, callback); | 228 WebappRegistry.unregisterAllWebapps(RuntimeEnvironment.application, call
back); |
| 229 |
222 BackgroundShadowAsyncTask.runBackgroundTasks(); | 230 BackgroundShadowAsyncTask.runBackgroundTasks(); |
223 Robolectric.runUiThreadTasks(); | 231 ShadowLooper.runUiThreadTasks(); |
224 | 232 |
225 assertTrue(callback.getCallbackCalled()); | 233 assertTrue(callback.getCallbackCalled()); |
226 } | 234 } |
227 | 235 |
228 @Test | 236 @Test |
229 @Feature({"Webapp"}) | 237 @Feature({"Webapp"}) |
230 public void testUnregisterClearsRegistry() throws Exception { | 238 public void testUnregisterClearsRegistry() throws Exception { |
231 addWebappsToRegistry("test"); | 239 addWebappsToRegistry("test"); |
232 | 240 |
233 CallbackRunner callback = new CallbackRunner(); | 241 CallbackRunner callback = new CallbackRunner(); |
234 WebappRegistry.unregisterAllWebapps(Robolectric.application, callback); | 242 WebappRegistry.unregisterAllWebapps(RuntimeEnvironment.application, call
back); |
| 243 |
235 BackgroundShadowAsyncTask.runBackgroundTasks(); | 244 BackgroundShadowAsyncTask.runBackgroundTasks(); |
236 Robolectric.runUiThreadTasks(); | 245 ShadowLooper.runUiThreadTasks(); |
237 | 246 |
238 assertTrue(callback.getCallbackCalled()); | 247 assertTrue(callback.getCallbackCalled()); |
239 assertTrue(getRegisteredWebapps().isEmpty()); | 248 assertTrue(getRegisteredWebapps().isEmpty()); |
240 } | 249 } |
241 | 250 |
242 @Test | 251 @Test |
243 @Feature({"Webapp"}) | 252 @Feature({"Webapp"}) |
244 public void testUnregisterClearsWebappDataStorage() throws Exception { | 253 public void testUnregisterClearsWebappDataStorage() throws Exception { |
245 addWebappsToRegistry("test"); | 254 addWebappsToRegistry("test"); |
246 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere
nces( | 255 SharedPreferences webAppPrefs = RuntimeEnvironment.application.getShared
Preferences( |
247 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); | 256 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD
E_PRIVATE); |
248 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, 100L).apply(
); | 257 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, 100L).apply(
); |
249 | 258 |
250 WebappRegistry.unregisterAllWebapps(Robolectric.application, null); | 259 WebappRegistry.unregisterAllWebapps(RuntimeEnvironment.application, null
); |
251 BackgroundShadowAsyncTask.runBackgroundTasks(); | 260 BackgroundShadowAsyncTask.runBackgroundTasks(); |
252 | 261 |
253 Map<String, ?> actual = webAppPrefs.getAll(); | 262 Map<String, ?> actual = webAppPrefs.getAll(); |
254 assertTrue(actual.isEmpty()); | 263 assertTrue(actual.isEmpty()); |
255 } | 264 } |
256 | 265 |
257 @Test | 266 @Test |
258 @Feature({"Webapp"}) | 267 @Feature({"Webapp"}) |
259 public void testCleanupDoesNotRunTooOften() throws Exception { | 268 public void testCleanupDoesNotRunTooOften() throws Exception { |
260 // Put the current time to just before the task should run. | 269 // Put the current time to just before the task should run. |
261 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION -
1; | 270 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION -
1; |
262 | 271 |
263 addWebappsToRegistry("oldWebapp"); | 272 addWebappsToRegistry("oldWebapp"); |
264 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere
nces( | 273 SharedPreferences webAppPrefs = RuntimeEnvironment.application.getShared
Preferences( |
265 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); | 274 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); |
266 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VAL
UE).apply(); | 275 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VAL
UE).apply(); |
267 | 276 |
268 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime
); | 277 WebappRegistry.unregisterOldWebapps(RuntimeEnvironment.application, curr
entTime); |
269 BackgroundShadowAsyncTask.runBackgroundTasks(); | 278 BackgroundShadowAsyncTask.runBackgroundTasks(); |
270 | 279 |
271 Set<String> actual = mSharedPreferences.getStringSet( | 280 Set<String> actual = mSharedPreferences.getStringSet( |
272 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 281 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
273 assertEquals(new HashSet<String>(Arrays.asList("oldWebapp")), actual); | 282 assertEquals(new HashSet<String>(Arrays.asList("oldWebapp")), actual); |
274 | 283 |
275 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 284 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, |
276 WebappDataStorage.LAST_USED_INVALID); | 285 WebappDataStorage.LAST_USED_INVALID); |
277 assertEquals(Long.MIN_VALUE, actualLastUsed); | 286 assertEquals(Long.MIN_VALUE, actualLastUsed); |
278 | 287 |
279 // The last cleanup time was set to 0 in setUp() so check that this hasn
't changed. | 288 // The last cleanup time was set to 0 in setUp() so check that this hasn
't changed. |
280 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 289 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
281 assertEquals(INITIAL_TIME, lastCleanup); | 290 assertEquals(INITIAL_TIME, lastCleanup); |
282 } | 291 } |
283 | 292 |
284 @Test | 293 @Test |
285 @Feature({"Webapp"}) | 294 @Feature({"Webapp"}) |
286 public void testCleanupDoesNotRemoveRecentApps() throws Exception { | 295 public void testCleanupDoesNotRemoveRecentApps() throws Exception { |
287 // Put the current time such that the task runs. | 296 // Put the current time such that the task runs. |
288 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; | 297 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; |
289 | 298 |
290 // Put the last used time just inside the no-cleanup window. | 299 // Put the last used time just inside the no-cleanup window. |
291 addWebappsToRegistry("recentWebapp"); | 300 addWebappsToRegistry("recentWebapp"); |
292 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere
nces( | 301 SharedPreferences webAppPrefs = RuntimeEnvironment.application.getShared
Preferences( |
293 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "recentWebapp", Con
text.MODE_PRIVATE); | 302 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "recentWebapp", Con
text.MODE_PRIVATE); |
294 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION + 1; | 303 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION + 1; |
295 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); | 304 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); |
296 | 305 |
297 // Because the time is just inside the window, there should be a cleanup
but the web app | 306 // Because the time is just inside the window, there should be a cleanup
but the web app |
298 // should not be deleted as it was used recently. The last cleanup time
should also be | 307 // should not be deleted as it was used recently. The last cleanup time
should also be |
299 // set to the current time. | 308 // set to the current time. |
300 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime
); | 309 WebappRegistry.unregisterOldWebapps(RuntimeEnvironment.application, curr
entTime); |
301 BackgroundShadowAsyncTask.runBackgroundTasks(); | 310 BackgroundShadowAsyncTask.runBackgroundTasks(); |
302 | 311 |
303 Set<String> actual = mSharedPreferences.getStringSet( | 312 Set<String> actual = mSharedPreferences.getStringSet( |
304 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 313 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
305 assertEquals(new HashSet<String>(Arrays.asList("recentWebapp")), actual)
; | 314 assertEquals(new HashSet<String>(Arrays.asList("recentWebapp")), actual)
; |
306 | 315 |
307 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 316 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, |
308 WebappDataStorage.LAST_USED_INVALID); | 317 WebappDataStorage.LAST_USED_INVALID); |
309 assertEquals(lastUsed, actualLastUsed); | 318 assertEquals(lastUsed, actualLastUsed); |
310 | 319 |
311 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 320 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
312 assertEquals(currentTime, lastCleanup); | 321 assertEquals(currentTime, lastCleanup); |
313 } | 322 } |
314 | 323 |
315 @Test | 324 @Test |
316 @Feature({"Webapp"}) | 325 @Feature({"Webapp"}) |
317 public void testCleanupRemovesOldApps() throws Exception { | 326 public void testCleanupRemovesOldApps() throws Exception { |
318 // Put the current time such that the task runs. | 327 // Put the current time such that the task runs. |
319 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; | 328 long currentTime = INITIAL_TIME + WebappRegistry.FULL_CLEANUP_DURATION; |
320 | 329 |
321 // Put the last used time just outside the no-cleanup window. | 330 // Put the last used time just outside the no-cleanup window. |
322 addWebappsToRegistry("oldWebapp"); | 331 addWebappsToRegistry("oldWebapp"); |
323 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere
nces( | 332 SharedPreferences webAppPrefs = RuntimeEnvironment.application.getShared
Preferences( |
324 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); | 333 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex
t.MODE_PRIVATE); |
325 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION; | 334 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR
ATION; |
326 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); | 335 webAppPrefs.edit().putLong(WebappDataStorage.KEY_LAST_USED, lastUsed).ap
ply(); |
327 | 336 |
328 // Because the time is just inside the window, there should be a cleanup
of old web apps and | 337 // Because the time is just inside the window, there should be a cleanup
of old web apps and |
329 // the last cleaned up time should be set to the current time. | 338 // the last cleaned up time should be set to the current time. |
330 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime
); | 339 WebappRegistry.unregisterOldWebapps(RuntimeEnvironment.application, curr
entTime); |
331 BackgroundShadowAsyncTask.runBackgroundTasks(); | 340 BackgroundShadowAsyncTask.runBackgroundTasks(); |
332 | 341 |
333 Set<String> actual = mSharedPreferences.getStringSet( | 342 Set<String> actual = mSharedPreferences.getStringSet( |
334 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 343 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
335 assertTrue(actual.isEmpty()); | 344 assertTrue(actual.isEmpty()); |
336 | 345 |
337 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, | 346 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE
D, |
338 WebappDataStorage.LAST_USED_INVALID); | 347 WebappDataStorage.LAST_USED_INVALID); |
339 assertEquals(WebappDataStorage.LAST_USED_INVALID, actualLastUsed); | 348 assertEquals(WebappDataStorage.LAST_USED_INVALID, actualLastUsed); |
340 | 349 |
341 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); | 350 long lastCleanup = mSharedPreferences.getLong(WebappRegistry.KEY_LAST_CL
EANUP, -1); |
342 assertEquals(currentTime, lastCleanup); | 351 assertEquals(currentTime, lastCleanup); |
343 } | 352 } |
344 | 353 |
345 @Test | 354 @Test |
346 @Feature({"WebApk"}) | 355 @Feature({"WebApk"}) |
347 public void testCleanupRemovesUninstalledWebApks() throws Exception { | 356 public void testCleanupRemovesUninstalledWebApks() throws Exception { |
348 String webappId1 = "webapk:uninstalledWebApk1"; | 357 String webappId1 = "webapk:uninstalledWebApk1"; |
349 String webApkPackage1 = "uninstalledWebApk1"; | 358 String webApkPackage1 = "uninstalledWebApk1"; |
350 String webappId2 = "webapk:uninstalledWebApk2"; | 359 String webappId2 = "webapk:uninstalledWebApk2"; |
351 String webApkPackage2 = "uninstalledWebApk2"; | 360 String webApkPackage2 = "uninstalledWebApk2"; |
352 | 361 |
353 FetchStorageCallback storageCallback1 = new FetchStorageCallback( | 362 FetchStorageCallback storageCallback1 = new FetchStorageCallback( |
354 createWebApkIntent(webappId1, webApkPackage1)); | 363 createWebApkIntent(webappId1, webApkPackage1)); |
355 WebappRegistry.registerWebapp(Robolectric.application, webappId1, storag
eCallback1); | 364 WebappRegistry.registerWebapp(RuntimeEnvironment.application, webappId1,
storageCallback1); |
356 BackgroundShadowAsyncTask.runBackgroundTasks(); | 365 BackgroundShadowAsyncTask.runBackgroundTasks(); |
357 Robolectric.runUiThreadTasks(); | 366 ShadowLooper.runUiThreadTasks(); |
358 assertTrue(storageCallback1.getCallbackCalled()); | 367 assertTrue(storageCallback1.getCallbackCalled()); |
359 | 368 |
360 FetchStorageCallback storageCallback2 = new FetchStorageCallback( | 369 FetchStorageCallback storageCallback2 = new FetchStorageCallback( |
361 createWebApkIntent(webappId1, webApkPackage2)); | 370 createWebApkIntent(webappId1, webApkPackage2)); |
362 WebappRegistry.registerWebapp(Robolectric.application, webappId2, storag
eCallback2); | 371 WebappRegistry.registerWebapp(RuntimeEnvironment.application, webappId2,
storageCallback2); |
363 BackgroundShadowAsyncTask.runBackgroundTasks(); | 372 BackgroundShadowAsyncTask.runBackgroundTasks(); |
364 Robolectric.runUiThreadTasks(); | 373 ShadowLooper.runUiThreadTasks(); |
365 assertTrue(storageCallback2.getCallbackCalled()); | 374 assertTrue(storageCallback2.getCallbackCalled()); |
366 | 375 |
367 // Verify that both WebAPKs are registered. | 376 // Verify that both WebAPKs are registered. |
368 Set<String> actual = mSharedPreferences.getStringSet( | 377 Set<String> actual = mSharedPreferences.getStringSet( |
369 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 378 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
370 assertEquals(2, actual.size()); | 379 assertEquals(2, actual.size()); |
371 assertTrue(actual.contains(webappId1)); | 380 assertTrue(actual.contains(webappId1)); |
372 assertTrue(actual.contains(webappId2)); | 381 assertTrue(actual.contains(webappId2)); |
373 | 382 |
374 // Set the current time such that the task runs. | 383 // Set the current time such that the task runs. |
375 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA
NUP_DURATION; | 384 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA
NUP_DURATION; |
376 // Because the time is just inside the window, there should be a cleanup
of | 385 // Because the time is just inside the window, there should be a cleanup
of |
377 // uninstalled WebAPKs and the last cleaned up time should be set to the | 386 // uninstalled WebAPKs and the last cleaned up time should be set to the |
378 // current time. | 387 // current time. |
379 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime
); | 388 WebappRegistry.unregisterOldWebapps(RuntimeEnvironment.application, curr
entTime); |
380 BackgroundShadowAsyncTask.runBackgroundTasks(); | 389 BackgroundShadowAsyncTask.runBackgroundTasks(); |
381 Robolectric.runUiThreadTasks(); | 390 ShadowLooper.runUiThreadTasks(); |
382 | 391 |
383 actual = mSharedPreferences.getStringSet( | 392 actual = mSharedPreferences.getStringSet( |
384 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 393 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
385 assertTrue(actual.isEmpty()); | 394 assertTrue(actual.isEmpty()); |
386 | 395 |
387 long lastCleanup = mSharedPreferences.getLong( | 396 long lastCleanup = mSharedPreferences.getLong( |
388 WebappRegistry.KEY_LAST_CLEANUP, -1); | 397 WebappRegistry.KEY_LAST_CLEANUP, -1); |
389 assertEquals(currentTime, lastCleanup); | 398 assertEquals(currentTime, lastCleanup); |
390 } | 399 } |
391 | 400 |
392 @Test | 401 @Test |
393 @Feature({"WebApk"}) | 402 @Feature({"WebApk"}) |
394 public void testCleanupDoesNotRemoveInstalledWebApks() throws Exception { | 403 public void testCleanupDoesNotRemoveInstalledWebApks() throws Exception { |
395 String webappId = "webapk:installedWebApk"; | 404 String webappId = "webapk:installedWebApk"; |
396 String webApkPackage = "installedWebApk"; | 405 String webApkPackage = "installedWebApk"; |
397 String uninstalledWebappId = "webapk:uninstalledWebApk"; | 406 String uninstalledWebappId = "webapk:uninstalledWebApk"; |
398 String uninstalledWebApkPackage = "uninstalledWebApk"; | 407 String uninstalledWebApkPackage = "uninstalledWebApk"; |
399 | 408 |
400 FetchStorageCallback storageCallback = new FetchStorageCallback( | 409 FetchStorageCallback storageCallback = new FetchStorageCallback( |
401 createWebApkIntent(webappId, webApkPackage)); | 410 createWebApkIntent(webappId, webApkPackage)); |
402 WebappRegistry.registerWebapp(Robolectric.application, webappId, storage
Callback); | 411 WebappRegistry.registerWebapp(RuntimeEnvironment.application, webappId,
storageCallback); |
403 BackgroundShadowAsyncTask.runBackgroundTasks(); | 412 BackgroundShadowAsyncTask.runBackgroundTasks(); |
404 Robolectric.runUiThreadTasks(); | 413 ShadowLooper.runUiThreadTasks(); |
405 assertTrue(storageCallback.getCallbackCalled()); | 414 assertTrue(storageCallback.getCallbackCalled()); |
406 | 415 |
407 FetchStorageCallback storageCallback2 = new FetchStorageCallback( | 416 FetchStorageCallback storageCallback2 = new FetchStorageCallback( |
408 createWebApkIntent(uninstalledWebappId, uninstalledWebApkPackage
)); | 417 createWebApkIntent(uninstalledWebappId, uninstalledWebApkPackage
)); |
409 WebappRegistry.registerWebapp(Robolectric.application, uninstalledWebapp
Id, | 418 WebappRegistry.registerWebapp(RuntimeEnvironment.application, uninstalle
dWebappId, |
410 storageCallback2); | 419 storageCallback2); |
411 BackgroundShadowAsyncTask.runBackgroundTasks(); | 420 BackgroundShadowAsyncTask.runBackgroundTasks(); |
412 Robolectric.runUiThreadTasks(); | 421 ShadowLooper.runUiThreadTasks(); |
413 assertTrue(storageCallback2.getCallbackCalled()); | 422 assertTrue(storageCallback2.getCallbackCalled()); |
414 | 423 |
415 // Verify that both WebAPKs are registered. | 424 // Verify that both WebAPKs are registered. |
416 Set<String> actual = mSharedPreferences.getStringSet( | 425 Set<String> actual = mSharedPreferences.getStringSet( |
417 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 426 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
418 assertEquals(2, actual.size()); | 427 assertEquals(2, actual.size()); |
419 assertTrue(actual.contains(webappId)); | 428 assertTrue(actual.contains(webappId)); |
420 assertTrue(actual.contains(uninstalledWebappId)); | 429 assertTrue(actual.contains(uninstalledWebappId)); |
421 | 430 |
422 Robolectric.packageManager.addPackage(webApkPackage); | 431 RuntimeEnvironment.getRobolectricPackageManager().addPackage(webApkPacka
ge); |
423 | 432 |
424 // Set the current time such that the task runs. | 433 // Set the current time such that the task runs. |
425 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA
NUP_DURATION; | 434 long currentTime = System.currentTimeMillis() + WebappRegistry.FULL_CLEA
NUP_DURATION; |
426 // Because the time is just inside the window, there should be a cleanup
of | 435 // Because the time is just inside the window, there should be a cleanup
of |
427 // uninstalled WebAPKs and the last cleaned up time should be set to the | 436 // uninstalled WebAPKs and the last cleaned up time should be set to the |
428 // current time. | 437 // current time. |
429 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime
); | 438 WebappRegistry.unregisterOldWebapps(RuntimeEnvironment.application, curr
entTime); |
430 BackgroundShadowAsyncTask.runBackgroundTasks(); | 439 BackgroundShadowAsyncTask.runBackgroundTasks(); |
431 Robolectric.runUiThreadTasks(); | 440 ShadowLooper.runUiThreadTasks(); |
432 | 441 |
433 actual = mSharedPreferences.getStringSet( | 442 actual = mSharedPreferences.getStringSet( |
434 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 443 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
435 assertEquals(1, actual.size()); | 444 assertEquals(1, actual.size()); |
436 assertTrue(actual.contains(webappId)); | 445 assertTrue(actual.contains(webappId)); |
437 | 446 |
438 long lastCleanup = mSharedPreferences.getLong( | 447 long lastCleanup = mSharedPreferences.getLong( |
439 WebappRegistry.KEY_LAST_CLEANUP, -1); | 448 WebappRegistry.KEY_LAST_CLEANUP, -1); |
440 assertEquals(currentTime, lastCleanup); | 449 assertEquals(currentTime, lastCleanup); |
441 } | 450 } |
442 | 451 |
443 @Test | 452 @Test |
444 @Feature({"Webapp"}) | 453 @Feature({"Webapp"}) |
445 public void testClearWebappHistoryRunsCallback() throws Exception { | 454 public void testClearWebappHistoryRunsCallback() throws Exception { |
446 CallbackRunner callback = new CallbackRunner(); | 455 CallbackRunner callback = new CallbackRunner(); |
447 WebappRegistry.clearWebappHistory(Robolectric.application, callback); | 456 WebappRegistry.clearWebappHistory(RuntimeEnvironment.application, callba
ck); |
448 BackgroundShadowAsyncTask.runBackgroundTasks(); | 457 BackgroundShadowAsyncTask.runBackgroundTasks(); |
449 Robolectric.runUiThreadTasks(); | 458 ShadowLooper.runUiThreadTasks(); |
450 | 459 |
451 assertTrue(callback.getCallbackCalled()); | 460 assertTrue(callback.getCallbackCalled()); |
452 } | 461 } |
453 | 462 |
454 @Test | 463 @Test |
455 @Feature({"Webapp"}) | 464 @Feature({"Webapp"}) |
456 public void testClearWebappHistory() throws Exception { | 465 public void testClearWebappHistory() throws Exception { |
457 final String webapp1Url = "https://www.google.com"; | 466 final String webapp1Url = "https://www.google.com"; |
458 final String webapp2Url = "https://drive.google.com"; | 467 final String webapp2Url = "https://drive.google.com"; |
459 Intent shortcutIntent1 = createShortcutIntent(webapp1Url); | 468 Intent shortcutIntent1 = createShortcutIntent(webapp1Url); |
460 Intent shortcutIntent2 = createShortcutIntent(webapp2Url); | 469 Intent shortcutIntent2 = createShortcutIntent(webapp2Url); |
461 | 470 |
462 FetchStorageCallback storageCallback1 = new FetchStorageCallback(shortcu
tIntent1); | 471 FetchStorageCallback storageCallback1 = new FetchStorageCallback(shortcu
tIntent1); |
463 WebappRegistry.registerWebapp(Robolectric.application, "webapp1", storag
eCallback1); | 472 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp1",
storageCallback1); |
464 BackgroundShadowAsyncTask.runBackgroundTasks(); | 473 BackgroundShadowAsyncTask.runBackgroundTasks(); |
465 Robolectric.runUiThreadTasks(); | 474 ShadowLooper.runUiThreadTasks(); |
466 assertTrue(storageCallback1.getCallbackCalled()); | 475 assertTrue(storageCallback1.getCallbackCalled()); |
467 | 476 |
468 FetchStorageCallback storageCallback2 = new FetchStorageCallback(shortcu
tIntent2); | 477 FetchStorageCallback storageCallback2 = new FetchStorageCallback(shortcu
tIntent2); |
469 WebappRegistry.registerWebapp(Robolectric.application, "webapp2", storag
eCallback2); | 478 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp2",
storageCallback2); |
470 BackgroundShadowAsyncTask.runBackgroundTasks(); | 479 BackgroundShadowAsyncTask.runBackgroundTasks(); |
471 Robolectric.runUiThreadTasks(); | 480 ShadowLooper.runUiThreadTasks(); |
472 assertTrue(storageCallback2.getCallbackCalled()); | 481 assertTrue(storageCallback2.getCallbackCalled()); |
473 | 482 |
474 SharedPreferences webapp1Prefs = Robolectric.application.getSharedPrefer
ences( | 483 SharedPreferences webapp1Prefs = RuntimeEnvironment.application.getShare
dPreferences( |
475 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context.
MODE_PRIVATE); | 484 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context.
MODE_PRIVATE); |
476 SharedPreferences webapp2Prefs = Robolectric.application.getSharedPrefer
ences( | 485 SharedPreferences webapp2Prefs = RuntimeEnvironment.application.getShare
dPreferences( |
477 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context.
MODE_PRIVATE); | 486 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context.
MODE_PRIVATE); |
478 | 487 |
479 CallbackRunner callback = new CallbackRunner(); | 488 CallbackRunner callback = new CallbackRunner(); |
480 WebappRegistry.clearWebappHistory(Robolectric.application, callback); | 489 WebappRegistry.clearWebappHistory(RuntimeEnvironment.application, callba
ck); |
481 BackgroundShadowAsyncTask.runBackgroundTasks(); | 490 BackgroundShadowAsyncTask.runBackgroundTasks(); |
482 Robolectric.runUiThreadTasks(); | 491 ShadowLooper.runUiThreadTasks(); |
483 assertTrue(callback.getCallbackCalled()); | 492 assertTrue(callback.getCallbackCalled()); |
484 | 493 |
485 Set<String> actual = mSharedPreferences.getStringSet( | 494 Set<String> actual = mSharedPreferences.getStringSet( |
486 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 495 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
487 assertEquals(2, actual.size()); | 496 assertEquals(2, actual.size()); |
488 assertTrue(actual.contains("webapp1")); | 497 assertTrue(actual.contains("webapp1")); |
489 assertTrue(actual.contains("webapp2")); | 498 assertTrue(actual.contains("webapp2")); |
490 | 499 |
491 // Verify that the last used time for both web apps is WebappDataStorage
.LAST_USED_UNSET. | 500 // Verify that the last used time for both web apps is WebappDataStorage
.LAST_USED_UNSET. |
492 long actualLastUsed = webapp1Prefs.getLong( | 501 long actualLastUsed = webapp1Prefs.getLong( |
(...skipping 14 matching lines...) Expand all Loading... |
507 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 516 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
508 assertEquals(WebappDataStorage.URL_INVALID, actualScope); | 517 assertEquals(WebappDataStorage.URL_INVALID, actualScope); |
509 actualUrl = webapp2Prefs.getString( | 518 actualUrl = webapp2Prefs.getString( |
510 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); | 519 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); |
511 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); | 520 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); |
512 } | 521 } |
513 | 522 |
514 @Test | 523 @Test |
515 @Feature({"Webapp"}) | 524 @Feature({"Webapp"}) |
516 public void testGetAfterClearWebappHistory() throws Exception { | 525 public void testGetAfterClearWebappHistory() throws Exception { |
517 WebappRegistry.registerWebapp(Robolectric.application, "webapp", null); | 526 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp",
null); |
518 BackgroundShadowAsyncTask.runBackgroundTasks(); | 527 BackgroundShadowAsyncTask.runBackgroundTasks(); |
519 | 528 |
520 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere
nces( | 529 SharedPreferences webappPrefs = RuntimeEnvironment.application.getShared
Preferences( |
521 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); | 530 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); |
522 CallbackRunner callback = new CallbackRunner(); | 531 CallbackRunner callback = new CallbackRunner(); |
523 WebappRegistry.clearWebappHistory(Robolectric.application, callback); | 532 WebappRegistry.clearWebappHistory(RuntimeEnvironment.application, callba
ck); |
524 BackgroundShadowAsyncTask.runBackgroundTasks(); | 533 BackgroundShadowAsyncTask.runBackgroundTasks(); |
525 Robolectric.runUiThreadTasks(); | 534 ShadowLooper.runUiThreadTasks(); |
526 assertTrue(callback.getCallbackCalled()); | 535 assertTrue(callback.getCallbackCalled()); |
527 | 536 |
528 // Open the webapp up to set the last used time. | 537 // Open the webapp up to set the last used time. |
529 FetchStorageCallback storageCallback = new FetchStorageCallback(null); | 538 FetchStorageCallback storageCallback = new FetchStorageCallback(null); |
530 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp", s
torageCallback); | 539 WebappRegistry.getWebappDataStorage( |
| 540 RuntimeEnvironment.application, "webapp", storageCallback); |
531 BackgroundShadowAsyncTask.runBackgroundTasks(); | 541 BackgroundShadowAsyncTask.runBackgroundTasks(); |
532 Robolectric.runUiThreadTasks(); | 542 ShadowLooper.runUiThreadTasks(); |
533 assertTrue(storageCallback.getCallbackCalled()); | 543 assertTrue(storageCallback.getCallbackCalled()); |
534 | 544 |
535 // Verify that the last used time is valid. | 545 // Verify that the last used time is valid. |
536 long actualLastUsed = webappPrefs.getLong( | 546 long actualLastUsed = webappPrefs.getLong( |
537 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_INV
ALID); | 547 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_INV
ALID); |
538 assertTrue(WebappDataStorage.LAST_USED_INVALID != actualLastUsed); | 548 assertTrue(WebappDataStorage.LAST_USED_INVALID != actualLastUsed); |
539 assertTrue(WebappDataStorage.LAST_USED_UNSET != actualLastUsed); | 549 assertTrue(WebappDataStorage.LAST_USED_UNSET != actualLastUsed); |
540 } | 550 } |
541 | 551 |
542 @Test | 552 @Test |
543 @Feature({"Webapp"}) | 553 @Feature({"Webapp"}) |
544 public void testUpdateAfterClearWebappHistory() throws Exception { | 554 public void testUpdateAfterClearWebappHistory() throws Exception { |
545 final String webappUrl = "http://www.google.com"; | 555 final String webappUrl = "http://www.google.com"; |
546 final String webappScope = "http://www.google.com/"; | 556 final String webappScope = "http://www.google.com/"; |
547 final Intent shortcutIntent = createShortcutIntent(webappUrl); | 557 final Intent shortcutIntent = createShortcutIntent(webappUrl); |
548 WebappRegistry.registerWebapp(Robolectric.application, "webapp", | 558 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp", |
549 new FetchStorageCallback(shortcutIntent)); | 559 new FetchStorageCallback(shortcutIntent)); |
550 BackgroundShadowAsyncTask.runBackgroundTasks(); | 560 BackgroundShadowAsyncTask.runBackgroundTasks(); |
551 Robolectric.runUiThreadTasks(); | 561 ShadowLooper.runUiThreadTasks(); |
552 | 562 |
553 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere
nces( | 563 SharedPreferences webappPrefs = RuntimeEnvironment.application.getShared
Preferences( |
554 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); | 564 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M
ODE_PRIVATE); |
555 | 565 |
556 // Verify that the URL and scope match the original in the intent. | 566 // Verify that the URL and scope match the original in the intent. |
557 String actualUrl = webappPrefs.getString( | 567 String actualUrl = webappPrefs.getString( |
558 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); | 568 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); |
559 assertEquals(webappUrl, actualUrl); | 569 assertEquals(webappUrl, actualUrl); |
560 String actualScope = webappPrefs.getString( | 570 String actualScope = webappPrefs.getString( |
561 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 571 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
562 assertEquals(webappScope, actualScope); | 572 assertEquals(webappScope, actualScope); |
563 | 573 |
564 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR
unner()); | 574 WebappRegistry.clearWebappHistory(RuntimeEnvironment.application, new Ca
llbackRunner()); |
565 BackgroundShadowAsyncTask.runBackgroundTasks(); | 575 BackgroundShadowAsyncTask.runBackgroundTasks(); |
566 Robolectric.runUiThreadTasks(); | 576 ShadowLooper.runUiThreadTasks(); |
567 | 577 |
568 // Update the webapp from the intent again. | 578 // Update the webapp from the intent again. |
569 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp", | 579 WebappRegistry.getWebappDataStorage(RuntimeEnvironment.application, "web
app", |
570 new FetchStorageCallback(shortcutIntent)); | 580 new FetchStorageCallback(shortcutIntent)); |
571 BackgroundShadowAsyncTask.runBackgroundTasks(); | 581 BackgroundShadowAsyncTask.runBackgroundTasks(); |
572 Robolectric.runUiThreadTasks(); | 582 ShadowLooper.runUiThreadTasks(); |
573 | 583 |
574 // Verify that the URL and scope match the original in the intent. | 584 // Verify that the URL and scope match the original in the intent. |
575 actualUrl = webappPrefs.getString(WebappDataStorage.KEY_URL, WebappDataS
torage.URL_INVALID); | 585 actualUrl = webappPrefs.getString(WebappDataStorage.KEY_URL, WebappDataS
torage.URL_INVALID); |
576 assertEquals(webappUrl, actualUrl); | 586 assertEquals(webappUrl, actualUrl); |
577 actualScope = webappPrefs.getString( | 587 actualScope = webappPrefs.getString( |
578 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); | 588 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); |
579 assertEquals(webappScope, actualScope); | 589 assertEquals(webappScope, actualScope); |
580 } | 590 } |
581 | 591 |
582 @Test | 592 @Test |
(...skipping 15 matching lines...) Expand all Loading... |
598 final String test4Url = "https://www.google.com/drive/docs/recent/index.
html"; | 608 final String test4Url = "https://www.google.com/drive/docs/recent/index.
html"; |
599 final String test5Url = "https://drive.google.com/docs/recent/trash"; | 609 final String test5Url = "https://drive.google.com/docs/recent/trash"; |
600 final String test6Url = "https://maps.google.com/"; | 610 final String test6Url = "https://maps.google.com/"; |
601 | 611 |
602 Intent shortcutIntent1 = createShortcutIntent(webapp1Url); | 612 Intent shortcutIntent1 = createShortcutIntent(webapp1Url); |
603 Intent shortcutIntent2 = createShortcutIntent(webapp2Url); | 613 Intent shortcutIntent2 = createShortcutIntent(webapp2Url); |
604 Intent shortcutIntent3 = createShortcutIntent(webapp3Url); | 614 Intent shortcutIntent3 = createShortcutIntent(webapp3Url); |
605 Intent shortcutIntent4 = createShortcutIntent(webapp4Url); | 615 Intent shortcutIntent4 = createShortcutIntent(webapp4Url); |
606 | 616 |
607 // Register the four web apps. | 617 // Register the four web apps. |
608 WebappRegistry.registerWebapp(Robolectric.application, "webapp1", | 618 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp1", |
609 new FetchStorageCallback(shortcutIntent1)); | 619 new FetchStorageCallback(shortcutIntent1)); |
610 BackgroundShadowAsyncTask.runBackgroundTasks(); | 620 BackgroundShadowAsyncTask.runBackgroundTasks(); |
611 Robolectric.runUiThreadTasks(); | 621 ShadowLooper.runUiThreadTasks(); |
612 | 622 |
613 WebappRegistry.registerWebapp(Robolectric.application, "webapp2", | 623 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp2", |
614 new FetchStorageCallback(shortcutIntent2)); | 624 new FetchStorageCallback(shortcutIntent2)); |
615 BackgroundShadowAsyncTask.runBackgroundTasks(); | 625 BackgroundShadowAsyncTask.runBackgroundTasks(); |
616 Robolectric.runUiThreadTasks(); | 626 ShadowLooper.runUiThreadTasks(); |
617 | 627 |
618 WebappRegistry.registerWebapp(Robolectric.application, "webapp3", | 628 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp3", |
619 new FetchStorageCallback(shortcutIntent3)); | 629 new FetchStorageCallback(shortcutIntent3)); |
620 BackgroundShadowAsyncTask.runBackgroundTasks(); | 630 BackgroundShadowAsyncTask.runBackgroundTasks(); |
621 Robolectric.runUiThreadTasks(); | 631 ShadowLooper.runUiThreadTasks(); |
622 | 632 |
623 WebappRegistry.registerWebapp(Robolectric.application, "webapp4", | 633 WebappRegistry.registerWebapp(RuntimeEnvironment.application, "webapp4", |
624 new FetchStorageCallback(shortcutIntent4)); | 634 new FetchStorageCallback(shortcutIntent4)); |
625 BackgroundShadowAsyncTask.runBackgroundTasks(); | 635 BackgroundShadowAsyncTask.runBackgroundTasks(); |
626 Robolectric.runUiThreadTasks(); | 636 ShadowLooper.runUiThreadTasks(); |
627 | 637 |
628 // test1Url should return webapp1. | 638 // test1Url should return webapp1. |
629 FetchStorageByUrlCallback callback = new FetchStorageByUrlCallback(webap
p1Url, webapp1Url); | 639 FetchStorageByUrlCallback callback = new FetchStorageByUrlCallback(webap
p1Url, webapp1Url); |
630 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test1
Url, callback); | 640 WebappRegistry.getWebappDataStorageForUrl( |
| 641 RuntimeEnvironment.application, test1Url, callback); |
631 BackgroundShadowAsyncTask.runBackgroundTasks(); | 642 BackgroundShadowAsyncTask.runBackgroundTasks(); |
632 Robolectric.runUiThreadTasks(); | 643 ShadowLooper.runUiThreadTasks(); |
633 assertTrue(callback.getCallbackCalled()); | 644 assertTrue(callback.getCallbackCalled()); |
634 | 645 |
635 // test2Url should return webapp3. | 646 // test2Url should return webapp3. |
636 callback = new FetchStorageByUrlCallback(webapp3Url, webapp3Scope); | 647 callback = new FetchStorageByUrlCallback(webapp3Url, webapp3Scope); |
637 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test2
Url, callback); | 648 WebappRegistry.getWebappDataStorageForUrl( |
| 649 RuntimeEnvironment.application, test2Url, callback); |
638 BackgroundShadowAsyncTask.runBackgroundTasks(); | 650 BackgroundShadowAsyncTask.runBackgroundTasks(); |
639 Robolectric.runUiThreadTasks(); | 651 ShadowLooper.runUiThreadTasks(); |
640 assertTrue(callback.getCallbackCalled()); | 652 assertTrue(callback.getCallbackCalled()); |
641 | 653 |
642 // test3Url should return webapp4. | 654 // test3Url should return webapp4. |
643 callback = new FetchStorageByUrlCallback(webapp4Url, webapp4Scope); | 655 callback = new FetchStorageByUrlCallback(webapp4Url, webapp4Scope); |
644 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test3
Url, callback); | 656 WebappRegistry.getWebappDataStorageForUrl( |
| 657 RuntimeEnvironment.application, test3Url, callback); |
645 BackgroundShadowAsyncTask.runBackgroundTasks(); | 658 BackgroundShadowAsyncTask.runBackgroundTasks(); |
646 Robolectric.runUiThreadTasks(); | 659 ShadowLooper.runUiThreadTasks(); |
647 assertTrue(callback.getCallbackCalled()); | 660 assertTrue(callback.getCallbackCalled()); |
648 | 661 |
649 // test4Url should return webapp4. | 662 // test4Url should return webapp4. |
650 callback = new FetchStorageByUrlCallback(webapp4Url, webapp4Scope); | 663 callback = new FetchStorageByUrlCallback(webapp4Url, webapp4Scope); |
651 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test4
Url, callback); | 664 WebappRegistry.getWebappDataStorageForUrl( |
| 665 RuntimeEnvironment.application, test4Url, callback); |
652 BackgroundShadowAsyncTask.runBackgroundTasks(); | 666 BackgroundShadowAsyncTask.runBackgroundTasks(); |
653 Robolectric.runUiThreadTasks(); | 667 ShadowLooper.runUiThreadTasks(); |
654 assertTrue(callback.getCallbackCalled()); | 668 assertTrue(callback.getCallbackCalled()); |
655 | 669 |
656 // test5Url should return webapp2. | 670 // test5Url should return webapp2. |
657 callback = new FetchStorageByUrlCallback(webapp2Url, webapp2Url); | 671 callback = new FetchStorageByUrlCallback(webapp2Url, webapp2Url); |
658 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test5
Url, callback); | 672 WebappRegistry.getWebappDataStorageForUrl( |
| 673 RuntimeEnvironment.application, test5Url, callback); |
659 BackgroundShadowAsyncTask.runBackgroundTasks(); | 674 BackgroundShadowAsyncTask.runBackgroundTasks(); |
660 Robolectric.runUiThreadTasks(); | 675 ShadowLooper.runUiThreadTasks(); |
661 assertTrue(callback.getCallbackCalled()); | 676 assertTrue(callback.getCallbackCalled()); |
662 | 677 |
663 // test6Url doesn't correspond to a web app, so the storage returned is
null. | 678 // test6Url doesn't correspond to a web app, so the storage returned is
null. |
664 // This must use a member variable; local variables must be final or eff
ectively final to be | 679 // This must use a member variable; local variables must be final or eff
ectively final to be |
665 // accessible inside an inner class. | 680 // accessible inside an inner class. |
666 mCallbackCalled = false; | 681 mCallbackCalled = false; |
667 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test6
Url, | 682 WebappRegistry.getWebappDataStorageForUrl(RuntimeEnvironment.application
, test6Url, |
668 new WebappRegistry.FetchWebappDataStorageCallback() { | 683 new WebappRegistry.FetchWebappDataStorageCallback() { |
669 @Override | 684 @Override |
670 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { | 685 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
671 assertEquals(null, storage); | 686 assertEquals(null, storage); |
672 mCallbackCalled = true; | 687 mCallbackCalled = true; |
673 } | 688 } |
674 } | 689 } |
675 ); | 690 ); |
676 BackgroundShadowAsyncTask.runBackgroundTasks(); | 691 BackgroundShadowAsyncTask.runBackgroundTasks(); |
677 Robolectric.runUiThreadTasks(); | 692 ShadowLooper.runUiThreadTasks(); |
678 assertTrue(mCallbackCalled); | 693 assertTrue(mCallbackCalled); |
679 } | 694 } |
680 | 695 |
681 private Set<String> addWebappsToRegistry(String... webapps) { | 696 private Set<String> addWebappsToRegistry(String... webapps) { |
682 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps))
; | 697 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps))
; |
683 mSharedPreferences.edit().putStringSet(WebappRegistry.KEY_WEBAPP_SET, ex
pected).apply(); | 698 mSharedPreferences.edit().putStringSet(WebappRegistry.KEY_WEBAPP_SET, ex
pected).apply(); |
684 return expected; | 699 return expected; |
685 } | 700 } |
686 | 701 |
687 private Set<String> getRegisteredWebapps() { | 702 private Set<String> getRegisteredWebapps() { |
688 return mSharedPreferences.getStringSet( | 703 return mSharedPreferences.getStringSet( |
689 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 704 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
690 } | 705 } |
691 | 706 |
692 private Intent createShortcutIntent(String url) { | 707 private Intent createShortcutIntent(String url) { |
693 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, | 708 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, |
694 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, | 709 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null, |
695 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon
e, 0, 0, 0, false); | 710 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, WebDisplayMode.Standalon
e, 0, 0, 0, false); |
696 } | 711 } |
697 | 712 |
698 private Intent createWebApkIntent(String webappId, String webApkPackage) { | 713 private Intent createWebApkIntent(String webappId, String webApkPackage) { |
699 Intent intent = new Intent(); | 714 Intent intent = new Intent(); |
700 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) | 715 intent.putExtra(ShortcutHelper.EXTRA_ID, webappId) |
701 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") | 716 .putExtra(ShortcutHelper.EXTRA_URL, "https://foo.com") |
702 .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage)
; | 717 .putExtra(ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage)
; |
703 return intent; | 718 return intent; |
704 } | 719 } |
705 } | 720 } |
OLD | NEW |