Skip to content

Commit

Permalink
1.49.x Disable copy-clean-link-by-default for osx (uplift #17752) (#1…
Browse files Browse the repository at this point in the history
…7761)

Disable copy-clean-link-by-default for osx (#17752)
  • Loading branch information
spylogsster authored Mar 27, 2023
1 parent 98b56a9 commit 239825f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
11 changes: 10 additions & 1 deletion browser/brave_app_controller_mac_browsertest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion browser/brave_browser_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
* 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 {

// 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
56 changes: 54 additions & 2 deletions browser/ui/views/omnibox/brave_omnibox_view_views_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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<views::Textfield*>(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)));
Expand All @@ -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"([
Expand All @@ -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) {
Expand Down

0 comments on commit 239825f

Please sign in to comment.