~unity-team/nux/x-sru1

« back to all changes in this revision

Viewing changes to tests/gtest-nux-windowcompositor.cpp

  • Committer: CI Train Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2015-09-21 17:41:44 UTC
  • mfrom: (865.1.8 emit-mouse-leave-on-new-over-area)
  • Revision ID: ci-train-bot@canonical.com-20150921174144-3bs7j0bt0qltk7is
WindowCompositor: emit mouse_leave signal when releasing mouse over a new area

When the mouse button is released we update the mouse over area, but we also need
to signal the old mouse over area that mouse is not hovering it anymore.
Otherwise IsMouseInside will still be true for that (sicne it caches this value). Fixes: #1496140
Approved by: PS Jenkins bot, Andrea Azzarone

Show diffs side-by-side

added added

removed removed

Lines of Context:
686
686
  EXPECT_EQ(area.GetPointer(), nullptr);
687
687
}
688
688
 
 
689
TEST_F(TestWindowCompositor, UpdateInputAreaMouseInsideOnRelease)
 
690
{
 
691
  Event ev;
 
692
  ObjectPtr<TestBaseWindow> ia1(new TestBaseWindow());
 
693
 
 
694
  ev.type = EVENT_MOUSE_DOWN;
 
695
  nux::GetWindowCompositor().ProcessEvent(ev);
 
696
 
 
697
  ASSERT_TRUE(ia1->input_area->IsMouseInside());
 
698
  ASSERT_TRUE(ia1->input_area->IsMouseOwner());
 
699
 
 
700
  ObjectPtr<TestBaseWindow> ia2(new TestBaseWindow());
 
701
  ev.type = EVENT_MOUSE_UP;
 
702
  nux::GetWindowCompositor().ProcessEvent(ev);
 
703
 
 
704
  EXPECT_FALSE(ia1->input_area->IsMouseOwner());
 
705
  EXPECT_FALSE(ia1->input_area->IsMouseInside());
 
706
  EXPECT_NE(GetMouseOverArea(), ia1->input_area.GetPointer());
 
707
}
 
708
 
 
709
TEST_F(TestWindowCompositor, UpdateNewInputAreaMouseInsideOnRelease)
 
710
{
 
711
  Event ev;
 
712
  ObjectPtr<TestBaseWindow> ia1(new TestBaseWindow());
 
713
 
 
714
  ev.type = EVENT_MOUSE_DOWN;
 
715
  nux::GetWindowCompositor().ProcessEvent(ev);
 
716
 
 
717
  ASSERT_TRUE(ia1->input_area->IsMouseInside());
 
718
  ASSERT_TRUE(ia1->input_area->IsMouseOwner());
 
719
 
 
720
  ObjectPtr<TestBaseWindow> ia2(new TestBaseWindow());
 
721
  ev.type = EVENT_MOUSE_UP;
 
722
  nux::GetWindowCompositor().ProcessEvent(ev);
 
723
 
 
724
  EXPECT_FALSE(ia2->input_area->IsMouseOwner());
 
725
  EXPECT_TRUE(ia2->input_area->IsMouseInside());
 
726
  EXPECT_EQ(GetMouseOverArea(), ia2->input_area.GetPointer());
 
727
}
 
728
 
 
729
TEST_F(TestWindowCompositor, UpdateNewInputAreaMouseOwnerBeforeSignalEmission)
 
730
{
 
731
  Event ev;
 
732
  ObjectPtr<TestBaseWindow> ia1(new TestBaseWindow());
 
733
 
 
734
  ev.type = EVENT_MOUSE_DOWN;
 
735
  nux::GetWindowCompositor().ProcessEvent(ev);
 
736
  ASSERT_TRUE(ia1->input_area->IsMouseInside());
 
737
  ASSERT_TRUE(ia1->input_area->IsMouseOwner());
 
738
 
 
739
  bool got_cb = false;
 
740
  ia1->input_area->mouse_up.connect([this, &ia1, &got_cb] (int, int, unsigned long, unsigned long) {
 
741
    got_cb = true;
 
742
    EXPECT_TRUE(ia1->input_area->IsMouseInside());
 
743
    EXPECT_FALSE(ia1->input_area->IsMouseOwner());
 
744
  });
 
745
 
 
746
  ev.type = EVENT_MOUSE_UP;
 
747
  nux::GetWindowCompositor().ProcessEvent(ev);
 
748
 
 
749
  ASSERT_TRUE(got_cb);
 
750
  EXPECT_TRUE(ia1->input_area->IsMouseInside());
 
751
  EXPECT_FALSE(ia1->input_area->IsMouseOwner());
 
752
  EXPECT_EQ(GetMouseOverArea(), ia1->input_area.GetPointer());
 
753
}
 
