diff --git a/browser/brave_app_controller_mac_browsertest.mm b/browser/brave_app_controller_mac_browsertest.mm index dfbd576dfc5d..1b448be1a37f 100644 --- a/browser/brave_app_controller_mac_browsertest.mm +++ b/browser/brave_app_controller_mac_browsertest.mm @@ -32,7 +32,16 @@ const char kTestingPage[] = "/empty.html"; -using BraveAppControllerBrowserTest = InProcessBrowserTest; +class BraveAppControllerBrowserTest : public InProcessBrowserTest { + public: + BraveAppControllerBrowserTest() { + features_.InitWithFeatureState(features::kBraveCopyCleanLinkByDefault, + true); + } + + private: + base::test::ScopedFeatureList features_; +}; class BraveAppControllerCleanLinkFeatureDisabledBrowserTest : public InProcessBrowserTest { diff --git a/browser/brave_browser_features.cc b/browser/brave_browser_features.cc index 854a2581b4bd..bac0c5842048 100644 --- a/browser/brave_browser_features.cc +++ b/browser/brave_browser_features.cc @@ -4,6 +4,7 @@ * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/browser/brave_browser_features.h" +#include "build/build_config.h" namespace features { @@ -15,6 +16,11 @@ BASE_FEATURE(kBraveCleanupSessionCookiesOnSessionRestore, // Sanitize url before copying, replaces default ctrl+c hotkey for urls. BASE_FEATURE(kBraveCopyCleanLinkByDefault, "brave-copy-clean-link-by-default", - base::FEATURE_ENABLED_BY_DEFAULT); +#if BUILDFLAG(IS_MAC) + base::FEATURE_DISABLED_BY_DEFAULT +#else + base::FEATURE_ENABLED_BY_DEFAULT +#endif +); } // namespace features diff --git a/browser/ui/views/omnibox/brave_omnibox_view_views_browsertest.cc b/browser/ui/views/omnibox/brave_omnibox_view_views_browsertest.cc index 08d9a774642a..7a8ca145bf9a 100644 --- a/browser/ui/views/omnibox/brave_omnibox_view_views_browsertest.cc +++ b/browser/ui/views/omnibox/brave_omnibox_view_views_browsertest.cc @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "brave/browser/brave_browser_features.h" #include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h" #include "brave/components/url_sanitizer/browser/url_sanitizer_service.h" #include "build/build_config.h" @@ -28,6 +29,30 @@ class BraveOmniboxViewViewsTest : public InProcessBrowserTest { OmniboxViewViews* omnibox_view() { return location_bar()->omnibox_view(); } }; +class BraveOmniboxViewViewsEnabledFeatureTest + : public BraveOmniboxViewViewsTest { + public: + BraveOmniboxViewViewsEnabledFeatureTest() { + features_.InitWithFeatureState(features::kBraveCopyCleanLinkByDefault, + true); + } + + private: + base::test::ScopedFeatureList features_; +}; + +class BraveOmniboxViewViewsDisabledFeatureTest + : public BraveOmniboxViewViewsTest { + public: + BraveOmniboxViewViewsDisabledFeatureTest() { + features_.InitWithFeatureState(features::kBraveCopyCleanLinkByDefault, + false); + } + + private: + base::test::ScopedFeatureList features_; +}; + // Load brave url and check copied url also has brave scheme. IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, CopyInternalURLToClipboardTest) { @@ -97,6 +122,33 @@ IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, CopyURLToClipboardTest) { "utm_content=removethis&e=&f=g&=end"); } +IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsEnabledFeatureTest, + CopyCleanedURLToClipboardByHotkey) { + brave::URLSanitizerServiceFactory::GetForBrowserContext(browser()->profile()) + ->Initialize(R"([ + { "include": [ "*://*/*"], "params": ["utm_content"] } + ])"); + const std::string test_url( + "https://dev-pages.bravesoftware.com/clean-urls/" + "?brave_testing1=foo&brave_testing2=bar&brave_testing3=keep&&;b&" + "d&utm_content=removethis&e=&f=g&=end"); + ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GURL(test_url))); + + omnibox_view()->SelectAll(true); + + auto* textfield = static_cast(omnibox_view()); + textfield->AcceleratorPressed( + ui::Accelerator(ui::VKEY_C, ui::EF_PLATFORM_ACCELERATOR)); + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + std::string text_from_clipboard; + clipboard->ReadAsciiText(ui::ClipboardBuffer::kCopyPaste, + /* data_dst = */ nullptr, &text_from_clipboard); + EXPECT_EQ(text_from_clipboard, + "https://dev-pages.bravesoftware.com/clean-urls/" + "?brave_testing1=foo&brave_testing2=bar&brave_testing3=keep&&;b&d&" + "e=&f=g&=end"); +} + IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, DoNotSanitizeInternalURLS) { const std::string test_url("brave://settings/?utm_ad=1"); ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GURL(test_url))); @@ -115,7 +167,7 @@ IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, DoNotSanitizeInternalURLS) { EXPECT_EQ(text_from_clipboard, "brave://settings/?utm_ad=1"); } -IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, +IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsDisabledFeatureTest, CopyCleanedURLToClipboardByHotkey) { brave::URLSanitizerServiceFactory::GetForBrowserContext(browser()->profile()) ->Initialize(R"([ @@ -139,7 +191,7 @@ IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, EXPECT_EQ(text_from_clipboard, "https://dev-pages.bravesoftware.com/clean-urls/" "?brave_testing1=foo&brave_testing2=bar&brave_testing3=keep&&;b&d&" - "e=&f=g&=end"); + "utm_content=removethis&e=&f=g&=end"); } IN_PROC_BROWSER_TEST_F(BraveOmniboxViewViewsTest, CopyTextToClipboardByHotkey) {