Skip to content

Commit c7bdbfb

Browse files
authored
Enabling app notification tests (#5781)
* Adding basic stuff * adding try catch on method uninit * Removing toast verification from unpackaged * Revert "Removing toast verification from unpackaged" This reverts commit 0368799. * Removing unpackaged self contained * Revert "Removing unpackaged self contained" This reverts commit e97e184. * Revert "adding try catch on method uninit" This reverts commit 413ca91. * Disabling unpackaged tests * Nit changes * Testing on Win10 rs5 * Revert "Testing on Win10 rs5" This reverts commit 345d65c. * Fixing message * Increasing timeout * Revert "Increasing timeout" This reverts commit 2a5ec5b. * Enabling only x64 * Revert "Enabling only x64" This reverts commit 7d8c0b6. * Testing with error expected * Refactoring test method * Trying with error not found * Revert "Trying with error not found" This reverts commit 417686d. * Reenabling unpackaged * Keeping manager reference * Trying log instead of throwing * Revert "Trying log instead of throwing" This reverts commit daa049e. * Trying try catch * Testing supported thing * Revert "Testing supported thing" This reverts commit c2eda3a. * Trying removing static variable * Revert "Trying removing static variable" This reverts commit e03a455. * Forcing is supported * Revert "Trying try catch" This reverts commit 63ba13e. * Revert "Keeping manager reference" This reverts commit 5beb012. * Forcing run as restricted user in commandline * Revert "Forcing is supported" This reverts commit a90be93. * Reapply "Forcing is supported" This reverts commit 3933960. * Revert "Forcing run as restricted user in commandline" This reverts commit 7fb3f7a. * Running as LowIL * Revert "Reapply "Forcing is supported"" This reverts commit 38f06ed. * Removing static * debugging il level * Using custom runas * Using medium IL and method level runas * Reorganizing code * Adding static * Trying normal restricted user * Removing debug logging * Disabling all tests for old windows 10 versions * Removing unused include * Removing arm64 to not be misleading
1 parent fdbbcaa commit c7bdbfb

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

test/AppNotificationTests/AppNotification-Test-Constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ inline const std::wstring c_appUserModelId{ L"TaefTestAppId" };
1111
inline const std::chrono::milliseconds c_sleepTimeout{ 5000 };
1212
inline const std::chrono::milliseconds c_delay{ 25 };
1313
constexpr PCWSTR c_nonExistentPackage{ L"NonExistentPackage" };
14+
constexpr PCWSTR c_fakePackageFamilyName{ L"AppNotificationTest.PackageFamilyName.DoesNotExist_1234567890abc" };
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Tests": [
3+
{
4+
"Description": "App Notification Tests Packaged",
5+
"Filename": "AppNotificationTests.dll",
6+
"Parameters": "/name:PackagedTests*",
7+
"Architectures": ["x64", "x86"],
8+
"Status": "Enabled"
9+
},
10+
{
11+
"Description": "App Notification Tests Unpackaged",
12+
"Filename": "AppNotificationTests.dll",
13+
"Parameters": "/name:UnpackagedTests*",
14+
"Architectures": ["x64", "x86"],
15+
"Status": "Enabled"
16+
}
17+
]
18+
}

test/AppNotificationTests/AppNotificationTests.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<Target Name="CopyFiles" AfterTargets="AfterBuild">
170170
<Copy SkipUnchangedFiles="true" SourceFiles="$(OutDir)\..\WindowsAppRuntime_BootstrapDLL\Microsoft.WindowsAppRuntime.Bootstrap.dll" DestinationFolder="$(OutDir)" />
171171
<Copy SkipUnchangedFiles="true" SourceFiles="$(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Internal.FrameworkUdk.dll" DestinationFolder="$(OutDir)" />
172+
<Copy SkipUnchangedFiles="true" SourceFiles="AppNotificationTests.testdef" DestinationFolder="$(OutDir)" />
172173
</Target>
173174
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
174175
<PropertyGroup>

test/AppNotificationTests/BaseTestSuite.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "AppNotification-Test-Constants.h"
77
#include "AppNotifications.Test.h"
88
#include "BaseTestSuite.h"
9+
#include "MddWin11.h"
910

