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/memory/scoped_nsobject.h" | 7 #include "base/memory/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" |
| 12 #import "ui/app_list/cocoa/current_user_menu_item_view.h" |
11 #include "ui/app_list/search_box_model.h" | 13 #include "ui/app_list/search_box_model.h" |
| 14 #include "ui/app_list/test/app_list_test_model.h" |
| 15 #include "ui/app_list/test/app_list_test_view_delegate.h" |
12 #import "ui/base/test/ui_cocoa_test_helper.h" | 16 #import "ui/base/test/ui_cocoa_test_helper.h" |
13 | 17 |
14 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { | 18 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { |
15 @private | 19 @private |
16 app_list::SearchBoxModel searchBoxModel_; | 20 app_list::SearchBoxModel searchBoxModel_; |
| 21 app_list::test::AppListTestViewDelegate appListDelegate_; |
17 int textChangeCount_; | 22 int textChangeCount_; |
18 } | 23 } |
19 | 24 |
20 @property(assign, nonatomic) int textChangeCount; | 25 @property(assign, nonatomic) int textChangeCount; |
21 | 26 |
22 @end | 27 @end |
23 | 28 |
24 @implementation TestAppsSearchBoxDelegate | 29 @implementation TestAppsSearchBoxDelegate |
25 | 30 |
26 @synthesize textChangeCount = textChangeCount_; | 31 @synthesize textChangeCount = textChangeCount_; |
27 | 32 |
28 - (app_list::SearchBoxModel*)searchBoxModel { | 33 - (app_list::SearchBoxModel*)searchBoxModel { |
29 return &searchBoxModel_; | 34 return &searchBoxModel_; |
30 } | 35 } |
31 | 36 |
| 37 - (app_list::AppListViewDelegate*)appListDelegate { |
| 38 return &appListDelegate_; |
| 39 } |
| 40 |
32 - (BOOL)control:(NSControl*)control | 41 - (BOOL)control:(NSControl*)control |
33 textView:(NSTextView*)textView | 42 textView:(NSTextView*)textView |
34 doCommandBySelector:(SEL)command { | 43 doCommandBySelector:(SEL)command { |
35 return NO; | 44 return NO; |
36 } | 45 } |
37 | 46 |
38 - (void)modelTextDidChange { | 47 - (void)modelTextDidChange { |
39 ++textChangeCount_; | 48 ++textChangeCount_; |
40 } | 49 } |
41 | 50 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // Test pressing escape clears the search. | 121 // Test pressing escape clears the search. |
113 model->SetText(search_text); | 122 model->SetText(search_text); |
114 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text), | 123 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text), |
115 [[apps_search_box_controller_ searchTextField] stringValue]); | 124 [[apps_search_box_controller_ searchTextField] stringValue]); |
116 SimulateKeyAction(@selector(complete:)); | 125 SimulateKeyAction(@selector(complete:)); |
117 EXPECT_NSEQ([NSString string], | 126 EXPECT_NSEQ([NSString string], |
118 [[apps_search_box_controller_ searchTextField] stringValue]); | 127 [[apps_search_box_controller_ searchTextField] stringValue]); |
119 EXPECT_EQ(2, [delegate_ textChangeCount]); | 128 EXPECT_EQ(2, [delegate_ textChangeCount]); |
120 } | 129 } |
121 | 130 |
| 131 // Test the popup menu items. |
| 132 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { |
| 133 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; |
| 134 EXPECT_TRUE([apps_search_box_controller_ appListMenu]); |
| 135 ui::MenuModel* menu_model |
| 136 = [apps_search_box_controller_ appListMenu]->menu_model(); |
| 137 // Add one to the item count to account for the blank, first item that Cocoa |
| 138 // has in its popup menus. |
| 139 EXPECT_EQ(menu_model->GetItemCount() + 1, |
| 140 [[menu_control menu] numberOfItems]); |
| 141 |
| 142 // The CURRENT_USER item should contain our custom view. |
| 143 ui::MenuModel* found_menu_model = menu_model; |
| 144 int index; |
| 145 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| 146 AppListMenu::CURRENT_USER, &menu_model, &index)); |
| 147 EXPECT_EQ(found_menu_model, menu_model); |
| 148 NSMenuItem* current_user_item = [[menu_control menu] itemAtIndex:index + 1]; |
| 149 EXPECT_TRUE([current_user_item view]); |
| 150 |
| 151 // A regular item should have just the label. |
| 152 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( |
| 153 AppListMenu::SHOW_SETTINGS, &menu_model, &index)); |
| 154 EXPECT_EQ(found_menu_model, menu_model); |
| 155 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1]; |
| 156 EXPECT_FALSE([settings_item view]); |
| 157 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), |
| 158 [settings_item title]); |
| 159 } |
| 160 |
| 161 // Test initialization and display of the custom menu item that shows the |
| 162 // currently signed-in user. This is a non-interactive view. |
| 163 class AppsSearchBoxCustomMenuItemTest : public ui::CocoaTest { |
| 164 public: |
| 165 AppsSearchBoxCustomMenuItemTest() { |
| 166 Init(); |
| 167 } |
| 168 |
| 169 virtual void SetUp() OVERRIDE { |
| 170 scoped_ptr<AppListViewDelegate> delegate(new AppListTestViewDelegate); |
| 171 current_user_menu_item_.reset([[[CurrentUserMenuItemView alloc] |
| 172 initWithDelegate:delegate.get()] retain]); |
| 173 ui::CocoaTest::SetUp(); |
| 174 [[test_window() contentView] addSubview:current_user_menu_item_]; |
| 175 } |
| 176 |
| 177 protected: |
| 178 scoped_nsobject<NSView> current_user_menu_item_; |
| 179 |
| 180 private: |
| 181 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxCustomMenuItemTest); |
| 182 }; |
| 183 |
| 184 TEST_VIEW(AppsSearchBoxCustomMenuItemTest, current_user_menu_item_); |
| 185 |
122 } // namespace test | 186 } // namespace test |
123 } // namespace app_list | 187 } // namespace app_list |
OLD | NEW |