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

Side by Side Diff: chrome/browser/ui/cocoa/menu_controller_unittest.mm

Issue 12279015: Mac Chromium style checker cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 10 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
(...skipping 15 matching lines...) Expand all
26 class Delegate : public ui::SimpleMenuModel::Delegate { 26 class Delegate : public ui::SimpleMenuModel::Delegate {
27 public: 27 public:
28 Delegate() 28 Delegate()
29 : execute_count_(0), 29 : execute_count_(0),
30 enable_count_(0), 30 enable_count_(0),
31 menu_to_close_(nil), 31 menu_to_close_(nil),
32 did_show_(false), 32 did_show_(false),
33 did_close_(false) { 33 did_close_(false) {
34 } 34 }
35 35
36 virtual bool IsCommandIdChecked(int command_id) const { return false; } 36 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
37 virtual bool IsCommandIdEnabled(int command_id) const { 37 return false;
38 }
39 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
38 ++enable_count_; 40 ++enable_count_;
39 return true; 41 return true;
40 } 42 }
41 virtual bool GetAcceleratorForCommandId( 43 virtual bool GetAcceleratorForCommandId(
42 int command_id, 44 int command_id,
43 ui::Accelerator* accelerator) { return false; } 45 ui::Accelerator* accelerator) OVERRIDE { return false; }
44 virtual void ExecuteCommand(int command_id) { ++execute_count_; } 46 virtual void ExecuteCommand(int command_id) OVERRIDE { ++execute_count_; }
45 47
46 virtual void MenuWillShow(ui::SimpleMenuModel* /*source*/) { 48 virtual void MenuWillShow(ui::SimpleMenuModel* /*source*/) OVERRIDE {
47 EXPECT_FALSE(did_show_); 49 EXPECT_FALSE(did_show_);
48 EXPECT_FALSE(did_close_); 50 EXPECT_FALSE(did_close_);
49 did_show_ = true; 51 did_show_ = true;
50 NSArray* modes = [NSArray arrayWithObjects:NSEventTrackingRunLoopMode, 52 NSArray* modes = [NSArray arrayWithObjects:NSEventTrackingRunLoopMode,
51 NSDefaultRunLoopMode, 53 NSDefaultRunLoopMode,
52 nil]; 54 nil];
53 [menu_to_close_ performSelector:@selector(cancelTracking) 55 [menu_to_close_ performSelector:@selector(cancelTracking)
54 withObject:nil 56 withObject:nil
55 afterDelay:0.1 57 afterDelay:0.1
56 inModes:modes]; 58 inModes:modes];
57 } 59 }
58 60
59 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) { 61 virtual void MenuClosed(ui::SimpleMenuModel* /*source*/) OVERRIDE {
60 EXPECT_TRUE(did_show_); 62 EXPECT_TRUE(did_show_);
61 EXPECT_FALSE(did_close_); 63 EXPECT_FALSE(did_close_);
62 did_close_ = true; 64 did_close_ = true;
63 } 65 }
64 66
65 int execute_count_; 67 int execute_count_;
66 mutable int enable_count_; 68 mutable int enable_count_;
67 // The menu on which to call |-cancelTracking| after a short delay in 69 // The menu on which to call |-cancelTracking| after a short delay in
68 // MenuWillShow. 70 // MenuWillShow.
69 NSMenu* menu_to_close_; 71 NSMenu* menu_to_close_;
70 bool did_show_; 72 bool did_show_;
71 bool did_close_; 73 bool did_close_;
72 }; 74 };
73 75
74 // Just like Delegate, except the items are treated as "dynamic" so updates to 76 // Just like Delegate, except the items are treated as "dynamic" so updates to
75 // the label/icon in the model are reflected in the menu. 77 // the label/icon in the model are reflected in the menu.
76 class DynamicDelegate : public Delegate { 78 class DynamicDelegate : public Delegate {
77 public: 79 public:
78 DynamicDelegate() {} 80 DynamicDelegate() {}
79 virtual bool IsItemForCommandIdDynamic(int command_id) const { return true; } 81 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE {
80 virtual string16 GetLabelForCommandId(int command_id) const { return label_; } 82 return true;
81 virtual bool GetIconForCommandId(int command_id, gfx::Image* icon) const { 83 }
84 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE {
85 return label_;
86 }
87 virtual bool GetIconForCommandId(
88 int command_id,
89 gfx::Image* icon) const OVERRIDE {
82 if (icon_.IsEmpty()) { 90 if (icon_.IsEmpty()) {
83 return false; 91 return false;
84 } else { 92 } else {
85 *icon = icon_; 93 *icon = icon_;
86 return true; 94 return true;
87 } 95 }
88 } 96 }
89 void SetDynamicLabel(string16 label) { label_ = label; } 97 void SetDynamicLabel(string16 label) { label_ = label; }
90 void SetDynamicIcon(const gfx::Image& icon) { icon_ = icon; } 98 void SetDynamicIcon(const gfx::Image& icon) { icon_ = icon; }
91 99
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 EXPECT_FALSE(delegate.did_close_); 335 EXPECT_FALSE(delegate.did_close_);
328 336
329 // Pump the task that notifies the delegate. 337 // Pump the task that notifies the delegate.
330 message_loop.RunUntilIdle(); 338 message_loop.RunUntilIdle();
331 339
332 // Expect that the delegate got notified properly. 340 // Expect that the delegate got notified properly.
333 EXPECT_TRUE(delegate.did_close_); 341 EXPECT_TRUE(delegate.did_close_);
334 } 342 }
335 343
336 } // namespace 344 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698