From ccda434f69d5fd39042d9573f1610aa6ff01d0e7 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 17 Feb 2021 06:53:13 -0600 Subject: [PATCH] A bunch of test fixes --- .../LocalTests_SettingsModel/CommandTests.cpp | 8 ----- .../LocalTests_TerminalApp/TabTests.cpp | 28 ++++++++++++++- src/cascadia/TerminalApp/AppLogic.cpp | 3 ++ src/cascadia/TerminalApp/TerminalPage.cpp | 35 ++++++++++++++----- src/cascadia/TerminalApp/TerminalTab.cpp | 20 +++++++---- 5 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/CommandTests.cpp b/src/cascadia/LocalTests_SettingsModel/CommandTests.cpp index 5aea359850..11d4064288 100644 --- a/src/cascadia/LocalTests_SettingsModel/CommandTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/CommandTests.cpp @@ -275,14 +275,6 @@ namespace SettingsModelLocalTests void CommandTests::TestAutogeneratedName() { - // Tests run in Helix can't report Skipped until GH#7286 is resolved. - // Set ignore flag to make Helix run completely overlook it. - BEGIN_TEST_METHOD_PROPERTIES() - TEST_METHOD_PROPERTY(L"Ignore", L"True") - END_TEST_METHOD_PROPERTIES() - - // This test to be corrected as a part of GH#7281 - // This test ensures that we'll correctly create commands for actions // that don't have given names, pursuant to the spec in GH#6532. diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp index 2479f16283..6c2592f8d7 100644 --- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp @@ -868,13 +868,39 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(4u, page->_mruTabs.Size()); Log::Comment(L"give alphabetical names to all switch tab actions"); - RunOnUIThread([&page]() { + TestOnUIThread([&page]() { page->_GetTerminalTabImpl(page->_tabs.GetAt(0))->Title(L"a"); + }); + TestOnUIThread([&page]() { page->_GetTerminalTabImpl(page->_tabs.GetAt(1))->Title(L"b"); + }); + TestOnUIThread([&page]() { page->_GetTerminalTabImpl(page->_tabs.GetAt(2))->Title(L"c"); + }); + TestOnUIThread([&page]() { page->_GetTerminalTabImpl(page->_tabs.GetAt(3))->Title(L"d"); }); + // Mysteriously, setting the title isn't instantaneous. If you don't + // sleep here, then it's very possible that the checks below to sanity + // check the titles _will fail_. + Log::Comment(L"Sleep to let events propagate"); + Sleep(500); + + TestOnUIThread([&page]() { + Log::Comment(L"Sanity check the titles of our tabs are what we set them to."); + + VERIFY_ARE_EQUAL(L"a", page->_tabs.GetAt(0).Title()); + VERIFY_ARE_EQUAL(L"b", page->_tabs.GetAt(1).Title()); + VERIFY_ARE_EQUAL(L"c", page->_tabs.GetAt(2).Title()); + VERIFY_ARE_EQUAL(L"d", page->_tabs.GetAt(3).Title()); + + VERIFY_ARE_EQUAL(L"d", page->_mruTabs.GetAt(0).Title()); + VERIFY_ARE_EQUAL(L"c", page->_mruTabs.GetAt(1).Title()); + VERIFY_ARE_EQUAL(L"b", page->_mruTabs.GetAt(2).Title()); + VERIFY_ARE_EQUAL(L"a", page->_mruTabs.GetAt(3).Title()); + }); + Log::Comment(L"Change the tab switch order to MRU switching"); TestOnUIThread([&page]() { page->_settings.GlobalSettings().TabSwitcherMode(TabSwitcherMode::MostRecentlyUsed); diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index d29f0a2a88..f0b597087b 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -173,6 +173,9 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Returns the settings currently in use by the entire Terminal application. + // - IMPORTANT! This can throw! Make sure to try/catch this, so that the + // LocalTests don't crash (because their Application::Current() won't be a + // AppLogic) // Throws: // - HR E_INVALIDARG if the app isn't up and running. const CascadiaSettings AppLogic::CurrentAppSettings() diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 45ef2f9735..4418701f25 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -135,8 +135,7 @@ namespace winrt::TerminalApp::implementation } CATCH_LOG(); - _tabRow.PointerMoved({ this, &TerminalPage::_RestorePointerCursorHandler }); - + _tabRow.PointerMoved({ get_weak(), &TerminalPage::_RestorePointerCursorHandler }); _tabView.CanReorderTabs(!isElevated); _tabView.CanDragTabs(!isElevated); @@ -261,7 +260,11 @@ namespace winrt::TerminalApp::implementation // Store cursor, so we can restore it, e.g., after mouse vanishing // (we'll need to adapt this logic once we make cursor context aware) - _defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor(); + try + { + _defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor(); + } + CATCH_LOG(); } // Method Description: @@ -1374,8 +1377,8 @@ namespace winrt::TerminalApp::implementation // Add an event handler for when the terminal wants to set a progress indicator on the taskbar term.SetTaskbarProgress({ this, &TerminalPage::_SetTaskbarProgressHandler }); - term.HidePointerCursor({ this, &TerminalPage::_HidePointerCursorHandler }); - term.RestorePointerCursor({ this, &TerminalPage::_RestorePointerCursorHandler }); + term.HidePointerCursor({ get_weak(), &TerminalPage::_HidePointerCursorHandler }); + term.RestorePointerCursor({ get_weak(), &TerminalPage::_RestorePointerCursorHandler }); // Bind Tab events to the TermControl and the Tab's Pane hostingTab.Initialize(term); @@ -3183,8 +3186,15 @@ namespace winrt::TerminalApp::implementation { if (_shouldMouseVanish && !_isMouseHidden) { - CoreWindow::GetForCurrentThread().PointerCursor(nullptr); - _isMouseHidden = true; + if (auto window{ CoreWindow::GetForCurrentThread() }) + { + try + { + window.PointerCursor(nullptr); + _isMouseHidden = true; + } + CATCH_LOG(); + } } } @@ -3196,8 +3206,15 @@ namespace winrt::TerminalApp::implementation { if (_isMouseHidden) { - CoreWindow::GetForCurrentThread().PointerCursor(_defaultPointerCursor); - _isMouseHidden = false; + if (auto window{ CoreWindow::GetForCurrentThread() }) + { + try + { + window.PointerCursor(_defaultPointerCursor); + _isMouseHidden = false; + } + CATCH_LOG(); + } } } diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 274a9c0251..d6c090c9a0 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -104,15 +104,21 @@ namespace winrt::TerminalApp::implementation if (auto tab{ weakThis.get() }) { - const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() }; - if (settings.GlobalSettings().TabWidthMode() == winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::SizeToContent) + try { - tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthTitleLength); - } - else - { - tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthDefault); + // Make sure to try/catch this, because the LocalTests won't be + // able to use this helper. + const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() }; + if (settings.GlobalSettings().TabWidthMode() == winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::SizeToContent) + { + tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthTitleLength); + } + else + { + tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthDefault); + } } + CATCH_LOG() } }