| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 static org.hamcrest.Matchers.containsString; | 7 import static org.hamcrest.Matchers.containsString; |
| 8 import static org.hamcrest.Matchers.not; | 8 import static org.hamcrest.Matchers.not; |
| 9 import static org.junit.Assert.assertThat; | 9 import static org.junit.Assert.assertThat; |
| 10 | 10 |
| 11 import android.content.Context; | 11 import android.content.Context; |
| 12 import android.preference.CheckBoxPreference; | 12 import android.preference.CheckBoxPreference; |
| 13 import android.preference.PreferenceScreen; | 13 import android.preference.PreferenceScreen; |
| 14 import android.support.test.InstrumentationRegistry; | 14 import android.support.test.InstrumentationRegistry; |
| 15 import android.support.test.filters.SmallTest; | 15 import android.support.test.filters.SmallTest; |
| 16 | 16 |
| 17 import org.junit.After; | 17 import org.junit.After; |
| 18 import org.junit.Before; | 18 import org.junit.Before; |
| 19 import org.junit.Rule; | 19 import org.junit.Rule; |
| 20 import org.junit.Test; | 20 import org.junit.Test; |
| 21 import org.junit.runner.RunWith; | 21 import org.junit.runner.RunWith; |
| 22 | 22 |
| 23 import org.chromium.base.CollectionUtil; |
| 23 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
| 24 import org.chromium.base.test.util.CommandLineFlags; | 25 import org.chromium.base.test.util.CommandLineFlags; |
| 25 import org.chromium.chrome.browser.ChromeActivity; | 26 import org.chromium.chrome.browser.ChromeActivity; |
| 26 import org.chromium.chrome.browser.ChromeSwitches; | 27 import org.chromium.chrome.browser.ChromeSwitches; |
| 27 import org.chromium.chrome.browser.preferences.Preferences; | 28 import org.chromium.chrome.browser.preferences.Preferences; |
| 28 import org.chromium.chrome.browser.sync.ProfileSyncService; | 29 import org.chromium.chrome.browser.sync.ProfileSyncService; |
| 29 import org.chromium.chrome.test.ChromeActivityTestRule; | 30 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 30 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 31 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 31 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; | 32 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; |
| 32 import org.chromium.components.sync.AndroidSyncSettings; | 33 import org.chromium.components.sync.AndroidSyncSettings; |
| 34 import org.chromium.components.sync.ModelType; |
| 33 import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate; | 35 import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate; |
| 34 | 36 |
| 37 import java.util.HashSet; |
| 38 import java.util.Set; |
| 39 |
| 35 /** | 40 /** |
| 36 * Integration tests for ClearBrowsingDataPreferencesBasic. | 41 * Integration tests for ClearBrowsingDataPreferencesBasic. |
| 37 */ | 42 */ |
| 38 @RunWith(ChromeJUnit4ClassRunner.class) | 43 @RunWith(ChromeJUnit4ClassRunner.class) |
| 39 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, | 44 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 40 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) | 45 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 41 public class ClearBrowsingDataPreferencesBasicTest { | 46 public class ClearBrowsingDataPreferencesBasicTest { |
| 42 @Rule | 47 @Rule |
| 43 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = | 48 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 44 new ChromeActivityTestRule<>(ChromeActivity.class); | 49 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 45 | 50 |
| 46 private static final String GOOGLE_ACCOUNT = "Google Account"; | 51 private static final String GOOGLE_ACCOUNT = "Google Account"; |
| 47 private static final String OTHER_ACTIVITY = "other activity"; | 52 private static final String OTHER_ACTIVITY = "other forms of browsing histor
y"; |
| 48 private static final String SIGNED_IN_DEVICES = "signed-in devices"; | 53 private static final String SIGNED_IN_DEVICES = "signed-in devices"; |
| 49 | 54 |
| 50 @Before | 55 @Before |
| 51 public void setUp() throws InterruptedException { | 56 public void setUp() throws InterruptedException { |
| 52 SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentati
on()); | 57 SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentati
on()); |
| 53 mActivityTestRule.startMainActivityOnBlankPage(); | 58 mActivityTestRule.startMainActivityOnBlankPage(); |
| 54 } | 59 } |
| 55 | 60 |
| 56 @After | 61 @After |
| 57 public void tearDown() throws Exception { | 62 public void tearDown() throws Exception { |
| 58 ProfileSyncService.overrideForTests(null); | 63 ProfileSyncService.overrideForTests(null); |
| 59 } | 64 } |
| 60 | 65 |
| 61 private static class StubProfileSyncService extends ProfileSyncService { | 66 private static class StubProfileSyncService extends ProfileSyncService { |
| 62 StubProfileSyncService() { | 67 private final boolean mSyncable; |
| 68 |
| 69 StubProfileSyncService(boolean syncable) { |
| 63 super(); | 70 super(); |
| 71 mSyncable = syncable; |
| 72 } |
| 73 |
| 74 public Set<Integer> getActiveDataTypes() { |
| 75 if (mSyncable) { |
| 76 return CollectionUtil.newHashSet(ModelType.HISTORY_DELETE_DIRECT
IVES); |
| 77 } else { |
| 78 return new HashSet<Integer>(); |
| 79 } |
| 64 } | 80 } |
| 65 } | 81 } |
| 66 | 82 |
| 67 private void setSyncable(boolean syncable) { | 83 private void setSyncable(final boolean syncable) { |
| 68 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); | 84 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); |
| 69 MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDe
legate(); | 85 MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDe
legate(); |
| 70 delegate.setMasterSyncAutomatically(syncable); | 86 delegate.setMasterSyncAutomatically(syncable); |
| 71 AndroidSyncSettings.overrideForTests(context, delegate); | 87 AndroidSyncSettings.overrideForTests(context, delegate); |
| 72 if (syncable) { | 88 if (syncable) { |
| 73 AndroidSyncSettings.enableChromeSync(context); | 89 AndroidSyncSettings.enableChromeSync(context); |
| 74 } else { | 90 } else { |
| 75 AndroidSyncSettings.disableChromeSync(context); | 91 AndroidSyncSettings.disableChromeSync(context); |
| 76 } | 92 } |
| 77 | 93 |
| 78 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 94 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 79 @Override | 95 @Override |
| 80 public void run() { | 96 public void run() { |
| 81 ProfileSyncService.overrideForTests(new StubProfileSyncService()
); | 97 ProfileSyncService.overrideForTests(new StubProfileSyncService(s
yncable)); |
| 82 } | 98 } |
| 83 }); | 99 }); |
| 84 } | 100 } |
| 85 | 101 |
| 86 private String getCheckboxSummary(PreferenceScreen screen, String preference
) { | 102 private String getCheckboxSummary(PreferenceScreen screen, String preference
) { |
| 87 CheckBoxPreference checkbox = (CheckBoxPreference) screen.findPreference
(preference); | 103 CheckBoxPreference checkbox = (CheckBoxPreference) screen.findPreference
(preference); |
| 88 return new StringBuilder(checkbox.getSummary()).toString(); | 104 return new StringBuilder(checkbox.getSummary()).toString(); |
| 89 } | 105 } |
| 90 | 106 |
| 91 /** | 107 /** |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 String historySummary = | 191 String historySummary = |
| 176 getCheckboxSummary(screen, ClearBrowsingDataPreferencesB
asic.PREF_HISTORY); | 192 getCheckboxSummary(screen, ClearBrowsingDataPreferencesB
asic.PREF_HISTORY); |
| 177 | 193 |
| 178 assertThat(cookiesSummary, containsString(GOOGLE_ACCOUNT)); | 194 assertThat(cookiesSummary, containsString(GOOGLE_ACCOUNT)); |
| 179 assertThat(historySummary, containsString(OTHER_ACTIVITY)); | 195 assertThat(historySummary, containsString(OTHER_ACTIVITY)); |
| 180 assertThat(historySummary, containsString(SIGNED_IN_DEVICES)); | 196 assertThat(historySummary, containsString(SIGNED_IN_DEVICES)); |
| 181 } | 197 } |
| 182 }); | 198 }); |
| 183 } | 199 } |
| 184 } | 200 } |
| OLD | NEW |