Fix LocalTests that were working before (#3807)

## Summary of the Pull Request

Fixes the LocalTests that should work. This does _not_ fix the TabTests.


## PR Checklist
* [x] Closes #3536
* [x] I work here
* [x] This is literally making the tests work
* [n/a] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments

In a previous PR, we broke unpackaged activation. This had the unintended side-effect of breaking these tests. The solution here is to run these unittests _packaged_.

This also makes things a little bit better for the TabTests, but doesn't fix them (inexplicably). A mail thread internally is tracking the progress of fixing those tests.
This commit is contained in:
Mike Griese 2019-12-03 13:29:48 -06:00 committed by msftbot[bot]
parent a47a53c893
commit 72761fceab
6 changed files with 92 additions and 101 deletions

View file

@ -20,15 +20,14 @@ namespace TerminalAppLocalTests
class ColorSchemeTests : public JsonTestClass
{
// Use a custom manifest to ensure that we can activate winrt types from
// our test. This property will tell taef to manually use this as the
// sxs manifest during this test class. It includes all the cppwinrt
// types we've defined, so if your test is crashing for an unknown
// reason, make sure it's included in that file.
// If you want to do anything XAML-y, you'll need to run your test in a
// packaged context. See TabTests.cpp for more details on that.
// Use a custom AppxManifest to ensure that we can activate winrt types
// from our test. This property will tell taef to manually use this as
// the AppxManifest for this test class.
// This does not yet work for anything XAML-y. See TabTests.cpp for more
// details on that.
BEGIN_TEST_CLASS(ColorSchemeTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.LocalTests.manifest")
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
TEST_METHOD(CanLayerColorScheme);

View file

@ -22,15 +22,14 @@ namespace TerminalAppLocalTests
class KeyBindingsTests : public JsonTestClass
{
// Use a custom manifest to ensure that we can activate winrt types from
// our test. This property will tell taef to manually use this as the
// sxs manifest during this test class. It includes all the cppwinrt
// types we've defined, so if your test is crashing for an unknown
// reason, make sure it's included in that file.
// If you want to do anything XAML-y, you'll need to run your test in a
// packaged context. See TabTests.cpp for more details on that.
// Use a custom AppxManifest to ensure that we can activate winrt types
// from our test. This property will tell taef to manually use this as
// the AppxManifest for this test class.
// This does not yet work for anything XAML-y. See TabTests.cpp for more
// details on that.
BEGIN_TEST_CLASS(KeyBindingsTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.LocalTests.manifest")
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
TEST_METHOD(ManyKeysSameAction);
@ -57,6 +56,22 @@ namespace TerminalAppLocalTests
static const ActionAndArgs KeyBindingsTests::GetActionAndArgs(const implementation::AppKeyBindings& bindings,
const KeyChord& kc)
{
std::wstring buffer{ L"" };
if (WI_IsFlagSet(kc.Modifiers(), KeyModifiers::Ctrl))
{
buffer += L"Ctrl+";
}
if (WI_IsFlagSet(kc.Modifiers(), KeyModifiers::Shift))
{
buffer += L"Shift+";
}
if (WI_IsFlagSet(kc.Modifiers(), KeyModifiers::Alt))
{
buffer += L"Alt+";
}
buffer += static_cast<wchar_t>(MapVirtualKeyW(kc.Vkey(), MAPVK_VK_TO_CHAR));
Log::Comment(NoThrowString().Format(L"Looking for key:%s", buffer.c_str()));
const auto keyIter = bindings._keyShortcuts.find(kc);
VERIFY_IS_TRUE(keyIter != bindings._keyShortcuts.end(), L"Expected to find an action bound to the given KeyChord");
if (keyIter != bindings._keyShortcuts.end())
@ -199,8 +214,8 @@ namespace TerminalAppLocalTests
{ "command": { "action": "copy", "madeUpBool": true }, "keys": ["ctrl+b"] },
{ "command": { "action": "copy" }, "keys": ["ctrl+shift+b"] },
{ "command": "decreaseFontSize", "keys": ["ctrl+-"] },
{ "command": "increaseFontSize", "keys": ["ctrl+="] }
{ "command": "increaseFontSize", "keys": ["ctrl+f"] },
{ "command": "decreaseFontSize", "keys": ["ctrl+g"] }
])" };
@ -344,7 +359,7 @@ namespace TerminalAppLocalTests
{
Log::Comment(NoThrowString().Format(
L"Verify that `increaseFontSize` without args parses as AdjustFontSize(Delta=1)"));
KeyChord kc{ false, true, false, static_cast<int32_t>('=') };
KeyChord kc{ true, false, false, static_cast<int32_t>('F') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::IncreaseFontSize, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<AdjustFontSizeArgs>();
@ -356,7 +371,7 @@ namespace TerminalAppLocalTests
{
Log::Comment(NoThrowString().Format(
L"Verify that `decreaseFontSize` without args parses as AdjustFontSize(Delta=-1)"));
KeyChord kc{ false, true, false, static_cast<int32_t>('-') };
KeyChord kc{ true, false, false, static_cast<int32_t>('G') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::DecreaseFontSize, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<AdjustFontSizeArgs>();
@ -368,19 +383,14 @@ namespace TerminalAppLocalTests
void KeyBindingsTests::TestSplitPaneArgs()
{
// TODO:GH#3536 - These tests _should_ work, but since the LocalTests
// fail to run at all right now, I can't be sure that they do. When
// #3536 is fixed, make sure that these tests were authored correctly.
const std::string bindings0String{ R"([
{ "command": "splitVertical", "keys": ["ctrl+a"] },
{ "command": "splitHorizontal", "keys": ["ctrl+b"] },
{ "command": { "action": "splitPane", "split": null }, "keys": ["ctrl+c"] },
{ "command": { "action": "splitPane", "split": "vertical" }, "keys": ["ctrl+d"] },
{ "command": { "action": "splitPane", "split": "horizontal" }, "keys": ["ctrl+e"] },
{ "command": { "action": "splitPane", "split": "none" }, "keys": ["ctrl+f"] },
{ "command": { "action": "splitPane" }, "keys": ["ctrl+g"] }
{ "keys": ["ctrl+a"], "command": "splitVertical" },
{ "keys": ["ctrl+b"], "command": "splitHorizontal" },
{ "keys": ["ctrl+c"], "command": { "action": "splitPane", "split": null } },
{ "keys": ["ctrl+d"], "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": ["ctrl+e"], "command": { "action": "splitPane", "split": "horizontal" } },
{ "keys": ["ctrl+f"], "command": { "action": "splitPane", "split": "none" } },
{ "keys": ["ctrl+g"], "command": { "action": "splitPane" } }
])" };
const auto bindings0Json = VerifyParseSucceeded(bindings0String);
@ -392,25 +402,25 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(7u, appKeyBindings->_keyShortcuts.size());
{
KeyChord kc{ true, false, true, static_cast<int32_t>('A') };
KeyChord kc{ true, false, false, static_cast<int32_t>('A') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
VERIFY_ARE_EQUAL(ShortcutAction::SplitVertical, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('B') };
KeyChord kc{ true, false, false, static_cast<int32_t>('B') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
VERIFY_ARE_EQUAL(ShortcutAction::SplitHorizontal, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('C') };
KeyChord kc{ true, false, false, static_cast<int32_t>('C') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
@ -419,7 +429,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::None, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('D') };
KeyChord kc{ true, false, false, static_cast<int32_t>('D') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
@ -428,7 +438,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('E') };
KeyChord kc{ true, false, false, static_cast<int32_t>('E') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
@ -437,7 +447,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('F') };
KeyChord kc{ true, false, false, static_cast<int32_t>('F') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
@ -446,7 +456,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::None, realArgs.SplitStyle());
}
{
KeyChord kc{ true, false, true, static_cast<int32_t>('G') };
KeyChord kc{ true, false, false, static_cast<int32_t>('G') };
auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();

View file

@ -20,15 +20,14 @@ namespace TerminalAppLocalTests
class ProfileTests : public JsonTestClass
{
// Use a custom manifest to ensure that we can activate winrt types from
// our test. This property will tell taef to manually use this as the
// sxs manifest during this test class. It includes all the cppwinrt
// types we've defined, so if your test is crashing for an unknown
// reason, make sure it's included in that file.
// If you want to do anything XAML-y, you'll need to run your test in a
// packaged context. See TabTests.cpp for more details on that.
// Use a custom AppxManifest to ensure that we can activate winrt types
// from our test. This property will tell taef to manually use this as
// the AppxManifest for this test class.
// This does not yet work for anything XAML-y. See TabTests.cpp for more
// details on that.
BEGIN_TEST_CLASS(ProfileTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.LocalTests.manifest")
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
TEST_METHOD(CanLayerProfile);

View file

@ -21,15 +21,14 @@ namespace TerminalAppLocalTests
class SettingsTests : public JsonTestClass
{
// Use a custom manifest to ensure that we can activate winrt types from
// our test. This property will tell taef to manually use this as the
// sxs manifest during this test class. It includes all the cppwinrt
// types we've defined, so if your test is crashing for an unknown
// reason, make sure it's included in that file.
// If you want to do anything XAML-y, you'll need to run your test in a
// packaged context. See TabTests.cpp for more details on that.
// Use a custom AppxManifest to ensure that we can activate winrt types
// from our test. This property will tell taef to manually use this as
// the AppxManifest for this test class.
// This does not yet work for anything XAML-y. See TabTests.cpp for more
// details on that.
BEGIN_TEST_CLASS(SettingsTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.LocalTests.manifest")
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
TEST_METHOD(TryCreateWinRTType);

View file

@ -18,51 +18,36 @@ namespace TerminalAppLocalTests
class TabTests
{
// For this set of tests, we need to activate some XAML content. To do
// that, we need to be able to activate Xaml Islands(XI), using the Xaml
// Hosting APIs. Because XI looks at the manifest of the exe running, we
// can't just use the TerminalApp.Unit.Tests.manifest as our
// ActivationContext. XI is going to inspect `te.exe`s manifest to try
// and find the maxversiontested property, but te.exe hasn't set that.
// Instead, this test will run as a UAP application, as a packaged
// centenial (win32) app. We'll specify our own AppxManifest, so that
// we'll be able to also load all the dll's for the types we've defined
// (and want to use here). This does come with a minor caveat, as
// deploying the appx takes a bit, so use sparingly (though it will
// deploy once per class when used like this.)
// For this set of tests, we need to activate some XAML content. For
// release builds, the application runs as a centennial application,
// which lets us run full trust, and means that we need to use XAML
// Islands to host our UI. However, in these tests, we don't really need
// to run full trust - we just need to get some UI elements created. So
// we can just rely on the normal UWP activation to create us.
// UNFORTUNATELY, this doesn't seem to work yet, and the tests fail when
// instantiating XAML elements
BEGIN_TEST_CLASS(TabTests)
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:WaitForXamlWindowActivation", L"true")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
// These four tests act as canary tests. If one of them fails, then they
// can help you identify if something much lower in the stack has
// failed.
TEST_METHOD(TryInitXamlIslands);
TEST_METHOD(EnsureTestsActivate);
TEST_METHOD(TryCreateLocalWinRTType);
TEST_METHOD(TryCreateXamlObjects);
TEST_METHOD(TryCreateTab);
TEST_CLASS_SETUP(ClassSetup)
{
winrt::init_apartment(winrt::apartment_type::single_threaded);
// Initialize the Xaml Hosting Manager
_manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
_source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{};
return true;
}
private:
winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr };
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };
};
void TabTests::TryInitXamlIslands()
void TabTests::EnsureTestsActivate()
{
// Ensures that XAML Islands was initialized correctly
VERIFY_IS_NOT_NULL(_manager);
VERIFY_IS_NOT_NULL(_source);
// This test was originally used to ensure that XAML Islands was
// initialized correctly. Now, it's used to ensure that the tests
// actually deployed and activated. This test _should_ always pass.
VERIFY_IS_TRUE(true);
}
void TabTests::TryCreateLocalWinRTType()

View file

@ -3,49 +3,48 @@
<!-- This file is used as the Appxmanifest for tests that _need_ to run in a
packaged environment. It will be copied to the test's OutDir as part of the
PostBuid step. It's highly similar to the "PackagedCwaFullTrust" manifest that
PostBuid step. It's highly similar to the "SUA" manifest that
TAEF ships with, with the following modifications:
1. All of our winrt types are included in this manifest, including types from
MUX.dll. Should this list of types ever change, we'll need to manually
update this file. The easiest way of doing that is deploying the app from
VS, then copying the Extensions from the Appxmanifest.xml that's generated
under `src/cascadia/CascadiaPackage/bin/$(platform)/$(configuration)/appx`.
MUX.dll. This is done in a custom build step that automatically adds each
of our types to this manifest.
2. We also _NEED_ the two vclibs listed under the `PackageDependency` block.
If your test fails for whatever reason, it's likely possible you're testing a
type that's _not_ included in this file for some reason. So, here be dragons. -->
-->
<Identity Name="TerminalApp.LocalTests.Package"
ProcessorArchitecture="neutral"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
Version="1.0.0.0"
ResourceId="en-us" />
<Properties>
<DisplayName>TerminalApp.LocalTests.Package Host Process</DisplayName>
<PublisherDisplayName>Microsoft Corp.</PublisherDisplayName>
<Logo>taef.png</Logo>
<Description>TAEF Packaged Cwa FullTrust Application Host Process</Description>
<Description>TAEF Packaged UWP Application Host Process</Description>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.18362.0" MaxVersionTested="10.0.18362.0" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.27023.1" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug.UWPDesktop" MinVersion="14.0.27027.1" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
</Dependencies>
<Resources>
<Resource Language="en-us" />
</Resources>
<Applications>
<Application Id="TE.ProcessHost" Executable="TE.ProcessHost.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="TAEF Packaged Cwa FullTrust Application Host Process" Square150x150Logo="taef.png" Square44x44Logo="taef.png" Description="TAEF Packaged Cwa Application Host Process" BackgroundColor="#222222">
<Application Id="TE.ProcessHost" Executable="TE.ProcessHost.UAP.exe" EntryPoint="ProcessHostApplication">
<uap:VisualElements DisplayName="TAEF UWA Host Process" Square150x150Logo="taef.png" Square44x44Logo="taef.png" Description="TAEF UWA Host Process" BackgroundColor="#222222">
<uap:SplashScreen Image="taef.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust"/>
</Capabilities>