Commit a9949096 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

Adds a Feature to disable promo browser commands

The added Feature is enabled by default and is meant to allow disabling
promo browser commands via Finch.

For more information see go/promos-deeplinking-settings

Bug: 1106421
Change-Id: Ia74973644657af5e8642021f78fd3f0a6c88dfc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335403Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794304}
parent 49bb0053
...@@ -11,6 +11,10 @@ namespace features { ...@@ -11,6 +11,10 @@ namespace features {
const base::Feature kClosedTabCache{"ClosedTabCache", const base::Feature kClosedTabCache{"ClosedTabCache",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Enables executing the browser commands sent by the NTP promos.
const base::Feature kEnablePromoBrowserCommands{
"EnablePromoBrowserCommands", base::FEATURE_ENABLED_BY_DEFAULT};
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Enables being able to zoom a web page by double tapping in Chrome OS tablet // Enables being able to zoom a web page by double tapping in Chrome OS tablet
// mode. // mode.
......
...@@ -18,6 +18,8 @@ namespace features { ...@@ -18,6 +18,8 @@ namespace features {
extern const base::Feature kClosedTabCache; extern const base::Feature kClosedTabCache;
extern const base::Feature kEnablePromoBrowserCommands;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
extern const base::Feature kDoubleTapToZoomInTabletMode; extern const base::Feature kDoubleTapToZoomInTabletMode;
#endif #endif
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h" #include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/command_updater_impl.h" #include "chrome/browser/command_updater_impl.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/promos/promo_service.h" #include "chrome/browser/search/promos/promo_service.h"
...@@ -25,6 +27,9 @@ PromoBrowserCommandHandler::PromoBrowserCommandHandler( ...@@ -25,6 +27,9 @@ PromoBrowserCommandHandler::PromoBrowserCommandHandler(
: profile_(profile), : profile_(profile),
command_updater_(std::make_unique<CommandUpdaterImpl>(this)), command_updater_(std::make_unique<CommandUpdaterImpl>(this)),
page_handler_(this, std::move(pending_page_handler)) { page_handler_(this, std::move(pending_page_handler)) {
if (!base::FeatureList::IsEnabled(features::kEnablePromoBrowserCommands))
return;
// Explicitly enable supported commands. // Explicitly enable supported commands.
command_updater_->UpdateCommandEnabled( command_updater_->UpdateCommandEnabled(
static_cast<int>(Command::kUnknownCommand), true); static_cast<int>(Command::kUnknownCommand), true);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/command_updater_impl.h" #include "chrome/browser/command_updater_impl.h"
#include "chrome/browser/promo_browser_command/promo_browser_command.mojom.h" #include "chrome/browser/promo_browser_command/promo_browser_command.mojom.h"
#include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h" #include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h"
...@@ -115,3 +117,21 @@ TEST_F(PromoBrowserCommandHandlerTest, SupportedCommands) { ...@@ -115,3 +117,21 @@ TEST_F(PromoBrowserCommandHandlerTest, SupportedCommands) {
histogram_tester.ExpectBucketCount( histogram_tester.ExpectBucketCount(
PromoBrowserCommandHandler::kPromoBrowserCommandHistogramName, 0, 1); PromoBrowserCommandHandler::kPromoBrowserCommandHistogramName, 0, 1);
} }
TEST_F(PromoBrowserCommandHandlerTest, DisableHandlingCommands) {
base::HistogramTester histogram_tester;
// Disabling features::kEnablePromoBrowserCommands prevents the commands from
// being executed.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(features::kEnablePromoBrowserCommands);
// The PromoBrowserCommandHandler instance needs to be recreated for the
// feature to take effect.
command_handler_ = std::make_unique<PromoBrowserCommandHandler>(
mojo::PendingReceiver<CommandHandler>(), &profile_);
EXPECT_FALSE(ExecuteCommand(Command::kUnknownCommand, ClickInfo::New()));
histogram_tester.ExpectTotalCount(
PromoBrowserCommandHandler::kPromoBrowserCommandHistogramName, 0);
}
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