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

Side by Side Diff: chrome/browser/cocoa/chrome_event_processing_window_unittest.mm

Issue 344008: Implemented most of HtmlDialogWindowController, which is a Cocoa port (Closed)
Patch Set: Added TODOs. Created 11 years, 1 month 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
OLDNEW
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 5
6 #include "base/scoped_nsobject.h" 6 #include "base/scoped_nsobject.h"
7 #include "chrome/app/chrome_dll_resource.h" 7 #include "chrome/app/chrome_dll_resource.h"
8 #import "chrome/browser/cocoa/chrome_event_processing_window.h" 8 #import "chrome/browser/cocoa/chrome_event_processing_window.h"
9 #import "chrome/browser/cocoa/browser_window_controller.h" 9 #import "chrome/browser/cocoa/browser_window_controller.h"
10 #import "chrome/browser/cocoa/browser_frame_view.h" 10 #import "chrome/browser/cocoa/browser_frame_view.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // |pdfData| can differ for windows which look the same, so make it 60 // |pdfData| can differ for windows which look the same, so make it
61 // canonical. 61 // canonical.
62 NSImage* image = [[[NSImage alloc] initWithData:pdfData] autorelease]; 62 NSImage* image = [[[NSImage alloc] initWithData:pdfData] autorelease];
63 return [image TIFFRepresentation]; 63 return [image TIFFRepresentation];
64 } 64 }
65 65
66 ChromeEventProcessingWindow* window_; 66 ChromeEventProcessingWindow* window_;
67 }; 67 };
68 68
69 id CreateBrowserWindowControllerMock() {
70 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]];
71 // Make conformsToProtocol return YES for @protocol(BrowserCommandExecutor)
72 // to satisfy the DCHECK() in handleExtraKeyboardShortcut.
73 //
74 // TODO(akalin): Figure out how to replace OCMOCK_ANY below with
75 // @protocol(BrowserCommandExecutor) and have it work.
76 BOOL yes = YES;
77 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)]
78 conformsToProtocol:OCMOCK_ANY];
79 return delegate;
80 }
81
69 // Verify that the window intercepts a particular key event and 82 // Verify that the window intercepts a particular key event and
70 // forwards it to [delegate executeCommand:]. Assume that other 83 // forwards it to [delegate executeCommand:]. Assume that other
71 // CommandForKeyboardShortcut() will work the same for the rest. 84 // CommandForKeyboardShortcut() will work the same for the rest.
72 TEST_F(ChromeEventProcessingWindowTest, 85 TEST_F(ChromeEventProcessingWindowTest,
73 PerformKeyEquivalentForwardToExecuteCommand) { 86 PerformKeyEquivalentForwardToExecuteCommand) {
74 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); 87 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1);
75 88
76 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; 89 id delegate = CreateBrowserWindowControllerMock();
77 // -stub to satisfy the DCHECK.
78 BOOL yes = YES;
79 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)]
80 isKindOfClass:[BrowserWindowController class]];
81 [[delegate expect] executeCommand:IDC_SELECT_TAB_0]; 90 [[delegate expect] executeCommand:IDC_SELECT_TAB_0];
82 91
83 [window_ setDelegate:delegate]; 92 [window_ setDelegate:delegate];
84 [window_ performKeyEquivalent:event]; 93 [window_ performKeyEquivalent:event];
85 94
86 // Don't wish to mock all the way down... 95 // Don't wish to mock all the way down...
87 [window_ setDelegate:nil]; 96 [window_ setDelegate:nil];
88 [delegate verify]; 97 [delegate verify];
89 } 98 }
90 99
91 // Verify that an unhandled shortcut does not get forwarded via 100 // Verify that an unhandled shortcut does not get forwarded via
92 // -executeCommand:. 101 // -executeCommand:.
93 // TODO(shess) Think of a way to test that it is sent to the 102 // TODO(shess) Think of a way to test that it is sent to the
94 // superclass. 103 // superclass.
95 TEST_F(ChromeEventProcessingWindowTest, PerformKeyEquivalentNoForward) { 104 TEST_F(ChromeEventProcessingWindowTest, PerformKeyEquivalentNoForward) {
96 NSEvent* event = KeyEvent(0, 0); 105 NSEvent* event = KeyEvent(0, 0);
97 106
98 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; 107 id delegate = CreateBrowserWindowControllerMock();
99 // -stub to satisfy the DCHECK.
100 BOOL yes = YES;
101 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)]
102 isKindOfClass:[BrowserWindowController class]];
103 108
104 [window_ setDelegate:delegate]; 109 [window_ setDelegate:delegate];
105 [window_ performKeyEquivalent:event]; 110 [window_ performKeyEquivalent:event];
106 111
107 // Don't wish to mock all the way down... 112 // Don't wish to mock all the way down...
108 [window_ setDelegate:nil]; 113 [window_ setDelegate:nil];
109 [delegate verify]; 114 [delegate verify];
110 } 115 }
111 116
112 } // namespace 117 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/chrome_event_processing_window.mm ('k') | chrome/browser/cocoa/html_dialog_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698