Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: ui/app_list/cocoa/apps_search_box_controller_unittest.mm

Issue 15955003: Menu for the OSX app launcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: split Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/app_list_menu_cocoa.h"
13 #include "ui/app_list/test/app_list_test_model.h"
14 #include "ui/app_list/test/app_list_test_view_delegate.h"
11 #include "ui/app_list/search_box_model.h" 15 #include "ui/app_list/search_box_model.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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Test pressing escape clears the search. 116 // Test pressing escape clears the search.
108 model->SetText(search_text); 117 model->SetText(search_text);
109 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text), 118 EXPECT_NSEQ(base::SysUTF16ToNSString(search_text),
110 [[apps_search_box_controller_ textField] stringValue]); 119 [[apps_search_box_controller_ textField] stringValue]);
111 SimulateKeyAction(@selector(complete:)); 120 SimulateKeyAction(@selector(complete:));
112 EXPECT_NSEQ([NSString string], 121 EXPECT_NSEQ([NSString string],
113 [[apps_search_box_controller_ textField] stringValue]); 122 [[apps_search_box_controller_ textField] stringValue]);
114 EXPECT_EQ(2, [delegate_ textChangeCount]); 123 EXPECT_EQ(2, [delegate_ textChangeCount]);
115 } 124 }
116 125
126 // Test the popup menu items.
127 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) {
128 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl];
129 // Force an update.
130 [apps_search_box_controller_ menuNeedsUpdate:[menu_control menu]];
131 EXPECT_TRUE([apps_search_box_controller_ appListMenu]);
132 ui::MenuModel* menu_model
133 = [apps_search_box_controller_ appListMenu]->menu_model();
134 EXPECT_EQ(menu_model->GetItemCount(), [[menu_control menu] numberOfItems]);
135
136 // The CURRENT_USER item should contain our custom view.
137 ui::MenuModel* found_menu_model = menu_model;
138 int index;
139 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId(
140 AppListMenu::CURRENT_USER, &menu_model, &index));
141 EXPECT_EQ(found_menu_model, menu_model);
142 NSMenuItem* current_user_item = [[menu_control menu] itemAtIndex:index];
143 EXPECT_TRUE([current_user_item view]);
144
145 // A regular item should have just the label.
146 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId(
147 AppListMenu::SHOW_SETTINGS, &menu_model, &index));
148 EXPECT_EQ(found_menu_model, menu_model);
149 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index];
150 EXPECT_FALSE([settings_item view]);
151 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)),
152 [settings_item title]);
153 }
154
155 // Test initialization and display of the NSPopUpButton that shows the drop-
156 // down menu. Don't try to show the menu, since it will block the thread.
157 class AppsSearchBoxMenuTest : public ui::CocoaTest {
158 public:
159 AppsSearchBoxMenuTest() {
160 Init();
161 }
162
163 virtual void SetUp() OVERRIDE {
164 custom_menu_button_.reset(
165 [[AppListMenuCocoa alloc] initWithFrame:NSMakeRect(0, 0, 29, 29)]);
166 ui::CocoaTest::SetUp();
167 [[test_window() contentView] addSubview:custom_menu_button_];
168 }
169
170 protected:
171 scoped_nsobject<AppListMenuCocoa> custom_menu_button_;
172
173 private:
174 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxMenuTest);
175 };
176
177 TEST_VIEW(AppsSearchBoxMenuTest, custom_menu_button_);
178
179 // Test initialization and display of the custom menu item that shows the
180 // currently signed-in user. This is a non-interactive view.
181 class AppsSearchBoxCustomMenuItemTest : public ui::CocoaTest {
182 public:
183 AppsSearchBoxCustomMenuItemTest() {
184 Init();
185 }
186
187 virtual void SetUp() OVERRIDE {
188 scoped_ptr<AppListViewDelegate> delegate(new AppListTestViewDelegate);
189 current_user_menu_item_.reset(
190 [[AppListMenuCocoa makeCurrentUserView:delegate.get()] retain]);
191 ui::CocoaTest::SetUp();
192 [[test_window() contentView] addSubview:current_user_menu_item_];
193 }
194
195 protected:
196 scoped_nsobject<NSView> current_user_menu_item_;
197
198 private:
199 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxCustomMenuItemTest);
200 };
201
202 TEST_VIEW(AppsSearchBoxCustomMenuItemTest, current_user_menu_item_);
203
117 } // namespace test 204 } // namespace test
118 } // namespace app_list 205 } // namespace app_list
OLDNEW
« ui/app_list/cocoa/app_list_menu_cocoa.mm ('K') | « ui/app_list/cocoa/apps_search_box_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698