| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 void SetDynamicLabel(base::string16 label) { label_ = label; } | 105 void SetDynamicLabel(base::string16 label) { label_ = label; } |
| 106 void SetDynamicIcon(const gfx::Image& icon) { icon_ = icon; } | 106 void SetDynamicIcon(const gfx::Image& icon) { icon_ = icon; } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 base::string16 label_; | 109 base::string16 label_; |
| 110 gfx::Image icon_; | 110 gfx::Image icon_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 // Menu model that returns a gfx::Font object for one of the items in the menu. | 113 // Menu model that returns a gfx::FontList object for one of the items in the |
| 114 class FontMenuModel : public SimpleMenuModel { | 114 // menu. |
| 115 class FontListMenuModel : public SimpleMenuModel { |
| 115 public: | 116 public: |
| 116 FontMenuModel(SimpleMenuModel::Delegate* delegate, | 117 FontListMenuModel(SimpleMenuModel::Delegate* delegate, |
| 117 const gfx::Font* font, int index) | 118 const gfx::FontList* font_list, int index) |
| 118 : SimpleMenuModel(delegate), | 119 : SimpleMenuModel(delegate), |
| 119 font_(font), | 120 font_list_(font_list), |
| 120 index_(index) { | 121 index_(index) { |
| 121 } | 122 } |
| 122 virtual ~FontMenuModel() {} | 123 virtual ~FontListMenuModel() {} |
| 123 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE { | 124 virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE { |
| 124 return (index == index_) ? font_ : NULL; | 125 return (index == index_) ? font_list_ : NULL; |
| 125 } | 126 } |
| 126 | 127 |
| 127 private: | 128 private: |
| 128 const gfx::Font* font_; | 129 const gfx::FontList* font_list_; |
| 129 const int index_; | 130 const int index_; |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 TEST_F(MenuControllerTest, EmptyMenu) { | 133 TEST_F(MenuControllerTest, EmptyMenu) { |
| 133 Delegate delegate; | 134 Delegate delegate; |
| 134 SimpleMenuModel model(&delegate); | 135 SimpleMenuModel model(&delegate); |
| 135 base::scoped_nsobject<MenuController> menu( | 136 base::scoped_nsobject<MenuController> menu( |
| 136 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); | 137 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); |
| 137 EXPECT_EQ([[menu menu] numberOfItems], 0); | 138 EXPECT_EQ([[menu menu] numberOfItems], 0); |
| 138 } | 139 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 model.AddSubMenuWithStringId(3, kTestLabelResourceId, &submodel); | 266 model.AddSubMenuWithStringId(3, kTestLabelResourceId, &submodel); |
| 266 | 267 |
| 267 base::scoped_nsobject<MenuController> menu( | 268 base::scoped_nsobject<MenuController> menu( |
| 268 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); | 269 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); |
| 269 EXPECT_EQ([[menu menu] numberOfItems], 3); | 270 EXPECT_EQ([[menu menu] numberOfItems], 3); |
| 270 | 271 |
| 271 Validate(menu.get(), [menu menu]); | 272 Validate(menu.get(), [menu menu]); |
| 272 } | 273 } |
| 273 | 274 |
| 274 // Tests that items which have a font set actually use that font. | 275 // Tests that items which have a font set actually use that font. |
| 275 TEST_F(MenuControllerTest, LabelFont) { | 276 TEST_F(MenuControllerTest, LabelFontList) { |
| 276 Delegate delegate; | 277 Delegate delegate; |
| 277 gfx::Font bold = (gfx::Font()).DeriveFont(0, gfx::Font::BOLD); | 278 const gfx::FontList& bold = ResourceBundle::GetSharedInstance().GetFontList( |
| 278 FontMenuModel model(&delegate, &bold, 0); | 279 ResourceBundle::BoldFont); |
| 280 FontListMenuModel model(&delegate, &bold, 0); |
| 279 model.AddItem(1, ASCIIToUTF16("one")); | 281 model.AddItem(1, ASCIIToUTF16("one")); |
| 280 model.AddItem(2, ASCIIToUTF16("two")); | 282 model.AddItem(2, ASCIIToUTF16("two")); |
| 281 | 283 |
| 282 base::scoped_nsobject<MenuController> menu( | 284 base::scoped_nsobject<MenuController> menu( |
| 283 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); | 285 [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); |
| 284 EXPECT_EQ([[menu menu] numberOfItems], 2); | 286 EXPECT_EQ([[menu menu] numberOfItems], 2); |
| 285 | 287 |
| 286 Validate(menu.get(), [menu menu]); | 288 Validate(menu.get(), [menu menu]); |
| 287 | 289 |
| 288 EXPECT_TRUE([[[menu menu] itemAtIndex:0] attributedTitle] != nil); | 290 EXPECT_TRUE([[[menu menu] itemAtIndex:0] attributedTitle] != nil); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // Pump the task that notifies the delegate. | 394 // Pump the task that notifies the delegate. |
| 393 message_loop.RunUntilIdle(); | 395 message_loop.RunUntilIdle(); |
| 394 | 396 |
| 395 // Expect that the delegate got notified properly. | 397 // Expect that the delegate got notified properly. |
| 396 EXPECT_TRUE(delegate.did_close_); | 398 EXPECT_TRUE(delegate.did_close_); |
| 397 } | 399 } |
| 398 | 400 |
| 399 } // namespace | 401 } // namespace |
| 400 | 402 |
| 401 } // namespace ui | 403 } // namespace ui |
| OLD | NEW |