Chromium Code Reviews| 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 c9d079758a0377f2e57b670858accbbd9bc440b2..b00d02ae1d0d24b10df1315a6d6a623be07461af 100644 |
| --- a/ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
| +++ b/ui/app_list/cocoa/apps_search_box_controller_unittest.mm |
| @@ -9,16 +9,17 @@ |
| #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/cocoa/menu_controller.h" |
| #import "ui/base/test/ui_cocoa_test_helper.h" |
| @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { |
| @private |
| app_list::SearchBoxModel searchBoxModel_; |
| app_list::test::AppListTestViewDelegate appListDelegate_; |
| + app_list::test::AppListTestModel appListModel_; |
| int textChangeCount_; |
| } |
| @@ -30,6 +31,20 @@ |
| @synthesize textChangeCount = textChangeCount_; |
| +- (id)init { |
| + if ((self = [super init])) { |
|
tapted
2013/09/13 23:12:17
you need to indent this function an extra space
calamity
2013/09/16 19:45:26
Done.
|
| + app_list::AppListModel::Users users; |
|
tapted
2013/09/13 23:12:17
maybe delete the next two lines and construct like
calamity
2013/09/16 19:45:26
Done.
|
| + users.push_back(app_list::AppListModel::User()); |
| + users.push_back(app_list::AppListModel::User()); |
| + users[0].name = ASCIIToUTF16("user1"); |
| + users[1].name = ASCIIToUTF16("user2"); |
| + users[1].email = ASCIIToUTF16("user2@chromium.org"); |
| + users[1].active = true; |
| + appListModel_.SetUsers(users); |
| + } |
| + return self; |
| +} |
| + |
| - (app_list::SearchBoxModel*)searchBoxModel { |
| return &searchBoxModel_; |
| } |
| @@ -52,12 +67,8 @@ |
| return 3; |
| } |
| -- (NSString*)currentUserName { |
| - return @""; |
| -} |
| - |
| -- (NSString*)currentUserEmail { |
| - return @""; |
| +- (app_list::AppListModel*)appListModel { |
| + return &appListModel_; |
| } |
| @end |
| @@ -140,6 +151,21 @@ TEST_F(AppsSearchBoxControllerTest, SearchBoxModel) { |
| } |
| // Test the popup menu items. |
|
tapted
2013/09/13 23:12:17
nit: different comments for the two tests.
calamity
2013/09/16 19:45:26
Done.
|
| +TEST_F(AppsSearchBoxControllerTest, SearchBoxMenuSingleUser) { |
| + app_list::AppListModel::Users users; |
|
tapted
2013/09/13 23:12:17
users(1);
you could even just do `[delegate_ appL
calamity
2013/09/16 19:45:26
Done.
|
| + users.push_back(app_list::AppListModel::User()); |
| + [delegate_ appListModel]->SetUsers(users); |
| + 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]); |
| +} |
|
tapted
2013/09/13 23:12:17
I think this is missing something. We want to ensu
calamity
2013/09/16 19:45:26
Done.
|
| + |
| +// Test the popup menu items. |
| TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
| NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; |
| EXPECT_TRUE([apps_search_box_controller_ appListMenu]); |
| @@ -150,14 +176,31 @@ TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
| 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; |
| + MenuController* controller = [[menu_control menu] delegate]; |
| + |
| + // The first user item is an unchecked label. |
| EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| - AppListMenu::CURRENT_USER, &menu_model, &index)); |
| + AppListMenu::SELECT_PROFILE, &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]); |
| + NSMenuItem* unchecked_user_item = [[menu_control menu] itemAtIndex:index + 1]; |
| + [controller validateUserInterfaceItem:unchecked_user_item]; |
| + EXPECT_FALSE([unchecked_user_item view]); |
|
tapted
2013/09/13 23:12:17
we can drop the checks for a view, since they're a
calamity
2013/09/16 19:45:26
Done.
|
| + EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), |
|
tapted
2013/09/13 23:12:17
can this check against the AppListModel::Users col
calamity
2013/09/16 19:45:26
Done.
|
| + [unchecked_user_item title]); |
| + EXPECT_EQ(NSOffState, [unchecked_user_item state]); |
| + |
| + // The second user item is a checked label. |
|
tapted
2013/09/13 23:12:17
nit: say why it is checked (i.e. since it is the a
calamity
2013/09/16 19:45:26
Done.
|
| + EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| + AppListMenu::SELECT_PROFILE + 1, &menu_model, &index)); |
| + EXPECT_EQ(found_menu_model, menu_model); |
| + NSMenuItem* checked_user_item = [[menu_control menu] itemAtIndex:index + 1]; |
| + [controller validateUserInterfaceItem:checked_user_item]; |
| + EXPECT_FALSE([checked_user_item view]); |
| + EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), |
| + [checked_user_item title]); |
| + EXPECT_EQ(NSOnState, [checked_user_item state]); |
| // A regular item should have just the label. |
| EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| @@ -169,30 +212,5 @@ TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
| [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 { |
| - current_user_menu_item_.reset([[[CurrentUserMenuItemView alloc] |
| - initWithCurrentUser:@"testUser" |
| - userEmail:@"testUser@chromium.org"] retain]); |
| - ui::CocoaTest::SetUp(); |
| - [[test_window() contentView] addSubview:current_user_menu_item_]; |
| - } |
| - |
| - protected: |
| - base::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 |