Index: ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
diff --git a/ui/app_list/cocoa/apps_search_box_controller_unittest.mm b/ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
index 2c75127e813a5736f04ed819995de20b6c5cf8e7..e2c2563abdc5156993c2c25b0064de5578326b27 100644 |
--- a/ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
+++ b/ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
@@ -8,12 +8,17 @@ |
#include "base/strings/sys_string_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#import "testing/gtest_mac.h" |
+#include "ui/app_list/app_list_menu.h" |
+#import "ui/app_list/cocoa/current_user_menu_item_view.h" |
#include "ui/app_list/search_box_model.h" |
+#include "ui/app_list/test/app_list_test_model.h" |
+#include "ui/app_list/test/app_list_test_view_delegate.h" |
#import "ui/base/test/ui_cocoa_test_helper.h" |
@interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { |
@private |
app_list::SearchBoxModel searchBoxModel_; |
+ app_list::test::AppListTestViewDelegate appListDelegate_; |
int textChangeCount_; |
} |
@@ -29,6 +34,10 @@ |
return &searchBoxModel_; |
} |
+- (app_list::AppListViewDelegate*)appListDelegate { |
+ return &appListDelegate_; |
+} |
+ |
- (BOOL)control:(NSControl*)control |
textView:(NSTextView*)textView |
doCommandBySelector:(SEL)command { |
@@ -120,5 +129,60 @@ TEST_F(AppsSearchBoxControllerTest, SearchBoxModel) { |
EXPECT_EQ(2, [delegate_ textChangeCount]); |
} |
+// Test the popup menu items. |
+TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
+ NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; |
+ EXPECT_TRUE([apps_search_box_controller_ appListMenu]); |
+ ui::MenuModel* menu_model |
+ = [apps_search_box_controller_ appListMenu]->menu_model(); |
+ // Add one to the item count to account for the blank, first item that Cocoa |
+ // has in its popup menus. |
+ EXPECT_EQ(menu_model->GetItemCount() + 1, |
+ [[menu_control menu] numberOfItems]); |
+ |
+ // The CURRENT_USER item should contain our custom view. |
+ ui::MenuModel* found_menu_model = menu_model; |
+ int index; |
+ EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
+ AppListMenu::CURRENT_USER, &menu_model, &index)); |
+ EXPECT_EQ(found_menu_model, menu_model); |
+ NSMenuItem* current_user_item = [[menu_control menu] itemAtIndex:index + 1]; |
+ EXPECT_TRUE([current_user_item view]); |
+ |
+ // A regular item should have just the label. |
+ EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
+ AppListMenu::SHOW_SETTINGS, &menu_model, &index)); |
+ EXPECT_EQ(found_menu_model, menu_model); |
+ NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1]; |
+ EXPECT_FALSE([settings_item view]); |
+ EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), |
+ [settings_item title]); |
+} |
+ |
+// Test initialization and display of the custom menu item that shows the |
+// currently signed-in user. This is a non-interactive view. |
+class AppsSearchBoxCustomMenuItemTest : public ui::CocoaTest { |
+ public: |
+ AppsSearchBoxCustomMenuItemTest() { |
+ Init(); |
+ } |
+ |
+ virtual void SetUp() OVERRIDE { |
+ scoped_ptr<AppListViewDelegate> delegate(new AppListTestViewDelegate); |
+ current_user_menu_item_.reset([[[CurrentUserMenuItemView alloc] |
+ initWithDelegate:delegate.get()] retain]); |
+ ui::CocoaTest::SetUp(); |
+ [[test_window() contentView] addSubview:current_user_menu_item_]; |
+ } |
+ |
+ protected: |
+ scoped_nsobject<NSView> current_user_menu_item_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxCustomMenuItemTest); |
+}; |
+ |
+TEST_VIEW(AppsSearchBoxCustomMenuItemTest, current_user_menu_item_); |
+ |
} // namespace test |
} // namespace app_list |