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

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

Issue 2928993004: Revert of [Android Refactor] Merge WebappDataStorage#LAST_USED_UNSET and LAST_USED_INVALID (Closed)
Patch Set: 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
21 import org.robolectric.RuntimeEnvironment; 22 import org.robolectric.RuntimeEnvironment;
22 import org.robolectric.annotation.Config; 23 import org.robolectric.annotation.Config;
23 import org.robolectric.shadows.ShadowLooper; 24 import org.robolectric.shadows.ShadowLooper;
24 25
25 import org.chromium.base.ContextUtils; 26 import org.chromium.base.ContextUtils;
26 import org.chromium.base.test.util.Feature; 27 import org.chromium.base.test.util.Feature;
27 import org.chromium.blink_public.platform.WebDisplayMode; 28 import org.chromium.blink_public.platform.WebDisplayMode;
28 import org.chromium.chrome.browser.ShortcutHelper; 29 import org.chromium.chrome.browser.ShortcutHelper;
29 import org.chromium.chrome.browser.webapps.WebappDataStorage.Clock; 30 import org.chromium.chrome.browser.webapps.WebappDataStorage.Clock;
30 import org.chromium.testing.local.BackgroundShadowAsyncTask; 31 import org.chromium.testing.local.BackgroundShadowAsyncTask;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 WebappDataStorage.setClockForTests(clock); 187 WebappDataStorage.setClockForTests(clock);
187 188
188 // Opening a data storage doesn't count as a launch. 189 // Opening a data storage doesn't count as a launch.
189 WebappDataStorage storage = WebappDataStorage.open("test"); 190 WebappDataStorage storage = WebappDataStorage.open("test");
190 assertTrue(!storage.wasLaunchedRecently()); 191 assertTrue(!storage.wasLaunchedRecently());
191 192
192 // When the last used time is updated, then it is a launch. 193 // When the last used time is updated, then it is a launch.
193 storage.updateLastUsedTime(); 194 storage.updateLastUsedTime();
194 assertTrue(storage.wasLaunchedRecently()); 195 assertTrue(storage.wasLaunchedRecently());
195 196
196 long lastUsedTime = mSharedPreferences.getLong( 197 long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAS T_USED,
197 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.TIMESTAMP_INV ALID); 198 WebappDataStorage.LAST_USED_INVALID);
198 199
199 assertTrue(lastUsedTime != WebappDataStorage.TIMESTAMP_INVALID); 200 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_UNSET);
201 assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_INVALID);
200 202
201 // Move the last used time one day in the past. 203 // Move the last used time one day in the past.
202 mSharedPreferences.edit() 204 mSharedPreferences.edit()
203 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(1L)) 205 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(1L))
204 .apply(); 206 .apply();
205 assertTrue(storage.wasLaunchedRecently()); 207 assertTrue(storage.wasLaunchedRecently());
206 208
207 // Move the last used time three days in the past. 209 // Move the last used time three days in the past.
208 mSharedPreferences.edit() 210 mSharedPreferences.edit()
209 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(3L)) 211 .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUni t.DAYS.toMillis(3L))
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (actual.getPixel(i, j) != 0) return false; 419 if (actual.getPixel(i, j) != 0) return false;
418 } 420 }
419 } 421 }
420 return true; 422 return true;
421 } 423 }
422 424
423 private static Bitmap createBitmap() { 425 private static Bitmap createBitmap() {
424 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); 426 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
425 } 427 }
426 } 428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698