1011
using namespace WEX::Common;
1112
using namespace WEX::Logging;
@@ -23,6 +24,13 @@ using namespace AppNotifications::Test;
2324

2425
void BaseTestSuite::ClassSetup()
2526
{
27+
// Skip tests on Win10 RS5 and earlier due to COM registration issues
28+
if (!WindowsVersion::IsWindows10_19H1OrGreater())
29+
{
30+
WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, L"AppNotification require Win10 19H1 or greater due to COM registration compatibility. Skipping tests on this OS version.");
31+
return;
32+
}
33+
2634
::Test::Bootstrap::Setup();
2735
}
2836

@@ -36,17 +44,24 @@ void BaseTestSuite::MethodSetup()
3644
bool isSelfContained{};
3745
VERIFY_SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained));
3846

39-
if (!isSelfContained)
47+
PCWSTR testFrameworkPackageFamilyName{ ::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName };
48+
PCWSTR testMainPackageFamilyName{ ::Test::Bootstrap::TP::WindowsAppRuntimeMain::c_PackageFamilyName };
49+
50+
if (isSelfContained)
4051
{
41-
::WindowsAppRuntime::VersionInfo::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName,
42-
::Test::Bootstrap::TP::WindowsAppRuntimeMain::c_PackageFamilyName);
43-
VERIFY_IS_FALSE(::WindowsAppRuntime::SelfContained::IsSelfContained());
52+
testFrameworkPackageFamilyName = testMainPackageFamilyName = c_fakePackageFamilyName;
4453
}
45-
else
54+
55+
// For Windows 11 newer versions, the TestInitialize will fail fast if we pass a non null package family name.
56+
// https://github.com/microsoft/WindowsAppSDK/blob/main/dev/Common/WindowsAppRuntime.VersionInfo.cpp#L123-L133
57+
if (MddCore::Win11::IsSupported())
4658
{
47-
::WindowsAppRuntime::VersionInfo::TestInitialize(L"I_don't_exist_package!", L"I_don't_exist_package!");
48-
VERIFY_IS_TRUE(::WindowsAppRuntime::SelfContained::IsSelfContained());
59+
testMainPackageFamilyName = nullptr;
4960
}
61+
62+
::WindowsAppRuntime::VersionInfo::TestInitialize(testFrameworkPackageFamilyName, testMainPackageFamilyName);
63+
64+
VERIFY_ARE_EQUAL(isSelfContained, ::WindowsAppRuntime::SelfContained::IsSelfContained());
5065
}
5166

5267
void BaseTestSuite::MethodCleanup()
@@ -369,7 +384,16 @@ void BaseTestSuite::VerifyRemoveWithIdentifierAsyncUsingNonActiveToastIdentifier
369384
removeNotificationAsync.Cancel();
370385
});
371386

372-
VERIFY_ARE_EQUAL(removeNotificationAsync.wait_for(c_timeout), winrt::Windows::Foundation::AsyncStatus::Completed);
387+
// On x86, the wait_for may return Error instead of Completed.
388+
// We check if the HR is E_INVALIDARG in that case.
389+
auto status = removeNotificationAsync.wait_for(c_timeout);
390+
VERIFY_IS_TRUE(status == winrt::Windows::Foundation::AsyncStatus::Completed || status == winrt::Windows::Foundation::AsyncStatus::Error);
391+
392+
if (status == winrt::Windows::Foundation::AsyncStatus::Error)
393+
{
394+
VERIFY_THROWS_HR(removeNotificationAsync.GetResults(), E_INVALIDARG);
395+
}
396+
373397
scope_exit.release();
374398
}
375399

test/AppNotificationTests/UnpackagedTests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
#include "pch.h"
@@ -13,7 +13,7 @@ class UnpackagedTests : BaseTestSuite
1313
BEGIN_TEST_CLASS(UnpackagedTests)
1414
TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK App Notifications test")
1515
TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA")
16-
TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser")
16+
TEST_CLASS_PROPERTY(L"RunAs", L"RestrictedUser")
1717
TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class")
1818
TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}")
1919
END_TEST_CLASS()

0 commit comments

Comments
 (0)