Chromium Code Reviews| 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 "ui/app_list/cocoa/apps_search_box_controller.h" | 5 #import "ui/app_list/cocoa/apps_search_box_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.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 #import "testing/gtest_mac.h" | 10 #import "testing/gtest_mac.h" |
| 11 #include "ui/app_list/app_list_menu.h" | 11 #include "ui/app_list/app_list_menu.h" |
| 12 #import "ui/app_list/cocoa/current_user_menu_item_view.h" | |
| 13 #include "ui/app_list/search_box_model.h" | 12 #include "ui/app_list/search_box_model.h" |
| 14 #include "ui/app_list/test/app_list_test_model.h" | 13 #include "ui/app_list/test/app_list_test_model.h" |
| 15 #include "ui/app_list/test/app_list_test_view_delegate.h" | 14 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 15 #import "ui/base/cocoa/menu_controller.h" | |
| 16 #import "ui/base/test/ui_cocoa_test_helper.h" | 16 #import "ui/base/test/ui_cocoa_test_helper.h" |
| 17 | 17 |
| 18 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { | 18 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { |
| 19 @private | 19 @private |
| 20 app_list::SearchBoxModel searchBoxModel_; | 20 app_list::SearchBoxModel searchBoxModel_; |
| 21 app_list::test::AppListTestViewDelegate appListDelegate_; | 21 app_list::test::AppListTestViewDelegate appListDelegate_; |
| 22 app_list::test::AppListTestModel appListModel_; | |
| 22 int textChangeCount_; | 23 int textChangeCount_; |
| 23 } | 24 } |
| 24 | 25 |
| 25 @property(assign, nonatomic) int textChangeCount; | 26 @property(assign, nonatomic) int textChangeCount; |
| 26 | 27 |
| 27 @end | 28 @end |
| 28 | 29 |
| 29 @implementation TestAppsSearchBoxDelegate | 30 @implementation TestAppsSearchBoxDelegate |
| 30 | 31 |
| 31 @synthesize textChangeCount = textChangeCount_; | 32 @synthesize textChangeCount = textChangeCount_; |
| 32 | 33 |
| 34 - (id)init { | |
| 35 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.
| |
| 36 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.
| |
| 37 users.push_back(app_list::AppListModel::User()); | |
| 38 users.push_back(app_list::AppListModel::User()); | |
| 39 users[0].name = ASCIIToUTF16("user1"); | |
| 40 users[1].name = ASCIIToUTF16("user2"); | |
| 41 users[1].email = ASCIIToUTF16("user2@chromium.org"); | |
| 42 users[1].active = true; | |
| 43 appListModel_.SetUsers(users); | |
| 44 } | |
| 45 return self; | |
| 46 } | |
| 47 | |
| 33 - (app_list::SearchBoxModel*)searchBoxModel { | 48 - (app_list::SearchBoxModel*)searchBoxModel { |
| 34 return &searchBoxModel_; | 49 return &searchBoxModel_; |
| 35 } | 50 } |
| 36 | 51 |
| 37 - (app_list::AppListViewDelegate*)appListDelegate { | 52 - (app_list::AppListViewDelegate*)appListDelegate { |
| 38 return &appListDelegate_; | 53 return &appListDelegate_; |
| 39 } | 54 } |
| 40 | 55 |
| 41 - (BOOL)control:(NSControl*)control | 56 - (BOOL)control:(NSControl*)control |
| 42 textView:(NSTextView*)textView | 57 textView:(NSTextView*)textView |
| 43 doCommandBySelector:(SEL)command { | 58 doCommandBySelector:(SEL)command { |
| 44 return NO; | 59 return NO; |
| 45 } | 60 } |
| 46 | 61 |
| 47 - (void)modelTextDidChange { | 62 - (void)modelTextDidChange { |
| 48 ++textChangeCount_; | 63 ++textChangeCount_; |
| 49 } | 64 } |
| 50 | 65 |
| 51 - (CGFloat)bubbleCornerRadius { | 66 - (CGFloat)bubbleCornerRadius { |
| 52 return 3; | 67 return 3; |
| 53 } | 68 } |
| 54 | 69 |
| 55 - (NSString*)currentUserName { | 70 - (app_list::AppListModel*)appListModel { |
| 56 return @""; | 71 return &appListModel_; |
| 57 } | |
| 58 | |
| 59 - (NSString*)currentUserEmail { | |
| 60 return @""; | |
| 61 } | 72 } |
| 62 | 73 |
| 63 @end | 74 @end |
| 64 | 75 |
| 65 namespace app_list { | 76 namespace app_list { |
| 66 namespace test { | 77 namespace test { |
| 67 | 78 |
| 68 class AppsSearchBoxControllerTest : public ui::CocoaTest { | 79 class AppsSearchBoxControllerTest : public ui::CocoaTest { |
| 69 public: | 80 public: |
| 70 AppsSearchBoxControllerTest() { | 81 AppsSearchBoxControllerTest() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 EXPECT_EQ(3, [delegate_ textChangeCount]); | 143 EXPECT_EQ(3, [delegate_ textChangeCount]); |
| 133 | 144 |
| 134 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text), | 145 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text), |
| 135 [[apps_search_box_controller_ searchTextField] stringValue]); | 146 [[apps_search_box_controller_ searchTextField] stringValue]); |
| 136 SimulateKeyAction(@selector(complete:)); | 147 SimulateKeyAction(@selector(complete:)); |
| 137 EXPECT_NSEQ([NSString string], | 148 EXPECT_NSEQ([NSString string], |
| 138 [[apps_search_box_controller_ searchTextField] stringValue]); | 149 [[apps_search_box_controller_ searchTextField] stringValue]); |
| 139 EXPECT_EQ(4, [delegate_ textChangeCount]); | 150 EXPECT_EQ(4, [delegate_ textChangeCount]); |
| 140 } | 151 } |
| 141 | 152 |
| 142 // Test the popup menu items. | 153 // 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.
| |
| 154 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenuSingleUser) { | |
| 155 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.
| |
| 156 users.push_back(app_list::AppListModel::User()); | |
| 157 [delegate_ appListModel]->SetUsers(users); | |
| 158 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; | |
| 159 EXPECT_TRUE([apps_search_box_controller_ appListMenu]); | |
| 160 ui::MenuModel* menu_model | |
| 161 = [apps_search_box_controller_ appListMenu]->menu_model(); | |
| 162 // Add one to the item count to account for the blank, first item that Cocoa | |
| 163 // has in its popup menus. | |
| 164 EXPECT_EQ(menu_model->GetItemCount() + 1, | |
| 165 [[menu_control menu] numberOfItems]); | |
| 166 } | |
|
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.
| |
| 167 | |
| 168 // Test the popup menu items. | |
| 143 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { | 169 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
| 144 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; | 170 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; |
| 145 EXPECT_TRUE([apps_search_box_controller_ appListMenu]); | 171 EXPECT_TRUE([apps_search_box_controller_ appListMenu]); |
| 146 ui::MenuModel* menu_model | 172 ui::MenuModel* menu_model |
| 147 = [apps_search_box_controller_ appListMenu]->menu_model(); | 173 = [apps_search_box_controller_ appListMenu]->menu_model(); |
| 148 // Add one to the item count to account for the blank, first item that Cocoa | 174 // Add one to the item count to account for the blank, first item that Cocoa |
| 149 // has in its popup menus. | 175 // has in its popup menus. |
| 150 EXPECT_EQ(menu_model->GetItemCount() + 1, | 176 EXPECT_EQ(menu_model->GetItemCount() + 1, |
| 151 [[menu_control menu] numberOfItems]); | 177 [[menu_control menu] numberOfItems]); |
| 152 | 178 |
| 153 // The CURRENT_USER item should contain our custom view. | |
| 154 ui::MenuModel* found_menu_model = menu_model; | 179 ui::MenuModel* found_menu_model = menu_model; |
| 155 int index; | 180 int index; |
| 181 MenuController* controller = [[menu_control menu] delegate]; | |
| 182 | |
| 183 // The first user item is an unchecked label. | |
| 156 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( | 184 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| 157 AppListMenu::CURRENT_USER, &menu_model, &index)); | 185 AppListMenu::SELECT_PROFILE, &menu_model, &index)); |
| 158 EXPECT_EQ(found_menu_model, menu_model); | 186 EXPECT_EQ(found_menu_model, menu_model); |
| 159 NSMenuItem* current_user_item = [[menu_control menu] itemAtIndex:index + 1]; | 187 NSMenuItem* unchecked_user_item = [[menu_control menu] itemAtIndex:index + 1]; |
| 160 EXPECT_TRUE([current_user_item view]); | 188 [controller validateUserInterfaceItem:unchecked_user_item]; |
| 189 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.
| |
| 190 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.
| |
| 191 [unchecked_user_item title]); | |
| 192 EXPECT_EQ(NSOffState, [unchecked_user_item state]); | |
| 193 | |
| 194 // 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.
| |
| 195 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( | |
| 196 AppListMenu::SELECT_PROFILE + 1, &menu_model, &index)); | |
| 197 EXPECT_EQ(found_menu_model, menu_model); | |
| 198 NSMenuItem* checked_user_item = [[menu_control menu] itemAtIndex:index + 1]; | |
| 199 [controller validateUserInterfaceItem:checked_user_item]; | |
| 200 EXPECT_FALSE([checked_user_item view]); | |
| 201 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), | |
| 202 [checked_user_item title]); | |
| 203 EXPECT_EQ(NSOnState, [checked_user_item state]); | |
| 161 | 204 |
| 162 // A regular item should have just the label. | 205 // A regular item should have just the label. |
| 163 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( | 206 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| 164 AppListMenu::SHOW_SETTINGS, &menu_model, &index)); | 207 AppListMenu::SHOW_SETTINGS, &menu_model, &index)); |
| 165 EXPECT_EQ(found_menu_model, menu_model); | 208 EXPECT_EQ(found_menu_model, menu_model); |
| 166 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1]; | 209 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1]; |
| 167 EXPECT_FALSE([settings_item view]); | 210 EXPECT_FALSE([settings_item view]); |
| 168 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), | 211 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), |
| 169 [settings_item title]); | 212 [settings_item title]); |
| 170 } | 213 } |
| 171 | 214 |
| 172 // Test initialization and display of the custom menu item that shows the | |
| 173 // currently signed-in user. This is a non-interactive view. | |
| 174 class AppsSearchBoxCustomMenuItemTest : public ui::CocoaTest { | |
| 175 public: | |
| 176 AppsSearchBoxCustomMenuItemTest() { | |
| 177 Init(); | |
| 178 } | |
| 179 | |
| 180 virtual void SetUp() OVERRIDE { | |
| 181 current_user_menu_item_.reset([[[CurrentUserMenuItemView alloc] | |
| 182 initWithCurrentUser:@"testUser" | |
| 183 userEmail:@"testUser@chromium.org"] retain]); | |
| 184 ui::CocoaTest::SetUp(); | |
| 185 [[test_window() contentView] addSubview:current_user_menu_item_]; | |
| 186 } | |
| 187 | |
| 188 protected: | |
| 189 base::scoped_nsobject<NSView> current_user_menu_item_; | |
| 190 | |
| 191 private: | |
| 192 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxCustomMenuItemTest); | |
| 193 }; | |
| 194 | |
| 195 TEST_VIEW(AppsSearchBoxCustomMenuItemTest, current_user_menu_item_); | |
| 196 | |
| 197 } // namespace test | 215 } // namespace test |
| 198 } // namespace app_list | 216 } // namespace app_list |
| OLD | NEW |