754
 
 
755
TEST_F(TestWindowCompositor, InvalidMouseOverAreaOnReleaseDontCrash)
 
756
{
 
757
  Event ev;
 
758
  ObjectPtr<TestBaseWindow> ia1(new TestBaseWindow());
 
759
 
 
760
  ev.type = EVENT_MOUSE_DOWN;
 
761
  nux::GetWindowCompositor().ProcessEvent(ev);
 
762
  ASSERT_TRUE(ia1->input_area->IsMouseInside());
 
763
  ASSERT_TRUE(ia1->input_area->IsMouseOwner());
 
764
 
 
765
  // We save a copy of the input area, so that WC still things it's alive but
 
766
  // the test window won't return it as the target area for events.
 
767
  auto old_mouse_owner_area = ia1->input_area; (void)old_mouse_owner_area;
 
768
  ia1->input_area.Release();
 
769
 
 
770
  ev.type = EVENT_MOUSE_UP;
 
771
  nux::GetWindowCompositor().ProcessEvent(ev);
 
772
}
 
773
 
 
774
TEST_F(TestWindowCompositor, EmitMouseCancelOnReleasedMouseOwner)
 
775
{
 
776
  Event ev;
 
777
  ObjectPtr<TestBaseWindow> ia1(new TestBaseWindow());
 
778
 
 
779
  ev.type = EVENT_MOUSE_DOWN;
 
780
  nux::GetWindowCompositor().ProcessEvent(ev);
 
781
  ASSERT_TRUE(ia1->input_area->IsMouseOwner());
 
782
 
 
783
  bool mouse_cancel_called = false;
 
784
  ia1->input_area->mouse_cancel.connect([this, &mouse_cancel_called] {
 
785
    mouse_cancel_called = true;
 
786
  });
 
787
 
 
788
  ev.type = EVENT_MOUSE_UP;
 
789
  nux::GetWindowCompositor().ProcessEvent(ev);
 
790
 
 
791
  EXPECT_TRUE(mouse_cancel_called);
 
792
}
 
793
 
689
794
class DraggedWindow : public nux::BaseWindow
690
795
{
691
796
 public:
770
875
    bool wants_mouse_ownership;
771
876
 
772
877
  protected:
773
 
    virtual void EmitMouseUpSignal(int x, int y,
774
 
                                   unsigned long mouse_button_state,
775
 
                                   unsigned long special_keys_state)
 
878
    virtual void EmitMouseUpSignal(int, int,
 
879
                                   unsigned long,
 
880
                                   unsigned long)
776
881
    {
777
882
      ++mouse_up_emission_count;
778
883
    }
779
884
 
780
 
    virtual void EmitMouseDragSignal(int x, int y,
 
885
    virtual void EmitMouseDragSignal(int, int,
781
886
                                     int dx, int dy,
782
 
                                     unsigned long mouse_button_state,
783
 
                                     unsigned long special_keys_state)
 
887
                                     unsigned long,
 
888
                                     unsigned long)
784
889
    {
785
890
      ++mouse_drag_emission_count;
786
891
      mouse_drag_dx = dx;
804
909
    {}
805
910
 
806
911
  protected:
807
 
    virtual void EmitMouseDownSignal(int x, int y,
808
 
                                     unsigned long mouse_button_state,
809
 
                                     unsigned long special_keys_state)
 
912
    virtual void EmitMouseDownSignal(int, int,
 
913
                                     unsigned long,
 
914
                                     unsigned long)
810
915
    {
811
916
      ++mouse_down_emission_count;
812
917
    }
813
918
 
814
 
    virtual void EmitMouseUpSignal(int x, int y,
815
 
                                   unsigned long mouse_button_state,
816
 
                                   unsigned long special_keys_state)
 
919
    virtual void EmitMouseUpSignal(int, int,
 
920
                                   unsigned long,
 
921
                                   unsigned long)
817
922
    {
818
923
      ++mouse_up_emission_count;
819
924
    }
820
925
 
821
 
    virtual void EmitMouseDragSignal(int x, int y,
822
 
                                     int dx, int dy,
823
 
                                     unsigned long mouse_button_state,
824
 
                                     unsigned long special_keys_state)
 
926
    virtual void EmitMouseDragSignal(int, int,
 
927
                                     int, int,
 
928
                                     unsigned long,
 
929
                                     unsigned long)
825
930
    {
826
931
      ++mouse_drag_emission_count;
827
932
    }