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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 assertTrue(mCallbackCalled); | 182 assertTrue(mCallbackCalled); |
183 } | 183 } |
184 | 184 |
185 @Test | 185 @Test |
186 @Feature({"Webapp"}) | 186 @Feature({"Webapp"}) |
187 public void testWasLaunchedRecently() throws Exception { | 187 public void testWasLaunchedRecently() throws Exception { |
188 final TestClock clock = new TestClock(System.currentTimeMillis()); | 188 final TestClock clock = new TestClock(System.currentTimeMillis()); |
189 WebappDataStorage.setClockForTests(clock); | 189 WebappDataStorage.setClockForTests(clock); |
190 | 190 |
| 191 // Opening a data storage doesn't count as a launch. |
191 WebappDataStorage storage = WebappDataStorage.open(Robolectric.applicati
on, "test"); | 192 WebappDataStorage storage = WebappDataStorage.open(Robolectric.applicati
on, "test"); |
| 193 BackgroundShadowAsyncTask.runBackgroundTasks(); |
| 194 Robolectric.runUiThreadTasks(); |
| 195 assertTrue(!storage.wasLaunchedRecently()); |
| 196 |
| 197 // When the last used time is updated, then it is a launch. |
192 storage.updateLastUsedTime(); | 198 storage.updateLastUsedTime(); |
193 BackgroundShadowAsyncTask.runBackgroundTasks(); | 199 BackgroundShadowAsyncTask.runBackgroundTasks(); |
194 Robolectric.runUiThreadTasks(); | 200 Robolectric.runUiThreadTasks(); |
195 assertTrue(!storage.wasLaunchedRecently()); | 201 assertTrue(storage.wasLaunchedRecently()); |
196 | 202 |
197 long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAS
T_USED, | 203 long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAS
T_USED, |
198 WebappDataStorage.LAST_USED_INVALID); | 204 WebappDataStorage.LAST_USED_INVALID); |
199 | 205 |
200 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_UNSET); | 206 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_UNSET); |
201 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_INVALID); | 207 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_INVALID); |
202 | 208 |
203 // Mark as launched, check launched recently. | |
204 mSharedPreferences.edit() | |
205 .putBoolean(WebappDataStorage.KEY_LAUNCHED, true) | |
206 .commit(); | |
207 assertTrue(storage.wasLaunchedRecently()); | |
208 | |
209 // Move the last used time one day in the past. | 209 // Move the last used time one day in the past. |
210 mSharedPreferences.edit() | 210 mSharedPreferences.edit() |
211 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(1L)) | 211 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(1L)) |
212 .commit(); | 212 .commit(); |
213 assertTrue(storage.wasLaunchedRecently()); | 213 assertTrue(storage.wasLaunchedRecently()); |
214 | 214 |
215 // Move the last used time three days in the past. | 215 // Move the last used time three days in the past. |
216 mSharedPreferences.edit() | 216 mSharedPreferences.edit() |
217 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(3L)) | 217 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(3L)) |
218 .commit(); | 218 .commit(); |
219 assertTrue(storage.wasLaunchedRecently()); | 219 assertTrue(storage.wasLaunchedRecently()); |
220 | 220 |
221 // Move the last used time one week in the past. | 221 // Move the last used time one week in the past. |
222 mSharedPreferences.edit() | 222 mSharedPreferences.edit() |
223 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(7L)) | 223 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni
t.DAYS.toMillis(7L)) |
224 .commit(); | 224 .commit(); |
225 assertTrue(storage.wasLaunchedRecently()); | 225 assertTrue(storage.wasLaunchedRecently()); |
226 | 226 |
227 // Move the last used time just under ten days in the past. | 227 // Move the last used time just under ten days in the past. |
228 mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, | 228 mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, |
229 lastUsedTime - TimeUnit.DAYS.toMillis(10L) + 1).commit(); | 229 lastUsedTime - TimeUnit.DAYS.toMillis(10L) + 1).commit(); |
230 assertTrue(storage.wasLaunchedRecently()); | 230 assertTrue(storage.wasLaunchedRecently()); |
231 | 231 |
232 // Mark as not launched. | |
233 mSharedPreferences.edit() | |
234 .putBoolean(WebappDataStorage.KEY_LAUNCHED, false) | |
235 .commit(); | |
236 assertTrue(!storage.wasLaunchedRecently()); | |
237 | |
238 // Mark as launched. | |
239 mSharedPreferences.edit() | |
240 .putBoolean(WebappDataStorage.KEY_LAUNCHED, true) | |
241 .commit(); | |
242 assertTrue(storage.wasLaunchedRecently()); | |
243 | |
244 // Move the last used time to exactly ten days in the past. | 232 // Move the last used time to exactly ten days in the past. |
245 mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, | 233 mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, |
246 lastUsedTime - TimeUnit.DAYS.toMillis(10L)).commit(); | 234 lastUsedTime - TimeUnit.DAYS.toMillis(10L)).commit(); |
247 assertTrue(!storage.wasLaunchedRecently()); | 235 assertTrue(!storage.wasLaunchedRecently()); |
248 } | 236 } |
249 | 237 |
250 @Test | 238 @Test |
251 @Feature({"Webapp"}) | 239 @Feature({"Webapp"}) |
252 public void testIntentUpdate() throws Exception { | 240 public void testIntentUpdate() throws Exception { |
253 final String id = "id"; | 241 final String id = "id"; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 if (actual.getPixel(i, j) != 0) return false; | 339 if (actual.getPixel(i, j) != 0) return false; |
352 } | 340 } |
353 } | 341 } |
354 return true; | 342 return true; |
355 } | 343 } |
356 | 344 |
357 private static Bitmap createBitmap() { | 345 private static Bitmap createBitmap() { |
358 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444); | 346 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444); |
359 } | 347 } |
360 } | 348 } |
OLD | NEW |