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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc

Issue 111043002: Cursor state should be global for desktop Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test added Created 7 years 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "ui/aura/client/cursor_client.h"
7 #include "ui/aura/root_window.h" 8 #include "ui/aura/root_window.h"
8 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
9 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
11 12
12 namespace views { 13 namespace views {
13 14
14 typedef ViewsTestBase DesktopNativeWidgetAuraTest; 15 typedef ViewsTestBase DesktopNativeWidgetAuraTest;
15 16
16 // Verifies creating a Widget with a parent that is not in a RootWindow doesn't 17 // Verifies creating a Widget with a parent that is not in a RootWindow doesn't
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 TEST_F(DesktopNativeWidgetAuraTest, NativeViewInitiallyHidden) { 61 TEST_F(DesktopNativeWidgetAuraTest, NativeViewInitiallyHidden) {
61 Widget widget; 62 Widget widget;
62 Widget::InitParams init_params = 63 Widget::InitParams init_params =
63 CreateParams(Widget::InitParams::TYPE_WINDOW); 64 CreateParams(Widget::InitParams::TYPE_WINDOW);
64 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 65 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
65 init_params.native_widget = new DesktopNativeWidgetAura(&widget); 66 init_params.native_widget = new DesktopNativeWidgetAura(&widget);
66 widget.Init(init_params); 67 widget.Init(init_params);
67 EXPECT_FALSE(widget.GetNativeView()->IsVisible()); 68 EXPECT_FALSE(widget.GetNativeView()->IsVisible());
68 } 69 }
69 70
71 // Verify that the cursor state is shared between two native widgets.
72 TEST_F(DesktopNativeWidgetAuraTest, GlobalCursorState) {
73 // Create two native widgets, each owning different root windows.
74 Widget widget_a;
75 Widget::InitParams init_params_a =
76 CreateParams(Widget::InitParams::TYPE_WINDOW);
77 init_params_a.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
78 DesktopNativeWidgetAura* desktop_native_widget_aura_a =
79 new DesktopNativeWidgetAura(&widget_a);
80 init_params_a.native_widget = desktop_native_widget_aura_a;
81 widget_a.Init(init_params_a);
82
83 Widget widget_b;
84 Widget::InitParams init_params_b =
85 CreateParams(Widget::InitParams::TYPE_WINDOW);
86 init_params_b.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
87 DesktopNativeWidgetAura* desktop_native_widget_aura_b =
88 new DesktopNativeWidgetAura(&widget_b);
89 init_params_b.native_widget = desktop_native_widget_aura_b;
90 widget_b.Init(init_params_b);
91
92 aura::client::CursorClient* cursor_client_a = aura::client::GetCursorClient(
93 desktop_native_widget_aura_a->root_window()->window());
94 aura::client::CursorClient* cursor_client_b = aura::client::GetCursorClient(
95 desktop_native_widget_aura_b->root_window()->window());
96
97 // Verify the cursor can be locked using one client and unlocked using
98 // another.
99 EXPECT_FALSE(cursor_client_a->IsCursorLocked());
100 EXPECT_FALSE(cursor_client_b->IsCursorLocked());
101
102 cursor_client_a->LockCursor();
103 EXPECT_TRUE(cursor_client_a->IsCursorLocked());
104 EXPECT_TRUE(cursor_client_b->IsCursorLocked());
105
106 cursor_client_b->UnlockCursor();
107 EXPECT_FALSE(cursor_client_a->IsCursorLocked());
108 EXPECT_FALSE(cursor_client_b->IsCursorLocked());
109
110 // Verify that mouse events can be disabled using one client and then
111 // re-enabled using another. Note that disabling mouse events should also
112 // have the side effect of making the cursor invisible.
113 EXPECT_TRUE(cursor_client_a->IsCursorVisible());
114 EXPECT_TRUE(cursor_client_b->IsCursorVisible());
115 EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
116 EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
117
118 cursor_client_b->DisableMouseEvents();
119 EXPECT_FALSE(cursor_client_a->IsCursorVisible());
120 EXPECT_FALSE(cursor_client_b->IsCursorVisible());
121 EXPECT_FALSE(cursor_client_a->IsMouseEventsEnabled());
122 EXPECT_FALSE(cursor_client_b->IsMouseEventsEnabled());
123
124 cursor_client_a->EnableMouseEvents();
125 EXPECT_TRUE(cursor_client_a->IsCursorVisible());
126 EXPECT_TRUE(cursor_client_b->IsCursorVisible());
127 EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
128 EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
129
130 // Verify that setting the cursor using one cursor client
131 // will set it for all root windows.
132 EXPECT_EQ(ui::kCursorNone, cursor_client_a->GetCursor().native_type());
133 EXPECT_EQ(ui::kCursorNone, cursor_client_b->GetCursor().native_type());
134
135 cursor_client_b->SetCursor(ui::kCursorPointer);
136 EXPECT_EQ(ui::kCursorPointer, cursor_client_a->GetCursor().native_type());
137 EXPECT_EQ(ui::kCursorPointer, cursor_client_b->GetCursor().native_type());
138
139 // Verify that hiding the cursor using one cursor client will
140 // hide it for all root windows. Note that hiding the cursor
141 // should not disable mouse events.
142 cursor_client_a->HideCursor();
143 EXPECT_FALSE(cursor_client_a->IsCursorVisible());
144 EXPECT_FALSE(cursor_client_b->IsCursorVisible());
145 EXPECT_TRUE(cursor_client_a->IsMouseEventsEnabled());
146 EXPECT_TRUE(cursor_client_b->IsMouseEventsEnabled());
147
148 // Verify that the visibility state cannot be changed using one
149 // cursor client when the cursor was locked using another.
150 cursor_client_b->LockCursor();
151 cursor_client_a->ShowCursor();
152 EXPECT_FALSE(cursor_client_a->IsCursorVisible());
153 EXPECT_FALSE(cursor_client_b->IsCursorVisible());
154
155 // Verify the cursor becomes visible on unlock (since a request
156 // to make it visible was queued up while the cursor was locked).
157 cursor_client_b->UnlockCursor();
158 EXPECT_TRUE(cursor_client_a->IsCursorVisible());
159 EXPECT_TRUE(cursor_client_b->IsCursorVisible());
160 }
161
70 } // namespace views 162 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698