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

Unified 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: Add @VisibleForTesting to address test failures Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.java
index a9b26f69d9e7d726a2e4c40fcacf460587d8a8a1..e943998d0b4fac97e4c0124b8f93941c833a463d 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesTest.java
@@ -13,6 +13,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.preferences.ButtonPreference;
import org.chromium.chrome.browser.preferences.Preferences;
+import org.chromium.chrome.browser.webapps.WebappDataStorage;
import org.chromium.chrome.browser.webapps.WebappRegistry;
import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.content.browser.test.util.Criteria;
@@ -45,7 +46,7 @@ public class ClearBrowsingDataPreferencesTest
*/
@MediumTest
public void testClearingSiteDataClearsWebapps() throws Exception {
- WebappRegistry.registerWebapp(getActivity(), "first");
+ WebappRegistry.registerWebapp(getActivity(), "first", "https://www.google.com");
WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry.FetchCallback() {
@Override
public void onWebappIdsRetrieved(Set<String> ids) {
@@ -100,6 +101,102 @@ public class ClearBrowsingDataPreferencesTest
}
/**
+ * Tests that web app URLs and last launch times are cleared when the "history" option is
+ * selected. However, the webapp is not removed from the registry.
+ */
+ @MediumTest
+ public void testClearingHistoryClearsWebappURLsAndLaunchTimes() throws Exception {
+ WebappRegistry.registerWebapp(getActivity(), "first", "https://www.google.com");
+ WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry.FetchCallback() {
+ @Override
+ public void onWebappIdsRetrieved(Set<String> ids) {
+ assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
+ mCallbackCalled = true;
+ }
+ });
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mCallbackCalled;
+ }
+ });
+ mCallbackCalled = false;
+
+ final Preferences preferences =
+ startPreferences(HistoryClearBrowsingDataPreferences.class.getName());
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ClearBrowsingDataPreferences fragment =
+ (ClearBrowsingDataPreferences) preferences.getFragmentForTest();
+ PreferenceScreen screen = fragment.getPreferenceScreen();
+ ButtonPreference clearButton = (ButtonPreference) screen.findPreference(
+ ClearBrowsingDataPreferences.PREF_CLEAR_BUTTON);
+ clearButton.getOnPreferenceClickListener().onPreferenceClick(clearButton);
+ }
+ });
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ ClearBrowsingDataPreferences fragment =
+ (ClearBrowsingDataPreferences) preferences.getFragmentForTest();
+ return fragment.getProgressDialog() == null;
+ }
+ });
+
+ // The webapp should still exist in the registry.
gone 2016/03/08 23:03:52 web app?
dominickn 2016/03/09 08:18:32 Done.
+ WebappRegistry.getRegisteredWebappIds(getActivity(), new WebappRegistry.FetchCallback() {
+ @Override
+ public void onWebappIdsRetrieved(Set<String> ids) {
+ assertEquals(new HashSet<String>(Arrays.asList("first")), ids);
+ mCallbackCalled = true;
+ }
+ });
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mCallbackCalled;
+ }
+ });
+ mCallbackCalled = false;
+
+ // URL should be empty.
+ WebappDataStorage.getOriginUrl(getActivity(), "first",
gone 2016/03/08 23:03:52 Indenting here seems like it's kind of all over th
dominickn 2016/03/09 08:18:32 Indenting Java I don't know how
gone 2016/03/10 23:27:21 I want to say it's kind of subjective in these cas
+ new WebappDataStorage.FetchCallback<String>() {
+ @Override
+ public void onDataRetrieved(String readObject) {
+ assertEquals(readObject, "");
+ mCallbackCalled = true;
+ }
+ });
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mCallbackCalled;
+ }
+ });
+ mCallbackCalled = false;
+
+ // The last used time should be 0.
+ WebappDataStorage.getLastUsedTime(getActivity(), "first",
+ new WebappDataStorage.FetchCallback<Long>() {
+ @Override
+ public void onDataRetrieved(Long readObject) {
+ long lastUsed = readObject;
+ assertEquals(lastUsed, 0);
+ mCallbackCalled = true;
+ }
+ });
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mCallbackCalled;
+ }
+ });
+ }
+
+ /**
* Tests that a fragment with all options preselected indeed has all checkboxes checked
* on startup, and that deletion with all checkboxes checked completes successfully.
*/
@@ -156,6 +253,20 @@ public class ClearBrowsingDataPreferencesTest
}
/**
+ * A testing version of ClearBrowsingDataPreferences that preselects the history option.
+ * Must be public, as ChromeActivityTestCaseBase.startPreferences references it by name.
+ */
+ public static class HistoryClearBrowsingDataPreferences extends ClearBrowsingDataPreferences {
+ private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of(
+ ClearBrowsingDataPreferences.DialogOption.CLEAR_HISTORY);
+
+ @Override
+ protected boolean isOptionSelectedByDefault(DialogOption option) {
+ return DEFAULT_OPTIONS.contains(option);
+ }
+ }
+
+ /**
* A testing version of ClearBrowsingDataPreferences that includes all possible options,
* and preselects all of them. Must be public, as ChromeActivityTestCaseBase.startPreferences
* references it by name.

Powered by Google App Engine
This is Rietveld 408576698