| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/scoped_nsobject.h" |
| 6 #import "chrome/browser/cocoa/bookmark_button.h" |
| 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" |
| 10 |
| 11 NSEvent* Event(const NSPoint point, const NSEventType type) { |
| 12 static NSUInteger eventNumber = 0; // thx shess |
| 13 return [NSEvent mouseEventWithType:type |
| 14 location:point |
| 15 modifierFlags:0 |
| 16 timestamp:0 |
| 17 windowNumber:183 // picked out of thin air. |
| 18 context:nil |
| 19 eventNumber:eventNumber++ |
| 20 clickCount:1 |
| 21 pressure:0.0]; |
| 22 } |
| 23 |
| 24 // Make sure the basic case of "click" still works. |
| 25 TEST(DraggableButtonTest, DownUp) { |
| 26 scoped_nsobject<NSMutableArray> array; |
| 27 array.reset([[NSMutableArray alloc] init]); |
| 28 [array addObject:@"foo"]; |
| 29 [array addObject:@"bar"]; |
| 30 |
| 31 scoped_nsobject<DraggableButton> button; |
| 32 button.reset([[DraggableButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
| 33 |
| 34 [button setTarget:array.get()]; |
| 35 [button setAction:@selector(removeAllObjects)]; |
| 36 EXPECT_FALSE([[button cell] isHighlighted]); |
| 37 |
| 38 NSEvent* downEvent(Event(NSMakePoint(10,10), NSLeftMouseDown)); |
| 39 NSEvent* upEvent(Event(NSMakePoint(10,10), NSLeftMouseDown)); |
| 40 [button mouseDown:downEvent]; |
| 41 EXPECT_TRUE([[button cell] isHighlighted]); |
| 42 [button mouseUp:upEvent]; |
| 43 EXPECT_FALSE([[button cell] isHighlighted]); |
| 44 EXPECT_FALSE([array count]); // confirms target/action fired |
| 45 } |
| OLD | NEW |