| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #import "chrome/browser/cocoa/bookmark_button.h" | 6 #import "chrome/browser/cocoa/bookmark_button.h" |
| 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
| 10 | 10 |
| 11 class BookmarkButtonTest : public CocoaTest { | 11 class BookmarkButtonTest : public CocoaTest { |
| 12 public: | 12 public: |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 NSEvent* Event(const NSPoint point, const NSEventType type) { | 15 // Make sure nothing leaks |
| 16 static NSUInteger eventNumber = 0; // thx shess | 16 TEST_F(BookmarkButtonTest, Create) { |
| 17 return [NSEvent mouseEventWithType:type | |
| 18 location:point | |
| 19 modifierFlags:0 | |
| 20 timestamp:0 | |
| 21 windowNumber:183 // picked out of thin air. | |
| 22 context:nil | |
| 23 eventNumber:eventNumber++ | |
| 24 clickCount:1 | |
| 25 pressure:0.0]; | |
| 26 } | |
| 27 | |
| 28 // Make sure the basic case of "click" still works. | |
| 29 TEST_F(BookmarkButtonTest, DownUp) { | |
| 30 scoped_nsobject<NSMutableArray> array; | |
| 31 array.reset([[NSMutableArray alloc] init]); | |
| 32 [array addObject:@"foo"]; | |
| 33 [array addObject:@"bar"]; | |
| 34 | |
| 35 scoped_nsobject<BookmarkButton> button; | 17 scoped_nsobject<BookmarkButton> button; |
| 36 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); | 18 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
| 37 | |
| 38 [button setTarget:array.get()]; | |
| 39 [button setAction:@selector(removeAllObjects)]; | |
| 40 EXPECT_FALSE([[button cell] isHighlighted]); | |
| 41 | |
| 42 NSEvent* downEvent(Event(NSMakePoint(10,10), NSLeftMouseDown)); | |
| 43 NSEvent* upEvent(Event(NSMakePoint(10,10), NSLeftMouseDown)); | |
| 44 [button mouseDown:downEvent]; | |
| 45 EXPECT_TRUE([[button cell] isHighlighted]); | |
| 46 [button mouseUp:upEvent]; | |
| 47 EXPECT_FALSE([[button cell] isHighlighted]); | |
| 48 EXPECT_FALSE([array count]); // confirms target/action fired | |
| 49 } | 19 } |
| OLD | NEW |