Commit cf0d87b6 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Return ComPtr via move constructor rather than "Double Pointer"

While "Double Pointer" is commonly used in C, let's use (implicit) move
semantics in the modern C++ era.

Bug: 886957
Change-Id: I15693413a8a2474fb8200fc1778d4f9fe4656905
Reviewed-on: https://chromium-review.googlesource.com/1242298
Commit-Queue: Xi Cheng <chengx@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593996}
parent 433d11fc
...@@ -155,14 +155,11 @@ class NotificationPlatformBridgeWinImpl ...@@ -155,14 +155,11 @@ class NotificationPlatformBridgeWinImpl
// NotificationTemplateBuilder). This function is only used when displaying // NotificationTemplateBuilder). This function is only used when displaying
// notification in production code, which explains why the UMA metrics record // notification in production code, which explains why the UMA metrics record
// within are classified with the display path. // within are classified with the display path.
HRESULT GetToastNotification( mswr::ComPtr<winui::Notifications::IToastNotification> GetToastNotification(
const message_center::Notification& notification, const message_center::Notification& notification,
const NotificationTemplateBuilder& notification_template_builder, const NotificationTemplateBuilder& notification_template_builder,
const std::string& profile_id, const std::string& profile_id,
bool incognito, bool incognito) {
winui::Notifications::IToastNotification** toast_notification) {
*toast_notification = nullptr;
ScopedHString ref_class_name = ScopedHString ref_class_name =
ScopedHString::Create(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument); ScopedHString::Create(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument);
mswr::ComPtr<IInspectable> inspectable; mswr::ComPtr<IInspectable> inspectable;
...@@ -171,7 +168,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -171,7 +168,7 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::RO_ACTIVATE_FAILED); LogDisplayHistogram(DisplayStatus::RO_ACTIVATE_FAILED);
DLOG(ERROR) << "Unable to activate the XML Document " << std::hex << hr; DLOG(ERROR) << "Unable to activate the XML Document " << std::hex << hr;
return hr; return nullptr;
} }
mswr::ComPtr<winxml::Dom::IXmlDocumentIO> document_io; mswr::ComPtr<winxml::Dom::IXmlDocumentIO> document_io;
...@@ -181,7 +178,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -181,7 +178,7 @@ class NotificationPlatformBridgeWinImpl
DisplayStatus::CONVERSION_FAILED_INSPECTABLE_TO_XML_IO); DisplayStatus::CONVERSION_FAILED_INSPECTABLE_TO_XML_IO);
DLOG(ERROR) << "Failed to get XmlDocument as IXmlDocumentIO " << std::hex DLOG(ERROR) << "Failed to get XmlDocument as IXmlDocumentIO " << std::hex
<< hr; << hr;
return hr; return nullptr;
} }
base::string16 notification_template = base::string16 notification_template =
...@@ -192,7 +189,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -192,7 +189,7 @@ class NotificationPlatformBridgeWinImpl
LogDisplayHistogram(DisplayStatus::LOAD_XML_FAILED); LogDisplayHistogram(DisplayStatus::LOAD_XML_FAILED);
DLOG(ERROR) << "Unable to load the template's XML into the document " DLOG(ERROR) << "Unable to load the template's XML into the document "
<< std::hex << hr; << std::hex << hr;
return hr; return nullptr;
} }
mswr::ComPtr<winxml::Dom::IXmlDocument> document; mswr::ComPtr<winxml::Dom::IXmlDocument> document;
...@@ -200,7 +197,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -200,7 +197,7 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::CONVERSION_FAILED_XML_IO_TO_XML); LogDisplayHistogram(DisplayStatus::CONVERSION_FAILED_XML_IO_TO_XML);
DLOG(ERROR) << "Unable to get as XMLDocument " << std::hex << hr; DLOG(ERROR) << "Unable to get as XMLDocument " << std::hex << hr;
return hr; return nullptr;
} }
mswr::ComPtr<winui::Notifications::IToastNotificationFactory> mswr::ComPtr<winui::Notifications::IToastNotificationFactory>
...@@ -212,25 +209,26 @@ class NotificationPlatformBridgeWinImpl ...@@ -212,25 +209,26 @@ class NotificationPlatformBridgeWinImpl
LogDisplayHistogram(DisplayStatus::CREATE_FACTORY_FAILED); LogDisplayHistogram(DisplayStatus::CREATE_FACTORY_FAILED);
DLOG(ERROR) << "Unable to create the IToastNotificationFactory " DLOG(ERROR) << "Unable to create the IToastNotificationFactory "
<< std::hex << hr; << std::hex << hr;
return hr; return nullptr;
} }
mswr::ComPtr<winui::Notifications::IToastNotification> toast_notification;
hr = toast_notification_factory->CreateToastNotification( hr = toast_notification_factory->CreateToastNotification(
document.Get(), toast_notification); document.Get(), toast_notification.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::CREATE_TOAST_NOTIFICATION_FAILED); LogDisplayHistogram(DisplayStatus::CREATE_TOAST_NOTIFICATION_FAILED);
DLOG(ERROR) << "Unable to create the IToastNotification " << std::hex DLOG(ERROR) << "Unable to create the IToastNotification " << std::hex
<< hr; << hr;
return hr; return nullptr;
} }
mswr::ComPtr<winui::Notifications::IToastNotification2> toast2; mswr::ComPtr<winui::Notifications::IToastNotification2> toast2;
hr = (*toast_notification)->QueryInterface(IID_PPV_ARGS(&toast2)); hr = toast_notification->QueryInterface(IID_PPV_ARGS(&toast2));
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::CREATE_TOAST_NOTIFICATION2_FAILED); LogDisplayHistogram(DisplayStatus::CREATE_TOAST_NOTIFICATION2_FAILED);
DLOG(ERROR) << "Failed to get IToastNotification2 object " << std::hex DLOG(ERROR) << "Failed to get IToastNotification2 object " << std::hex
<< hr; << hr;
return hr; return nullptr;
} }
// Set the Group and Tag values for the notification, in order to support // Set the Group and Tag values for the notification, in order to support
...@@ -249,14 +247,14 @@ class NotificationPlatformBridgeWinImpl ...@@ -249,14 +247,14 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::SETTING_GROUP_FAILED); LogDisplayHistogram(DisplayStatus::SETTING_GROUP_FAILED);
DLOG(ERROR) << "Failed to set Group " << std::hex << hr; DLOG(ERROR) << "Failed to set Group " << std::hex << hr;
return hr; return nullptr;
} }
hr = toast2->put_Tag(tag.get()); hr = toast2->put_Tag(tag.get());
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::SETTING_TAG_FAILED); LogDisplayHistogram(DisplayStatus::SETTING_TAG_FAILED);
DLOG(ERROR) << "Failed to set Tag " << std::hex << hr; DLOG(ERROR) << "Failed to set Tag " << std::hex << hr;
return hr; return nullptr;
} }
// By default, Windows 10 will always show the notification on screen. // By default, Windows 10 will always show the notification on screen.
...@@ -278,7 +276,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -278,7 +276,7 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::GET_GROUP_FAILED); LogDisplayHistogram(DisplayStatus::GET_GROUP_FAILED);
DLOG(ERROR) << "Failed to get group value " << std::hex << hr; DLOG(ERROR) << "Failed to get group value " << std::hex << hr;
return hr; return nullptr;
} }
ScopedHString scoped_group(hstring_group); ScopedHString scoped_group(hstring_group);
...@@ -287,7 +285,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -287,7 +285,7 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::GET_TAG_FAILED); LogDisplayHistogram(DisplayStatus::GET_TAG_FAILED);
DLOG(ERROR) << "Failed to get tag value " << std::hex << hr; DLOG(ERROR) << "Failed to get tag value " << std::hex << hr;
return hr; return nullptr;
} }
ScopedHString scoped_tag(hstring_tag); ScopedHString scoped_tag(hstring_tag);
...@@ -298,12 +296,12 @@ class NotificationPlatformBridgeWinImpl ...@@ -298,12 +296,12 @@ class NotificationPlatformBridgeWinImpl
if (FAILED(hr)) { if (FAILED(hr)) {
LogDisplayHistogram(DisplayStatus::SUPPRESS_POPUP_FAILED); LogDisplayHistogram(DisplayStatus::SUPPRESS_POPUP_FAILED);
DLOG(ERROR) << "Failed to set suppress value " << std::hex << hr; DLOG(ERROR) << "Failed to set suppress value " << std::hex << hr;
return hr; return nullptr;
} }
} }
} }
return S_OK; return toast_notification;
} }
void Display(NotificationHandler::Type notification_type, void Display(NotificationHandler::Type notification_type,
...@@ -360,14 +358,11 @@ class NotificationPlatformBridgeWinImpl ...@@ -360,14 +358,11 @@ class NotificationPlatformBridgeWinImpl
std::unique_ptr<NotificationTemplateBuilder> notification_template = std::unique_ptr<NotificationTemplateBuilder> notification_template =
NotificationTemplateBuilder::Build( NotificationTemplateBuilder::Build(
image_retainer_->AsWeakPtr(), launch_id, profile_id, *notification); image_retainer_->AsWeakPtr(), launch_id, profile_id, *notification);
mswr::ComPtr<winui::Notifications::IToastNotification> toast; mswr::ComPtr<winui::Notifications::IToastNotification> toast =
hr = GetToastNotification(*notification, *notification_template, profile_id, GetToastNotification(*notification, *notification_template, profile_id,
incognito, &toast); incognito);
if (FAILED(hr)) { if (!toast)
// A histogram should have already been logged for this failure.
DLOG(ERROR) << "Unable to get a toast notification " << std::hex << hr;
return; return;
}
// Activation via user interaction with the toast is handled in // Activation via user interaction with the toast is handled in
// HandleActivation() by way of the notification_helper. // HandleActivation() by way of the notification_helper.
...@@ -408,8 +403,9 @@ class NotificationPlatformBridgeWinImpl ...@@ -408,8 +403,9 @@ class NotificationPlatformBridgeWinImpl
const std::string& notification_id) { const std::string& notification_id) {
DCHECK(notification_task_runner_->RunsTasksInCurrentSequence()); DCHECK(notification_task_runner_->RunsTasksInCurrentSequence());
mswr::ComPtr<winui::Notifications::IToastNotificationHistory> history; mswr::ComPtr<winui::Notifications::IToastNotificationHistory> history =
if (!GetIToastNotificationHistory(&history)) { GetIToastNotificationHistory();
if (!history) {
LogCloseHistogram(CloseStatus::GET_TOAST_HISTORY_FAILED); LogCloseHistogram(CloseStatus::GET_TOAST_HISTORY_FAILED);
DLOG(ERROR) << "Failed to get IToastNotificationHistory"; DLOG(ERROR) << "Failed to get IToastNotificationHistory";
return; return;
...@@ -431,9 +427,8 @@ class NotificationPlatformBridgeWinImpl ...@@ -431,9 +427,8 @@ class NotificationPlatformBridgeWinImpl
} }
} }
bool GetIToastNotificationHistory( mswr::ComPtr<winui::Notifications::IToastNotificationHistory>
winui::Notifications::IToastNotificationHistory** notification_history) GetIToastNotificationHistory() const WARN_UNUSED_RESULT {
const WARN_UNUSED_RESULT {
mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics> mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics>
toast_manager; toast_manager;
HRESULT hr = CreateActivationFactory( HRESULT hr = CreateActivationFactory(
...@@ -444,7 +439,7 @@ class NotificationPlatformBridgeWinImpl ...@@ -444,7 +439,7 @@ class NotificationPlatformBridgeWinImpl
HistoryStatus::CREATE_TOAST_NOTIFICATION_MANAGER_FAILED); HistoryStatus::CREATE_TOAST_NOTIFICATION_MANAGER_FAILED);
DLOG(ERROR) << "Unable to create the ToastNotificationManager " DLOG(ERROR) << "Unable to create the ToastNotificationManager "
<< std::hex << hr; << std::hex << hr;
return false; return nullptr;
} }
mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics2> mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics2>
...@@ -457,26 +452,30 @@ class NotificationPlatformBridgeWinImpl ...@@ -457,26 +452,30 @@ class NotificationPlatformBridgeWinImpl
HistoryStatus::QUERY_TOAST_MANAGER_STATISTICS2_FAILED); HistoryStatus::QUERY_TOAST_MANAGER_STATISTICS2_FAILED);
DLOG(ERROR) << "Failed to get IToastNotificationManagerStatics2 " DLOG(ERROR) << "Failed to get IToastNotificationManagerStatics2 "
<< std::hex << hr; << std::hex << hr;
return false; return nullptr;
} }
hr = toast_manager2->get_History(notification_history); mswr::ComPtr<winui::Notifications::IToastNotificationHistory>
notification_history;
hr = toast_manager2->get_History(notification_history.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
LogHistoryHistogram(HistoryStatus::GET_TOAST_HISTORY_FAILED); LogHistoryHistogram(HistoryStatus::GET_TOAST_HISTORY_FAILED);
DLOG(ERROR) << "Failed to get IToastNotificationHistory " << std::hex DLOG(ERROR) << "Failed to get IToastNotificationHistory " << std::hex
<< hr; << hr;
return false; return nullptr;
} }
LogHistoryHistogram(HistoryStatus::SUCCESS); LogHistoryHistogram(HistoryStatus::SUCCESS);
return true;
return notification_history;
} }
std::vector<mswr::ComPtr<winui::Notifications::IToastNotification>> std::vector<mswr::ComPtr<winui::Notifications::IToastNotification>>
GetDisplayedFromActionCenter(const std::string& profile_id, GetDisplayedFromActionCenter(const std::string& profile_id,
bool incognito) const { bool incognito) const {
mswr::ComPtr<winui::Notifications::IToastNotificationHistory> history; mswr::ComPtr<winui::Notifications::IToastNotificationHistory> history =
if (!GetIToastNotificationHistory(&history)) { GetIToastNotificationHistory();
if (!history) {
LogGetDisplayedStatus(GetDisplayedStatus::GET_TOAST_HISTORY_FAILED); LogGetDisplayedStatus(GetDisplayedStatus::GET_TOAST_HISTORY_FAILED);
DLOG(ERROR) << "Failed to get IToastNotificationHistory"; DLOG(ERROR) << "Failed to get IToastNotificationHistory";
return {}; return {};
...@@ -920,13 +919,12 @@ void NotificationPlatformBridgeWin::SetNotifierForTesting( ...@@ -920,13 +919,12 @@ void NotificationPlatformBridgeWin::SetNotifierForTesting(
NotificationPlatformBridgeWinImpl::notifier_for_testing_ = notifier; NotificationPlatformBridgeWinImpl::notifier_for_testing_ = notifier;
} }
HRESULT NotificationPlatformBridgeWin::GetToastNotificationForTesting( mswr::ComPtr<winui::Notifications::IToastNotification>
NotificationPlatformBridgeWin::GetToastNotificationForTesting(
const message_center::Notification& notification, const message_center::Notification& notification,
const NotificationTemplateBuilder& notification_template_builder, const NotificationTemplateBuilder& notification_template_builder,
const std::string& profile_id, const std::string& profile_id,
bool incognito, bool incognito) {
winui::Notifications::IToastNotification** toast_notification) { return impl_->GetToastNotification(
return impl_->GetToastNotification(notification, notification, notification_template_builder, profile_id, incognito);
notification_template_builder, profile_id,
incognito, toast_notification);
} }
...@@ -82,12 +82,12 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge { ...@@ -82,12 +82,12 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
// Obtain an IToastNotification interface from a given XML (provided by the // Obtain an IToastNotification interface from a given XML (provided by the
// NotificationTemplateBuilder). For testing use only. // NotificationTemplateBuilder). For testing use only.
HRESULT GetToastNotificationForTesting( Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotification>
GetToastNotificationForTesting(
const message_center::Notification& notification, const message_center::Notification& notification,
const NotificationTemplateBuilder& notification_template_builder, const NotificationTemplateBuilder& notification_template_builder,
const std::string& profile_id, const std::string& profile_id,
bool incognito, bool incognito);
ABI::Windows::UI::Notifications::IToastNotification** toast_notification);
scoped_refptr<NotificationPlatformBridgeWinImpl> impl_; scoped_refptr<NotificationPlatformBridgeWinImpl> impl_;
......
...@@ -54,12 +54,11 @@ class NotificationPlatformBridgeWinTest : public testing::Test { ...@@ -54,12 +54,11 @@ class NotificationPlatformBridgeWinTest : public testing::Test {
std::make_unique<NotificationPlatformBridgeWin>()) {} std::make_unique<NotificationPlatformBridgeWin>()) {}
~NotificationPlatformBridgeWinTest() override = default; ~NotificationPlatformBridgeWinTest() override = default;
HRESULT GetToast( mswr::ComPtr<winui::Notifications::IToastNotification2> GetToast(
const NotificationLaunchId& launch_id, const NotificationLaunchId& launch_id,
bool renotify, bool renotify,
const std::string& profile_id, const std::string& profile_id,
bool incognito, bool incognito) {
mswr::ComPtr<winui::Notifications::IToastNotification2>* toast2) {
GURL origin(kOrigin); GURL origin(kOrigin);
auto notification = std::make_unique<message_center::Notification>( auto notification = std::make_unique<message_center::Notification>(
message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, L"title", message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, L"title",
...@@ -72,22 +71,22 @@ class NotificationPlatformBridgeWinTest : public testing::Test { ...@@ -72,22 +71,22 @@ class NotificationPlatformBridgeWinTest : public testing::Test {
NotificationTemplateBuilder::Build( NotificationTemplateBuilder::Build(
image_retainer->AsWeakPtr(), launch_id, profile_id, *notification); image_retainer->AsWeakPtr(), launch_id, profile_id, *notification);
mswr::ComPtr<winui::Notifications::IToastNotification> toast; mswr::ComPtr<winui::Notifications::IToastNotification> toast =
HRESULT hr =
notification_platform_bridge_win_->GetToastNotificationForTesting( notification_platform_bridge_win_->GetToastNotificationForTesting(
*notification, *builder, profile_id, incognito, &toast); *notification, *builder, profile_id, incognito);
if (FAILED(hr)) { if (!toast) {
LOG(ERROR) << "GetToastNotificationForTesting failed"; LOG(ERROR) << "GetToastNotificationForTesting failed";
return hr; return nullptr;
} }
hr = toast.As<winui::Notifications::IToastNotification2>(toast2); mswr::ComPtr<winui::Notifications::IToastNotification2> toast2;
HRESULT hr = toast.As<winui::Notifications::IToastNotification2>(&toast2);
if (FAILED(hr)) { if (FAILED(hr)) {
LOG(ERROR) << "Converting to IToastNotification2 failed"; LOG(ERROR) << "Converting to IToastNotification2 failed";
return hr; return nullptr;
} }
return S_OK; return toast2;
} }
protected: protected:
...@@ -111,9 +110,10 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTag) { ...@@ -111,9 +110,10 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTag) {
NotificationLaunchId launch_id(kLaunchId); NotificationLaunchId launch_id(kLaunchId);
ASSERT_TRUE(launch_id.is_valid()); ASSERT_TRUE(launch_id.is_valid());
mswr::ComPtr<winui::Notifications::IToastNotification2> toast2; mswr::ComPtr<winui::Notifications::IToastNotification2> toast2 =
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, kProfileId, GetToast(launch_id, /*renotify=*/false, kProfileId,
/*incognito=*/false, &toast2)); /*incognito=*/false);
ASSERT_TRUE(toast2);
HSTRING hstring_group; HSTRING hstring_group;
ASSERT_HRESULT_SUCCEEDED(toast2->get_Group(&hstring_group)); ASSERT_HRESULT_SUCCEEDED(toast2->get_Group(&hstring_group));
...@@ -149,10 +149,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) { ...@@ -149,10 +149,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) {
// Different profiles, same incognito status -> Unique tags. // Different profiles, same incognito status -> Unique tags.
{ {
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile1", toastA = GetToast(launch_id, /*renotify=*/false, "Profile1",
/*incognito=*/true, &toastA)); /*incognito=*/true);
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile2", toastB = GetToast(launch_id, /*renotify=*/false, "Profile2",
/*incognito=*/true, &toastB)); /*incognito=*/true);
ASSERT_TRUE(toastA);
ASSERT_TRUE(toastB);
ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA)); ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA));
base::win::ScopedHString tagA(hstring_tagA); base::win::ScopedHString tagA(hstring_tagA);
...@@ -165,10 +168,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) { ...@@ -165,10 +168,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) {
// Same profile, different incognito status -> Unique tags. // Same profile, different incognito status -> Unique tags.
{ {
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile1", toastA = GetToast(launch_id, /*renotify=*/false, "Profile1",
/*incognito=*/true, &toastA)); /*incognito=*/true);
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile1", toastB = GetToast(launch_id, /*renotify=*/false, "Profile1",
/*incognito=*/false, &toastB)); /*incognito=*/false);
ASSERT_TRUE(toastA);
ASSERT_TRUE(toastB);
ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA)); ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA));
base::win::ScopedHString tagA(hstring_tagA); base::win::ScopedHString tagA(hstring_tagA);
...@@ -181,10 +187,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) { ...@@ -181,10 +187,13 @@ TEST_F(NotificationPlatformBridgeWinTest, GroupAndTagUniqueness) {
// Same profile, same incognito status -> Identical tags. // Same profile, same incognito status -> Identical tags.
{ {
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile1", toastA = GetToast(launch_id, /*renotify=*/false, "Profile1",
/*incognito=*/true, &toastA)); /*incognito=*/true);
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, "Profile1", toastB = GetToast(launch_id, /*renotify=*/false, "Profile1",
/*incognito=*/true, &toastB)); /*incognito=*/true);
ASSERT_TRUE(toastA);
ASSERT_TRUE(toastB);
ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA)); ASSERT_HRESULT_SUCCEEDED(toastA->get_Tag(&hstring_tagA));
base::win::ScopedHString tagA(hstring_tagA); base::win::ScopedHString tagA(hstring_tagA);
...@@ -218,10 +227,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) { ...@@ -218,10 +227,12 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) {
// Make sure this works a toast is not suppressed when no notifications are // Make sure this works a toast is not suppressed when no notifications are
// registered. // registered.
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, kProfileId, toast2 = GetToast(launch_id, /*renotify=*/false, kProfileId,
/*incognito=*/false, &toast2)); /*incognito=*/false);
ASSERT_TRUE(toast2);
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_FALSE(suppress); ASSERT_FALSE(suppress);
toast2.Reset();
// Register a single notification with a specific tag. // Register a single notification with a specific tag.
std::string tag_data = std::string(kNotificationId) + "|" + kProfileId + "|0"; std::string tag_data = std::string(kNotificationId) + "|" + kProfileId + "|0";
...@@ -232,16 +243,20 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) { ...@@ -232,16 +243,20 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) {
L"<toast launch=\"0|0|Default|0|https://foo.com/|id\"></toast>", tag)); L"<toast launch=\"0|0|Default|0|https://foo.com/|id\"></toast>", tag));
// Request this notification with renotify true (should not be suppressed). // Request this notification with renotify true (should not be suppressed).
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/true, kProfileId, toast2 = GetToast(launch_id, /*renotify=*/true, kProfileId,
/*incognito=*/false, &toast2)); /*incognito=*/false);
ASSERT_TRUE(toast2);
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_FALSE(suppress); ASSERT_FALSE(suppress);
toast2.Reset();
// Request this notification with renotify false (should be suppressed). // Request this notification with renotify false (should be suppressed).
ASSERT_HRESULT_SUCCEEDED(GetToast(launch_id, /*renotify=*/false, kProfileId, toast2 = GetToast(launch_id, /*renotify=*/false, kProfileId,
/*incognito=*/false, &toast2)); /*incognito=*/false);
ASSERT_TRUE(toast2);
ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress)); ASSERT_HRESULT_SUCCEEDED(toast2->get_SuppressPopup(&suppress));
ASSERT_TRUE(suppress); ASSERT_TRUE(suppress);
toast2.Reset();
notification_platform_bridge_win_->SetDisplayedNotificationsForTesting( notification_platform_bridge_win_->SetDisplayedNotificationsForTesting(
nullptr); nullptr);
......
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