(KeyboardFocusManager) Use weak handle instead of calling FindChildById repeatedly
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-KeyboardFocusManager.cpp
index 465834a..f1cccda 100644 (file)
@@ -46,7 +46,6 @@ namespace
 
 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
 
-
 // Functors to test whether GetNextFocusableActor() method of CustomAlgorithmInterface is called when the keyboard focus is about to change
 class CustomAlgorithm : public Dali::Toolkit::DevelKeyboardFocusManager::CustomAlgorithmInterface
 {
@@ -866,7 +865,7 @@ int UtcDaliKeyboardFocusManagerSignalFocusedActorActivated(void)
   FocusedActorActivatedCallback focusedActorActivatedCallback(focusedActorActivatedSignalVerified);
   manager.FocusedActorEnterKeySignal().Connect( &focusedActorActivatedCallback, &FocusedActorActivatedCallback::Callback );
 
-  Integration::KeyEvent returnEvent("Return", "", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME );
+  Integration::KeyEvent returnEvent( "Return", "", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
 
   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
   // It makes mIsFocusIndicatorEnabled true
@@ -924,8 +923,8 @@ int UtcDaliKeyboardFocusManagerSignalFocusGroupChanged(void)
   FocusGroupChangedCallback focusGroupChangedCallback(focusGroupChangedSignalVerified);
   manager.FocusGroupChangedSignal().Connect( &focusGroupChangedCallback, &FocusGroupChangedCallback::Callback );
 
-  Integration::KeyEvent tabEvent("Tab", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
-  Integration::KeyEvent shiftTabEvent("Tab", "", 0, 1, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME);
+  Integration::KeyEvent tabEvent( "Tab", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent shiftTabEvent( "Tab", "", 0, 1, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
 
   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
   // It makes mIsFocusIndicatorEnabled true
@@ -1047,12 +1046,12 @@ int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void)
   FocusChangedCallback focusChangedCallback(focusChangedSignalVerified);
   manager.FocusChangedSignal().Connect( &focusChangedCallback, &FocusChangedCallback::Callback );
 
-  Integration::KeyEvent leftEvent("Left", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME);
-  Integration::KeyEvent rightEvent("Right", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
-  Integration::KeyEvent upEvent("Up", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
-  Integration::KeyEvent downEvent("Down", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
-  Integration::KeyEvent pageUpEvent("Prior", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
-  Integration::KeyEvent pageDownEvent("Next", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME );
+  Integration::KeyEvent leftEvent( "Left", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent rightEvent( "Right", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent upEvent( "Up", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent downEvent( "Down", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent pageUpEvent( "Prior", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
+  Integration::KeyEvent pageDownEvent( "Next", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE );
 
   // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager
   // It makes mIsFocusIndicatorEnabled true
@@ -1381,3 +1380,31 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void)
 
   END_TEST;
 }
+
+int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline( "Ensure we cannot set an actor to be focused if it is not staged and that we do not retrieve an actor if it has been unstaged" );
+
+  KeyboardFocusManager manager = KeyboardFocusManager::Get();
+  DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
+
+  Actor actor = Actor::New();
+  actor.SetKeyboardFocusable( true );
+
+  tet_infoline( "Attempt to set unstaged actor, no actor should be returned from KeyboardFocusManager" );
+  manager.SetCurrentFocusActor( actor );
+  DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
+
+  tet_infoline( "Add actor to stage and attempt to set, our actor should be returned from KeyboardFocusManager" );
+  Stage::GetCurrent().Add( actor );
+  manager.SetCurrentFocusActor( actor );
+  DALI_TEST_CHECK( manager.GetCurrentFocusActor() == actor );
+
+  tet_infoline( "Remove actor from stage and attempt to retrieve, no actor should be returned from KeyboardFocusManager" );
+  actor.Unparent();
+  DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() );
+
+  END_TEST;
+}