OLD | NEW |
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/common/shelf/shelf_types.h" | 7 #include "ash/common/shelf/shelf_types.h" |
8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/display/mouse_cursor_event_filter.h" | 10 #include "ash/display/mouse_cursor_event_filter.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 private: | 43 private: |
44 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegate); | 44 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegate); |
45 }; | 45 }; |
46 | 46 |
47 class MockImmersiveFullscreenControllerDelegate | 47 class MockImmersiveFullscreenControllerDelegate |
48 : public ImmersiveFullscreenController::Delegate { | 48 : public ImmersiveFullscreenController::Delegate { |
49 public: | 49 public: |
50 MockImmersiveFullscreenControllerDelegate(views::View* top_container_view) | 50 MockImmersiveFullscreenControllerDelegate(views::View* top_container_view) |
51 : top_container_view_(top_container_view), | 51 : top_container_view_(top_container_view), |
52 enabled_(false), | 52 enabled_(false), |
53 visible_fraction_(1) { | 53 visible_fraction_(1) {} |
54 } | |
55 ~MockImmersiveFullscreenControllerDelegate() override {} | 54 ~MockImmersiveFullscreenControllerDelegate() override {} |
56 | 55 |
57 // ImmersiveFullscreenController::Delegate overrides: | 56 // ImmersiveFullscreenController::Delegate overrides: |
58 void OnImmersiveRevealStarted() override { | 57 void OnImmersiveRevealStarted() override { |
59 enabled_ = true; | 58 enabled_ = true; |
60 visible_fraction_ = 0; | 59 visible_fraction_ = 0; |
61 } | 60 } |
62 void OnImmersiveRevealEnded() override { visible_fraction_ = 0; } | 61 void OnImmersiveRevealEnded() override { visible_fraction_ = 0; } |
63 void OnImmersiveFullscreenExited() override { | 62 void OnImmersiveFullscreenExited() override { |
64 enabled_ = false; | 63 enabled_ = false; |
65 visible_fraction_ = 1; | 64 visible_fraction_ = 1; |
66 } | 65 } |
67 void SetVisibleFraction(double visible_fraction) override { | 66 void SetVisibleFraction(double visible_fraction) override { |
68 visible_fraction_ = visible_fraction; | 67 visible_fraction_ = visible_fraction; |
69 } | 68 } |
70 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override { | 69 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override { |
71 std::vector<gfx::Rect> bounds_in_screen; | 70 std::vector<gfx::Rect> bounds_in_screen; |
72 bounds_in_screen.push_back(top_container_view_->GetBoundsInScreen()); | 71 bounds_in_screen.push_back(top_container_view_->GetBoundsInScreen()); |
73 return bounds_in_screen; | 72 return bounds_in_screen; |
74 } | 73 } |
75 | 74 |
76 bool is_enabled() const { | 75 bool is_enabled() const { return enabled_; } |
77 return enabled_; | |
78 } | |
79 | 76 |
80 double visible_fraction() const { | 77 double visible_fraction() const { return visible_fraction_; } |
81 return visible_fraction_; | |
82 } | |
83 | 78 |
84 private: | 79 private: |
85 views::View* top_container_view_; | 80 views::View* top_container_view_; |
86 bool enabled_; | 81 bool enabled_; |
87 double visible_fraction_; | 82 double visible_fraction_; |
88 | 83 |
89 DISALLOW_COPY_AND_ASSIGN(MockImmersiveFullscreenControllerDelegate); | 84 DISALLOW_COPY_AND_ASSIGN(MockImmersiveFullscreenControllerDelegate); |
90 }; | 85 }; |
91 | 86 |
92 class ConsumeEventHandler : public ui::test::TestEventHandler { | 87 class ConsumeEventHandler : public ui::test::TestEventHandler { |
(...skipping 20 matching lines...) Expand all Loading... |
113 enum Modality { | 108 enum Modality { |
114 MODALITY_MOUSE, | 109 MODALITY_MOUSE, |
115 MODALITY_GESTURE_TAP, | 110 MODALITY_GESTURE_TAP, |
116 MODALITY_GESTURE_SCROLL | 111 MODALITY_GESTURE_SCROLL |
117 }; | 112 }; |
118 | 113 |
119 ImmersiveFullscreenControllerTest() | 114 ImmersiveFullscreenControllerTest() |
120 : widget_(nullptr), top_container_(nullptr), content_view_(nullptr) {} | 115 : widget_(nullptr), top_container_(nullptr), content_view_(nullptr) {} |
121 ~ImmersiveFullscreenControllerTest() override {} | 116 ~ImmersiveFullscreenControllerTest() override {} |
122 | 117 |
123 ImmersiveFullscreenController* controller() { | 118 ImmersiveFullscreenController* controller() { return controller_.get(); } |
124 return controller_.get(); | |
125 } | |
126 | 119 |
127 views::NativeViewHost* content_view() { | 120 views::NativeViewHost* content_view() { return content_view_; } |
128 return content_view_; | |
129 } | |
130 | 121 |
131 views::View* top_container() { | 122 views::View* top_container() { return top_container_; } |
132 return top_container_; | |
133 } | |
134 | 123 |
135 views::Widget* widget() { return widget_; } | 124 views::Widget* widget() { return widget_; } |
136 | 125 |
137 aura::Window* window() { | 126 aura::Window* window() { return widget_->GetNativeWindow(); } |
138 return widget_->GetNativeWindow(); | |
139 } | |
140 | 127 |
141 MockImmersiveFullscreenControllerDelegate* delegate() { | 128 MockImmersiveFullscreenControllerDelegate* delegate() { |
142 return delegate_.get(); | 129 return delegate_.get(); |
143 } | 130 } |
144 | 131 |
145 // Access to private data from the controller. | 132 // Access to private data from the controller. |
146 bool top_edge_hover_timer_running() const { | 133 bool top_edge_hover_timer_running() const { |
147 return controller_->top_edge_hover_timer_.IsRunning(); | 134 return controller_->top_edge_hover_timer_.IsRunning(); |
148 } | 135 } |
149 int mouse_x_when_hit_top() const { | 136 int mouse_x_when_hit_top() const { |
(...skipping 12 matching lines...) Expand all Loading... |
162 | 149 |
163 window()->SetProperty(aura::client::kShowStateKey, | 150 window()->SetProperty(aura::client::kShowStateKey, |
164 ui::SHOW_STATE_FULLSCREEN); | 151 ui::SHOW_STATE_FULLSCREEN); |
165 | 152 |
166 gfx::Size window_size = widget_->GetWindowBoundsInScreen().size(); | 153 gfx::Size window_size = widget_->GetWindowBoundsInScreen().size(); |
167 content_view_ = new views::NativeViewHost(); | 154 content_view_ = new views::NativeViewHost(); |
168 content_view_->SetBounds(0, 0, window_size.width(), window_size.height()); | 155 content_view_->SetBounds(0, 0, window_size.width(), window_size.height()); |
169 widget_->GetContentsView()->AddChildView(content_view_); | 156 widget_->GetContentsView()->AddChildView(content_view_); |
170 | 157 |
171 top_container_ = new views::View(); | 158 top_container_ = new views::View(); |
172 top_container_->SetBounds( | 159 top_container_->SetBounds(0, 0, window_size.width(), 100); |
173 0, 0, window_size.width(), 100); | |
174 top_container_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | 160 top_container_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
175 widget_->GetContentsView()->AddChildView(top_container_); | 161 widget_->GetContentsView()->AddChildView(top_container_); |
176 | 162 |
177 delegate_.reset( | 163 delegate_.reset( |
178 new MockImmersiveFullscreenControllerDelegate(top_container_)); | 164 new MockImmersiveFullscreenControllerDelegate(top_container_)); |
179 controller_.reset(new ImmersiveFullscreenController); | 165 controller_.reset(new ImmersiveFullscreenController); |
180 controller_->Init(delegate_.get(), widget_, top_container_); | 166 controller_->Init(delegate_.get(), widget_, top_container_); |
181 controller_->SetupForTest(); | 167 controller_->SetupForTest(); |
182 | 168 |
183 // The mouse is moved so that it is not over |top_container_| by | 169 // The mouse is moved so that it is not over |top_container_| by |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 break; | 233 break; |
248 } | 234 } |
249 case MODALITY_GESTURE_SCROLL: { | 235 case MODALITY_GESTURE_SCROLL: { |
250 gfx::Point start(0, revealed ? 0 : top_container_->height() - 2); | 236 gfx::Point start(0, revealed ? 0 : top_container_->height() - 2); |
251 gfx::Vector2d scroll_delta(0, 40); | 237 gfx::Vector2d scroll_delta(0, 40); |
252 gfx::Point end = revealed ? start + scroll_delta : start - scroll_delta; | 238 gfx::Point end = revealed ? start + scroll_delta : start - scroll_delta; |
253 views::View::ConvertPointToScreen(top_container_, &start); | 239 views::View::ConvertPointToScreen(top_container_, &start); |
254 views::View::ConvertPointToScreen(top_container_, &end); | 240 views::View::ConvertPointToScreen(top_container_, &end); |
255 ui::test::EventGenerator& event_generator(GetEventGenerator()); | 241 ui::test::EventGenerator& event_generator(GetEventGenerator()); |
256 event_generator.GestureScrollSequence( | 242 event_generator.GestureScrollSequence( |
257 start, end, | 243 start, end, base::TimeDelta::FromMilliseconds(30), 1); |
258 base::TimeDelta::FromMilliseconds(30), 1); | |
259 break; | 244 break; |
260 } | 245 } |
261 } | 246 } |
262 } | 247 } |
263 | 248 |
264 std::unique_ptr<ImmersiveFullscreenController> controller_; | 249 std::unique_ptr<ImmersiveFullscreenController> controller_; |
265 std::unique_ptr<MockImmersiveFullscreenControllerDelegate> delegate_; | 250 std::unique_ptr<MockImmersiveFullscreenControllerDelegate> delegate_; |
266 views::Widget* widget_; // Owned by the native widget. | 251 views::Widget* widget_; // Owned by the native widget. |
267 views::View* top_container_; // Owned by |widget_|'s root-view. | 252 views::View* top_container_; // Owned by |widget_|'s root-view. |
268 views::NativeViewHost* content_view_; // Owned by |widget_|'s root-view. | 253 views::NativeViewHost* content_view_; // Owned by |widget_|'s root-view. |
269 | 254 |
270 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerTest); | 255 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenControllerTest); |
271 }; | 256 }; |
272 | 257 |
273 // Test the initial state and that the delegate gets notified of the | 258 // Test the initial state and that the delegate gets notified of the |
274 // top-of-window views getting hidden and revealed. | 259 // top-of-window views getting hidden and revealed. |
275 TEST_F(ImmersiveFullscreenControllerTest, Delegate) { | 260 TEST_F(ImmersiveFullscreenControllerTest, Delegate) { |
276 // Initial state. | 261 // Initial state. |
277 EXPECT_FALSE(controller()->IsEnabled()); | 262 EXPECT_FALSE(controller()->IsEnabled()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 EXPECT_FALSE(top_edge_hover_timer_running()); | 358 EXPECT_FALSE(top_edge_hover_timer_running()); |
374 | 359 |
375 // Move to top edge of screen starts hover timer running. We cannot use | 360 // Move to top edge of screen starts hover timer running. We cannot use |
376 // MoveMouse() because MoveMouse() stops the timer if it started running. | 361 // MoveMouse() because MoveMouse() stops the timer if it started running. |
377 event_generator.MoveMouseTo(top_edge_pos); | 362 event_generator.MoveMouseTo(top_edge_pos); |
378 EXPECT_TRUE(top_edge_hover_timer_running()); | 363 EXPECT_TRUE(top_edge_hover_timer_running()); |
379 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top()); | 364 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top()); |
380 | 365 |
381 // Moving |ImmersiveFullscreenControllerTest::kMouseRevealBoundsHeight| down | 366 // Moving |ImmersiveFullscreenControllerTest::kMouseRevealBoundsHeight| down |
382 // from the top edge stops it. | 367 // from the top edge stops it. |
383 event_generator.MoveMouseBy(0, | 368 event_generator.MoveMouseBy( |
384 ImmersiveFullscreenController::kMouseRevealBoundsHeight); | 369 0, ImmersiveFullscreenController::kMouseRevealBoundsHeight); |
385 EXPECT_FALSE(top_edge_hover_timer_running()); | 370 EXPECT_FALSE(top_edge_hover_timer_running()); |
386 | 371 |
387 // Moving back to the top starts the timer again. | 372 // Moving back to the top starts the timer again. |
388 event_generator.MoveMouseTo(top_edge_pos); | 373 event_generator.MoveMouseTo(top_edge_pos); |
389 EXPECT_TRUE(top_edge_hover_timer_running()); | 374 EXPECT_TRUE(top_edge_hover_timer_running()); |
390 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top()); | 375 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top()); |
391 | 376 |
392 // Slight move to the right keeps the timer running for the same hit point. | 377 // Slight move to the right keeps the timer running for the same hit point. |
393 event_generator.MoveMouseBy(1, 0); | 378 event_generator.MoveMouseBy(1, 0); |
394 EXPECT_TRUE(top_edge_hover_timer_running()); | 379 EXPECT_TRUE(top_edge_hover_timer_running()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 gfx::Rect top_container_bounds_in_screen = | 451 gfx::Rect top_container_bounds_in_screen = |
467 top_container()->GetBoundsInScreen(); | 452 top_container()->GetBoundsInScreen(); |
468 gfx::Rect popup_bounds_in_screen = popup_widget->GetWindowBoundsInScreen(); | 453 gfx::Rect popup_bounds_in_screen = popup_widget->GetWindowBoundsInScreen(); |
469 ASSERT_EQ(top_container_bounds_in_screen.origin().ToString(), | 454 ASSERT_EQ(top_container_bounds_in_screen.origin().ToString(), |
470 popup_bounds_in_screen.origin().ToString()); | 455 popup_bounds_in_screen.origin().ToString()); |
471 ASSERT_GT(top_container_bounds_in_screen.right(), | 456 ASSERT_GT(top_container_bounds_in_screen.right(), |
472 popup_bounds_in_screen.right()); | 457 popup_bounds_in_screen.right()); |
473 | 458 |
474 // The top-of-window views should stay hidden if the cursor is at the top edge | 459 // The top-of-window views should stay hidden if the cursor is at the top edge |
475 // but above an obscured portion of the top-of-window views. | 460 // but above an obscured portion of the top-of-window views. |
476 MoveMouse(popup_bounds_in_screen.x(), | 461 MoveMouse(popup_bounds_in_screen.x(), top_container_bounds_in_screen.y()); |
477 top_container_bounds_in_screen.y()); | |
478 EXPECT_FALSE(controller()->IsRevealed()); | 462 EXPECT_FALSE(controller()->IsRevealed()); |
479 | 463 |
480 // The top-of-window views should reveal if the cursor is at the top edge and | 464 // The top-of-window views should reveal if the cursor is at the top edge and |
481 // above an unobscured portion of the top-of-window views. | 465 // above an unobscured portion of the top-of-window views. |
482 MoveMouse(top_container_bounds_in_screen.right() - 1, | 466 MoveMouse(top_container_bounds_in_screen.right() - 1, |
483 top_container_bounds_in_screen.y()); | 467 top_container_bounds_in_screen.y()); |
484 EXPECT_TRUE(controller()->IsRevealed()); | 468 EXPECT_TRUE(controller()->IsRevealed()); |
485 | 469 |
486 // The top-of-window views should stay revealed if the cursor is moved off | 470 // The top-of-window views should stay revealed if the cursor is moved off |
487 // of the top edge. | 471 // of the top edge. |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1041 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
1058 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 1042 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
1059 | 1043 |
1060 // Entering immersive fullscreen keeps auto-hide. | 1044 // Entering immersive fullscreen keeps auto-hide. |
1061 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 1045 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
1062 SetEnabled(true); | 1046 SetEnabled(true); |
1063 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 1047 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
1064 | 1048 |
1065 // Disabling immersive fullscreen maintains the user's auto-hide selection. | 1049 // Disabling immersive fullscreen maintains the user's auto-hide selection. |
1066 SetEnabled(false); | 1050 SetEnabled(false); |
1067 window()->SetProperty(aura::client::kShowStateKey, | 1051 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
1068 ui::SHOW_STATE_NORMAL); | |
1069 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 1052 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
1070 } | 1053 } |
1071 | 1054 |
1072 } // namespase ash | 1055 } // namespase ash |
OLD | NEW |