From 72761fceab44cee2ff4cedca23a8409606a2644c Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 3 Dec 2019 13:29:48 -0600 Subject: [PATCH] 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. --- .../ColorSchemeTests.cpp | 15 ++-- .../KeyBindingsTests.cpp | 76 +++++++++++-------- .../LocalTests_TerminalApp/ProfileTests.cpp | 15 ++-- .../LocalTests_TerminalApp/SettingsTests.cpp | 15 ++-- .../LocalTests_TerminalApp/TabTests.cpp | 47 ++++-------- ...lApp.LocalTests.AppxManifest.prototype.xml | 25 +++--- 6 files changed, 92 insertions(+), 101 deletions(-) diff --git a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp index ac6f5efc86..f96c7283ae 100644 --- a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp @@ -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); diff --git a/src/cascadia/LocalTests_TerminalApp/KeyBindingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/KeyBindingsTests.cpp index 505270adc7..91cbd1bd6e 100644 --- a/src/cascadia/LocalTests_TerminalApp/KeyBindingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/KeyBindingsTests.cpp @@ -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(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('=') }; + KeyChord kc{ true, false, false, static_cast('F') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::IncreaseFontSize, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -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('-') }; + KeyChord kc{ true, false, false, static_cast('G') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::DecreaseFontSize, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -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('A') }; + KeyChord kc{ true, false, false, static_cast('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(); 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('B') }; + KeyChord kc{ true, false, false, static_cast('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(); 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('C') }; + KeyChord kc{ true, false, false, static_cast('C') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -419,7 +429,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::None, realArgs.SplitStyle()); } { - KeyChord kc{ true, false, true, static_cast('D') }; + KeyChord kc{ true, false, false, static_cast('D') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -428,7 +438,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle()); } { - KeyChord kc{ true, false, true, static_cast('E') }; + KeyChord kc{ true, false, false, static_cast('E') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -437,7 +447,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle()); } { - KeyChord kc{ true, false, true, static_cast('F') }; + KeyChord kc{ true, false, false, static_cast('F') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); @@ -446,7 +456,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::None, realArgs.SplitStyle()); } { - KeyChord kc{ true, false, true, static_cast('G') }; + KeyChord kc{ true, false, false, static_cast('G') }; auto actionAndArgs = GetActionAndArgs(*appKeyBindings, kc); VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().try_as(); diff --git a/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp b/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp index ef460b39c1..2f1e8b3bc8 100644 --- a/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp @@ -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); diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index a2c2cf26d8..3ca17df479 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -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); diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp index bb7853061f..902f5583e3 100644 --- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp @@ -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() diff --git a/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.AppxManifest.prototype.xml b/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.AppxManifest.prototype.xml index c297907488..d34d3dcd00 100644 --- a/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.AppxManifest.prototype.xml +++ b/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.AppxManifest.prototype.xml @@ -3,49 +3,48 @@ + --> + TerminalApp.LocalTests.Package Host Process Microsoft Corp. taef.png - TAEF Packaged Cwa FullTrust Application Host Process + TAEF Packaged UWP Application Host Process + + + - - + + - - - +