diff --git a/dev/AppNotifications/AppNotificationActivatedEventArgs.cpp b/dev/AppNotifications/AppNotificationActivatedEventArgs.cpp new file mode 100644 index 0000000000..8bceba0006 --- /dev/null +++ b/dev/AppNotifications/AppNotificationActivatedEventArgs.cpp @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include "AppNotificationActivatedEventArgs.h" +#include "Microsoft.Windows.AppNotifications.AppNotificationActivatedEventArgs.g.cpp" +#include "AppNotificationBuilder/AppNotificationBuilderUtility.h" + +namespace winrt::Microsoft::Windows::AppNotifications::implementation +{ + winrt::Windows::Foundation::Collections::IMap AppNotificationActivatedEventArgs::DecodeArguments(std::wstring arguments) + { + auto result{ winrt::single_threaded_map() }; + + std::vector pairs{}; + size_t pos{ 0 }; + + // Separate the key/value pairs by ';' as the delimiter + while ((pos = arguments.find(L';')) != std::wstring::npos) + { + pairs.push_back(arguments.substr(0, pos)); + arguments.erase(0, pos + 1); + } + + // Need to push back final string + pairs.push_back(arguments); + + for (auto pair : pairs) + { + // Get the key/value individual values separated by '=' + pos = pair.find(L'='); + if (pos == std::wstring::npos) + { + result.Insert(Decode(pair).c_str(), L""); + } + else + { + result.Insert(Decode(pair.substr(0, pos)).c_str(), Decode(pair.substr(pos + 1)).c_str()); + } + } + return result; + } +} diff --git a/dev/AppNotifications/AppNotificationActivatedEventArgs.h b/dev/AppNotifications/AppNotificationActivatedEventArgs.h index fe109d3709..7c9d400d01 100644 --- a/dev/AppNotifications/AppNotificationActivatedEventArgs.h +++ b/dev/AppNotifications/AppNotificationActivatedEventArgs.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. #pragma once @@ -10,12 +10,17 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation { AppNotificationActivatedEventArgs() = default; - AppNotificationActivatedEventArgs(winrt::hstring const& arguments, winrt::Windows::Foundation::Collections::IMap const& userInput) : m_arguments(arguments), m_userInput(userInput) {}; - winrt::hstring Argument() { return m_arguments; }; + AppNotificationActivatedEventArgs(winrt::hstring const& argument, winrt::Windows::Foundation::Collections::IMap const& userInput) + : m_argument(argument), m_userInput(userInput), m_arguments(DecodeArguments(argument.c_str())) {}; + winrt::hstring Argument() { return m_argument; }; winrt::Windows::Foundation::Collections::IMap UserInput() { return m_userInput; }; + winrt::Windows::Foundation::Collections::IMap Arguments() { return m_arguments; }; private: - winrt::hstring m_arguments; + winrt::Windows::Foundation::Collections::IMap DecodeArguments(std::wstring arguments); + + winrt::hstring m_argument; winrt::Windows::Foundation::Collections::IMap m_userInput; + winrt::Windows::Foundation::Collections::IMap m_arguments{ nullptr }; }; } diff --git a/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilder.cpp b/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilder.cpp index 1982306d7e..46d2510564 100644 --- a/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilder.cpp +++ b/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilder.cpp @@ -31,7 +31,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { THROW_HR_IF_MSG(E_INVALIDARG, key.empty(), "You must provide a key when adding an argument"); - m_arguments.Insert(key, value); + m_arguments.Insert(EncodeArgument(key.c_str()), EncodeArgument(value.c_str())); return *this; } @@ -64,7 +64,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { THROW_HR_IF_MSG(E_INVALIDARG, m_textLines.size() >= c_maxTextElements, "Maximum number of text elements added"); - m_textLines.push_back(wil::str_printf(L"%ls", text.c_str()).c_str()); + m_textLines.push_back(wil::str_printf(L"%ls", EncodeXml(text).c_str()).c_str()); return *this; } @@ -73,7 +73,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, m_textLines.size() >= c_maxTextElements, "Maximum number of text elements added"); std::wstring props{ properties.as().ToString() }; - m_textLines.push_back(wil::str_printf(L"%ls%ls", props.c_str(), text.c_str()).c_str()); + m_textLines.push_back(wil::str_printf(L"%ls%ls", props.c_str(), EncodeXml(text).c_str()).c_str()); if (properties.IncomingCallAlignment()) { @@ -84,7 +84,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationBuilder AppNotificationBuilder::SetAttributionText(hstring const& text) { - m_attributionText = wil::str_printf(L"%ls", text.c_str()); + m_attributionText = wil::str_printf(L"%ls", EncodeXml(text).c_str()); return *this; } @@ -92,7 +92,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { THROW_HR_IF_MSG(E_INVALIDARG, language.empty(), "You must provide a language calling SetAttributionText"); - m_attributionText = wil::str_printf(L"%ls", language.c_str(), text.c_str()); + m_attributionText = wil::str_printf(L"%ls", language.c_str(), EncodeXml(text).c_str()); return *this; } @@ -121,7 +121,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, alternateText.empty(), "You must provide an alternate text string calling SetInlineImage"); std::wstring hintCrop { imageCrop == AppNotificationImageCrop::Circle ? L" hint-crop='circle'" : L"" }; - m_inlineImage = wil::str_printf(L"%ls", imageUri.ToString().c_str(), alternateText.c_str(), hintCrop.c_str()); + m_inlineImage = wil::str_printf(L"%ls", imageUri.ToString().c_str(), EncodeXml(alternateText).c_str(), hintCrop.c_str()); return *this; } @@ -151,7 +151,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, alternateText.empty(), "You must provide an alternate text string calling SetAppLogoOverride"); std::wstring hintCrop{ imageCrop == AppNotificationImageCrop::Circle ? L" hint-crop='circle'" : L"" }; - m_appLogoOverride = wil::str_printf(L"%ls", imageUri.ToString().c_str(), alternateText.c_str(), hintCrop.c_str()); + m_appLogoOverride = wil::str_printf(L"%ls", imageUri.ToString().c_str(), EncodeXml(alternateText).c_str(), hintCrop.c_str()); return *this; } @@ -166,7 +166,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { THROW_HR_IF_MSG(E_INVALIDARG, alternateText.empty(), "You must provide an alternate text string calling SetHeroImage"); - m_heroImage = wil::str_printf(L"%ls", imageUri.ToString().c_str(), alternateText.c_str()); + m_heroImage = wil::str_printf(L"%ls", imageUri.ToString().c_str(), EncodeXml(alternateText).c_str()); return *this; } @@ -213,7 +213,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, id.empty(), "You must provide an id for the TextBox"); - m_textBoxList.push_back(wil::str_printf(L"", id.c_str())); + m_textBoxList.push_back(wil::str_printf(L"", EncodeXml(id).c_str())); return *this; } @@ -222,7 +222,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation ThrowIfMaxInputItemsExceeded(); THROW_HR_IF_MSG(E_INVALIDARG, id.empty(), "You must provide an id for the TextBox"); - m_textBoxList.push_back(wil::str_printf(L"", id.c_str(), placeHolderText.c_str(), title.c_str())); + m_textBoxList.push_back(wil::str_printf(L"", EncodeXml(id).c_str(), EncodeXml(placeHolderText).c_str(), EncodeXml(title).c_str())); return *this; } diff --git a/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilderUtility.h b/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilderUtility.h index 000917cac3..5d270b80c1 100644 --- a/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilderUtility.h +++ b/dev/AppNotifications/AppNotificationBuilder/AppNotificationBuilderUtility.h @@ -1,13 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -#pragma once #include "pch.h" #include "winrt/Microsoft.Windows.AppNotifications.Builder.h" +#include +#include +#include +#include constexpr size_t c_maxAppNotificationPayload{ 5120 }; constexpr uint8_t c_maxTextElements{ 3 }; constexpr uint8_t c_maxButtonElements{ 5 }; +constexpr size_t c_maxEncodingSize{ 3 }; constexpr uint8_t c_maxTextInputElements{ 5 }; constexpr uint8_t c_maxSelectionElements{ 5 }; @@ -16,6 +20,24 @@ namespace AppNotificationBuilder using namespace winrt::Microsoft::Windows::AppNotifications::Builder; } +inline std::unordered_map GetXmlEscapeEncodings() +{ + static std::unordered_map encodings = { { L'&', L"&"}, { L'\"', L"""}, {L'<', L"<"}, {L'>', L">"}, {L'\'', L"'"}}; + return encodings; +} + +inline std::unordered_map GetPercentEncodings() +{ + static std::unordered_map encodings = {{ L'%', L"%25"}, {L';', L"%3B"}, {L'=', L"%3D"} }; + return encodings; +} + +inline std::unordered_map GetPercentEncodingsReverse() +{ + static std::unordered_map encodings = { { L"%25", L'%' }, {L"%3B", L';' }, { L"%3D", L'=' } }; + return encodings; +} + inline PCWSTR GetWinSoundEventString(AppNotificationBuilder::AppNotificationSoundEvent soundEvent) { switch (soundEvent) @@ -72,3 +94,73 @@ inline PCWSTR GetWinSoundEventString(AppNotificationBuilder::AppNotificationSoun return L"ms-winsoundevent:Notification.Default"; } } + +inline std::wstring EncodeArgument(std::wstring const& value) +{ + std::wstring encodedValue{}; + + auto percentEncodings{ GetPercentEncodings() }; + auto xmlEncodings{ GetXmlEscapeEncodings() }; + for (auto ch : value) + { + if (percentEncodings.find(ch) != percentEncodings.end()) + { + encodedValue.append(percentEncodings[ch]); + } + else if (xmlEncodings.find(ch) != xmlEncodings.end()) + { + encodedValue.append(xmlEncodings[ch]); + } + else + { + encodedValue.push_back(ch); + } + } + + return encodedValue; +} + +inline std::wstring EncodeXml(winrt::hstring const& value) +{ + std::wstring encodedValue{}; + + auto xmlEncodings{ GetXmlEscapeEncodings() }; + for (auto ch : value) + { + if (xmlEncodings.find(ch) != xmlEncodings.end()) + { + encodedValue.append(xmlEncodings[ch]); + } + else + { + encodedValue.push_back(ch); + } + } + + return encodedValue; +} + +// Decoding process based off the Windows Community Toolkit: +// https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/rel/7.1.0/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastArguments.cs#L389inline +inline std::wstring Decode(std::wstring const& value) +{ + std::wstring result{}; + auto percentEncodings{ GetPercentEncodingsReverse() }; + + // Need to unescape special characters + for (size_t index = 0; index < value.size();) + { + std::wstring curr{ value.substr(index, c_maxEncodingSize) }; + if (percentEncodings.find(curr) != percentEncodings.end()) + { + result.push_back(percentEncodings[curr]); + index += c_maxEncodingSize; + } + else + { + result.push_back(value.at(index)); + index++; + } + } + return result; +} diff --git a/dev/AppNotifications/AppNotificationBuilder/AppNotificationButton.cpp b/dev/AppNotifications/AppNotificationBuilder/AppNotificationButton.cpp index 64c1471e26..dafb587ea1 100644 --- a/dev/AppNotifications/AppNotificationBuilder/AppNotificationButton.cpp +++ b/dev/AppNotifications/AppNotificationBuilder/AppNotificationButton.cpp @@ -5,6 +5,7 @@ #include "AppNotificationButton.h" #include "Microsoft.Windows.AppNotifications.Builder.AppNotificationButton.g.cpp" #include +#include "AppNotificationBuilderUtility.h" namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { @@ -25,7 +26,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, key.empty(), "You must provide a key when adding an argument"); THROW_HR_IF_MSG(E_INVALIDARG, m_protocolUri, "You cannot add an argument after calling SetInvokeUri"); - m_arguments.Insert(key, value); + m_arguments.Insert(EncodeArgument(key.c_str()), EncodeArgument(value.c_str())); return *this; } @@ -37,7 +38,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationButton AppNotificationButton::SetToolTip(winrt::hstring const& value) { - m_toolTip = value; + m_toolTip = EncodeXml(value.c_str()).c_str(); return *this; } @@ -55,7 +56,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationButton AppNotificationButton::SetInputId(winrt::hstring const& value) { - m_inputId = value; + m_inputId = EncodeXml(value.c_str()).c_str(); return *this; } diff --git a/dev/AppNotifications/AppNotificationBuilder/AppNotificationComboBox.cpp b/dev/AppNotifications/AppNotificationBuilder/AppNotificationComboBox.cpp index 51bba27799..0004eccb6d 100644 --- a/dev/AppNotifications/AppNotificationBuilder/AppNotificationComboBox.cpp +++ b/dev/AppNotifications/AppNotificationBuilder/AppNotificationComboBox.cpp @@ -8,9 +8,10 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { - AppNotificationComboBox::AppNotificationComboBox(hstring const& id) : m_id(id) + AppNotificationComboBox::AppNotificationComboBox(hstring const& id) { THROW_HR_IF_MSG(E_INVALIDARG, id.empty(), "You must provide an id for the ComboBox"); + m_id = EncodeXml(id).c_str(); }; winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationComboBox AppNotificationComboBox::AddItem(winrt::hstring const& id, winrt::hstring const& content) @@ -18,14 +19,14 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation THROW_HR_IF_MSG(E_INVALIDARG, m_items.Size() >= c_maxSelectionElements, "Maximum number of items added"); THROW_HR_IF_MSG(E_INVALIDARG, id.empty(), "You must provide an id for the item"); - m_items.Insert(id, content); + m_items.Insert(EncodeXml(id).c_str(), EncodeXml(content).c_str()); return *this; } winrt::Microsoft::Windows::AppNotifications::Builder::AppNotificationComboBox AppNotificationComboBox::SetTitle(winrt::hstring const& value) { - m_title = value; + m_title = EncodeXml(value).c_str(); return *this; } @@ -34,7 +35,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { THROW_HR_IF_MSG(E_INVALIDARG, id.empty(), "You must provide an id for the selected item"); - m_selectedItem = id; + m_selectedItem = EncodeXml(id).c_str(); return *this; } diff --git a/dev/AppNotifications/AppNotificationBuilder/AppNotificationProgressBar.cpp b/dev/AppNotifications/AppNotificationBuilder/AppNotificationProgressBar.cpp index f2380a2cf6..39002ae4ea 100644 --- a/dev/AppNotifications/AppNotificationBuilder/AppNotificationProgressBar.cpp +++ b/dev/AppNotifications/AppNotificationBuilder/AppNotificationProgressBar.cpp @@ -4,6 +4,7 @@ #include "pch.h" #include "AppNotificationProgressBar.h" #include "Microsoft.Windows.AppNotifications.Builder.AppNotificationProgressBar.g.cpp" +#include "AppNotificationBuilderUtility.h" namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation { @@ -16,13 +17,13 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation void AppNotificationProgressBar::Title(winrt::hstring const& value) { - m_title = value; + m_title = EncodeXml(value).c_str(); m_titleBindMode = BindMode::Value; } void AppNotificationProgressBar::Status(winrt::hstring const& value) { - m_status = value; + m_status = EncodeXml(value).c_str(); m_statusBindMode = BindMode::Value; } @@ -36,7 +37,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::Builder::implementation void AppNotificationProgressBar::ValueStringOverride(winrt::hstring const& value) { - m_valueStringOverride = value; + m_valueStringOverride = EncodeXml(value).c_str(); m_valueStringOverrideBindMode = BindMode::Value; } diff --git a/dev/AppNotifications/AppNotifications.idl b/dev/AppNotifications/AppNotifications.idl index 11cea33beb..3b439b8ac9 100644 --- a/dev/AppNotifications/AppNotifications.idl +++ b/dev/AppNotifications/AppNotifications.idl @@ -4,7 +4,7 @@ import "..\AppLifecycle\AppLifecycle.idl"; namespace Microsoft.Windows.AppNotifications { - [contractversion(2)] + [contractversion(3)] apicontract AppNotificationsContract {} // Event args for the Notification Activation @@ -16,6 +16,10 @@ namespace Microsoft.Windows.AppNotifications // The data from the input elements of a Notification like a TextBox Windows.Foundation.Collections.IMap UserInput{ get; }; + + // Arguments from the invoked button built from AppNotificationBuilder + [contract(AppNotificationsContract, 3)] + Windows.Foundation.Collections.IMap Arguments{ get; }; } // Notification Progress Data diff --git a/dev/AppNotifications/AppNotifications.vcxitems b/dev/AppNotifications/AppNotifications.vcxitems index 63b054a559..72a89d2640 100644 --- a/dev/AppNotifications/AppNotifications.vcxitems +++ b/dev/AppNotifications/AppNotifications.vcxitems @@ -26,6 +26,7 @@ + diff --git a/test/AppNotificationBuilderTests/APITests.cpp b/test/AppNotificationBuilderTests/APITests.cpp index e1d64bc29d..0c12984176 100644 --- a/test/AppNotificationBuilderTests/APITests.cpp +++ b/test/AppNotificationBuilderTests/APITests.cpp @@ -3,7 +3,10 @@ #include "pch.h" -using namespace winrt::Microsoft::Windows::AppNotifications::Builder; +namespace winrt +{ + using namespace winrt::Microsoft::Windows::AppNotifications::Builder; +} namespace Test::AppNotification::Builder { @@ -47,7 +50,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderDefault) { - auto builder{ AppNotificationBuilder() }; + auto builder{ winrt::AppNotificationBuilder() }; auto expected{ L""}; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); } @@ -62,7 +65,7 @@ namespace Test::AppNotification::Builder std::time_t time{ mktime(&dateTime) }; auto timeStamp{ winrt::clock::from_time_t(time) }; - auto builder{ AppNotificationBuilder().SetTimeStamp(timeStamp) }; + auto builder{ winrt::AppNotificationBuilder().SetTimeStamp(timeStamp) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -70,7 +73,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddOneArgument) { - auto builder{ AppNotificationBuilder().AddArgument(L"key", L"value") }; + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"key", L"value") }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -78,7 +81,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTwoArguments) { - auto builder{ AppNotificationBuilder().AddArgument(L"key1", L"value1").AddArgument(L"key2", L"value2") }; + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"key1", L"value1").AddArgument(L"key2", L"value2") }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -86,20 +89,54 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddArgumentEmptyValue) { - auto builder{ AppNotificationBuilder().AddArgument(L"key", L"") }; + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"key", L"") }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); } + TEST_METHOD(AppNotificationBuilderAddArgumentWithPercentChar) + { + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"k%ey", L"v%alue") }; + auto expected{ L"" }; + + VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); + } + + TEST_METHOD(AppNotificationBuilderAddArgumentWithEqualChar) + { + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"k=ey", L"v=alue") }; + auto expected{ L"" }; + + VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); + } + + TEST_METHOD(AppNotificationBuilderAddArgumentWithSemicolonChar) + { + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"k;ey", L"v;alue") }; + auto expected{ L"" }; + + VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); + } + + TEST_METHOD(DecodeArguments) + { + VERIFY_ARE_EQUAL(Decode(L"key%3B"), L"key;"); + VERIFY_ARE_EQUAL(Decode(L"key%3D"), L"key="); + VERIFY_ARE_EQUAL(Decode(L"key%25"), L"key%"); + VERIFY_ARE_EQUAL(Decode(L"key%3B%3D%25"), L"key;=%"); + VERIFY_ARE_EQUAL(Decode(L"%25%25%25"), L"%%%"); + + } + TEST_METHOD(AppNotificationBuilderAddArgumentEmptyKey) { - VERIFY_THROWS_HR(AppNotificationBuilder().AddArgument(L"", L""), E_INVALIDARG); + VERIFY_THROWS_HR(winrt::AppNotificationBuilder().AddArgument(L"", L""), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderSetReminderScenario) { - auto builder{ AppNotificationBuilder().SetScenario(AppNotificationScenario::Reminder) }; + auto builder{ winrt::AppNotificationBuilder().SetScenario(winrt::AppNotificationScenario::Reminder) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -107,7 +144,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAlarmScenario) { - auto builder{ AppNotificationBuilder().SetScenario(AppNotificationScenario::Alarm) }; + auto builder{ winrt::AppNotificationBuilder().SetScenario(winrt::AppNotificationScenario::Alarm) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -115,7 +152,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetIncomingCallScenario) { - auto builder{ AppNotificationBuilder().SetScenario(AppNotificationScenario::IncomingCall) }; + auto builder{ winrt::AppNotificationBuilder().SetScenario(winrt::AppNotificationScenario::IncomingCall) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -123,7 +160,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetUrgentScenario) { - auto builder{ AppNotificationBuilder().SetScenario(AppNotificationScenario::Urgent) }; + auto builder{ winrt::AppNotificationBuilder().SetScenario(winrt::AppNotificationScenario::Urgent) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -131,7 +168,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddText) { - auto builder{ AppNotificationBuilder().AddText(L"content") }; + auto builder{ winrt::AppNotificationBuilder().AddText(L"content") }; auto expected{ L"content" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -139,8 +176,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextWithLanguage) { - auto builder{ AppNotificationBuilder() - .AddText(L"content", AppNotificationTextProperties() + auto builder{ winrt::AppNotificationBuilder() + .AddText(L"content", winrt::AppNotificationTextProperties() .SetLanguage(L"en-US")) }; auto expected{ L"content" }; @@ -150,8 +187,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextWithMaxLines) { - auto builder{ AppNotificationBuilder() - .AddText(L"content", AppNotificationTextProperties() + auto builder{ winrt::AppNotificationBuilder() + .AddText(L"content", winrt::AppNotificationTextProperties() .SetMaxLines(2)) }; auto expected{ L"content" }; @@ -161,8 +198,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextWithCallScenarioAlign) { - auto builder{ AppNotificationBuilder() - .AddText(L"content", AppNotificationTextProperties() + auto builder{ winrt::AppNotificationBuilder() + .AddText(L"content", winrt::AppNotificationTextProperties() .SetIncomingCallAlignment()) }; auto expected{ L"content" }; @@ -172,8 +209,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextWithAllProperties) { - auto builder{ AppNotificationBuilder() - .AddText(L"content", AppNotificationTextProperties() + auto builder{ winrt::AppNotificationBuilder() + .AddText(L"content", winrt::AppNotificationTextProperties() .SetLanguage(L"en-US") .SetMaxLines(2) .SetIncomingCallAlignment()) @@ -185,7 +222,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextThrows) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddText(L"content") .AddText(L"content") .AddText(L"content") @@ -194,7 +231,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddAttributionText) { - auto builder{ AppNotificationBuilder().SetAttributionText(L"content") }; + auto builder{ winrt::AppNotificationBuilder().SetAttributionText(L"content") }; auto expected{ L"content" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -202,7 +239,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddAttributionTextWithLanguage) { - auto builder{ AppNotificationBuilder().SetAttributionText(L"content", L"en-US")}; + auto builder{ winrt::AppNotificationBuilder().SetAttributionText(L"content", L"en-US")}; auto expected{ L"content" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -210,7 +247,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetInlineImage) { - auto builder{ AppNotificationBuilder().SetInlineImage(c_sampleUri) }; + auto builder{ winrt::AppNotificationBuilder().SetInlineImage(c_sampleUri) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -218,7 +255,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetInlineImageWithProperties) { - auto builder{ AppNotificationBuilder().SetInlineImage(c_sampleUri, AppNotificationImageCrop::Circle, L"altText")}; + auto builder{ winrt::AppNotificationBuilder().SetInlineImage(c_sampleUri, winrt::AppNotificationImageCrop::Circle, L"altText")}; auto expected{ L"altText" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -226,7 +263,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAppLogoOverride) { - auto builder{ AppNotificationBuilder().SetAppLogoOverride(c_sampleUri) }; + auto builder{ winrt::AppNotificationBuilder().SetAppLogoOverride(c_sampleUri) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -234,7 +271,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAppLogoOverrideProperties) { - auto builder{ AppNotificationBuilder().SetAppLogoOverride(c_sampleUri, AppNotificationImageCrop::Circle, L"altText") }; + auto builder{ winrt::AppNotificationBuilder().SetAppLogoOverride(c_sampleUri, winrt::AppNotificationImageCrop::Circle, L"altText") }; auto expected{ L"altText" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -242,7 +279,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetHeroImage) { - auto builder{ AppNotificationBuilder().SetHeroImage(c_sampleUri) }; + auto builder{ winrt::AppNotificationBuilder().SetHeroImage(c_sampleUri) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -250,7 +287,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetHeroImageWithAlt) { - auto builder{ AppNotificationBuilder().SetHeroImage(c_sampleUri, L"altText") }; + auto builder{ winrt::AppNotificationBuilder().SetHeroImage(c_sampleUri, L"altText") }; auto expected{ L"altText" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -258,8 +295,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddButton) { - auto builder{ AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + auto builder{ winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .AddArgument(L"key", L"value")) }; auto expected{ L"" }; @@ -269,8 +306,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddButtonWithPlacement) { - auto builder{ AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + auto builder{ winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .AddArgument(L"key", L"value") .SetContextMenuPlacement()) }; @@ -281,19 +318,19 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderTooManyButtons) { - VERIFY_THROWS_HR(AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content").AddArgument(L"key1", L"value1")) - .AddButton(AppNotificationButton(L"content").AddArgument(L"key2", L"value2")) - .AddButton(AppNotificationButton(L"content").AddArgument(L"key3", L"value3")) - .AddButton(AppNotificationButton(L"content").AddArgument(L"key4", L"value4")) - .AddButton(AppNotificationButton(L"content").AddArgument(L"key5", L"value5")) - .AddButton(AppNotificationButton(L"content").AddArgument(L"key6", L"value6")), E_INVALIDARG); + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key1", L"value1")) + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key2", L"value2")) + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key3", L"value3")) + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key4", L"value4")) + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key5", L"value5")) + .AddButton(winrt::AppNotificationButton(L"content").AddArgument(L"key6", L"value6")), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderAddButtonWithProtocolActivation) { - auto builder{ AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + auto builder{ winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .SetInvokeUri(c_sampleUri)) }; auto expected{ L"" }; @@ -303,10 +340,10 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddButtonWithProperties) { - auto builder{ AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + auto builder{ winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .AddArgument(L"key", L"value") - .SetButtonStyle(AppNotificationButtonStyle::Success) + .SetButtonStyle(winrt::AppNotificationButtonStyle::Success) .SetIcon(c_sampleUri) .SetInputId(L"inputId") .SetToolTip(L"toolTip")) @@ -318,27 +355,27 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddButtonWithEmptyKey) { - VERIFY_THROWS_HR(AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .AddArgument(L"", L"value")), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderAddButtonWithArgumentAndProtocol) { - VERIFY_THROWS_HR(AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .AddArgument(L"key", L"value") .SetInvokeUri(c_sampleUri)), E_INVALIDARG); - VERIFY_THROWS_HR(AppNotificationBuilder() - .AddButton(AppNotificationButton(L"content") + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() + .AddButton(winrt::AppNotificationButton(L"content") .SetInvokeUri(c_sampleUri) .AddArgument(L"key", L"value")), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderSetAudioWithUri) { - auto builder{ AppNotificationBuilder() + auto builder{ winrt::AppNotificationBuilder() .SetAudioUri(c_sampleUri) }; auto expected{ L"" }; @@ -347,9 +384,9 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAudioWithUriAndDuration) { - auto builder{ AppNotificationBuilder() - .SetDuration(AppNotificationDuration::Long) - .SetAudioUri(c_sampleUri, AppNotificationAudioLooping::Loop) }; + auto builder{ winrt::AppNotificationBuilder() + .SetDuration(winrt::AppNotificationDuration::Long) + .SetAudioUri(c_sampleUri, winrt::AppNotificationAudioLooping::Loop) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -357,8 +394,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAudioWithSoundEvent) { - auto builder{ AppNotificationBuilder() - .SetAudioEvent(AppNotificationSoundEvent::Reminder) }; + auto builder{ winrt::AppNotificationBuilder() + .SetAudioEvent(winrt::AppNotificationSoundEvent::Reminder) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -366,9 +403,9 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderSetAudioWithSoundEventAndDuration) { - auto builder{ AppNotificationBuilder() - .SetDuration(AppNotificationDuration::Long) - .SetAudioEvent(AppNotificationSoundEvent::Reminder, AppNotificationAudioLooping::Loop) }; + auto builder{ winrt::AppNotificationBuilder() + .SetDuration(winrt::AppNotificationDuration::Long) + .SetAudioEvent(winrt::AppNotificationSoundEvent::Reminder, winrt::AppNotificationAudioLooping::Loop) }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -376,7 +413,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderMuteAudio) { - auto builder{ AppNotificationBuilder().MuteAudio() }; + auto builder{ winrt::AppNotificationBuilder().MuteAudio() }; auto expected{ L"" }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); @@ -384,41 +421,41 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderBuildNotificationWithTooLargePayload) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddText(std::wstring(5120, 'A').c_str()) .BuildNotification(), E_INVALIDARG); } TEST_METHOD(AppNotificationAddProgressBar) { - auto builder{ AppNotificationBuilder() + auto builder{ winrt::AppNotificationBuilder() .AddText(L"Downloading this week's new music...") - .AddProgressBar(AppNotificationProgressBar() + .AddProgressBar(winrt::AppNotificationProgressBar() .BindTitle() .BindValueStringOverride()) }; - auto expected{ L"Downloading this week's new music..." }; + auto expected{ L"Downloading this week's new music..." }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); } TEST_METHOD(AppNotificationAddMoreThanOneProgressBar) { - auto builder{ AppNotificationBuilder() + auto builder{ winrt::AppNotificationBuilder() .AddText(L"Downloading this week's new music...") - .AddProgressBar(AppNotificationProgressBar() + .AddProgressBar(winrt::AppNotificationProgressBar() .BindTitle() .BindValueStringOverride()) - .AddProgressBar(AppNotificationProgressBar() + .AddProgressBar(winrt::AppNotificationProgressBar() .SetValue(0.8) .SetStatus(L"Still downloading...")) }; - auto expected{ L"Downloading this week's new music..." }; + auto expected{ L"Downloading this week's new music..." }; VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); } TEST_METHOD(AppNotificationProgressBarDefaults) { - auto progressBar{ AppNotificationProgressBar() }; + auto progressBar{ winrt::AppNotificationProgressBar() }; auto expected{ L"" }; VERIFY_ARE_EQUAL(progressBar.as().ToString(), expected); @@ -426,7 +463,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationProgressBarSetSpecificValue) { - auto progressBar{ AppNotificationProgressBar() }; + auto progressBar{ winrt::AppNotificationProgressBar() }; progressBar.Value(0.8); auto expected{ L"" }; @@ -435,23 +472,23 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationProgressBarSetValueLargerThanOne) { - auto progressBar{ AppNotificationProgressBar() }; + auto progressBar{ winrt::AppNotificationProgressBar() }; VERIFY_THROWS_HR(progressBar.Value(1.01), E_INVALIDARG); - VERIFY_THROWS_HR(AppNotificationProgressBar().SetValue(1.01), E_INVALIDARG); + VERIFY_THROWS_HR(winrt::AppNotificationProgressBar().SetValue(1.01), E_INVALIDARG); } TEST_METHOD(AppNotificationProgressBarSetValueSmallerThanZero) { - auto progressBar{ AppNotificationProgressBar() }; + auto progressBar{ winrt::AppNotificationProgressBar() }; VERIFY_THROWS_HR(progressBar.Value(-0.1), E_INVALIDARG); - VERIFY_THROWS_HR(AppNotificationProgressBar().SetValue(-0.1), E_INVALIDARG); + VERIFY_THROWS_HR(winrt::AppNotificationProgressBar().SetValue(-0.1), E_INVALIDARG); } TEST_METHOD(AppNotificationProgressBarSetSpecificValueThenChangeToBind) { - auto progressBar{ AppNotificationProgressBar() }; + auto progressBar{ winrt::AppNotificationProgressBar() }; progressBar.Value(0.8); progressBar.BindValue(); auto expected{ L"" }; @@ -461,7 +498,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationProgressBarBindTitleThenChangeToSpecificText) { - auto progressBar{ AppNotificationProgressBar() + auto progressBar{ winrt::AppNotificationProgressBar() .BindTitle() .SetTitle(L"Specific title") }; auto expected{ L"" }; @@ -471,7 +508,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextBox) { - auto builder{ AppNotificationBuilder() + auto builder{ winrt::AppNotificationBuilder() .AddTextBox(L"input1") }; auto expected{ L"" }; @@ -480,19 +517,19 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextBoxWithEmptyId) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddTextBox(L""), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderAddTextBoxWithEmptyIdAndPlaceHolderTextAndTitle) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddTextBox(L"", L"placeholder text", L"title"), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderAddTooManyTextBoxes) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddTextBox(L"input1") .AddTextBox(L"input2") .AddTextBox(L"input3") @@ -503,7 +540,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTextBoxWithPlaceHolderTextAndTitle) { - auto builder{ AppNotificationBuilder() + auto builder{ winrt::AppNotificationBuilder() .AddTextBox(L"some input id", L"Some placeholder text", L"A Title")}; auto expected{ L"" }; @@ -512,8 +549,8 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddComboBox) { - auto builder{ AppNotificationBuilder() - .AddComboBox(AppNotificationComboBox(L"comboBox1") + auto builder{ winrt::AppNotificationBuilder() + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text") .AddItem(L"item2", L"item2 text") .AddItem(L"item3", L"item3 text") @@ -526,38 +563,38 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationBuilderAddTooManyComboBox) { - VERIFY_THROWS_HR(AppNotificationBuilder() + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() .AddTextBox(L"input1") .AddTextBox(L"input2") .AddTextBox(L"input3") - .AddComboBox(AppNotificationComboBox(L"comboBox1") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox2") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox2") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox3") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox3") .AddItem(L"item1", L"item1 text")), E_INVALIDARG); } TEST_METHOD(AppNotificationBuilderAddTooManyInputElements) { - VERIFY_THROWS_HR(AppNotificationBuilder() - .AddComboBox(AppNotificationComboBox(L"comboBox1") + VERIFY_THROWS_HR(winrt::AppNotificationBuilder() + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox2") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox2") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox3") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox3") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox4") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox4") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox5") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox5") .AddItem(L"item1", L"item1 text")) - .AddComboBox(AppNotificationComboBox(L"comboBox6") + .AddComboBox(winrt::AppNotificationComboBox(L"comboBox6") .AddItem(L"item1", L"item1 text")), E_INVALIDARG); } TEST_METHOD(AppNotificationComboBoxAddTooManySelectionItems) { - VERIFY_THROWS_HR(AppNotificationComboBox(L"comboBox1") + VERIFY_THROWS_HR(winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text") .AddItem(L"item2", L"item2 text") .AddItem(L"item3", L"item3 text") @@ -568,7 +605,7 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationComboBoxAddFiveSelectionItems) { - auto comboBox{ AppNotificationComboBox(L"comboBox1") + auto comboBox{ winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text") .AddItem(L"item2", L"item2 text") .AddItem(L"item3", L"item3 text") @@ -581,13 +618,13 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationComboBoxAddSelectionItemWithoutAnId) { - VERIFY_THROWS_HR(AppNotificationComboBox(L"comboBox1") + VERIFY_THROWS_HR(winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"", L"item text"), E_INVALIDARG); } TEST_METHOD(AppNotificationComboBoxAddTwoSelectionItemsWithSameId) { - auto comboBox{ AppNotificationComboBox(L"comboBox1") + auto comboBox{ winrt::AppNotificationComboBox(L"comboBox1") .AddItem(L"item1", L"item1 text") .AddItem(L"item1", L"item2 text") }; auto expected{ L"" }; @@ -597,13 +634,34 @@ namespace Test::AppNotification::Builder TEST_METHOD(AppNotificationComboBoxSetSelectedItemWithoutAnId) { - VERIFY_THROWS_HR(AppNotificationComboBox(L"comboBox1") + VERIFY_THROWS_HR(winrt::AppNotificationComboBox(L"comboBox1") .SetSelectedItem(L""), E_INVALIDARG); } TEST_METHOD(AppNotificationCreateComboBoxWithoutAnId) { - VERIFY_THROWS_HR(AppNotificationComboBox(L""), E_INVALIDARG); + VERIFY_THROWS_HR(winrt::AppNotificationComboBox(L""), E_INVALIDARG); + } + + TEST_METHOD(AppNotificationBuilderEscapeXmlCharacters) + { + auto builder{ winrt::AppNotificationBuilder().AddText(LR"(&"'<>)") }; + std::wstring expected{ L"&"'<>"}; + + VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); + } + + TEST_METHOD(AppNotificationBuilderArgumentsWithXmlCharacters) + { + auto builder{ winrt::AppNotificationBuilder() + .AddArgument(LR"(&;"='%<>)", L"") + .AddArgument(LR"(&"'<>)", L";=%")}; + + std::wstring expected{ L"" }; + VERIFY_ARE_EQUAL(builder.BuildNotification().Payload(), expected); + + VERIFY_ARE_EQUAL(Decode(LR"(&%3B"%3D'%25<>)"), LR"(&;"='%<>)"); + VERIFY_ARE_EQUAL(Decode(L"%3B%3D%25"), L";=%"); } }; } diff --git a/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj b/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj index 4810cb5fac..2d92e195b0 100644 --- a/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj +++ b/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj @@ -75,7 +75,7 @@ Use true pch.h - $(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL + $(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(RepoRoot)\Dev\AppNotifications\AppNotificationBuilder;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL $(RepoRoot);%(AdditionalIncludeDirectories) diff --git a/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj.filters b/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj.filters index 3ba3a909fe..bb2b67149b 100644 --- a/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj.filters +++ b/test/AppNotificationBuilderTests/AppNotificationBuilderTests.vcxproj.filters @@ -5,15 +5,27 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + {4b514c96-7ee8-44e5-aeb3-64c1bc0d6b91} + + + {9f96baa5-3d60-4ef4-9ff2-5a5fe8d7367b} + - - + + Source Files + + + Source Files + - + - + + Header Files + \ No newline at end of file diff --git a/test/AppNotificationBuilderTests/pch.h b/test/AppNotificationBuilderTests/pch.h index 63ec412adb..b673f9e3a1 100644 --- a/test/AppNotificationBuilderTests/pch.h +++ b/test/AppNotificationBuilderTests/pch.h @@ -43,6 +43,7 @@ #include #include +#include #include #include diff --git a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj index c12b365ef4..2ec99b98fc 100644 --- a/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj +++ b/test/TestApps/ToastNotificationsDemoApp/ToastNotificationsDemoApp.vcxproj @@ -211,6 +211,11 @@ true $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll + + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.AppNotifications.Builder.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll + diff --git a/test/TestApps/ToastNotificationsDemoApp/main.cpp b/test/TestApps/ToastNotificationsDemoApp/main.cpp index 71fb31c6e5..5b8f8db5fd 100644 --- a/test/TestApps/ToastNotificationsDemoApp/main.cpp +++ b/test/TestApps/ToastNotificationsDemoApp/main.cpp @@ -18,6 +18,7 @@ namespace winrt using namespace winrt::Microsoft::Windows::AppLifecycle; using namespace winrt::Microsoft::Windows::PushNotifications; using namespace winrt::Microsoft::Windows::AppNotifications; + using namespace winrt::Microsoft::Windows::AppNotifications::Builder; using namespace winrt::Windows::ApplicationModel::Activation; using namespace winrt::Windows::ApplicationModel::Background; // BackgroundTask APIs using namespace winrt::Windows::Foundation; @@ -124,7 +125,9 @@ bool PostToastHelper(std::wstring const& tag, std::wstring const& group) toast.Tag(tag.c_str()); toast.Group(group.c_str()); - winrt::AppNotificationManager::Default().Show(toast); + auto builder{ winrt::AppNotificationBuilder().AddArgument(L"key", L"value").AddArgument(L"key", L"value").SetTag(tag.c_str()).SetGroup(group.c_str())}; + + winrt::AppNotificationManager::Default().Show(builder.BuildNotification()); if (toast.Id() == 0) { @@ -170,11 +173,11 @@ int main() winrt::event_token token = appNotificationManager.NotificationInvoked([](const auto&, winrt::AppNotificationActivatedEventArgs const& toastArgs) { std::wcout << L"AppNotification received foreground!\n"; - winrt::hstring arguments{ toastArgs.Argument() }; - std::wcout << arguments.c_str() << L"\n\n"; + winrt::hstring argument{ toastArgs.Argument() }; + std::wcout << argument.c_str() << L"\n\n"; - winrt::IMap userInput{ toastArgs.UserInput() }; - for (auto pair : userInput) + winrt::IMap arguments{ toastArgs.Arguments() }; + for (auto pair : arguments) { std::wcout << "Key= " << pair.Key().c_str() << " " << "Value= " << pair.Value().c_str() << L"\n"; } @@ -200,11 +203,11 @@ int main() { std::wcout << L"Activated by AppNotification from background.\n"; winrt::AppNotificationActivatedEventArgs appNotificationArgs{ args.Data().as() }; - winrt::hstring arguments{ appNotificationArgs.Argument() }; - std::wcout << arguments.c_str() << std::endl << std::endl; + winrt::hstring argument{ appNotificationArgs.Argument() }; + std::wcout << argument.c_str() << std::endl << std::endl; - winrt::IMap userInput = appNotificationArgs.UserInput(); - for (auto pair : userInput) + winrt::IMap arguments = appNotificationArgs.Arguments(); + for (auto pair : arguments) { std::wcout << "Key= " << pair.Key().c_str() << " " << "Value= " << pair.Value().c_str() << L"\n"; } diff --git a/test/TestApps/ToastNotificationsDemoApp/pch.h b/test/TestApps/ToastNotificationsDemoApp/pch.h index 508509bcca..cca5bcb982 100644 --- a/test/TestApps/ToastNotificationsDemoApp/pch.h +++ b/test/TestApps/ToastNotificationsDemoApp/pch.h @@ -17,3 +17,4 @@ #include #include #include +#include