Chromium Code Reviews| 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 #include <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 10 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/browser_frame_view.h" | 12 #import "chrome/browser/ui/cocoa/browser_frame_view.h" |
| 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 14 #include "third_party/ocmock/gtest_support.h" | 14 #include "third_party/ocmock/gtest_support.h" |
| 15 #import "third_party/ocmock/OCMock/OCMock.h" | 15 #import "third_party/ocmock/OCMock/OCMock.h" |
| 16 #import "third_party/ocmock/ocmock_extensions.h" | |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) { | 20 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) { |
| 20 return [NSEvent keyEventWithType:NSKeyDown | 21 return [NSEvent keyEventWithType:NSKeyDown |
| 21 location:NSZeroPoint | 22 location:NSZeroPoint |
| 22 modifierFlags:flags | 23 modifierFlags:flags |
| 23 timestamp:0.0 | 24 timestamp:0.0 |
| 24 windowNumber:0 | 25 windowNumber:0 |
| 25 context:nil | 26 context:nil |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 53 CocoaTest::TearDown(); | 54 CocoaTest::TearDown(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 ChromeEventProcessingWindow* window_; | 57 ChromeEventProcessingWindow* window_; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 id CreateBrowserWindowControllerMock() { | 60 id CreateBrowserWindowControllerMock() { |
| 60 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; | 61 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; |
| 61 // Make conformsToProtocol return YES for @protocol(BrowserCommandExecutor) | 62 // Make conformsToProtocol return YES for @protocol(BrowserCommandExecutor) |
| 62 // to satisfy the DCHECK() in handleExtraKeyboardShortcut. | 63 // to satisfy the DCHECK() in handleExtraKeyboardShortcut. |
| 63 // | |
| 64 // TODO(akalin): Figure out how to replace OCMOCK_ANY below with | |
| 65 // @protocol(BrowserCommandExecutor) and have it work. | |
| 66 BOOL yes = YES; | 64 BOOL yes = YES; |
| 67 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] | 65 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] |
|
TVL
2011/05/20 16:07:05
did you want to replace this also?
| |
| 68 conformsToProtocol:OCMOCK_ANY]; | 66 conformsToProtocol:[OCMArg conformsToProtocol: |
| 67 @protocol(BrowserCommandExecutor)]]; | |
| 69 return delegate; | 68 return delegate; |
| 70 } | 69 } |
| 71 | 70 |
| 72 // Verify that the window intercepts a particular key event and | 71 // Verify that the window intercepts a particular key event and |
| 73 // forwards it to [delegate executeCommand:]. Assume that other | 72 // forwards it to [delegate executeCommand:]. Assume that other |
| 74 // CommandForKeyboardShortcut() will work the same for the rest. | 73 // CommandForKeyboardShortcut() will work the same for the rest. |
| 75 TEST_F(ChromeEventProcessingWindowTest, | 74 TEST_F(ChromeEventProcessingWindowTest, |
| 76 PerformKeyEquivalentForwardToExecuteCommand) { | 75 PerformKeyEquivalentForwardToExecuteCommand) { |
| 77 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); | 76 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); |
| 78 | 77 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 98 | 97 |
| 99 [window_ setDelegate:delegate]; | 98 [window_ setDelegate:delegate]; |
| 100 [window_ performKeyEquivalent:event]; | 99 [window_ performKeyEquivalent:event]; |
| 101 | 100 |
| 102 // Don't wish to mock all the way down... | 101 // Don't wish to mock all the way down... |
| 103 [window_ setDelegate:nil]; | 102 [window_ setDelegate:nil]; |
| 104 EXPECT_OCMOCK_VERIFY(delegate); | 103 EXPECT_OCMOCK_VERIFY(delegate); |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace | 106 } // namespace |
| OLD | NEW |