X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-KeyboardFocusManager.cpp;h=a759616a055e2d8ac16e77335c2eb66c289c2e55;hp=6083bc22466f8e1835230e9919b45dbb562221bb;hb=8db599ebe35a704d4adfd70040c33ce8e31e8d64;hpb=83eaadeeed2e58e08a98065c8fde1bd2e0910891 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp old mode 100644 new mode 100755 index 6083bc2..a759616 --- a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp @@ -217,6 +217,34 @@ public: Actor mActivatedActor; }; +class KeyEventCallback : public Dali::ConnectionTracker +{ +public: + /** + * Constructor + * @param[in] returnValue Set return value of KeyEvent callback. + * */ + KeyEventCallback( bool consumed ) + : mConsumed( consumed ), + mIsCalled( false ) + { + } + + bool Callback( Control control, const KeyEvent& keyEvent ) + { + mIsCalled = true; + return mConsumed; + } + + void Callback( const KeyEvent& keyEvent ) + { + mIsCalled = true; + } + + bool mConsumed; + bool mIsCalled; +}; + // Used to connect to signals via the ConnectSignal Handle method struct CallbackFunctor { @@ -865,7 +893,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, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); + Integration::KeyEvent returnEvent( "Return", "", "", 0, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager // It makes mIsFocusIndicatorEnabled true @@ -923,8 +951,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, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent shiftTabEvent( "Tab", "", 0, 1, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); + Integration::KeyEvent tabEvent( "Tab", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent shiftTabEvent( "Tab", "", "", 0, 1, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager // It makes mIsFocusIndicatorEnabled true @@ -1063,12 +1091,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, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent rightEvent( "Right", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent upEvent( "Up", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent downEvent( "Down", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent pageUpEvent( "Prior", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); - Integration::KeyEvent pageDownEvent( "Next", "", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelDevice::Class::NONE, DevelDevice::Subclass::NONE ); + Integration::KeyEvent leftEvent( "Left", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent upEvent( "Up", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent downEvent( "Down", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent pageUpEvent( "Prior", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + Integration::KeyEvent pageDownEvent( "Next", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager // It makes mIsFocusIndicatorEnabled true @@ -1182,10 +1210,68 @@ int UtcDaliKeyboardFocusManagerChangeFocusDirectionByKeyEvents(void) DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor()); DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::RIGHT); + // Clear the focus again + manager.ClearFocus(); + + // Send the up event for line coverage, but nothing was focued so focus manager will try the initial focus + preFocusChangeCallback.Reset(); + application.ProcessEvent(upEvent); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified); + DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor()); + + // Clear the focus again + manager.ClearFocus(); + + // Send the down event for line coverage, but nothing was focued so focus manager will try the initial focus + preFocusChangeCallback.Reset(); + application.ProcessEvent(downEvent); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified); + DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor()); + END_TEST; } +int UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliKeyboardFocusManagerSignalChangedBySpaceKeyEvent"); + + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK(manager); + + bool preFocusChangeSignalVerified = false; + PreFocusChangeCallback preFocusChangeCallback(preFocusChangeSignalVerified); + manager.PreFocusChangeSignal().Connect( &preFocusChangeCallback, &PreFocusChangeCallback::Callback ); + + Integration::KeyEvent spaceEvent( "space", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + + // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager + // It makes mIsFocusIndicatorEnabled true + application.ProcessEvent(spaceEvent); + + // Send the space event + application.ProcessEvent(spaceEvent); + DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified); + DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor()); + + // Clear the focus again + manager.ClearFocus(); + + // Send the space event again for line coverage + preFocusChangeCallback.Reset(); + application.ProcessEvent(spaceEvent); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mSignalVerified); + DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == Actor()); + DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor()); + END_TEST; +} @@ -1425,3 +1511,108 @@ int UtcDaliKeyboardFocusManagerFocusedActorUnstaged(void) END_TEST; } + +int UtcDaliKeyboardFocusManagerEnableFocusIndicator(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 ); + Stage::GetCurrent().Add( actor ); + manager.SetCurrentFocusActor( actor ); + + // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager + // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor. + Integration::KeyEvent rightEvent( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent(rightEvent); + + Actor indicatorActor = manager.GetFocusIndicatorActor(); + + tet_infoline( "Indicator is added to focused actor" ); + DALI_TEST_CHECK( actor == indicatorActor.GetParent() ); + + Dali::Toolkit::DevelKeyboardFocusManager::EnableFocusIndicator(manager, false); + DALI_TEST_CHECK( !Dali::Toolkit::DevelKeyboardFocusManager::IsFocusIndicatorEnabled(manager) ); + + tet_infoline( "Indicator is removed from focused actor because mUseFocusIndicator is false" ); + DALI_TEST_CHECK( !indicatorActor.GetParent() ); + + END_TEST; +} + +int UtcDaliKeyboardFocusManagerCheckConsumedKeyEvent(void) +{ + ToolkitTestApplication application; + + tet_infoline( "Ensure Window can't receive KeyEvent when Control already consumed it" ); + Dali::Integration::Scene scene = application.GetScene(); + + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() ); + + // Create the first actor and add it to the stage + Control control = Control::New(); + control.SetKeyboardFocusable(true); + scene.Add(control); + + KeyEventCallback controlCallback( true ); + control.KeyEventSignal().Connect( &controlCallback, &KeyEventCallback::Callback ); + + KeyEventCallback sceneCallback( false ); + scene.KeyEventSignal().Connect( &sceneCallback, &KeyEventCallback::Callback ); + + manager.SetCurrentFocusActor( control ); + + // Press Any key to notice physical keyboard event is comming to KeyboardFocusManager + // It makes mIsFocusIndicatorEnabled true and add focus indicator to focused actor. + Integration::KeyEvent event1( "Right", "", "", 0, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ); + application.ProcessEvent(event1); + + DALI_TEST_CHECK( controlCallback.mIsCalled ); + DALI_TEST_CHECK( !sceneCallback.mIsCalled ); + + END_TEST; +} + +int UtcDaliKeyboardFocusManagerFocusPerWindow(void) +{ + ToolkitTestApplication application; + + tet_infoline( "Ensure Memory focus actors for each window "); + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK( ! manager.GetCurrentFocusActor() ); + + Window firstWindow = Window::New(PositionSize(0,0,300,500) ,"", false); + DALI_TEST_CHECK( firstWindow ); + Control first = Control::New(); + first.SetKeyboardFocusable(true); + firstWindow.Add(first); + + Window secondWindow = Window::New(PositionSize(0,0,400,600) ,"", false); + DALI_TEST_CHECK( secondWindow ); + Control second = Control::New(); + second.SetKeyboardFocusable(true); + secondWindow.Add( second ); + + DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); + + DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); + firstWindow.Raise(); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); + + secondWindow.Remove( second ); + secondWindow.Raise(); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() != second); + + secondWindow.Reset(); + END_TEST; +} + +