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

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

Issue 334016: First set of unittest fixes. Many more to come ;-)... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/cocoa/extension_shelf_controller_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import <Cocoa/Cocoa.h>
6 5
7 #include "base/scoped_nsobject.h" 6 #include "base/scoped_nsobject.h"
8 #include "chrome/app/chrome_dll_resource.h" 7 #include "chrome/app/chrome_dll_resource.h"
9 #import "chrome/browser/cocoa/chrome_event_processing_window.h" 8 #import "chrome/browser/cocoa/chrome_event_processing_window.h"
10 #import "chrome/browser/cocoa/browser_window_controller.h" 9 #import "chrome/browser/cocoa/browser_window_controller.h"
11 #import "chrome/browser/cocoa/browser_frame_view.h" 10 #import "chrome/browser/cocoa/browser_frame_view.h"
12 #import "chrome/browser/cocoa/cocoa_test_helper.h" 11 #import "chrome/browser/cocoa/cocoa_test_helper.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h"
15 #import "third_party/ocmock/OCMock/OCMock.h" 12 #import "third_party/ocmock/OCMock/OCMock.h"
16 13
17 namespace { 14 namespace {
18 15
19 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) { 16 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) {
20 return [NSEvent keyEventWithType:NSKeyDown 17 return [NSEvent keyEventWithType:NSKeyDown
21 location:NSZeroPoint 18 location:NSZeroPoint
22 modifierFlags:flags 19 modifierFlags:flags
23 timestamp:0.0 20 timestamp:0.0
24 windowNumber:0 21 windowNumber:0
25 context:nil 22 context:nil
26 characters:@"" 23 characters:@""
27 charactersIgnoringModifiers:@"" 24 charactersIgnoringModifiers:@""
28 isARepeat:NO 25 isARepeat:NO
29 keyCode:keyCode]; 26 keyCode:keyCode];
30 } 27 }
31 28
32 class ChromeEventProcessingWindowTest : public PlatformTest { 29 class ChromeEventProcessingWindowTest : public CocoaTest {
33 public: 30 public:
34 ChromeEventProcessingWindowTest() { 31 virtual void SetUp() {
32 CocoaTest::SetUp();
35 // Create a window. 33 // Create a window.
36 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask | 34 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask |
37 NSMiniaturizableWindowMask | NSResizableWindowMask; 35 NSMiniaturizableWindowMask | NSResizableWindowMask;
38 window_.reset([[ChromeEventProcessingWindow alloc] 36 window_ = [[ChromeEventProcessingWindow alloc]
39 initWithContentRect:NSMakeRect(0, 0, 800, 600) 37 initWithContentRect:NSMakeRect(0, 0, 800, 600)
40 styleMask:mask 38 styleMask:mask
41 backing:NSBackingStoreBuffered 39 backing:NSBackingStoreBuffered
42 defer:NO]); 40 defer:NO];
43 if (DebugUtil::BeingDebugged()) { 41 if (DebugUtil::BeingDebugged()) {
44 [window_ orderFront:nil]; 42 [window_ orderFront:nil];
45 } else { 43 } else {
46 [window_ orderBack:nil]; 44 [window_ orderBack:nil];
47 } 45 }
48 } 46 }
49 47
48 virtual void TearDown() {
49 [window_ close];
50 CocoaTest::TearDown();
51 }
52
50 // Returns a canonical snapshot of the window. 53 // Returns a canonical snapshot of the window.
51 NSData* WindowContentsAsTIFF() { 54 NSData* WindowContentsAsTIFF() {
52 NSRect frame([window_ frame]); 55 NSRect frame([window_ frame]);
53 frame.origin = [window_ convertScreenToBase:frame.origin]; 56 frame.origin = [window_ convertScreenToBase:frame.origin];
54 57
55 NSData* pdfData = [window_ dataWithPDFInsideRect:frame]; 58 NSData* pdfData = [window_ dataWithPDFInsideRect:frame];
56 59
57 // |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
58 // canonical. 61 // canonical.
59 NSImage* image = [[[NSImage alloc] initWithData:pdfData] autorelease]; 62 NSImage* image = [[[NSImage alloc] initWithData:pdfData] autorelease];
60 return [image TIFFRepresentation]; 63 return [image TIFFRepresentation];
61 } 64 }
62 65
63 CocoaNoWindowTestHelper cocoa_helper_; 66 ChromeEventProcessingWindow* window_;
64 scoped_nsobject<ChromeEventProcessingWindow> window_;
65 }; 67 };
66 68
67 // Verify that the window intercepts a particular key event and 69 // Verify that the window intercepts a particular key event and
68 // forwards it to [delegate executeCommand:]. Assume that other 70 // forwards it to [delegate executeCommand:]. Assume that other
69 // CommandForKeyboardShortcut() will work the same for the rest. 71 // CommandForKeyboardShortcut() will work the same for the rest.
70 TEST_F(ChromeEventProcessingWindowTest, 72 TEST_F(ChromeEventProcessingWindowTest,
71 PerformKeyEquivalentForwardToExecuteCommand) { 73 PerformKeyEquivalentForwardToExecuteCommand) {
72 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); 74 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1);
73 75
74 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; 76 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]];
(...skipping 25 matching lines...) Expand all
100 isKindOfClass:[BrowserWindowController class]]; 102 isKindOfClass:[BrowserWindowController class]];
101 103
102 [window_ setDelegate:delegate]; 104 [window_ setDelegate:delegate];
103 [window_ performKeyEquivalent:event]; 105 [window_ performKeyEquivalent:event];
104 106
105 // Don't wish to mock all the way down... 107 // Don't wish to mock all the way down...
106 [window_ setDelegate:nil]; 108 [window_ setDelegate:nil];
107 [delegate verify]; 109 [delegate verify];
108 } 110 }
109 111
110
111 } // namespace 112 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/extension_shelf_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698