Add an integration test to validate pick mode crash (#2935)
* add an integration test to validate pick mode crash Signed-off-by: hultonha <hultonha@amazon.co.uk> * update to test after review feedback Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
+29
@@ -65,6 +65,35 @@ namespace UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
bool FocusInteractionWidget::event(QEvent* event)
|
||||
{
|
||||
using AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus;
|
||||
|
||||
auto eventType = event->type();
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Event(
|
||||
AzToolsFramework::GetEntityContextId(), &EditorInteractionSystemViewportSelectionRequestBus::Events::SetDefaultHandler);
|
||||
return true;
|
||||
case QEvent::FocusIn:
|
||||
case QEvent::FocusOut:
|
||||
{
|
||||
bool handled = false;
|
||||
AzToolsFramework::ViewportInteraction::MouseInteraction mouseInteraction;
|
||||
EditorInteractionSystemViewportSelectionRequestBus::EventResult(
|
||||
handled, AzToolsFramework::GetEntityContextId(),
|
||||
&EditorInteractionSystemViewportSelectionRequestBus::Events::InternalHandleMouseViewportInteraction,
|
||||
AzToolsFramework::ViewportInteraction::MouseInteractionEvent(
|
||||
mouseInteraction, AzToolsFramework::ViewportInteraction::MouseEvent::Down));
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void TestEditorActions::Connect()
|
||||
{
|
||||
using AzToolsFramework::GetEntityContextId;
|
||||
|
||||
+15
-11
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
#include <AzCore/Slice/SliceAsset.h>
|
||||
@@ -31,6 +32,7 @@
|
||||
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
|
||||
#include <AzToolsFramework/SourceControl/PerforceConnection.h>
|
||||
#include <AzToolsFramework/UnitTest/ToolsTestApplication.h>
|
||||
#endif // !defined(Q_MOC_RUN)
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -40,7 +42,7 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
#define AUTO_RESULT_IF_SETTING_TRUE(_settingName, _result) \
|
||||
{ \
|
||||
bool settingValue = true; \
|
||||
bool settingValue = true; \
|
||||
if (auto* registry = AZ::SettingsRegistry::Get()) \
|
||||
{ \
|
||||
registry->Get(settingValue, _settingName); \
|
||||
@@ -51,23 +53,16 @@ AZ_POP_DISABLE_WARNING
|
||||
EXPECT_TRUE(_result); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class Entity;
|
||||
class EntityId;
|
||||
|
||||
} // namespace AZ
|
||||
}
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
constexpr AZStd::string_view prefabSystemSetting = "/Amazon/Preferences/EnablePrefabSystem";
|
||||
|
||||
/// Test widget to store QActions generated by EditorTransformComponentSelection.
|
||||
class TestWidget
|
||||
: public QWidget
|
||||
class TestWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TestWidget()
|
||||
: QWidget()
|
||||
@@ -79,6 +74,15 @@ namespace UnitTest
|
||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||
};
|
||||
|
||||
/// Widget used to trigger a viewport interaction event while a focus change is happening.
|
||||
class FocusInteractionWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FocusInteractionWidget(QWidget* parent = nullptr) : QWidget(parent) {}
|
||||
bool event(QEvent* event) override;
|
||||
};
|
||||
|
||||
/// Stores actions registered for either normal mode (regular viewport) editing and
|
||||
/// component mode editing.
|
||||
class TestEditorActions
|
||||
|
||||
@@ -50,6 +50,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
|
||||
ly_add_target(
|
||||
NAME AzToolsFrameworkTestCommon STATIC
|
||||
NAMESPACE AZ
|
||||
AUTOMOC
|
||||
FILES_CMAKE
|
||||
AzToolsFramework/aztoolsframeworktestcommon_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
@@ -68,6 +69,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
|
||||
ly_add_target(
|
||||
NAME AzToolsFramework.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
|
||||
NAMESPACE AZ
|
||||
AUTOMOC
|
||||
FILES_CMAKE
|
||||
Tests/aztoolsframeworktests_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
|
||||
@@ -31,8 +31,10 @@
|
||||
#include <AzToolsFramework/Viewport/ActionBus.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorDefaultSelection.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorPickEntitySelection.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorVisibleEntityDataCache.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -188,6 +190,47 @@ namespace UnitTest
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// EditorTransformComponentSelection Tests
|
||||
|
||||
TEST_F(EditorTransformComponentSelectionFixture, Focus_is_not_changed_while_switching_viewport_interaction_request_instance)
|
||||
{
|
||||
// setup a dummy widget and make it the active window to ensure focus in/out events are fired
|
||||
auto dummyWidget = AZStd::make_unique<QWidget>();
|
||||
QApplication::setActiveWindow(dummyWidget.get());
|
||||
|
||||
// note: it is important to make sure the focus widget is parented to the dummy widget to have focus in/out events fire
|
||||
auto focusWidget = AZStd::make_unique<UnitTest::FocusInteractionWidget>(dummyWidget.get());
|
||||
|
||||
const auto previousFocusWidget = QApplication::focusWidget();
|
||||
|
||||
// Given
|
||||
// setup viewport ui system
|
||||
AzToolsFramework::ViewportUi::ViewportUiManager viewportUiManager;
|
||||
viewportUiManager.ConnectViewportUiBus(AzToolsFramework::ViewportUi::DefaultViewportId);
|
||||
viewportUiManager.InitializeViewportUi(&m_editorActions.m_defaultWidget, focusWidget.get());
|
||||
|
||||
// begin EditorPickEntitySelection
|
||||
using AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus;
|
||||
EditorInteractionSystemViewportSelectionRequestBus::Event(
|
||||
AzToolsFramework::GetEntityContextId(), &EditorInteractionSystemViewportSelectionRequestBus::Events::SetHandler,
|
||||
[](const AzToolsFramework::EditorVisibleEntityDataCache* entityDataCache)
|
||||
{
|
||||
return AZStd::make_unique<AzToolsFramework::EditorPickEntitySelection>(entityDataCache);
|
||||
});
|
||||
|
||||
// When
|
||||
// a mouse event is sent to the focus widget (set to be the render overlay in the viewport ui system)
|
||||
QTest::mouseClick(focusWidget.get(), Qt::MouseButton::LeftButton);
|
||||
|
||||
// Then
|
||||
// focus should not change
|
||||
EXPECT_FALSE(focusWidget->hasFocus());
|
||||
EXPECT_EQ(previousFocusWidget, QApplication::focusWidget());
|
||||
|
||||
// clean up
|
||||
viewportUiManager.DisconnectViewportUiBus();
|
||||
focusWidget.reset();
|
||||
dummyWidget.reset();
|
||||
}
|
||||
|
||||
TEST_F(EditorTransformComponentSelectionFixture, ManipulatorOrientationIsResetWhenEntityOrientationIsReset)
|
||||
{
|
||||
using AzToolsFramework::EditorTransformComponentSelectionRequestBus;
|
||||
|
||||
Reference in New Issue
Block a user