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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesBasicTest.java

Issue 2730703003: Change CBD layout and texts (Closed)
Patch Set: try fix tests Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesBasicTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesBasicTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesBasicTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d3e793b1055a16e1b51be9a9128d5a98bb97b286
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferencesBasicTest.java
@@ -0,0 +1,181 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.preferences.privacy;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+
+import android.content.Context;
+import android.preference.CheckBoxPreference;
+import android.preference.PreferenceScreen;
+import android.support.test.filters.SmallTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.RetryOnFailure;
+import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.preferences.Preferences;
+import org.chromium.chrome.browser.sync.ProfileSyncService;
+import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
+import org.chromium.components.sync.AndroidSyncSettings;
+import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate;
+import org.chromium.net.test.EmbeddedTestServer;
+
+/**
+ * Integration tests for ClearBrowsingDataPreferencesBasic.
+ */
+@RetryOnFailure
+public class ClearBrowsingDataPreferencesBasicTest
+ extends ChromeActivityTestCaseBase<ChromeActivity> {
+ private static final String GOOGLE_ACCOUNT = "Google Account";
+ private static final String OTHER_ACTIVITY = "other activity";
+ private static final String SIGNED_IN_DEVICES = "signed-in devices";
+
+ private EmbeddedTestServer mTestServer;
+
+ public ClearBrowsingDataPreferencesBasicTest() {
+ super(ChromeActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ SigninTestUtil.setUpAuthForTest(getInstrumentation());
+ startMainActivityOnBlankPage();
+ }
+
+ private static class StubProfileSyncService extends ProfileSyncService {
+ StubProfileSyncService() {
+ super();
+ }
+ }
+
+ private void setSyncable(boolean syncable) {
+ Context context = getInstrumentation().getTargetContext();
+ MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate();
+ delegate.setMasterSyncAutomatically(syncable);
+ AndroidSyncSettings.overrideForTests(context, delegate);
+ if (syncable) {
+ AndroidSyncSettings.enableChromeSync(context);
+ } else {
+ AndroidSyncSettings.disableChromeSync(context);
+ }
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ProfileSyncService.overrideForTests(new StubProfileSyncService());
+ }
+ });
+ }
+
+ private String getCheckboxSummary(PreferenceScreen screen, String preference) {
+ CheckBoxPreference checkbox = (CheckBoxPreference) screen.findPreference(preference);
+ return new StringBuilder(checkbox.getSummary()).toString();
+ }
+
+ /**
+ * Tests that for users who are not signed in, only the general footnote is shown.
+ */
+ @SmallTest
+ public void testCheckBoxTextNonsigned() throws Exception {
+ SigninTestUtil.resetSigninState();
+
+ final Preferences preferences =
+ startPreferences(ClearBrowsingDataPreferencesBasic.class.getName());
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ClearBrowsingDataPreferencesBasic fragment =
+ (ClearBrowsingDataPreferencesBasic) preferences.getFragmentForTest();
+ PreferenceScreen screen = fragment.getPreferenceScreen();
+
+ String cookiesSummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.COOKIES_CHECKBOX);
+ String historySummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.HISTORY_CHECKBOX);
+
+ assertThat(cookiesSummary, not(containsString(GOOGLE_ACCOUNT)));
+ assertThat(historySummary, not(containsString(OTHER_ACTIVITY)));
+ assertThat(historySummary, not(containsString(SIGNED_IN_DEVICES)));
+ }
+ });
+ }
+
+ /**
+ * Tests that for users who are signed in but don't have sync activated, only the message about
+ * "other activity" is shown.
+ */
+ @SmallTest
+ public void testCheckBoxTextSigned() throws Exception {
+ SigninTestUtil.addAndSignInTestAccount();
+ setSyncable(false);
+
+ final Preferences preferences =
+ startPreferences(ClearBrowsingDataPreferencesBasic.class.getName());
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ClearBrowsingDataPreferencesBasic fragment =
+ (ClearBrowsingDataPreferencesBasic) preferences.getFragmentForTest();
+ PreferenceScreen screen = fragment.getPreferenceScreen();
+
+ String cookiesSummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.COOKIES_CHECKBOX);
+ String historySummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.HISTORY_CHECKBOX);
+
+ assertThat(cookiesSummary, containsString(GOOGLE_ACCOUNT));
+ assertThat(historySummary, containsString(OTHER_ACTIVITY));
+ assertThat(historySummary, not(containsString(SIGNED_IN_DEVICES)));
+ }
+ });
+ }
+
+ /**
+ * Tests that users who are signed in, and have sync enabled see a message about "other
+ * activity" and history on "signed in devices".
+ */
+ @SmallTest
+ public void testCheckBoxTextSignedAndSynced() throws Exception {
+ SigninTestUtil.addAndSignInTestAccount();
+ setSyncable(true);
+
+ final Preferences preferences =
+ startPreferences(ClearBrowsingDataPreferencesBasic.class.getName());
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ClearBrowsingDataPreferencesBasic fragment =
+ (ClearBrowsingDataPreferencesBasic) preferences.getFragmentForTest();
+ PreferenceScreen screen = fragment.getPreferenceScreen();
+
+ String cookiesSummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.COOKIES_CHECKBOX);
+ String historySummary = getCheckboxSummary(
+ screen, ClearBrowsingDataPreferencesBasic.HISTORY_CHECKBOX);
+
+ assertThat(cookiesSummary, containsString(GOOGLE_ACCOUNT));
+ assertThat(historySummary, containsString(OTHER_ACTIVITY));
+ assertThat(historySummary, containsString(SIGNED_IN_DEVICES));
+ }
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698