Commit 2f846131 authored by Ehimare Okoyomon's avatar Ehimare Okoyomon Committed by Commit Bot

Add improved cookie controls toggle to android incognito ntp

Create a new toggle that allows the ability to turn third-party cookie
blocking in incognito on and off.
https://screenshot.googleplex.com/LnvCaA3SB6W.png

Bug: 1040091
Change-Id: Iff32a67f6415b9fe72f9c92e4946074fdc9afc6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006548
Commit-Queue: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735494}
parent a3182e3f
...@@ -251,6 +251,7 @@ chrome_test_java_sources = [ ...@@ -251,6 +251,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializerTest.java", "javatests/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializerTest.java",
"javatests/src/org/chromium/chrome/browser/notifications/channels/ChannelsUpdaterTest.java", "javatests/src/org/chromium/chrome/browser/notifications/channels/ChannelsUpdaterTest.java",
"javatests/src/org/chromium/chrome/browser/notifications/channels/SiteChannelsManagerTest.java", "javatests/src/org/chromium/chrome/browser/notifications/channels/SiteChannelsManagerTest.java",
"javatests/src/org/chromium/chrome/browser/ntp/IncognitoNewTabPageTest.java",
"javatests/src/org/chromium/chrome/browser/ntp/NewTabPageLoadTest.java", "javatests/src/org/chromium/chrome/browser/ntp/NewTabPageLoadTest.java",
"javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java", "javatests/src/org/chromium/chrome/browser/ntp/NewTabPageNavigationTest.java",
"javatests/src/org/chromium/chrome/browser/ntp/NewTabPageTest.java", "javatests/src/org/chromium/chrome/browser/ntp/NewTabPageTest.java",
......
...@@ -48,6 +48,8 @@ public class TasksSurfaceCoordinator implements TasksSurface { ...@@ -48,6 +48,8 @@ public class TasksSurfaceCoordinator implements TasksSurface {
activity.getString(R.string.help_context_incognito_learn_more), activity.getString(R.string.help_context_incognito_learn_more),
Profile.getLastUsedProfile(), null); Profile.getLastUsedProfile(), null);
}; };
// TODO(crbug.com/1040091): Add parameter for CookieSettingsBridge to control the cookie
// controls toggle on the IncognitoNTP.
mMediator = new TasksSurfaceMediator( mMediator = new TasksSurfaceMediator(
propertyModel, fakeboxDelegate, incognitoLearnMoreClickListener, isTabCarousel); propertyModel, fakeboxDelegate, incognitoLearnMoreClickListener, isTabCarousel);
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 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. -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="@color/hairline_stroke_color_dark"/>
<corners android:radius="@dimen/default_rounded_corner_radius" />
</shape>
...@@ -43,28 +43,68 @@ ...@@ -43,28 +43,68 @@
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="start"> android:gravity="start">
<TextView <org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/new_tab_incognito_features" android:id="@+id/new_tab_incognito_features"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.WhiteBodyIncognito" android:textAppearance="@style/TextAppearance.WhiteBodyIncognito"
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" /> app:leading="@dimen/text_size_medium_leading" />
<TextView <org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/new_tab_incognito_warning" android:id="@+id/new_tab_incognito_warning"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.WhiteBodyIncognito" android:textAppearance="@style/TextAppearance.WhiteBodyIncognito"
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" /> app:leading="@dimen/text_size_medium_leading" />
</LinearLayout> </LinearLayout>
<TextView <org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/learn_more" android:id="@+id/learn_more"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/learn_more" android:text="@string/learn_more"
android:textAppearance="@style/TextAppearance.IncognitoNewTabLearnMoreLinkModern" android:textAppearance="@style/TextAppearance.IncognitoNewTabLearnMoreLinkModern"
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" /> app:leading="@dimen/text_size_medium_leading" />
<RelativeLayout
android:id="@+id/cookie_controls_card"
style="@style/CardTransparentForDark"
android:visibility="gone"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:padding="16dp">
<android.support.v7.widget.SwitchCompat
android:id="@+id/cookie_controls_card_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:theme="@style/SwitchCompatDark"
android:layout_alignParentEnd="true"
app:showText="false" />
<org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/cookie_controls_card_title"
android:text="@string/new_tab_otr_third_party_cookie"
android:textAppearance="@style/TextAppearance.WhiteTitle1"
android:layout_marginBottom="@dimen/md_incognito_ntp_line_spacing"
android:layout_alignParentStart="true"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<org.chromium.ui.widget.TextViewWithLeading
android:text="@string/new_tab_otr_third_party_cookie_sublabel"
android:textAppearance="@style/TextAppearance.WhiteBodyIncognito"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/cookie_controls_card_toggle"
android:layout_below="@id/cookie_controls_card_title"
app:leading="@dimen/text_size_medium_leading"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</RelativeLayout>
</org.chromium.chrome.browser.ntp.IncognitoDescriptionView> </org.chromium.chrome.browser.ntp.IncognitoDescriptionView>
...@@ -733,7 +733,10 @@ ...@@ -733,7 +733,10 @@
<!-- Card for General Use --> <!-- Card for General Use -->
<style name="Card"> <style name="Card">
<item name="android:background">@drawable/hairline_border_card_background</item> <item name="android:background">@drawable/hairline_border_card_background</item>
</style> </style>
<style name="CardTransparentForDark">
<item name="android:background">@drawable/hairline_border_card_dark_transparent_bg</item>
</style>
<!-- Content and Site Suggestions --> <!-- Content and Site Suggestions -->
<style name="SuggestionCardModern" parent="Card"> <style name="SuggestionCardModern" parent="Card">
<item name="android:layout_marginBottom">@dimen/content_suggestions_card_modern_margin</item> <item name="android:layout_marginBottom">@dimen/content_suggestions_card_modern_margin</item>
......
...@@ -8,14 +8,17 @@ import static org.chromium.ui.base.ViewUtils.dpToPx; ...@@ -8,14 +8,17 @@ import static org.chromium.ui.base.ViewUtils.dpToPx;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.support.v7.widget.SwitchCompat;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
...@@ -23,6 +26,7 @@ import androidx.annotation.StringRes; ...@@ -23,6 +26,7 @@ import androidx.annotation.StringRes;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.ui.text.NoUnderlineClickableSpan; import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.text.SpanApplier; import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.widget.ChromeBulletSpan; import org.chromium.ui.widget.ChromeBulletSpan;
...@@ -40,6 +44,8 @@ public class IncognitoDescriptionView extends LinearLayout { ...@@ -40,6 +44,8 @@ public class IncognitoDescriptionView extends LinearLayout {
private LinearLayout mBulletpointsContainer; private LinearLayout mBulletpointsContainer;
private TextView mLearnMore; private TextView mLearnMore;
private TextView[] mParagraphs; private TextView[] mParagraphs;
private RelativeLayout mCookieControlsCard;
private SwitchCompat mCookieControlsToggle;
private static final int BULLETPOINTS_HORIZONTAL_SPACING_DP = 40; private static final int BULLETPOINTS_HORIZONTAL_SPACING_DP = 40;
private static final int CONTENT_WIDTH_DP = 600; private static final int CONTENT_WIDTH_DP = 600;
...@@ -58,6 +64,22 @@ public class IncognitoDescriptionView extends LinearLayout { ...@@ -58,6 +64,22 @@ public class IncognitoDescriptionView extends LinearLayout {
mLearnMore.setOnClickListener(listener); mLearnMore.setOnClickListener(listener);
} }
/**
* Set cookie controls toggle on checked change listerner.
* @param listener The given listener.
*/
public void setCookieControlsToggleOnCheckedChangeListener(OnCheckedChangeListener listener) {
mCookieControlsToggle.setOnCheckedChangeListener(listener);
}
/**
* Set cookie controls toggle's checked value.
* @param enabled The value to set the toggle to.
*/
public void setCookieControlsToggle(boolean enabled) {
mCookieControlsToggle.setChecked(enabled);
}
@Override @Override
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
...@@ -75,6 +97,8 @@ public class IncognitoDescriptionView extends LinearLayout { ...@@ -75,6 +97,8 @@ public class IncognitoDescriptionView extends LinearLayout {
mParagraphs = new TextView[] {mSubtitle, findViewById(R.id.new_tab_incognito_features), mParagraphs = new TextView[] {mSubtitle, findViewById(R.id.new_tab_incognito_features),
findViewById(R.id.new_tab_incognito_warning), mLearnMore}; findViewById(R.id.new_tab_incognito_warning), mLearnMore};
mBulletpointsContainer = findViewById(R.id.new_tab_incognito_bulletpoints_container); mBulletpointsContainer = findViewById(R.id.new_tab_incognito_bulletpoints_container);
mCookieControlsCard = findViewById(R.id.cookie_controls_card);
mCookieControlsToggle = findViewById(R.id.cookie_controls_card_toggle);
adjustView(); adjustView();
} }
...@@ -97,6 +121,7 @@ public class IncognitoDescriptionView extends LinearLayout { ...@@ -97,6 +121,7 @@ public class IncognitoDescriptionView extends LinearLayout {
adjustIcon(); adjustIcon();
adjustLayout(); adjustLayout();
adjustLearnMore(); adjustLearnMore();
adjustCookieControlsCard();
} }
/** /**
...@@ -265,4 +290,15 @@ public class IncognitoDescriptionView extends LinearLayout { ...@@ -265,4 +290,15 @@ public class IncognitoDescriptionView extends LinearLayout {
mSubtitle.setText(textWithLearnMoreLink); mSubtitle.setText(textWithLearnMoreLink);
mSubtitle.setMovementMethod(LinkMovementMethod.getInstance()); mSubtitle.setMovementMethod(LinkMovementMethod.getInstance());
} }
/** Adjust the Cookie Controls Card. */
private void adjustCookieControlsCard() {
if (!ChromeFeatureList.isInitialized()
|| !ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROVED_COOKIE_CONTROLS)) {
mCookieControlsCard.setVisibility(View.GONE);
return;
}
mCookieControlsCard.setVisibility(View.VISIBLE);
}
} }
...@@ -18,11 +18,14 @@ import org.chromium.chrome.R; ...@@ -18,11 +18,14 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareThumbnailProvider; import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareThumbnailProvider;
import org.chromium.chrome.browser.help.HelpAndFeedback; import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.ntp.IncognitoNewTabPageView.IncognitoNewTabPageManager; import org.chromium.chrome.browser.ntp.IncognitoNewTabPageView.IncognitoNewTabPageManager;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.native_page.BasicNativePage; import org.chromium.chrome.browser.ui.native_page.BasicNativePage;
import org.chromium.chrome.browser.ui.native_page.NativePageHost; import org.chromium.chrome.browser.ui.native_page.NativePageHost;
import org.chromium.chrome.browser.util.UrlConstants; import org.chromium.chrome.browser.util.UrlConstants;
import org.chromium.chrome.browser.vr.VrModuleProvider; import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.components.content_settings.CookieControlsMode;
/** /**
* Provides functionality when the user interacts with the Incognito NTP. * Provides functionality when the user interacts with the Incognito NTP.
...@@ -72,6 +75,22 @@ public class IncognitoNewTabPage ...@@ -72,6 +75,22 @@ public class IncognitoNewTabPage
showIncognitoLearnMore(); showIncognitoLearnMore();
} }
@Override
public void setThirdPartyCookieBlocking(boolean enable) {
@CookieControlsMode
int new_mode = enable ? CookieControlsMode.INCOGNITO_ONLY : CookieControlsMode.OFF;
PrefServiceBridge.getInstance().setInteger(Pref.COOKIE_CONTROLS_MODE, new_mode);
}
@Override
public boolean shouldBlockThirdPartyCookies() {
// TODO(eokoyomon): add methods to CookieControlsBridge to implement this in order
// to be consistent with desktop cookie settings.
return PrefServiceBridge.getInstance().getBoolean(Pref.BLOCK_THIRD_PARTY_COOKIES)
|| (PrefServiceBridge.getInstance().getInteger(Pref.COOKIE_CONTROLS_MODE)
!= CookieControlsMode.OFF);
}
@Override @Override
public void onLoadingComplete() { public void onLoadingComplete() {
mIsLoaded = true; mIsLoaded = true;
......
...@@ -8,6 +8,8 @@ import android.content.Context; ...@@ -8,6 +8,8 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
...@@ -21,6 +23,7 @@ public class IncognitoNewTabPageView extends FrameLayout { ...@@ -21,6 +23,7 @@ public class IncognitoNewTabPageView extends FrameLayout {
private IncognitoNewTabPageManager mManager; private IncognitoNewTabPageManager mManager;
private boolean mFirstShow = true; private boolean mFirstShow = true;
private NewTabPageScrollView mScrollView; private NewTabPageScrollView mScrollView;
private IncognitoDescriptionView mDescriptionView;
private int mSnapshotWidth; private int mSnapshotWidth;
private int mSnapshotHeight; private int mSnapshotHeight;
...@@ -33,6 +36,20 @@ public class IncognitoNewTabPageView extends FrameLayout { ...@@ -33,6 +36,20 @@ public class IncognitoNewTabPageView extends FrameLayout {
/** Loads a page explaining details about incognito mode in the current tab. */ /** Loads a page explaining details about incognito mode in the current tab. */
void loadIncognitoLearnMore(); void loadIncognitoLearnMore();
/**
* Enables/disables cookie controls mode as set from incognito NTP. By default
* nothing happens.
* @param enable A boolean specifying the state of third party cookie blocking in
* incognito. True will enable third-party cookie blocking in incognito and false
* will disable this feature.
* */
void setThirdPartyCookieBlocking(boolean enable);
/**
* Returns whether third-party cookies are currently being blocked.
* */
boolean shouldBlockThirdPartyCookies();
/** /**
* Called when the NTP has completely finished loading (all views will be inflated * Called when the NTP has completely finished loading (all views will be inflated
* and any dependent resources will have been loaded). * and any dependent resources will have been loaded).
...@@ -59,14 +76,21 @@ public class IncognitoNewTabPageView extends FrameLayout { ...@@ -59,14 +76,21 @@ public class IncognitoNewTabPageView extends FrameLayout {
// any shortcut causes the UrlBar to be focused. See ViewRootImpl.leaveTouchMode(). // any shortcut causes the UrlBar to be focused. See ViewRootImpl.leaveTouchMode().
mScrollView.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS); mScrollView.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
IncognitoDescriptionView descriptionView = mDescriptionView =
(IncognitoDescriptionView) findViewById(R.id.new_tab_incognito_container); (IncognitoDescriptionView) findViewById(R.id.new_tab_incognito_container);
descriptionView.setLearnMoreOnclickListener(new OnClickListener() { mDescriptionView.setLearnMoreOnclickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mManager.loadIncognitoLearnMore(); mManager.loadIncognitoLearnMore();
} }
}); });
mDescriptionView.setCookieControlsToggleOnCheckedChangeListener(
new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mManager.setThirdPartyCookieBlocking(isChecked);
}
});
} }
@Override @Override
...@@ -85,6 +109,7 @@ public class IncognitoNewTabPageView extends FrameLayout { ...@@ -85,6 +109,7 @@ public class IncognitoNewTabPageView extends FrameLayout {
*/ */
void initialize(IncognitoNewTabPageManager manager) { void initialize(IncognitoNewTabPageManager manager) {
mManager = manager; mManager = manager;
mDescriptionView.setCookieControlsToggle(mManager.shouldBlockThirdPartyCookies());
} }
/** @return The IncognitoNewTabPageManager associated with this IncognitoNewTabPageView. */ /** @return The IncognitoNewTabPageManager associated with this IncognitoNewTabPageView. */
......
// Copyright 2020 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.ntp;
import android.support.test.filters.SmallTest;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.content_settings.CookieControlsMode;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* Integration tests for IncognitoNewTabPage.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@EnableFeatures(ChromeFeatureList.IMPROVED_COOKIE_CONTROLS)
public class IncognitoNewTabPageTest {
@Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
@Before
public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
}
/**
* Test cookie controls card is GONE when cookie controls flag disabled.
*/
@Test
@SmallTest
@DisableFeatures(ChromeFeatureList.IMPROVED_COOKIE_CONTROLS)
public void testCookieControlsCardGONE() throws Exception {
mActivityTestRule.newIncognitoTabFromMenu();
final IncognitoNewTabPage ntp = (IncognitoNewTabPage) mActivityTestRule.getActivity()
.getActivityTab()
.getNativePage();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals(
ntp.getView().findViewById(R.id.cookie_controls_card).getVisibility(),
View.GONE);
});
}
/**
* Test cookie controls toggle defaults to on if cookie controls mode is on.
*/
@Test
@SmallTest
public void testCookieControlsToggleStartsOn() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Set normal third-party cookie blocking to off.
PrefServiceBridge.getInstance().setBoolean(Pref.BLOCK_THIRD_PARTY_COOKIES, false);
// Set CookieControlsMode Pref to On
PrefServiceBridge.getInstance().setInteger(
Pref.COOKIE_CONTROLS_MODE, CookieControlsMode.INCOGNITO_ONLY);
});
mActivityTestRule.newIncognitoTabFromMenu();
final IncognitoNewTabPage ntp = (IncognitoNewTabPage) mActivityTestRule.getActivity()
.getActivityTab()
.getNativePage();
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Make sure cookie controls card is visible
Assert.assertEquals(
ntp.getView().findViewById(R.id.cookie_controls_card).getVisibility(),
View.VISIBLE);
// Assert the cookie controls toggle is checked
Assert.assertTrue(
((SwitchCompat) ntp.getView().findViewById(R.id.cookie_controls_card_toggle))
.isChecked());
});
}
/**
* Test cookie controls toggle turns on and off cookie controls mode as expected.
*/
@Test
@SmallTest
public void testCookieControlsToggleChanges() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Set normal third-party cookie blocking to off.
PrefServiceBridge.getInstance().setBoolean(Pref.BLOCK_THIRD_PARTY_COOKIES, false);
// Set CookieControlsMode Pref to Off
PrefServiceBridge.getInstance().setInteger(
Pref.COOKIE_CONTROLS_MODE, CookieControlsMode.OFF);
});
mActivityTestRule.newIncognitoTabFromMenu();
final IncognitoNewTabPage ntp = (IncognitoNewTabPage) mActivityTestRule.getActivity()
.getActivityTab()
.getNativePage();
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Make sure cookie controls card is visible
Assert.assertEquals(
ntp.getView().findViewById(R.id.cookie_controls_card).getVisibility(),
View.VISIBLE);
SwitchCompat toggle =
(SwitchCompat) ntp.getView().findViewById(R.id.cookie_controls_card_toggle);
Assert.assertFalse("Toggle should be unchecked", toggle.isChecked());
toggle.performClick();
Assert.assertTrue("Toggle should be checked", toggle.isChecked());
Assert.assertEquals("CookieControlsMode should be incognito_only",
PrefServiceBridge.getInstance().getInteger(Pref.COOKIE_CONTROLS_MODE),
CookieControlsMode.INCOGNITO_ONLY);
toggle.performClick();
Assert.assertFalse("Toggle should be unchecked again", toggle.isChecked());
Assert.assertEquals("CookieControlsMode should be off",
PrefServiceBridge.getInstance().getInteger(Pref.COOKIE_CONTROLS_MODE),
CookieControlsMode.OFF);
});
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<!-- TODO(crbug.com/1017190): Remove the UnusedResources workaround. --> <!-- TODO(crbug.com/1017190): Remove the UnusedResources workaround. -->
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedResources"> <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedResources">
<color name="light_active_color">@color/modern_blue_600</color> <color name="light_active_color">@color/control_active_color_light</color>
<!-- Text colors --> <!-- Text colors -->
<color name="default_primary_color">#F2F2F2</color> <color name="default_primary_color">#F2F2F2</color>
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
<!-- Control colors for toggles, checkboxes, ratio buttons, list item highlight, and accent. <!-- Control colors for toggles, checkboxes, ratio buttons, list item highlight, and accent.
Note that these should NOT be used for icon tint. --> Note that these should NOT be used for icon tint. -->
<color name="control_normal_color">@color/modern_grey_700</color> <color name="control_normal_color">@color/control_normal_color_light</color>
<color name="control_highlight_color" tools:ignore="UnusedResources"> <color name="control_highlight_color" tools:ignore="UnusedResources">
@color/modern_grey_800_alpha_38 @color/control_highlight_color_light
</color> </color>
</resources> </resources>
...@@ -74,4 +74,13 @@ ...@@ -74,4 +74,13 @@
<item name="android:popupBackground">@drawable/popup_bg_tinted</item> <item name="android:popupBackground">@drawable/popup_bg_tinted</item>
<item name="android:popupElevation" tools:targetApi="21">0dp</item> <item name="android:popupElevation" tools:targetApi="21">0dp</item>
</style> </style>
<!-- Switch styling for dark theme -->
<style name="SwitchCompatDark" >
<item name="colorAccent">@color/control_active_color_dark</item>
<item name="colorControlNormal">@color/control_normal_color_dark</item>
<item name="colorControlActivated">@color/control_active_color_dark</item>
<item name="colorControlHighlight">@color/control_highlight_color_dark</item>
<item name="android:colorForeground">@color/modern_grey_100</item>
</style>
</resources> </resources>
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
found in the LICENSE file. --> found in the LICENSE file. -->
<resources> <resources>
<color name="light_active_color">@color/modern_blue_300</color> <color name="light_active_color">@color/control_active_color_dark</color>
<!-- Control colors for toggles, checkboxes, radio buttons, list item highlight, and accent. <!-- Control colors for toggles, checkboxes, radio buttons, list item highlight, and accent.
Note that these should NOT be used for icon tint. --> Note that these should NOT be used for icon tint. -->
<color name="control_normal_color">@color/modern_grey_500</color> <color name="control_normal_color">@color/control_normal_color_dark</color>
<color name="control_highlight_color">@color/white_alpha_12</color> <color name="control_highlight_color">@color/control_highlight_color_dark</color>
<color name="text_highlight_color">@color/highlight_color_on_light_text</color> <color name="text_highlight_color">@color/highlight_color_on_light_text</color>
</resources> </resources>
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
@color/default_icon_color_blue_dark @color/default_icon_color_blue_dark
</color> </color>
<color name="default_icon_color_secondary" tools:ignore="UnusedResources">@color/default_icon_color_secondary_dark</color> <color name="default_icon_color_secondary" tools:ignore="UnusedResources">@color/default_icon_color_secondary_dark</color>
<color name="hairline_stroke_color">@color/modern_grey_300</color> <color name="hairline_stroke_color_light">@color/modern_grey_300</color>
<color name="hairline_stroke_color_dark">@color/modern_grey_700</color>
<color name="hairline_stroke_color">@color/hairline_stroke_color_light</color>
<!-- Common background and branding color. --> <!-- Common background and branding color. -->
<!-- TODO(huayinz): Change primary and secondary color to default_bg_color*. --> <!-- TODO(huayinz): Change primary and secondary color to default_bg_color*. -->
......
...@@ -59,6 +59,16 @@ ...@@ -59,6 +59,16 @@
<color name="divider_bg_color_dark">@color/modern_grey_300</color> <color name="divider_bg_color_dark">@color/modern_grey_300</color>
<color name="divider_bg_color_light">@color/white_alpha_12</color> <color name="divider_bg_color_light">@color/white_alpha_12</color>
<!-- Colors used for Widgets (checkboxes, switches, buttons, etc)-->
<color name="control_active_color_light" tools:ignore="UnusedResources">@color/modern_blue_600</color>
<color name="control_active_color_dark" tools:ignore="UnusedResources">@color/modern_blue_300</color>
<color name="control_normal_color_light" tools:ignore="UnusedResources">@color/modern_grey_700</color>
<color name="control_normal_color_dark" tools:ignore="UnusedResources">@color/modern_grey_500</color>
<color name="control_highlight_color_light" tools:ignore="UnusedResources">
@color/modern_grey_800_alpha_38
</color>
<color name="control_highlight_color_dark" tools:ignore="UnusedResources">@color/white_alpha_12</color>
<!-- Others --> <!-- Others -->
<color name="filled_button_bg_color_dark">@color/modern_blue_600</color> <color name="filled_button_bg_color_dark">@color/modern_blue_600</color>
<color name="filled_button_bg_color_light">@color/modern_blue_300</color> <color name="filled_button_bg_color_light">@color/modern_blue_300</color>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<color name="default_icon_color_inverse_disabled">@color/default_icon_color_disabled_dark</color> <color name="default_icon_color_inverse_disabled">@color/default_icon_color_disabled_dark</color>
<color name="default_icon_color_blue">@color/default_icon_color_blue_light</color> <color name="default_icon_color_blue">@color/default_icon_color_blue_light</color>
<color name="default_icon_color_secondary">@color/default_icon_color_secondary_light</color> <color name="default_icon_color_secondary">@color/default_icon_color_secondary_light</color>
<color name="hairline_stroke_color">@color/modern_grey_700</color> <color name="hairline_stroke_color">@color/hairline_stroke_color_dark</color>
<!-- Common background and branding color. --> <!-- Common background and branding color. -->
<color name="modern_primary_color">@color/default_bg_color_dark</color> <color name="modern_primary_color">@color/default_bg_color_dark</color>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment