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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.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 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.preferences.privacy; 5 package org.chromium.chrome.browser.preferences.privacy;
6 6
7 import android.preference.CheckBoxPreference; 7 import android.preference.CheckBoxPreference;
8 import android.preference.Preference; 8 import android.preference.Preference;
9 import android.preference.PreferenceScreen; 9 import android.preference.PreferenceScreen;
10 import android.test.suitebuilder.annotation.MediumTest; 10 import android.test.suitebuilder.annotation.MediumTest;
11 11
12 import org.chromium.base.ThreadUtils; 12 import org.chromium.base.ThreadUtils;
13 import org.chromium.chrome.browser.ChromeActivity; 13 import org.chromium.chrome.browser.ChromeActivity;
14 import org.chromium.chrome.browser.preferences.ButtonPreference; 14 import org.chromium.chrome.browser.preferences.ButtonPreference;
15 import org.chromium.chrome.browser.preferences.Preferences; 15 import org.chromium.chrome.browser.preferences.Preferences;
16 import org.chromium.chrome.browser.webapps.WebappDataStorage;
16 import org.chromium.chrome.browser.webapps.WebappRegistry; 17 import org.chromium.chrome.browser.webapps.WebappRegistry;
17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 18 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
18 import org.chromium.content.browser.test.util.Criteria; 19 import org.chromium.content.browser.test.util.Criteria;
19 import org.chromium.content.browser.test.util.CriteriaHelper; 20 import org.chromium.content.browser.test.util.CriteriaHelper;
20 21
21 import java.util.Arrays; 22 import java.util.Arrays;
22 import java.util.EnumSet; 23 import java.util.EnumSet;
23 import java.util.HashSet; 24 import java.util.HashSet;
24 import java.util.Set; 25 import java.util.Set;
25 26
(...skipping 12 matching lines...) Expand all
38 @Override 39 @Override
39 public void startMainActivity() throws InterruptedException { 40 public void startMainActivity() throws InterruptedException {
40 startMainActivityOnBlankPage(); 41 startMainActivityOnBlankPage();
41 } 42 }
42 43
43 /** 44 /**
44 * Tests that web apps are cleared when the "cookies and site data" option i s selected. 45 * Tests that web apps are cleared when the "cookies and site data" option i s selected.
45 */ 46 */
46 @MediumTest 47 @MediumTest
47 public void testClearingSiteDataClearsWebapps() throws Exception { 48 public void testClearingSiteDataClearsWebapps() throws Exception {
48 WebappRegistry.registerWebapp(getActivity(), "first"); 49 WebappRegistry.registerWebapp(getActivity(), "first", "https://www.googl e.com");
49 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() { 50 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
50 @Override 51 @Override
51 public void onWebappIdsRetrieved(Set<String> ids) { 52 public void onWebappIdsRetrieved(Set<String> ids) {
52 assertEquals(new HashSet<String>(Arrays.asList("first")), ids); 53 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
53 mCallbackCalled = true; 54 mCallbackCalled = true;
54 } 55 }
55 }); 56 });
56 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { 57 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
57 @Override 58 @Override
58 public boolean isSatisfied() { 59 public boolean isSatisfied() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }); 94 });
94 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { 95 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
95 @Override 96 @Override
96 public boolean isSatisfied() { 97 public boolean isSatisfied() {
97 return mCallbackCalled; 98 return mCallbackCalled;
98 } 99 }
99 }); 100 });
100 } 101 }
101 102
102 /** 103 /**
104 * Tests that web app URLs and last launch times are cleared when the "histo ry" option is
105 * selected. However, the web app is not removed from the registry.
106 */
107 @MediumTest
108 public void testClearingHistoryClearsWebappURLsAndLaunchTimes() throws Excep tion {
109 WebappRegistry.registerWebapp(getActivity(), "first", "https://www.googl e.com");
110 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
111 @Override
112 public void onWebappIdsRetrieved(Set<String> ids) {
113 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
114 mCallbackCalled = true;
115 }
116 });
117 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
118 @Override
119 public boolean isSatisfied() {
120 return mCallbackCalled;
121 }
122 });
123 mCallbackCalled = false;
124
125 final Preferences preferences =
126 startPreferences(HistoryClearBrowsingDataPreferences.class.getNa me());
127
128 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
129 @Override
130 public void run() {
131 ClearBrowsingDataPreferences fragment =
132 (ClearBrowsingDataPreferences) preferences.getFragmentFo rTest();
133 PreferenceScreen screen = fragment.getPreferenceScreen();
134 ButtonPreference clearButton = (ButtonPreference) screen.findPre ference(
135 ClearBrowsingDataPreferences.PREF_CLEAR_BUTTON);
136 clearButton.getOnPreferenceClickListener().onPreferenceClick(cle arButton);
137 }
138 });
139 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
140 @Override
141 public boolean isSatisfied() {
142 ClearBrowsingDataPreferences fragment =
143 (ClearBrowsingDataPreferences) preferences.getFragmentFo rTest();
144 return fragment.getProgressDialog() == null;
145 }
146 });
147
148 // The web app should still exist in the registry.
149 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
150 @Override
151 public void onWebappIdsRetrieved(Set<String> ids) {
152 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
153 mCallbackCalled = true;
154 }
155 });
156 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
157 @Override
158 public boolean isSatisfied() {
159 return mCallbackCalled;
160 }
161 });
162 mCallbackCalled = false;
163
164 // URL should be empty.
165 WebappDataStorage.getOriginUrl(getActivity(), "first",
166 new WebappDataStorage.FetchCallback<String>() {
167 @Override
168 public void onDataRetrieved(String readObject) {
169 assertEquals(readObject, "");
170 mCallbackCalled = true;
171 }
172 }
173 );
174 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
175 @Override
176 public boolean isSatisfied() {
177 return mCallbackCalled;
178 }
179 });
180 mCallbackCalled = false;
181
182 // The last used time should be 0.
183 WebappDataStorage.getLastUsedTime(getActivity(), "first",
184 new WebappDataStorage.FetchCallback<Long>() {
185 @Override
186 public void onDataRetrieved(Long readObject) {
187 long lastUsed = readObject;
188 assertEquals(lastUsed, 0);
189 mCallbackCalled = true;
190 }
191 });
192 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
193 @Override
194 public boolean isSatisfied() {
195 return mCallbackCalled;
196 }
197 });
198 }
199
200 /**
103 * Tests that a fragment with all options preselected indeed has all checkbo xes checked 201 * Tests that a fragment with all options preselected indeed has all checkbo xes checked
104 * on startup, and that deletion with all checkboxes checked completes succe ssfully. 202 * on startup, and that deletion with all checkboxes checked completes succe ssfully.
105 */ 203 */
106 @MediumTest 204 @MediumTest
107 public void testClearingEverything() throws Exception { 205 public void testClearingEverything() throws Exception {
108 final Preferences preferences = 206 final Preferences preferences =
109 startPreferences(ClearEverythingBrowsingDataPreferences.class.ge tName()); 207 startPreferences(ClearEverythingBrowsingDataPreferences.class.ge tName());
110 208
111 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 209 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
112 @Override 210 @Override
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of( 247 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of(
150 ClearBrowsingDataPreferences.DialogOption.CLEAR_COOKIES_AND_SITE _DATA); 248 ClearBrowsingDataPreferences.DialogOption.CLEAR_COOKIES_AND_SITE _DATA);
151 249
152 @Override 250 @Override
153 protected boolean isOptionSelectedByDefault(DialogOption option) { 251 protected boolean isOptionSelectedByDefault(DialogOption option) {
154 return DEFAULT_OPTIONS.contains(option); 252 return DEFAULT_OPTIONS.contains(option);
155 } 253 }
156 } 254 }
157 255
158 /** 256 /**
257 * A testing version of ClearBrowsingDataPreferences that preselects the his tory option.
258 * Must be public, as ChromeActivityTestCaseBase.startPreferences references it by name.
259 */
260 public static class HistoryClearBrowsingDataPreferences extends ClearBrowsin gDataPreferences {
261 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of(
262 ClearBrowsingDataPreferences.DialogOption.CLEAR_HISTORY);
263
264 @Override
265 protected boolean isOptionSelectedByDefault(DialogOption option) {
266 return DEFAULT_OPTIONS.contains(option);
267 }
268 }
269
270 /**
159 * A testing version of ClearBrowsingDataPreferences that includes all possi ble options, 271 * A testing version of ClearBrowsingDataPreferences that includes all possi ble options,
160 * and preselects all of them. Must be public, as ChromeActivityTestCaseBase .startPreferences 272 * and preselects all of them. Must be public, as ChromeActivityTestCaseBase .startPreferences
161 * references it by name. 273 * references it by name.
162 */ 274 */
163 public static class ClearEverythingBrowsingDataPreferences 275 public static class ClearEverythingBrowsingDataPreferences
164 extends ClearBrowsingDataPreferences { 276 extends ClearBrowsingDataPreferences {
165 @Override 277 @Override
166 protected void onOptionSelected() { 278 protected void onOptionSelected() {
167 // All options should be selected. 279 // All options should be selected.
168 EnumSet<DialogOption> options = getSelectedOptions(); 280 EnumSet<DialogOption> options = getSelectedOptions();
169 assertEquals(EnumSet.allOf(DialogOption.class), options); 281 assertEquals(EnumSet.allOf(DialogOption.class), options);
170 282
171 // Bookmarks currently must be handled on the Java side, and not pas sed to C++. 283 // Bookmarks currently must be handled on the Java side, and not pas sed to C++.
172 options.remove(DialogOption.CLEAR_BOOKMARKS_DATA); 284 options.remove(DialogOption.CLEAR_BOOKMARKS_DATA);
173 clearBrowsingData(options); 285 clearBrowsingData(options);
174 } 286 }
175 287
176 @Override 288 @Override
177 protected DialogOption[] getDialogOptions() { 289 protected DialogOption[] getDialogOptions() {
178 return DialogOption.values(); 290 return DialogOption.values();
179 } 291 }
180 292
181 @Override 293 @Override
182 protected boolean isOptionSelectedByDefault(DialogOption option) { 294 protected boolean isOptionSelectedByDefault(DialogOption option) {
183 return true; 295 return true;
184 } 296 }
185 } 297 }
186 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698