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

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 891003004: MacViews: Implement SetCursor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150129-MacViews-Bringup5
Patch Set: assign -> retain Created 5 years, 10 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
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/widget/native_widget_mac.h" 5 #import "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #import "ui/events/test/cocoa_test_event_utils.h"
11 #include "ui/events/test/event_generator.h"
12 #include "ui/views/native_cursor.h"
10 #include "ui/views/test/test_widget_observer.h" 13 #include "ui/views/test/test_widget_observer.h"
11 #include "ui/views/test/widget_test.h" 14 #include "ui/views/test/widget_test.h"
12 15
13 namespace views { 16 namespace views {
14 namespace test { 17 namespace test {
15 18
16 // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which 19 // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which
17 // need access to Cocoa APIs. 20 // need access to Cocoa APIs.
18 typedef WidgetTest NativeWidgetMacTest; 21 typedef WidgetTest NativeWidgetMacTest;
19 22
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 EXPECT_FALSE(widget->IsMinimized()); 253 EXPECT_FALSE(widget->IsMinimized());
251 254
252 // But this should work. 255 // But this should work.
253 widget->Minimize(); 256 widget->Minimize();
254 EXPECT_TRUE(widget->IsMinimized()); 257 EXPECT_TRUE(widget->IsMinimized());
255 258
256 // Test closing while minimized. 259 // Test closing while minimized.
257 widget->CloseNow(); 260 widget->CloseNow();
258 } 261 }
259 262
263 // Simple view for the SetCursor test that overrides View::GetCursor().
264 class CursorView : public View {
265 public:
266 CursorView(int x, NSCursor* cursor) : cursor_(cursor) {
267 SetBounds(x, 0, 100, 300);
268 }
269
270 // View:
271 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override {
272 return cursor_;
273 }
274
275 private:
276 NSCursor* cursor_;
277
278 DISALLOW_COPY_AND_ASSIGN(CursorView);
279 };
280
281 // Test for Widget::SetCursor(). There is no Widget::GetCursor(), so this uses
282 // -[NSCursor currentCursor] to validate expectations. Note that currentCursor
283 // is just "the top cursor on the application's cursor stack.", which is why it
284 // is safe to use this in a non-interactive UI test with the EventGenerator.
285 TEST_F(NativeWidgetMacTest, SetCursor) {
286 NSCursor* arrow = [NSCursor arrowCursor];
287 NSCursor* hand = GetNativeHandCursor();
288 NSCursor* ibeam = GetNativeIBeamCursor();
289
290 Widget* widget = CreateTopLevelPlatformWidget();
291 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
292 widget->GetContentsView()->AddChildView(new CursorView(0, hand));
293 widget->GetContentsView()->AddChildView(new CursorView(100, ibeam));
294 widget->Show();
295
296 // Events used to simulate tracking rectangle updates. These are not passed to
297 // toolkit-views, so it only matters whether they are inside or outside the
298 // content area.
299 NSEvent* event_in_content = cocoa_test_event_utils::MouseEventAtPoint(
300 NSMakePoint(100, 100), NSMouseMoved, 0);
301 NSEvent* event_out_of_content = cocoa_test_event_utils::MouseEventAtPoint(
302 NSMakePoint(-50, -50), NSMouseMoved, 0);
303
304 EXPECT_NE(arrow, hand);
305 EXPECT_NE(arrow, ibeam);
306
307 // At the start of the test, the cursor stack should be empty.
308 EXPECT_FALSE([NSCursor currentCursor]);
309
310 // Use an event generator to ask views code to set the cursor. However, note
311 // that this does not cause Cocoa to generate tracking rectangle updates.
312 ui::test::EventGenerator event_generator(GetContext(),
313 widget->GetNativeWindow());
314
315 // Move the mouse over the first view, then simulate a tracking rectangle
316 // update.
317 event_generator.MoveMouseTo(gfx::Point(50, 50));
318 [widget->GetNativeWindow() cursorUpdate:event_in_content];
319 EXPECT_EQ(hand, [NSCursor currentCursor]);
320
321 // A tracking rectangle update not in the content area should forward to
322 // the native NSWindow implementation, which sets the arrow cursor.
323 [widget->GetNativeWindow() cursorUpdate:event_out_of_content];
324 EXPECT_EQ(arrow, [NSCursor currentCursor]);
325
326 // Now move to the second view.
327 event_generator.MoveMouseTo(gfx::Point(150, 50));
328 [widget->GetNativeWindow() cursorUpdate:event_in_content];
329 EXPECT_EQ(ibeam, [NSCursor currentCursor]);
330
331 // Moving to the third view (but remaining in the content area) should also
332 // forward to the native NSWindow implementation.
333 event_generator.MoveMouseTo(gfx::Point(250, 50));
334 [widget->GetNativeWindow() cursorUpdate:event_in_content];
335 EXPECT_EQ(arrow, [NSCursor currentCursor]);
336
337 widget->CloseNow();
338 }
339
260 } // namespace test 340 } // namespace test
261 } // namespace views 341 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698