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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/BrowsingDataBridgeTest.java

Issue 2956283002: Expose Add/RemoveActionCallback to java (Closed)
Patch Set: Use assert instead of an exception Created 3 years, 5 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
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.preferences.privacy;
6
7 import static org.junit.Assert.assertThat;
8
9 import android.support.test.filters.SmallTest;
10
11 import org.hamcrest.Matchers;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.util.CallbackHelper;
20 import org.chromium.base.test.util.CommandLineFlags;
21 import org.chromium.base.test.util.UserActionTester;
22 import org.chromium.chrome.browser.ChromeActivity;
23 import org.chromium.chrome.browser.ChromeSwitches;
24 import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
25 import org.chromium.chrome.browser.browsing_data.TimePeriod;
26 import org.chromium.chrome.test.ChromeActivityTestRule;
27 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
28
29 /**
30 * Integration tests for ClearBrowsingDataPreferences.
31 */
32 @RunWith(ChromeJUnit4ClassRunner.class)
33 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
34 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
35 public class BrowsingDataBridgeTest {
36 @Rule
37 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
38 new ChromeActivityTestRule<>(ChromeActivity.class);
39
40 private CallbackHelper mCallbackHelper;
41 private BrowsingDataBridge.OnClearBrowsingDataListener mListener;
42 private UserActionTester mActionTester;
43
44 @Before
45 public void setUp() throws Exception {
46 mCallbackHelper = new CallbackHelper();
47 mListener = new BrowsingDataBridge.OnClearBrowsingDataListener() {
48 @Override
49 public void onBrowsingDataCleared() {
50 mCallbackHelper.notifyCalled();
51 }
52 };
53 mActivityTestRule.startMainActivityOnBlankPage();
54 mActionTester = new UserActionTester();
55 }
56
57 @After
58 public void tearDown() throws Exception {
59 mActionTester.tearDown();
60 }
61
62 /**
63 * Test no clear browsing data calls.
64 */
65 @Test
66 @SmallTest
67 public void testNoCalls() throws Exception {
68 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
69 @Override
70 public void run() {
71 BrowsingDataBridge.getInstance().clearBrowsingData(
72 mListener, new int[] {}, TimePeriod.ALL_TIME);
73 }
74 });
75 mCallbackHelper.waitForCallback(0);
76 assertThat(mActionTester.toString(), mActionTester.getActions(),
77 Matchers.contains("ClearBrowsingData_Everything"));
78 }
79
80 /**
81 * Test cookies deletion.
82 */
83 @Test
84 @SmallTest
85 public void testCookiesDeleted() throws Exception {
86 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
87 @Override
88 public void run() {
89 BrowsingDataBridge.getInstance().clearBrowsingData(
90 mListener, new int[] {BrowsingDataType.COOKIES}, TimePer iod.LAST_HOUR);
91 }
92 });
93 mCallbackHelper.waitForCallback(0);
94 assertThat(mActionTester.toString(), mActionTester.getActions(),
95 Matchers.containsInAnyOrder("ClearBrowsingData_LastHour",
96 "ClearBrowsingData_MaskContainsUnprotectedWeb",
97 "ClearBrowsingData_ChannelIDs", "ClearBrowsingData_Cooki es"));
98 }
99
100 /**
101 * Test history deletion.
102 */
103 @Test
104 @SmallTest
105 public void testHistoryDeleted() throws Exception {
106 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
107 @Override
108 public void run() {
109 BrowsingDataBridge.getInstance().clearBrowsingData(
110 mListener, new int[] {BrowsingDataType.HISTORY}, TimePer iod.LAST_DAY);
111 }
112 });
113 mCallbackHelper.waitForCallback(0);
114 assertThat(mActionTester.toString(), mActionTester.getActions(),
115 Matchers.containsInAnyOrder("ClearBrowsingData_LastDay",
116 "ClearBrowsingData_MaskContainsUnprotectedWeb",
117 "ClearBrowsingData_History"));
118 }
119
120 /**
121 * Test deleting cache and content settings.
122 */
123 @Test
124 @SmallTest
125 public void testClearingSiteSettingsAndCache() throws Exception {
126 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
127 @Override
128 public void run() {
129 BrowsingDataBridge.getInstance().clearBrowsingData(mListener,
130 new int[] {
131 BrowsingDataType.CACHE, BrowsingDataType.SITE_SE TTINGS,
132 },
133 TimePeriod.FOUR_WEEKS);
134 }
135 });
136 mCallbackHelper.waitForCallback(0);
137 assertThat(mActionTester.toString(), mActionTester.getActions(),
138 Matchers.containsInAnyOrder("ClearBrowsingData_LastMonth",
139 "ClearBrowsingData_MaskContainsUnprotectedWeb", "ClearBr owsingData_Cache",
140 "ClearBrowsingData_ShaderCache", "ClearBrowsingData_Cont entSettings"));
141 }
142
143 /**
144 * Test deleting cache and content settings with important sites.
145 */
146 @Test
147 @SmallTest
148 public void testClearingSiteSettingsAndCacheWithImportantSites() throws Exce ption {
149 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
150 @Override
151 public void run() {
152 BrowsingDataBridge.getInstance().clearBrowsingDataExcludingDomai ns(mListener,
153 new int[] {
154 BrowsingDataType.CACHE, BrowsingDataType.SITE_SE TTINGS,
155 },
156 TimePeriod.FOUR_WEEKS, new String[] {"google.com"}, new int[] {1},
157 new String[0], new int[0]);
158 }
159 });
160 mCallbackHelper.waitForCallback(0);
161 assertThat(mActionTester.toString(), mActionTester.getActions(),
162 Matchers.containsInAnyOrder("ClearBrowsingData_LastMonth",
163 // ClearBrowsingData_MaskContainsUnprotectedWeb is logge d
164 // twice because important storage is deleted separately .
165 "ClearBrowsingData_MaskContainsUnprotectedWeb",
166 "ClearBrowsingData_MaskContainsUnprotectedWeb", "ClearBr owsingData_Cache",
167 "ClearBrowsingData_ShaderCache", "ClearBrowsingData_Cont entSettings"));
168 }
169
170 /**
171 * Test deleting all browsing data. (Except bookmarks, they are deleted in J ava code)
172 */
173 @Test
174 @SmallTest
175 public void testClearingAll() throws Exception {
176 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
177 @Override
178 public void run() {
179 BrowsingDataBridge.getInstance().clearBrowsingData(mListener,
180 new int[] {
181 BrowsingDataType.CACHE, BrowsingDataType.COOKIES ,
182 BrowsingDataType.FORM_DATA, BrowsingDataType.HIS TORY,
183 BrowsingDataType.PASSWORDS, BrowsingDataType.SIT E_SETTINGS,
184 },
185 TimePeriod.LAST_WEEK);
186 }
187 });
188 mCallbackHelper.waitForCallback(0);
189 assertThat(mActionTester.toString(), mActionTester.getActions(),
190 Matchers.containsInAnyOrder("ClearBrowsingData_LastWeek",
191 "ClearBrowsingData_MaskContainsUnprotectedWeb", "ClearBr owsingData_Cache",
192 "ClearBrowsingData_ShaderCache", "ClearBrowsingData_Cook ies",
193 "ClearBrowsingData_ChannelIDs", "ClearBrowsingData_Autof ill",
194 "ClearBrowsingData_History", "ClearBrowsingData_Password s",
195 "ClearBrowsingData_ContentSettings"));
196 }
197 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698