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

Side by Side Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash_unittest.cc

Issue 27458002: Allow setting different hit test bounds overrides for mouse and touch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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 "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
10 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 13 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
13 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" 14 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
14 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" 15 #include "chrome/browser/ui/immersive_fullscreen_configuration.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" 17 #include "chrome/browser/ui/views/frame/test_with_browser_view.h"
17 #include "chrome/browser/ui/views/frame/top_container_view.h" 18 #include "chrome/browser/ui/views/frame/top_container_view.h"
18 #include "chrome/browser/ui/views/tabs/tab_strip.h" 19 #include "chrome/browser/ui/views/tabs/tab_strip.h"
19 #include "chrome/browser/ui/views/toolbar_view.h" 20 #include "chrome/browser/ui/views/toolbar_view.h"
21 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/client/cursor_client.h" 22 #include "ui/aura/client/cursor_client.h"
21 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
22 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
23 #include "ui/aura/test/event_generator.h" 25 #include "ui/aura/test/event_generator.h"
24 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
27 #include "ui/base/ui_base_types.h"
25 #include "ui/gfx/animation/slide_animation.h" 28 #include "ui/gfx/animation/slide_animation.h"
26 #include "ui/views/bubble/bubble_delegate.h" 29 #include "ui/views/bubble/bubble_delegate.h"
27 #include "ui/views/controls/webview/webview.h" 30 #include "ui/views/controls/webview/webview.h"
28 31
29 // For now, immersive fullscreen is Chrome OS only. 32 // For now, immersive fullscreen is Chrome OS only.
30 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
31 34
32 ///////////////////////////////////////////////////////////////////////////// 35 /////////////////////////////////////////////////////////////////////////////
33 36
34 class MockImmersiveModeControllerDelegate 37 class MockImmersiveModeControllerDelegate
35 : public ImmersiveModeController::Delegate { 38 : public ImmersiveModeController::Delegate {
36 public: 39 public:
37 MockImmersiveModeControllerDelegate() : immersive_style_(false) {} 40 MockImmersiveModeControllerDelegate() : immersive_style_(false) {}
38 virtual ~MockImmersiveModeControllerDelegate() {} 41 virtual ~MockImmersiveModeControllerDelegate() {}
39 42
40 bool immersive_style() const { return immersive_style_; } 43 bool immersive_style() const { return immersive_style_; }
41 44
42 // ImmersiveModeController::Delegate overrides: 45 // ImmersiveModeController::Delegate overrides:
43 virtual BookmarkBarView* GetBookmarkBar() OVERRIDE { return NULL; } 46 virtual BookmarkBarView* GetBookmarkBar() OVERRIDE { return NULL; }
44 virtual FullscreenController* GetFullscreenController() OVERRIDE { 47 virtual FullscreenController* GetFullscreenController() OVERRIDE {
45 return NULL; 48 return NULL;
46 } 49 }
47 virtual void FullscreenStateChanged() OVERRIDE {} 50 virtual void FullscreenStateChanged() OVERRIDE {}
48 virtual void SetImmersiveStyle(bool immersive) OVERRIDE { 51 virtual void SetImmersiveStyle(bool immersive) OVERRIDE {
49 immersive_style_ = immersive; 52 immersive_style_ = immersive;
50 } 53 }
51 virtual content::WebContents* GetWebContents() OVERRIDE {
52 return NULL;
53 }
54 54
55 private: 55 private:
56 bool immersive_style_; 56 bool immersive_style_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeControllerDelegate); 58 DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeControllerDelegate);
59 }; 59 };
60 60
61 // View which consumes all touch events.
62 class TouchEventConsumerView : public views::View {
63 public:
64 TouchEventConsumerView() {
65 }
66 virtual ~TouchEventConsumerView() {
67 }
68
69 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
70 event->SetHandled();
71 }
72 private:
73 DISALLOW_COPY_AND_ASSIGN(TouchEventConsumerView);
74 };
75
61 ///////////////////////////////////////////////////////////////////////////// 76 /////////////////////////////////////////////////////////////////////////////
62 77
63 class ImmersiveModeControllerAshTest : public ash::test::AshTestBase { 78 class ImmersiveModeControllerAshTest : public ash::test::AshTestBase {
64 public: 79 public:
65 enum Modality { 80 enum Modality {
66 MODALITY_MOUSE, 81 MODALITY_MOUSE,
67 MODALITY_TOUCH, 82 MODALITY_TOUCH,
68 MODALITY_GESTURE 83 MODALITY_GESTURE
69 }; 84 };
70 85
(...skipping 18 matching lines...) Expand all
89 104
90 ImmersiveFullscreenConfiguration::EnableImmersiveFullscreenForTest(); 105 ImmersiveFullscreenConfiguration::EnableImmersiveFullscreenForTest();
91 ASSERT_TRUE(ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()); 106 ASSERT_TRUE(ImmersiveFullscreenConfiguration::UseImmersiveFullscreen());
92 107
93 controller_.reset(new ImmersiveModeControllerAsh); 108 controller_.reset(new ImmersiveModeControllerAsh);
94 delegate_.reset(new MockImmersiveModeControllerDelegate); 109 delegate_.reset(new MockImmersiveModeControllerDelegate);
95 110
96 widget_ = new views::Widget(); 111 widget_ = new views::Widget();
97 views::Widget::InitParams params; 112 views::Widget::InitParams params;
98 params.context = CurrentContext(); 113 params.context = CurrentContext();
99 params.bounds = gfx::Rect(0, 0, 500, 500);
100 widget_->Init(params); 114 widget_->Init(params);
101 widget_->Show(); 115 widget_->Show();
102 116
117 widget_->GetNativeWindow()->SetProperty(aura::client::kShowStateKey,
118 ui::SHOW_STATE_FULLSCREEN);
119
103 top_container_ = new views::View(); 120 top_container_ = new views::View();
104 top_container_->SetBounds(0, 0, 500, 100); 121 top_container_->SetBounds(
122 0, 0, widget_->GetWindowBoundsInScreen().width(), 100);
105 top_container_->set_focusable(true); 123 top_container_->set_focusable(true);
106
107 widget_->GetContentsView()->AddChildView(top_container_); 124 widget_->GetContentsView()->AddChildView(top_container_);
108 125
109 controller_->Init(delegate_.get(), widget_, top_container_); 126 controller_->Init(delegate_.get(), widget_, top_container_);
110 SetAnimationsDisabled(true); 127 SetAnimationsDisabled(true);
111 128
112 // The mouse is moved so that it is not over |top_container_| by 129 // The mouse is moved so that it is not over |top_container_| by
113 // AshTestBase. 130 // AshTestBase.
114 } 131 }
115 132
116 // Enable or disable the immersive mode controller's animations. When the 133 // Enable or disable the immersive mode controller's animations. When the
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 controller()->SetEnabled(false); 261 controller()->SetEnabled(false);
245 EXPECT_FALSE(controller()->IsEnabled()); 262 EXPECT_FALSE(controller()->IsEnabled());
246 EXPECT_FALSE(controller()->IsRevealed()); 263 EXPECT_FALSE(controller()->IsRevealed());
247 EXPECT_FALSE(controller()->ShouldHideTopViews()); 264 EXPECT_FALSE(controller()->ShouldHideTopViews());
248 EXPECT_FALSE(delegate()->immersive_style()); 265 EXPECT_FALSE(delegate()->immersive_style());
249 } 266 }
250 267
251 // Test mouse event processing for top-of-screen reveal triggering. 268 // Test mouse event processing for top-of-screen reveal triggering.
252 TEST_F(ImmersiveModeControllerAshTest, OnMouseEvent) { 269 TEST_F(ImmersiveModeControllerAshTest, OnMouseEvent) {
253 // Set up initial state. 270 // Set up initial state.
271 UpdateDisplay("800x600,800x600");
272 ash::DisplayLayout display_layout(ash::DisplayLayout::RIGHT, 0);
273 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
274 display_layout);
275
276 // Set up initial state.
254 controller()->SetEnabled(true); 277 controller()->SetEnabled(true);
255 ASSERT_TRUE(controller()->IsEnabled()); 278 ASSERT_TRUE(controller()->IsEnabled());
256 ASSERT_FALSE(controller()->IsRevealed()); 279 ASSERT_FALSE(controller()->IsRevealed());
257 280
258 aura::test::EventGenerator& event_generator(GetEventGenerator()); 281 aura::test::EventGenerator& event_generator(GetEventGenerator());
259 282
260 gfx::Rect top_container_bounds_in_screen = 283 gfx::Rect top_container_bounds_in_screen =
261 top_container()->GetBoundsInScreen(); 284 top_container()->GetBoundsInScreen();
262 // A position along the top edge of TopContainerView in screen coordinates. 285 // A position along the top edge of TopContainerView in screen coordinates.
263 gfx::Point top_edge_pos(top_container_bounds_in_screen.x() + 100, 286 gfx::Point top_edge_pos(top_container_bounds_in_screen.x() + 100,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 EXPECT_TRUE(top_edge_hover_timer_running()); 318 EXPECT_TRUE(top_edge_hover_timer_running());
296 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top()); 319 EXPECT_EQ(top_edge_pos.x(), mouse_x_when_hit_top());
297 320
298 // Large move right restarts the timer (so it is still running) and considers 321 // Large move right restarts the timer (so it is still running) and considers
299 // this a new hit at the top. 322 // this a new hit at the top.
300 event_generator.MoveMouseTo(top_edge_pos.x() + 100, top_edge_pos.y()); 323 event_generator.MoveMouseTo(top_edge_pos.x() + 100, top_edge_pos.y());
301 EXPECT_TRUE(top_edge_hover_timer_running()); 324 EXPECT_TRUE(top_edge_hover_timer_running());
302 EXPECT_EQ(top_edge_pos.x() + 100, mouse_x_when_hit_top()); 325 EXPECT_EQ(top_edge_pos.x() + 100, mouse_x_when_hit_top());
303 326
304 // Moving off the top edge horizontally stops the timer. 327 // Moving off the top edge horizontally stops the timer.
305 EXPECT_GT(CurrentContext()->bounds().width(), top_container()->width()); 328 event_generator.MoveMouseTo(top_container_bounds_in_screen.right() + 1,
306 event_generator.MoveMouseTo(top_container_bounds_in_screen.right(),
307 top_container_bounds_in_screen.y()); 329 top_container_bounds_in_screen.y());
308 EXPECT_FALSE(top_edge_hover_timer_running()); 330 EXPECT_FALSE(top_edge_hover_timer_running());
309 331
310 // Once revealed, a move just a little below the top container doesn't end a 332 // Once revealed, a move just a little below the top container doesn't end a
311 // reveal. 333 // reveal.
312 AttemptReveal(MODALITY_MOUSE); 334 AttemptReveal(MODALITY_MOUSE);
313 event_generator.MoveMouseTo(top_container_bounds_in_screen.x(), 335 event_generator.MoveMouseTo(top_container_bounds_in_screen.x(),
314 top_container_bounds_in_screen.bottom() + 1); 336 top_container_bounds_in_screen.bottom() + 1);
315 EXPECT_TRUE(controller()->IsRevealed()); 337 EXPECT_TRUE(controller()->IsRevealed());
316 338
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen()); 990 ASSERT_TRUE(browser_view()->GetWidget()->IsFullscreen());
969 991
970 browser_view()->GetWidget()->Restore(); 992 browser_view()->GetWidget()->Restore();
971 // Exiting immersive fullscreen occurs as a result of a task posted to the 993 // Exiting immersive fullscreen occurs as a result of a task posted to the
972 // message loop. 994 // message loop.
973 content::RunAllPendingInMessageLoop(); 995 content::RunAllPendingInMessageLoop();
974 996
975 EXPECT_FALSE(controller()->IsEnabled()); 997 EXPECT_FALSE(controller()->IsEnabled());
976 } 998 }
977 999
1000 // Test that it is still possible to reveal and hide the top-of-window views
1001 // via a gesture when a child window consumes touch events.
1002 TEST_F(ImmersiveModeControllerAshTestWithBrowserView,
1003 RevealViaGestureChildWindowConsumesTouchEvents) {
1004 views::Widget* browser_widget = browser_view()->GetWidget();
1005
1006 // Create a child widget which consumes all touch events.
1007 views::Widget::InitParams child_params(
1008 views::Widget::InitParams::TYPE_CONTROL);
1009 child_params.ownership =
1010 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1011 child_params.parent = browser_widget->GetNativeView();
1012 child_params.bounds =
1013 gfx::Rect(browser_widget->GetWindowBoundsInScreen().size());
1014 scoped_ptr<views::Widget> child_widget(new views::Widget());
1015 child_widget->Init(child_params);
1016 child_widget->SetContentsView(new TouchEventConsumerView());
1017 child_widget->Show();
1018
1019 ASSERT_FALSE(controller()->IsEnabled());
1020 chrome::ToggleFullscreenMode(browser());
1021 ASSERT_TRUE(controller()->IsEnabled());
1022 EXPECT_FALSE(controller()->IsRevealed());
1023
1024 gfx::Rect top_container_bounds_in_root =
1025 ash::ScreenAsh::ConvertRectFromScreen(
1026 browser_widget->GetNativeView()->GetRootWindow(),
1027 browser_view()->top_container()->GetBoundsInScreen());
1028
1029 gfx::Point top(top_container_bounds_in_root.origin());
1030 gfx::Point bottom = top + gfx::Vector2d(0, 100);
1031 aura::test::EventGenerator generator(
1032 browser_widget->GetNativeView()->GetRootWindow());
1033 generator.GestureScrollSequence(top,
1034 bottom,
1035 base::TimeDelta::FromMilliseconds(10),
1036 3);
1037 EXPECT_TRUE(controller()->IsRevealed());
1038
1039 generator.GestureScrollSequence(bottom,
1040 top,
1041 base::TimeDelta::FromMilliseconds(10),
1042 3);
1043 EXPECT_FALSE(controller()->IsRevealed());
1044 }
1045
978 #endif // defined(OS_CHROMEOS) 1046 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698