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

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: Rebase 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.PrefServiceBridge; 15 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
16 import org.chromium.chrome.browser.preferences.Preferences; 16 import org.chromium.chrome.browser.preferences.Preferences;
17 import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferen ces.DialogOption; 17 import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferen ces.DialogOption;
18 import org.chromium.chrome.browser.webapps.WebappDataStorage;
18 import org.chromium.chrome.browser.webapps.WebappRegistry; 19 import org.chromium.chrome.browser.webapps.WebappRegistry;
19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
20 import org.chromium.content.browser.test.util.Criteria; 21 import org.chromium.content.browser.test.util.Criteria;
21 import org.chromium.content.browser.test.util.CriteriaHelper; 22 import org.chromium.content.browser.test.util.CriteriaHelper;
22 23
23 import java.util.Arrays; 24 import java.util.Arrays;
24 import java.util.HashSet; 25 import java.util.HashSet;
25 import java.util.List; 26 import java.util.List;
26 import java.util.Set; 27 import java.util.Set;
27 28
(...skipping 12 matching lines...) Expand all
40 @Override 41 @Override
41 public void startMainActivity() throws InterruptedException { 42 public void startMainActivity() throws InterruptedException {
42 startMainActivityOnBlankPage(); 43 startMainActivityOnBlankPage();
43 } 44 }
44 45
45 /** 46 /**
46 * Tests that web apps are cleared when the "cookies and site data" option i s selected. 47 * Tests that web apps are cleared when the "cookies and site data" option i s selected.
47 */ 48 */
48 @MediumTest 49 @MediumTest
49 public void testClearingSiteDataClearsWebapps() throws Exception { 50 public void testClearingSiteDataClearsWebapps() throws Exception {
50 WebappRegistry.registerWebapp(getActivity(), "first"); 51 WebappRegistry.registerWebapp(getActivity(), "first", "https://www.googl e.com");
51 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() { 52 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
52 @Override 53 @Override
53 public void onWebappIdsRetrieved(Set<String> ids) { 54 public void onWebappIdsRetrieved(Set<String> ids) {
54 assertEquals(new HashSet<String>(Arrays.asList("first")), ids); 55 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
55 mCallbackCalled = true; 56 mCallbackCalled = true;
56 } 57 }
57 }); 58 });
58 CriteriaHelper.pollUiThread(new Criteria() { 59 CriteriaHelper.pollUiThread(new Criteria() {
59 @Override 60 @Override
60 public boolean isSatisfied() { 61 public boolean isSatisfied() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }); 97 });
97 CriteriaHelper.pollUiThread(new Criteria() { 98 CriteriaHelper.pollUiThread(new Criteria() {
98 @Override 99 @Override
99 public boolean isSatisfied() { 100 public boolean isSatisfied() {
100 return mCallbackCalled; 101 return mCallbackCalled;
101 } 102 }
102 }); 103 });
103 } 104 }
104 105
105 /** 106 /**
107 * Tests that web app scopes and last launch times are cleared when the "his tory" option is
108 * selected. However, the web app is not removed from the registry.
109 */
110 @MediumTest
111 public void testClearingHistoryClearsWebappScopesAndLaunchTimes() throws Exc eption {
112 WebappRegistry.registerWebapp(getActivity(), "first", "https://www.googl e.com");
113 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
114 @Override
115 public void onWebappIdsRetrieved(Set<String> ids) {
116 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
117 mCallbackCalled = true;
118 }
119 });
120 CriteriaHelper.pollUiThread(new Criteria() {
121 @Override
122 public boolean isSatisfied() {
123 return mCallbackCalled;
124 }
125 });
126 mCallbackCalled = false;
127
128 setDataTypesToClear(Arrays.asList(DialogOption.CLEAR_HISTORY));
129 final Preferences preferences =
130 startPreferences(ClearBrowsingDataPreferences.class.getName());
131
132 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
133 @Override
134 public void run() {
135 ClearBrowsingDataPreferences fragment =
136 (ClearBrowsingDataPreferences) preferences.getFragmentFo rTest();
137 PreferenceScreen screen = fragment.getPreferenceScreen();
138 ButtonPreference clearButton = (ButtonPreference) screen.findPre ference(
139 ClearBrowsingDataPreferences.PREF_CLEAR_BUTTON);
140 clearButton.getOnPreferenceClickListener().onPreferenceClick(cle arButton);
141 }
142 });
143 CriteriaHelper.pollUiThread(new Criteria() {
144 @Override
145 public boolean isSatisfied() {
146 ClearBrowsingDataPreferences fragment =
147 (ClearBrowsingDataPreferences) preferences.getFragmentFo rTest();
148 return fragment.getProgressDialog() == null;
149 }
150 });
151
152 // The web app should still exist in the registry.
153 WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry. FetchCallback() {
154 @Override
155 public void onWebappIdsRetrieved(Set<String> ids) {
156 assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
157 mCallbackCalled = true;
158 }
159 });
160 CriteriaHelper.pollUiThread(new Criteria() {
161 @Override
162 public boolean isSatisfied() {
163 return mCallbackCalled;
164 }
165 });
166 mCallbackCalled = false;
167
168 // Scope should be empty.
169 WebappDataStorage.getScope(getActivity(), "first",
170 new WebappDataStorage.FetchCallback<String>() {
171 @Override
172 public void onDataRetrieved(String readObject) {
173 assertEquals(readObject, "");
174 mCallbackCalled = true;
175 }
176 }
177 );
178 CriteriaHelper.pollUiThread(new Criteria() {
179 @Override
180 public boolean isSatisfied() {
181 return mCallbackCalled;
182 }
183 });
184 mCallbackCalled = false;
185
186 // The last used time should be 0.
187 WebappDataStorage.getLastUsedTime(getActivity(), "first",
188 new WebappDataStorage.FetchCallback<Long>() {
189 @Override
190 public void onDataRetrieved(Long readObject) {
191 long lastUsed = readObject;
192 assertEquals(lastUsed, 0);
193 mCallbackCalled = true;
194 }
195 }
196 );
197 CriteriaHelper.pollUiThread(new Criteria() {
198 @Override
199 public boolean isSatisfied() {
200 return mCallbackCalled;
201 }
202 });
203 }
204
205 /**
106 * Tests that a fragment with all options preselected indeed has all checkbo xes checked 206 * Tests that a fragment with all options preselected indeed has all checkbo xes checked
107 * on startup, and that deletion with all checkboxes checked completes succe ssfully. 207 * on startup, and that deletion with all checkboxes checked completes succe ssfully.
108 */ 208 */
109 @MediumTest 209 @MediumTest
110 public void testClearingEverything() throws Exception { 210 public void testClearingEverything() throws Exception {
111 setDataTypesToClear(Arrays.asList(DialogOption.values())); 211 setDataTypesToClear(Arrays.asList(DialogOption.values()));
112 212
113 final Preferences preferences = 213 final Preferences preferences =
114 startPreferences(ClearBrowsingDataPreferences.class.getName()); 214 startPreferences(ClearBrowsingDataPreferences.class.getName());
115 215
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 public void run() { 252 public void run() {
153 for (DialogOption option : DialogOption.values()) { 253 for (DialogOption option : DialogOption.values()) {
154 boolean enabled = typesToClear.contains(option); 254 boolean enabled = typesToClear.contains(option);
155 PrefServiceBridge.getInstance().setBrowsingDataDeletionPrefe rence( 255 PrefServiceBridge.getInstance().setBrowsingDataDeletionPrefe rence(
156 option.getDataType(), enabled); 256 option.getDataType(), enabled);
157 } 257 }
158 } 258 }
159 }); 259 });
160 } 260 }
161 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698