| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/nsmenuitem_additions.h" | 5 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 | 10 |
| 11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 NSEvent* KeyEvent(const NSUInteger modifierFlags, | 15 NSEvent* KeyEvent(const NSUInteger modifierFlags, |
| 16 NSString* chars, | 16 NSString* chars, |
| 17 NSString* charsNoMods, | 17 NSString* charsNoMods, |
| 18 const NSUInteger keyCode) { | 18 const NSUInteger keyCode) { |
| 19 return [NSEvent keyEventWithType:NSKeyDown | 19 return [NSEvent keyEventWithType:NSKeyDown |
| 20 location:NSZeroPoint | 20 location:NSZeroPoint |
| 21 modifierFlags:modifierFlags | 21 modifierFlags:modifierFlags |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 bool compareCocoa) { | 49 bool compareCocoa) { |
| 50 EXPECT_EQ(result, [item cr_firesForKeyEvent:key]) << key << '\n' << item; | 50 EXPECT_EQ(result, [item cr_firesForKeyEvent:key]) << key << '\n' << item; |
| 51 | 51 |
| 52 // Make sure that Cocoa does in fact agree with our expectations. However, | 52 // Make sure that Cocoa does in fact agree with our expectations. However, |
| 53 // in some cases cocoa behaves weirdly (if you create e.g. a new event that | 53 // in some cases cocoa behaves weirdly (if you create e.g. a new event that |
| 54 // contains all fields of the event that you get when hitting cmd-a with a | 54 // contains all fields of the event that you get when hitting cmd-a with a |
| 55 // russion keyboard layout, the copy won't fire a menu item that has cmd-a as | 55 // russion keyboard layout, the copy won't fire a menu item that has cmd-a as |
| 56 // key equivalent, even though the original event would) and isn't a good | 56 // key equivalent, even though the original event would) and isn't a good |
| 57 // oracle function. | 57 // oracle function. |
| 58 if (compareCocoa) { | 58 if (compareCocoa) { |
| 59 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"Menu!"]); | 59 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"Menu!"]); |
| 60 [menu setAutoenablesItems:NO]; | 60 [menu setAutoenablesItems:NO]; |
| 61 EXPECT_FALSE([menu performKeyEquivalent:key]); | 61 EXPECT_FALSE([menu performKeyEquivalent:key]); |
| 62 [menu addItem:item]; | 62 [menu addItem:item]; |
| 63 EXPECT_EQ(result, [menu performKeyEquivalent:key]) << key << '\n' << item; | 63 EXPECT_EQ(result, [menu performKeyEquivalent:key]) << key << '\n' << item; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ExpectKeyFiresItem( | 67 void ExpectKeyFiresItem( |
| 68 NSEvent* key, NSMenuItem* item, bool compareCocoa = true) { | 68 NSEvent* key, NSMenuItem* item, bool compareCocoa = true) { |
| 69 ExpectKeyFiresItemEq(true, key, item, compareCocoa); | 69 ExpectKeyFiresItemEq(true, key, item, compareCocoa); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 342 } |
| 343 | 343 |
| 344 EventModifiers modifiers = cmdKey >> 8; | 344 EventModifiers modifiers = cmdKey >> 8; |
| 345 NSString* chars = keyCodeToCharacter(keyCode, modifiers, ref); | 345 NSString* chars = keyCodeToCharacter(keyCode, modifiers, ref); |
| 346 NSString* charsIgnoringMods = keyCodeToCharacter(keyCode, 0, ref); | 346 NSString* charsIgnoringMods = keyCodeToCharacter(keyCode, 0, ref); |
| 347 NSEvent* key = KeyEvent(0x100000, chars, charsIgnoringMods, keyCode); | 347 NSEvent* key = KeyEvent(0x100000, chars, charsIgnoringMods, keyCode); |
| 348 ExpectKeyFiresItem(key, item, false); | 348 ExpectKeyFiresItem(key, item, false); |
| 349 } | 349 } |
| 350 CFRelease(list); | 350 CFRelease(list); |
| 351 } | 351 } |
| OLD | NEW |