Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: ash/wm/immersive_fullscreen_controller_unittest.cc

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/immersive_fullscreen_controller.h" 5 #include "ash/wm/immersive_fullscreen_controller.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/display/mouse_cursor_event_filter.h" 8 #include "ash/display/mouse_cursor_event_filter.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 views::View::ConvertPointToScreen(top_container_, &end); 243 views::View::ConvertPointToScreen(top_container_, &end);
244 ui::test::EventGenerator& event_generator(GetEventGenerator()); 244 ui::test::EventGenerator& event_generator(GetEventGenerator());
245 event_generator.GestureScrollSequence( 245 event_generator.GestureScrollSequence(
246 start, end, 246 start, end,
247 base::TimeDelta::FromMilliseconds(30), 1); 247 base::TimeDelta::FromMilliseconds(30), 1);
248 break; 248 break;
249 } 249 }
250 } 250 }
251 } 251 }
252 252
253 scoped_ptr<ImmersiveFullscreenController> controller_; 253 std::unique_ptr<ImmersiveFullscreenController> controller_;
254 scoped_ptr<MockImmersiveFullscreenControllerDelegate> delegate_; 254 std::unique_ptr<MockImmersiveFullscreenControllerDelegate> delegate_;
255 views::Widget* widget_; // Owned by the native widget. 255 views::Widget* widget_; // Owned by the native widget.
256 views::View* top_container_; // Owned by |widget_|'s root-view. 256 views::View* top_container_; // Owned by |widget_|'s root-view.
257 views::NativeViewHost* content_view_; // Owned by |widget_|'s root-view. 257 views::NativeViewHost* content_view_; // Owned by |widget_|'s root-view.
258 258
259 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerTest); 259 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerTest);
260 }; 260 };
261 261
262 // Test the initial state and that the delegate gets notified of the 262 // Test the initial state and that the delegate gets notified of the
263 // top-of-window views getting hidden and revealed. 263 // top-of-window views getting hidden and revealed.
264 TEST_F(ImmersiveFullscreenControllerTest, Delegate) { 264 TEST_F(ImmersiveFullscreenControllerTest, Delegate) {
(...skipping 18 matching lines...) Expand all
283 283
284 // Disabling ends the immersive reveal. 284 // Disabling ends the immersive reveal.
285 SetEnabled(false); 285 SetEnabled(false);
286 EXPECT_FALSE(controller()->IsEnabled()); 286 EXPECT_FALSE(controller()->IsEnabled());
287 EXPECT_FALSE(controller()->IsRevealed()); 287 EXPECT_FALSE(controller()->IsRevealed());
288 EXPECT_FALSE(delegate()->is_enabled()); 288 EXPECT_FALSE(delegate()->is_enabled());
289 } 289 }
290 290
291 // GetRevealedLock() specific tests. 291 // GetRevealedLock() specific tests.
292 TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) { 292 TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) {
293 scoped_ptr<ImmersiveRevealedLock> lock1; 293 std::unique_ptr<ImmersiveRevealedLock> lock1;
294 scoped_ptr<ImmersiveRevealedLock> lock2; 294 std::unique_ptr<ImmersiveRevealedLock> lock2;
295 295
296 // Immersive fullscreen is not on by default. 296 // Immersive fullscreen is not on by default.
297 EXPECT_FALSE(controller()->IsEnabled()); 297 EXPECT_FALSE(controller()->IsEnabled());
298 298
299 // 1) Test acquiring and releasing a revealed state lock while immersive 299 // 1) Test acquiring and releasing a revealed state lock while immersive
300 // fullscreen is disabled. Acquiring or releasing the lock should have no 300 // fullscreen is disabled. Acquiring or releasing the lock should have no
301 // effect till immersive fullscreen is enabled. 301 // effect till immersive fullscreen is enabled.
302 lock1.reset(controller()->GetRevealedLock( 302 lock1.reset(controller()->GetRevealedLock(
303 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); 303 ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
304 EXPECT_FALSE(controller()->IsEnabled()); 304 EXPECT_FALSE(controller()->IsEnabled());
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 ASSERT_FALSE(top_container()->GetBoundsInScreen().Intersects( 577 ASSERT_FALSE(top_container()->GetBoundsInScreen().Intersects(
578 popup_widget->GetWindowBoundsInScreen())); 578 popup_widget->GetWindowBoundsInScreen()));
579 event_generator.MoveMouseTo(x, y_top_edge + 1); 579 event_generator.MoveMouseTo(x, y_top_edge + 1);
580 MoveMouse(x, y_top_edge - 2); 580 MoveMouse(x, y_top_edge - 2);
581 EXPECT_TRUE(controller()->IsRevealed()); 581 EXPECT_TRUE(controller()->IsRevealed());
582 } 582 }
583 583
584 // Test behavior when the mouse becomes hovered without moving. 584 // Test behavior when the mouse becomes hovered without moving.
585 TEST_F(ImmersiveFullscreenControllerTest, MouseHoveredWithoutMoving) { 585 TEST_F(ImmersiveFullscreenControllerTest, MouseHoveredWithoutMoving) {
586 SetEnabled(true); 586 SetEnabled(true);
587 scoped_ptr<ImmersiveRevealedLock> lock; 587 std::unique_ptr<ImmersiveRevealedLock> lock;
588 588
589 // 1) Test that if the mouse becomes hovered without the mouse moving due to a 589 // 1) Test that if the mouse becomes hovered without the mouse moving due to a
590 // lock causing the top-of-window views to be revealed (and the mouse 590 // lock causing the top-of-window views to be revealed (and the mouse
591 // happening to be near the top of the screen), the top-of-window views do not 591 // happening to be near the top of the screen), the top-of-window views do not
592 // hide till the mouse moves off of the top-of-window views. 592 // hide till the mouse moves off of the top-of-window views.
593 SetHovered(true); 593 SetHovered(true);
594 EXPECT_FALSE(controller()->IsRevealed()); 594 EXPECT_FALSE(controller()->IsRevealed());
595 lock.reset(controller()->GetRevealedLock( 595 lock.reset(controller()->GetRevealedLock(
596 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); 596 ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
597 EXPECT_TRUE(controller()->IsRevealed()); 597 EXPECT_TRUE(controller()->IsRevealed());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 EXPECT_FALSE(controller()->IsRevealed()); 687 EXPECT_FALSE(controller()->IsRevealed());
688 688
689 // The top-of-window views should no longer have focus. Clearing focus is 689 // The top-of-window views should no longer have focus. Clearing focus is
690 // important because it closes focus-related popup windows like the touch 690 // important because it closes focus-related popup windows like the touch
691 // selection handles. 691 // selection handles.
692 EXPECT_FALSE(top_container()->HasFocus()); 692 EXPECT_FALSE(top_container()->HasFocus());
693 693
694 // If some other code is holding onto a lock, a gesture should not be able to 694 // If some other code is holding onto a lock, a gesture should not be able to
695 // end the reveal. 695 // end the reveal.
696 AttemptReveal(MODALITY_MOUSE); 696 AttemptReveal(MODALITY_MOUSE);
697 scoped_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock( 697 std::unique_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock(
698 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); 698 ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
699 EXPECT_TRUE(controller()->IsRevealed()); 699 EXPECT_TRUE(controller()->IsRevealed());
700 AttemptUnreveal(MODALITY_GESTURE_SCROLL); 700 AttemptUnreveal(MODALITY_GESTURE_SCROLL);
701 EXPECT_TRUE(controller()->IsRevealed()); 701 EXPECT_TRUE(controller()->IsRevealed());
702 lock.reset(); 702 lock.reset();
703 EXPECT_FALSE(controller()->IsRevealed()); 703 EXPECT_FALSE(controller()->IsRevealed());
704 } 704 }
705 705
706 // Tests that touch-gesture can be used to reveal the top-of-window views when 706 // Tests that touch-gesture can be used to reveal the top-of-window views when
707 // the child window consumes all events. 707 // the child window consumes all events.
708 TEST_F(ImmersiveFullscreenControllerTest, RevealViaGestureChildConsumesEvents) { 708 TEST_F(ImmersiveFullscreenControllerTest, RevealViaGestureChildConsumesEvents) {
709 // Enabling initially hides the top views. 709 // Enabling initially hides the top views.
710 SetEnabled(true); 710 SetEnabled(true);
711 EXPECT_TRUE(controller()->IsEnabled()); 711 EXPECT_TRUE(controller()->IsEnabled());
712 EXPECT_FALSE(controller()->IsRevealed()); 712 EXPECT_FALSE(controller()->IsRevealed());
713 713
714 aura::test::TestWindowDelegate child_delegate; 714 aura::test::TestWindowDelegate child_delegate;
715 scoped_ptr<aura::Window> child( 715 std::unique_ptr<aura::Window> child(
716 CreateTestWindowInShellWithDelegateAndType(&child_delegate, 716 CreateTestWindowInShellWithDelegateAndType(
717 ui::wm::WINDOW_TYPE_CONTROL, 717 &child_delegate, ui::wm::WINDOW_TYPE_CONTROL, 1234, gfx::Rect()));
718 1234,
719 gfx::Rect()));
720 content_view()->Attach(child.get()); 718 content_view()->Attach(child.get());
721 child->Show(); 719 child->Show();
722 720
723 ConsumeEventHandler handler; 721 ConsumeEventHandler handler;
724 child->AddPreTargetHandler(&handler); 722 child->AddPreTargetHandler(&handler);
725 723
726 // Reveal the top views using a touch-scroll gesture. The child window should 724 // Reveal the top views using a touch-scroll gesture. The child window should
727 // not receive the touch events. 725 // not receive the touch events.
728 AttemptReveal(MODALITY_GESTURE_SCROLL); 726 AttemptReveal(MODALITY_GESTURE_SCROLL);
729 EXPECT_TRUE(controller()->IsRevealed()); 727 EXPECT_TRUE(controller()->IsRevealed());
730 EXPECT_EQ(0, handler.num_touch_events()); 728 EXPECT_EQ(0, handler.num_touch_events());
731 729
732 AttemptUnreveal(MODALITY_GESTURE_TAP); 730 AttemptUnreveal(MODALITY_GESTURE_TAP);
733 EXPECT_FALSE(controller()->IsRevealed()); 731 EXPECT_FALSE(controller()->IsRevealed());
734 EXPECT_GT(handler.num_touch_events(), 0); 732 EXPECT_GT(handler.num_touch_events(), 0);
735 child->RemovePreTargetHandler(&handler); 733 child->RemovePreTargetHandler(&handler);
736 } 734 }
737 735
738 // Make sure touch events towards the top of the window do not leak through to 736 // Make sure touch events towards the top of the window do not leak through to
739 // windows underneath. 737 // windows underneath.
740 TEST_F(ImmersiveFullscreenControllerTest, EventsDoNotLeakToWindowUnderneath) { 738 TEST_F(ImmersiveFullscreenControllerTest, EventsDoNotLeakToWindowUnderneath) {
741 gfx::Rect window_bounds = window()->GetBoundsInScreen(); 739 gfx::Rect window_bounds = window()->GetBoundsInScreen();
742 aura::test::TestWindowDelegate child_delegate; 740 aura::test::TestWindowDelegate child_delegate;
743 scoped_ptr<aura::Window> behind(CreateTestWindowInShellWithDelegate( 741 std::unique_ptr<aura::Window> behind(CreateTestWindowInShellWithDelegate(
744 &child_delegate, 1234, window_bounds)); 742 &child_delegate, 1234, window_bounds));
745 behind->Show(); 743 behind->Show();
746 behind->SetBounds(window_bounds); 744 behind->SetBounds(window_bounds);
747 widget()->StackAbove(behind.get()); 745 widget()->StackAbove(behind.get());
748 746
749 // Make sure the windows are aligned on top. 747 // Make sure the windows are aligned on top.
750 EXPECT_EQ(behind->GetBoundsInScreen().y(), window()->GetBoundsInScreen().y()); 748 EXPECT_EQ(behind->GetBoundsInScreen().y(), window()->GetBoundsInScreen().y());
751 int top = behind->GetBoundsInScreen().y(); 749 int top = behind->GetBoundsInScreen().y();
752 750
753 ui::TouchEvent touch(ui::ET_TOUCH_MOVED, gfx::Point(10, top), 0, 751 ui::TouchEvent touch(ui::ET_TOUCH_MOVED, gfx::Point(10, top), 0,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 EXPECT_FALSE(controller()->IsRevealed()); 831 EXPECT_FALSE(controller()->IsRevealed());
834 unrelated_view->RequestFocus(); 832 unrelated_view->RequestFocus();
835 SetEnabled(true); 833 SetEnabled(true);
836 EXPECT_FALSE(controller()->IsRevealed()); 834 EXPECT_FALSE(controller()->IsRevealed());
837 835
838 // Repeat test but with a revealed lock acquired when immersive mode is 836 // Repeat test but with a revealed lock acquired when immersive mode is
839 // disabled because the code path is different. 837 // disabled because the code path is different.
840 child_view->RequestFocus(); 838 child_view->RequestFocus();
841 EXPECT_TRUE(controller()->IsRevealed()); 839 EXPECT_TRUE(controller()->IsRevealed());
842 SetEnabled(false); 840 SetEnabled(false);
843 scoped_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock( 841 std::unique_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock(
844 ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); 842 ImmersiveFullscreenController::ANIMATE_REVEAL_NO));
845 EXPECT_FALSE(controller()->IsRevealed()); 843 EXPECT_FALSE(controller()->IsRevealed());
846 unrelated_view->RequestFocus(); 844 unrelated_view->RequestFocus();
847 SetEnabled(true); 845 SetEnabled(true);
848 EXPECT_TRUE(controller()->IsRevealed()); 846 EXPECT_TRUE(controller()->IsRevealed());
849 lock.reset(); 847 lock.reset();
850 EXPECT_FALSE(controller()->IsRevealed()); 848 EXPECT_FALSE(controller()->IsRevealed());
851 } 849 }
852 850
853 // Test how transient windows affect whether the top-of-window views are 851 // Test how transient windows affect whether the top-of-window views are
854 // revealed. 852 // revealed.
855 TEST_F(ImmersiveFullscreenControllerTest, Transient) { 853 TEST_F(ImmersiveFullscreenControllerTest, Transient) {
856 views::Widget* top_container_widget = top_container()->GetWidget(); 854 views::Widget* top_container_widget = top_container()->GetWidget();
857 855
858 SetEnabled(true); 856 SetEnabled(true);
859 ASSERT_FALSE(controller()->IsRevealed()); 857 ASSERT_FALSE(controller()->IsRevealed());
860 858
861 // 1) Test that a transient window which is not a bubble does not trigger a 859 // 1) Test that a transient window which is not a bubble does not trigger a
862 // reveal but does keep the top-of-window views revealed if they are already 860 // reveal but does keep the top-of-window views revealed if they are already
863 // revealed. 861 // revealed.
864 views::Widget::InitParams transient_params; 862 views::Widget::InitParams transient_params;
865 transient_params.ownership = 863 transient_params.ownership =
866 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 864 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
867 transient_params.parent = top_container_widget->GetNativeView(); 865 transient_params.parent = top_container_widget->GetNativeView();
868 transient_params.bounds = gfx::Rect(0, 100, 100, 100); 866 transient_params.bounds = gfx::Rect(0, 100, 100, 100);
869 scoped_ptr<views::Widget> transient_widget(new views::Widget()); 867 std::unique_ptr<views::Widget> transient_widget(new views::Widget());
870 transient_widget->Init(transient_params); 868 transient_widget->Init(transient_params);
871 869
872 EXPECT_FALSE(controller()->IsRevealed()); 870 EXPECT_FALSE(controller()->IsRevealed());
873 AttemptReveal(MODALITY_MOUSE); 871 AttemptReveal(MODALITY_MOUSE);
874 EXPECT_TRUE(controller()->IsRevealed()); 872 EXPECT_TRUE(controller()->IsRevealed());
875 transient_widget->Show(); 873 transient_widget->Show();
876 SetHovered(false); 874 SetHovered(false);
877 EXPECT_TRUE(controller()->IsRevealed()); 875 EXPECT_TRUE(controller()->IsRevealed());
878 transient_widget.reset(); 876 transient_widget.reset();
879 EXPECT_FALSE(controller()->IsRevealed()); 877 EXPECT_FALSE(controller()->IsRevealed());
880 878
881 // 2) Test that activating a non-transient window does not keep the 879 // 2) Test that activating a non-transient window does not keep the
882 // top-of-window views revealed. 880 // top-of-window views revealed.
883 views::Widget::InitParams non_transient_params; 881 views::Widget::InitParams non_transient_params;
884 non_transient_params.ownership = 882 non_transient_params.ownership =
885 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 883 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
886 non_transient_params.context = top_container_widget->GetNativeView(); 884 non_transient_params.context = top_container_widget->GetNativeView();
887 non_transient_params.bounds = gfx::Rect(0, 100, 100, 100); 885 non_transient_params.bounds = gfx::Rect(0, 100, 100, 100);
888 scoped_ptr<views::Widget> non_transient_widget(new views::Widget()); 886 std::unique_ptr<views::Widget> non_transient_widget(new views::Widget());
889 non_transient_widget->Init(non_transient_params); 887 non_transient_widget->Init(non_transient_params);
890 888
891 EXPECT_FALSE(controller()->IsRevealed()); 889 EXPECT_FALSE(controller()->IsRevealed());
892 AttemptReveal(MODALITY_MOUSE); 890 AttemptReveal(MODALITY_MOUSE);
893 EXPECT_TRUE(controller()->IsRevealed()); 891 EXPECT_TRUE(controller()->IsRevealed());
894 non_transient_widget->Show(); 892 non_transient_widget->Show();
895 SetHovered(false); 893 SetHovered(false);
896 EXPECT_FALSE(controller()->IsRevealed()); 894 EXPECT_FALSE(controller()->IsRevealed());
897 } 895 }
898 896
899 // Test how bubbles affect whether the top-of-window views are revealed. 897 // Test how bubbles affect whether the top-of-window views are revealed.
900 TEST_F(ImmersiveFullscreenControllerTest, Bubbles) { 898 TEST_F(ImmersiveFullscreenControllerTest, Bubbles) {
901 scoped_ptr<ImmersiveRevealedLock> revealed_lock; 899 std::unique_ptr<ImmersiveRevealedLock> revealed_lock;
902 views::Widget* top_container_widget = top_container()->GetWidget(); 900 views::Widget* top_container_widget = top_container()->GetWidget();
903 901
904 // Add views to the view hierarchy to which we will anchor bubbles. 902 // Add views to the view hierarchy to which we will anchor bubbles.
905 views::View* child_view = new views::View(); 903 views::View* child_view = new views::View();
906 child_view->SetBounds(0, 0, 10, 10); 904 child_view->SetBounds(0, 0, 10, 10);
907 top_container()->AddChildView(child_view); 905 top_container()->AddChildView(child_view);
908 views::View* unrelated_view = new views::View(); 906 views::View* unrelated_view = new views::View();
909 unrelated_view->SetBounds(0, 100, 10, 10); 907 unrelated_view->SetBounds(0, 100, 10, 10);
910 top_container()->parent()->AddChildView(unrelated_view); 908 top_container()->parent()->AddChildView(unrelated_view);
911 909
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 1053 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
1056 1054
1057 // Disabling immersive fullscreen maintains the user's auto-hide selection. 1055 // Disabling immersive fullscreen maintains the user's auto-hide selection.
1058 SetEnabled(false); 1056 SetEnabled(false);
1059 window()->SetProperty(aura::client::kShowStateKey, 1057 window()->SetProperty(aura::client::kShowStateKey,
1060 ui::SHOW_STATE_NORMAL); 1058 ui::SHOW_STATE_NORMAL);
1061 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state()); 1059 EXPECT_EQ(ash::SHELF_AUTO_HIDE, shelf->visibility_state());
1062 } 1060 }
1063 1061
1064 } // namespase ash 1062 } // namespase ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698