OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 webapp 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 webapp should still exist in the registry. | |
gone
2016/03/08 23:03:52
web app?
dominickn
2016/03/09 08:18:32
Done.
| |
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", | |
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
| |
166 new WebappDataStorage.FetchCallback<String>() { | |
167 @Override | |
168 public void onDataRetrieved(String readObject) { | |
169 assertEquals(readObject, ""); | |
170 mCallbackCalled = true; | |
171 } | |
172 }); | |
173 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | |
174 @Override | |
175 public boolean isSatisfied() { | |
176 return mCallbackCalled; | |
177 } | |
178 }); | |
179 mCallbackCalled = false; | |
180 | |
181 // The last used time should be 0. | |
182 WebappDataStorage.getLastUsedTime(getActivity(), "first", | |
183 new WebappDataStorage.FetchCallback<Long>() { | |
184 @Override | |
185 public void onDataRetrieved(Long readObject) { | |
186 long lastUsed = readObject; | |
187 assertEquals(lastUsed, 0); | |
188 mCallbackCalled = true; | |
189 } | |
190 }); | |
191 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | |
192 @Override | |
193 public boolean isSatisfied() { | |
194 return mCallbackCalled; | |
195 } | |
196 }); | |
197 } | |
198 | |
199 /** | |
103 * Tests that a fragment with all options preselected indeed has all checkbo xes checked | 200 * 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. | 201 * on startup, and that deletion with all checkboxes checked completes succe ssfully. |
105 */ | 202 */ |
106 @MediumTest | 203 @MediumTest |
107 public void testClearingEverything() throws Exception { | 204 public void testClearingEverything() throws Exception { |
108 final Preferences preferences = | 205 final Preferences preferences = |
109 startPreferences(ClearEverythingBrowsingDataPreferences.class.ge tName()); | 206 startPreferences(ClearEverythingBrowsingDataPreferences.class.ge tName()); |
110 | 207 |
111 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 208 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
112 @Override | 209 @Override |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of( | 246 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of( |
150 ClearBrowsingDataPreferences.DialogOption.CLEAR_COOKIES_AND_SITE _DATA); | 247 ClearBrowsingDataPreferences.DialogOption.CLEAR_COOKIES_AND_SITE _DATA); |
151 | 248 |
152 @Override | 249 @Override |
153 protected boolean isOptionSelectedByDefault(DialogOption option) { | 250 protected boolean isOptionSelectedByDefault(DialogOption option) { |
154 return DEFAULT_OPTIONS.contains(option); | 251 return DEFAULT_OPTIONS.contains(option); |
155 } | 252 } |
156 } | 253 } |
157 | 254 |
158 /** | 255 /** |
256 * A testing version of ClearBrowsingDataPreferences that preselects the his tory option. | |
257 * Must be public, as ChromeActivityTestCaseBase.startPreferences references it by name. | |
258 */ | |
259 public static class HistoryClearBrowsingDataPreferences extends ClearBrowsin gDataPreferences { | |
260 private static final EnumSet<DialogOption> DEFAULT_OPTIONS = EnumSet.of( | |
261 ClearBrowsingDataPreferences.DialogOption.CLEAR_HISTORY); | |
262 | |
263 @Override | |
264 protected boolean isOptionSelectedByDefault(DialogOption option) { | |
265 return DEFAULT_OPTIONS.contains(option); | |
266 } | |
267 } | |
268 | |
269 /** | |
159 * A testing version of ClearBrowsingDataPreferences that includes all possi ble options, | 270 * A testing version of ClearBrowsingDataPreferences that includes all possi ble options, |
160 * and preselects all of them. Must be public, as ChromeActivityTestCaseBase .startPreferences | 271 * and preselects all of them. Must be public, as ChromeActivityTestCaseBase .startPreferences |
161 * references it by name. | 272 * references it by name. |
162 */ | 273 */ |
163 public static class ClearEverythingBrowsingDataPreferences | 274 public static class ClearEverythingBrowsingDataPreferences |
164 extends ClearBrowsingDataPreferences { | 275 extends ClearBrowsingDataPreferences { |
165 @Override | 276 @Override |
166 protected void onOptionSelected() { | 277 protected void onOptionSelected() { |
167 // All options should be selected. | 278 // All options should be selected. |
168 EnumSet<DialogOption> options = getSelectedOptions(); | 279 EnumSet<DialogOption> options = getSelectedOptions(); |
169 assertEquals(EnumSet.allOf(DialogOption.class), options); | 280 assertEquals(EnumSet.allOf(DialogOption.class), options); |
170 | 281 |
171 // Bookmarks currently must be handled on the Java side, and not pas sed to C++. | 282 // Bookmarks currently must be handled on the Java side, and not pas sed to C++. |
172 options.remove(DialogOption.CLEAR_BOOKMARKS_DATA); | 283 options.remove(DialogOption.CLEAR_BOOKMARKS_DATA); |
173 clearBrowsingData(options); | 284 clearBrowsingData(options); |
174 } | 285 } |
175 | 286 |
176 @Override | 287 @Override |
177 protected DialogOption[] getDialogOptions() { | 288 protected DialogOption[] getDialogOptions() { |
178 return DialogOption.values(); | 289 return DialogOption.values(); |
179 } | 290 } |
180 | 291 |
181 @Override | 292 @Override |
182 protected boolean isOptionSelectedByDefault(DialogOption option) { | 293 protected boolean isOptionSelectedByDefault(DialogOption option) { |
183 return true; | 294 return true; |
184 } | 295 } |
185 } | 296 } |
186 } | 297 } |
OLD | NEW |