Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java

Issue 2935853002: [Android Refactor] Reland: Merge WebappDataStorage#LAST_USED_UNSET and LAST_USED_INVALID (Closed)
Patch Set: Merge branch 'master' into reland Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.assertFalse; 8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertTrue; 9 import static org.junit.Assert.assertTrue;
10 10
11 import android.content.Context; 11 import android.content.Context;
12 import android.content.Intent; 12 import android.content.Intent;
13 import android.content.SharedPreferences; 13 import android.content.SharedPreferences;
14 import android.graphics.Bitmap; 14 import android.graphics.Bitmap;
15 import android.os.AsyncTask; 15 import android.os.AsyncTask;
16 16
17 import org.junit.After; 17 import org.junit.After;
18 import org.junit.Before; 18 import org.junit.Before;
19 import org.junit.Test; 19 import org.junit.Test;
20 import org.junit.runner.RunWith; 20 import org.junit.runner.RunWith;
21
22 import org.robolectric.RuntimeEnvironment; 21 import org.robolectric.RuntimeEnvironment;
23 import org.robolectric.annotation.Config; 22 import org.robolectric.annotation.Config;
24 import org.robolectric.shadows.ShadowLooper; 23 import org.robolectric.shadows.ShadowLooper;
25 24
26 import org.chromium.base.ContextUtils; 25 import org.chromium.base.ContextUtils;
27 import org.chromium.base.test.util.Feature; 26 import org.chromium.base.test.util.Feature;
28 import org.chromium.blink_public.platform.WebDisplayMode; 27 import org.chromium.blink_public.platform.WebDisplayMode;
29 import org.chromium.chrome.browser.ShortcutHelper; 28 import org.chromium.chrome.browser.ShortcutHelper;
30 import org.chromium.chrome.browser.webapps.WebappDataStorage.Clock; 29 import org.chromium.chrome.browser.webapps.WebappDataStorage.Clock;
31 import org.chromium.testing.local.BackgroundShadowAsyncTask; 30 import org.chromium.testing.local.BackgroundShadowAsyncTask;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 WebappDataStorage.setClockForTests(clock); 186 WebappDataStorage.setClockForTests(clock);
188 187
189 // Opening a data storage doesn't count as a launch. 188 // Opening a data storage doesn't count as a launch.
190 WebappDataStorage storage = WebappDataStorage.open("test"); 189 WebappDataStorage storage = WebappDataStorage.open("test");
191 assertTrue(!storage.wasLaunchedRecently()); 190 assertTrue(!storage.wasLaunchedRecently());
192 191
193 // When the last used time is updated, then it is a launch. 192 // When the last used time is updated, then it is a launch.
194 storage.updateLastUsedTime(); 193 storage.updateLastUsedTime();
195 assertTrue(storage.wasLaunchedRecently()); 194 assertTrue(storage.wasLaunchedRecently());
196 195
197 long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAS T_USED, 196 long lastUsedTime = mSharedPreferences.getLong(
198 WebappDataStorage.LAST_USED_INVALID); 197 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV ALID);
199 198
200 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_UNSET); 199 assertTrue(lastUsedTime != WebappDataStorage.TIMESTAMP_INVALID);
201 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_INVALID);
202 200
203 // Move the last used time one day in the past. 201 // Move the last used time one day in the past.
204 mSharedPreferences.edit() 202 mSharedPreferences.edit()
205 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(1L)) 203 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(1L))
206 .apply(); 204 .apply();
207 assertTrue(storage.wasLaunchedRecently()); 205 assertTrue(storage.wasLaunchedRecently());
208 206
209 // Move the last used time three days in the past. 207 // Move the last used time three days in the past.
210 mSharedPreferences.edit() 208 mSharedPreferences.edit()
211 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(3L)) 209 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(3L))
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 if (actual.getPixel(i, j) != 0) return false; 417 if (actual.getPixel(i, j) != 0) return false;
420 } 418 }
421 } 419 }
422 return true; 420 return true;
423 } 421 }
424 422
425 private static Bitmap createBitmap() { 423 private static Bitmap createBitmap() {
426 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); 424 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
427 } 425 }
428 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698