-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't show toast notifications when copying links or images
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "chrome/browser/ui/toasts/toast_controller.h" | ||
|
||
#define MaybeShowToast MaybeShowToast_ChromiumImpl | ||
#include "src/chrome/browser/ui/toasts/toast_controller.cc" | ||
#undef MaybeShowToast | ||
|
||
bool ToastController::MaybeShowToast(ToastParams params) { | ||
if (params.toast_id == ToastId::kLinkCopied || | ||
params.toast_id == ToastId::kImageCopied) { | ||
return false; | ||
} | ||
return MaybeShowToast_ChromiumImpl(std::move(params)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOASTS_TOAST_CONTROLLER_H_ | ||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOASTS_TOAST_CONTROLLER_H_ | ||
|
||
#define MaybeShowToast \ | ||
MaybeShowToast_ChromiumImpl(ToastParams params); \ | ||
bool MaybeShowToast | ||
|
||
#include "src/chrome/browser/ui/toasts/toast_controller.h" // IWYU pragma: export | ||
|
||
#undef MaybeShowToast | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOASTS_TOAST_CONTROLLER_H_ |
43 changes: 43 additions & 0 deletions
43
chromium_src/chrome/browser/ui/toasts/toast_controller_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "chrome/browser/ui/toasts/api/toast_id.h" | ||
|
||
// All of the upstream unit tests use kLinkCopied or kImageCopied when creating | ||
// test toasts, but those are the two notifications we want to hide so redefine | ||
// their identifiers here so we can continue to run the upstream tests. | ||
#define kLinkCopied kLinkToHighlightCopied | ||
#define kImageCopied kAddedToReadingList | ||
#include "src/chrome/browser/ui/toasts/toast_controller_unittest.cc" | ||
#undef kImageCopied | ||
#undef kLinkCopied | ||
|
||
TEST_F(ToastControllerUnitTest, NeverShowToastForLinkCopied) { | ||
ToastRegistry* const registry = toast_registry(); | ||
registry->RegisterToast( | ||
ToastId::kLinkCopied, | ||
ToastSpecification::Builder(vector_icons::kEmailIcon, 0).Build()); | ||
|
||
auto controller = std::make_unique<TestToastController>(registry); | ||
|
||
EXPECT_FALSE(controller->IsShowingToast()); | ||
EXPECT_TRUE(controller->CanShowToast(ToastId::kLinkCopied)); | ||
EXPECT_FALSE(controller->MaybeShowToast(ToastParams(ToastId::kLinkCopied))); | ||
EXPECT_FALSE(controller->IsShowingToast()); | ||
} | ||
|
||
TEST_F(ToastControllerUnitTest, NeverShowToastForImageCopied) { | ||
ToastRegistry* const registry = toast_registry(); | ||
registry->RegisterToast( | ||
ToastId::kImageCopied, | ||
ToastSpecification::Builder(vector_icons::kEmailIcon, 0).Build()); | ||
|
||
auto controller = std::make_unique<TestToastController>(registry); | ||
|
||
EXPECT_FALSE(controller->IsShowingToast()); | ||
EXPECT_TRUE(controller->CanShowToast(ToastId::kImageCopied)); | ||
EXPECT_FALSE(controller->MaybeShowToast(ToastParams(ToastId::kImageCopied))); | ||
EXPECT_FALSE(controller->IsShowingToast()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters