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

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

Issue 1749603002: Store URLs in WebappDataStorage, and purge them when history is cleared. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing reviewer comments. Add dependency patchset for unit test hanging Created 4 years, 9 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.assertTrue; 8 import static org.junit.Assert.assertTrue;
9 9
10 import android.content.Context; 10 import android.content.Context;
(...skipping 14 matching lines...) Expand all
25 * Tests the WebappDataStorage class by ensuring that it persists data to 25 * Tests the WebappDataStorage class by ensuring that it persists data to
26 * SharedPreferences as expected. 26 * SharedPreferences as expected.
27 */ 27 */
28 @RunWith(LocalRobolectricTestRunner.class) 28 @RunWith(LocalRobolectricTestRunner.class)
29 @Config(manifest = Config.NONE, shadows = {BackgroundShadowAsyncTask.class}) 29 @Config(manifest = Config.NONE, shadows = {BackgroundShadowAsyncTask.class})
30 public class WebappDataStorageTest { 30 public class WebappDataStorageTest {
31 31
32 private SharedPreferences mSharedPreferences; 32 private SharedPreferences mSharedPreferences;
33 private boolean mCallbackCalled; 33 private boolean mCallbackCalled;
34 34
35 private class FetchCallback<T> implements WebappDataStorage.FetchCallback<T> {
36 FetchCallback(T expected) {
37 mExpected = expected;
38 }
39
40 @Override
41 public void onDataRetrieved(T readObject) {
42 mCallbackCalled = true;
43 assertEquals(mExpected, readObject);
44 }
45
46 T mExpected;
gone 2016/03/10 23:27:22 Put this field up at the top.
dominickn 2016/03/11 05:14:43 Done.
47 }
48
35 @Before 49 @Before
36 public void setUp() throws Exception { 50 public void setUp() throws Exception {
37 mSharedPreferences = Robolectric.application 51 mSharedPreferences = Robolectric.application
38 .getSharedPreferences("webapp_test", Context.MODE_PRIVATE); 52 .getSharedPreferences("webapp_test", Context.MODE_PRIVATE);
39 53
40 // Set the last_used as if the web app had been registered by WebappRegi stry. 54 // Set the last_used as if the web app had been registered by WebappRegi stry.
41 mSharedPreferences.edit().putLong("last_used", 0).commit(); 55 mSharedPreferences.edit().putLong("last_used", 0).commit();
42 56
43 mCallbackCalled = false; 57 mCallbackCalled = false;
44 } 58 }
45 59
46 @Test 60 @Test
47 @Feature({"Webapp"}) 61 @Feature({"Webapp"})
48 public void testBackwardCompat() { 62 public void testBackwardCompat() {
49 assertEquals("webapp_", WebappDataStorage.SHARED_PREFS_FILE_PREFIX); 63 assertEquals("webapp_", WebappDataStorage.SHARED_PREFS_FILE_PREFIX);
50 assertEquals("splash_icon", WebappDataStorage.KEY_SPLASH_ICON); 64 assertEquals("splash_icon", WebappDataStorage.KEY_SPLASH_ICON);
51 assertEquals("last_used", WebappDataStorage.KEY_LAST_USED); 65 assertEquals("last_used", WebappDataStorage.KEY_LAST_USED);
66 assertEquals("origin_url", WebappDataStorage.KEY_ORIGIN_URL);
52 } 67 }
53 68
54 @Test 69 @Test
55 @Feature({"Webapp"}) 70 @Feature({"Webapp"})
56 public void testLastUsedRetrieval() throws Exception { 71 public void testLastUsedRetrieval() throws Exception {
57 mSharedPreferences.edit() 72 mSharedPreferences.edit()
58 .putLong(WebappDataStorage.KEY_LAST_USED, 100L) 73 .putLong(WebappDataStorage.KEY_LAST_USED, 100L)
59 .commit(); 74 .commit();
60 75
61 WebappDataStorage.getLastUsedTime(Robolectric.application, "test", 76 WebappDataStorage.getLastUsedTime(Robolectric.application, "test",
62 new WebappDataStorage.FetchCallback<Long>() { 77 new FetchCallback<Long>(new Long(100L)));
63 @Override
64 public void onDataRetrieved(Long readObject) {
65 mCallbackCalled = true;
66 assertEquals(100L, (long) readObject);
67 }
68 });
69 BackgroundShadowAsyncTask.runBackgroundTasks(); 78 BackgroundShadowAsyncTask.runBackgroundTasks();
70 Robolectric.runUiThreadTasks(); 79 Robolectric.runUiThreadTasks();
71 80
72 assertTrue(mCallbackCalled); 81 assertTrue(mCallbackCalled);
73 } 82 }
74 83
75 @Test 84 @Test
76 @Feature({"Webapp"}) 85 @Feature({"Webapp"})
77 public void testOpenUpdatesLastUsed() throws Exception { 86 public void testOpenUpdatesLastUsed() throws Exception {
78 long before = System.currentTimeMillis(); 87 long before = System.currentTimeMillis();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 for (int j = 0; j < actual.getHeight(); j++) { 145 for (int j = 0; j < actual.getHeight(); j++) {
137 if (actual.getPixel(i, j) != 0) return false; 146 if (actual.getPixel(i, j) != 0) return false;
138 } 147 }
139 } 148 }
140 return true; 149 return true;
141 } 150 }
142 151
143 private static Bitmap createBitmap() { 152 private static Bitmap createBitmap() {
144 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444); 153 return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
145 } 154 }
146 } 155
156 @Test
157 @Feature({"Webapp"})
158 public void testOriginUrlRetrieval() throws Exception {
159 final String origin = "http://drive.google.com";
160 mSharedPreferences.edit()
161 .putString(WebappDataStorage.KEY_ORIGIN_URL, origin)
162 .commit();
163
164 WebappDataStorage.getOriginUrl(Robolectric.application, "test",
165 new FetchCallback<String>(origin));
166 BackgroundShadowAsyncTask.runBackgroundTasks();
167 Robolectric.runUiThreadTasks();
168
169 assertTrue(mCallbackCalled);
170 }
171
172 @Test
173 @Feature({"Webapp"})
174 public void testOriginUrlUpdate() throws Exception {
175 final String origin = "http://maps.google.com";
176
177 WebappDataStorage.updateOriginUrl(Robolectric.application, "test", origi n);
178 BackgroundShadowAsyncTask.runBackgroundTasks();
179 Robolectric.runUiThreadTasks();
180
181 assertEquals(origin, mSharedPreferences.getString(WebappDataStorage.KEY_ ORIGIN_URL, null));
182 }
183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698