Chromium Code Reviews| 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; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 .putLong(WebappDataStorage.KEY_LAST_USED, 100L) | 177 .putLong(WebappDataStorage.KEY_LAST_USED, 100L) |
| 178 .commit(); | 178 .commit(); |
| 179 | 179 |
| 180 WebappRegistry.unregisterAllWebapps(Robolectric.application, null); | 180 WebappRegistry.unregisterAllWebapps(Robolectric.application, null); |
| 181 BackgroundShadowAsyncTask.runBackgroundTasks(); | 181 BackgroundShadowAsyncTask.runBackgroundTasks(); |
| 182 | 182 |
| 183 Map<String, ?> actual = webAppPrefs.getAll(); | 183 Map<String, ?> actual = webAppPrefs.getAll(); |
| 184 assertTrue(actual.isEmpty()); | 184 assertTrue(actual.isEmpty()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 @Test | |
| 188 @Feature({"Webapp"}) | |
| 189 public void testCleanupDoesNotRunTooOften() throws Exception { | |
| 190 addWebappsToRegistry("oldWebapp"); | |
| 191 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere nces( | |
| 192 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex t.MODE_PRIVATE); | |
| 193 webAppPrefs.edit() | |
| 194 .putLong(WebappDataStorage.KEY_LAST_USED, Long.MIN_VALUE) | |
| 195 .commit(); | |
| 196 | |
| 197 // Time just before the task should run. | |
| 198 WebappRegistry.unregisterOldWebapps(Robolectric.application, | |
| 199 WebappRegistry.FULL_CLEANUP_DURATION - 1); | |
| 200 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 201 | |
| 202 Set<String> actual = mSharedPreferences.getStringSet( | |
| 203 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | |
| 204 assertEquals(new HashSet<String>(Arrays.asList("test")), actual); | |
|
gone
2015/09/24 12:45:10
teeeeeeeeeeeeeeeeest?
Lalit Maganti
2015/09/24 12:49:25
Done.
| |
| 205 | |
| 206 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE D, | |
| 207 WebappDataStorage.INVALID_LAST_USED); | |
| 208 assertEquals(Long.MIN_VALUE, actualLastUsed); | |
| 209 } | |
| 210 | |
| 211 @Test | |
| 212 @Feature({"Webapp"}) | |
| 213 public void testCleanupDoesNotRemoveRecentApps() throws Exception { | |
| 214 long currentTime = WebappRegistry.FULL_CLEANUP_DURATION; | |
| 215 | |
| 216 addWebappsToRegistry("recentWebapp"); | |
| 217 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere nces( | |
| 218 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "recentWebapp", Con text.MODE_PRIVATE); | |
| 219 | |
| 220 // Put the last used time just inside the no-cleanup window. | |
| 221 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR ATION + 1; | |
| 222 webAppPrefs.edit() | |
| 223 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsed) | |
| 224 .commit(); | |
| 225 | |
| 226 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime ); | |
| 227 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 228 | |
| 229 Set<String> actual = mSharedPreferences.getStringSet( | |
| 230 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | |
| 231 assertEquals(new HashSet<String>(Arrays.asList("test")), actual); | |
|
gone
2015/09/24 12:45:10
"test"?
Lalit Maganti
2015/09/24 12:49:25
Done.
| |
| 232 | |
| 233 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE D, | |
| 234 WebappDataStorage.INVALID_LAST_USED); | |
| 235 assertEquals(lastUsed, actualLastUsed); | |
| 236 } | |
| 237 | |
| 238 @Test | |
| 239 @Feature({"Webapp"}) | |
| 240 public void testCleanupRemovesOldApps() throws Exception { | |
| 241 long currentTime = WebappRegistry.FULL_CLEANUP_DURATION; | |
| 242 | |
| 243 addWebappsToRegistry("oldWebapp"); | |
| 244 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere nces( | |
| 245 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "oldWebapp", Contex t.MODE_PRIVATE); | |
| 246 | |
| 247 // Put the last used time just outside the no-cleanup window. | |
| 248 long lastUsed = currentTime - WebappRegistry.WEBAPP_UNOPENED_CLEANUP_DUR ATION; | |
|
gone
2015/09/24 12:45:10
any reason why this doesn't +1 but the one above d
Lalit Maganti
2015/09/24 12:49:25
The one above is just outside the cleanup window a
| |
| 249 webAppPrefs.edit() | |
| 250 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsed) | |
| 251 .commit(); | |
| 252 | |
| 253 WebappRegistry.unregisterOldWebapps(Robolectric.application, currentTime ); | |
| 254 BackgroundShadowAsyncTask.runBackgroundTasks(); | |
| 255 | |
| 256 Set<String> actual = mSharedPreferences.getStringSet( | |
| 257 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | |
| 258 assertTrue(actual.isEmpty()); | |
| 259 | |
| 260 long actualLastUsed = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USE D, | |
| 261 WebappDataStorage.INVALID_LAST_USED); | |
| 262 assertEquals(WebappDataStorage.INVALID_LAST_USED, actualLastUsed); | |
| 263 } | |
| 264 | |
| 187 private Set<String> addWebappsToRegistry(String... webapps) { | 265 private Set<String> addWebappsToRegistry(String... webapps) { |
| 188 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps)) ; | 266 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps)) ; |
| 189 mSharedPreferences.edit() | 267 mSharedPreferences.edit() |
| 190 .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected) | 268 .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected) |
| 191 .commit(); | 269 .commit(); |
| 192 return expected; | 270 return expected; |
| 193 } | 271 } |
| 194 | 272 |
| 195 private Set<String> getRegisteredWebapps() { | 273 private Set<String> getRegisteredWebapps() { |
| 196 return mSharedPreferences.getStringSet( | 274 return mSharedPreferences.getStringSet( |
| 197 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); | 275 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); |
| 198 } | 276 } |
| 199 } | 277 } |
| OLD | NEW |