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

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

Issue 25535006: Fix rebuilding the profile selector on the OSX App Launcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « ui/app_list/cocoa/apps_search_box_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 #include "ui/app_list/app_list_model_observer.h"
12 #include "ui/app_list/search_box_model.h" 13 #include "ui/app_list/search_box_model.h"
13 #include "ui/app_list/test/app_list_test_model.h" 14 #include "ui/app_list/test/app_list_test_model.h"
14 #include "ui/app_list/test/app_list_test_view_delegate.h" 15 #include "ui/app_list/test/app_list_test_view_delegate.h"
15 #import "ui/base/cocoa/menu_controller.h" 16 #import "ui/base/cocoa/menu_controller.h"
16 #import "ui/base/test/ui_cocoa_test_helper.h" 17 #import "ui/base/test/ui_cocoa_test_helper.h"
17 18
18 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> { 19 @interface TestAppsSearchBoxDelegate : NSObject<AppsSearchBoxDelegate> {
19 @private 20 @private
20 app_list::SearchBoxModel searchBoxModel_; 21 app_list::SearchBoxModel searchBoxModel_;
21 app_list::test::AppListTestViewDelegate appListDelegate_; 22 app_list::test::AppListTestViewDelegate appListDelegate_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 68
68 - (app_list::AppListModel*)appListModel { 69 - (app_list::AppListModel*)appListModel {
69 return &appListModel_; 70 return &appListModel_;
70 } 71 }
71 72
72 @end 73 @end
73 74
74 namespace app_list { 75 namespace app_list {
75 namespace test { 76 namespace test {
76 77
77 class AppsSearchBoxControllerTest : public ui::CocoaTest { 78 class AppsSearchBoxControllerTest : public ui::CocoaTest,
79 public AppListModelObserver {
78 public: 80 public:
79 AppsSearchBoxControllerTest() { 81 AppsSearchBoxControllerTest() {
80 Init(); 82 Init();
81 } 83 }
82 84
83 virtual void SetUp() OVERRIDE { 85 virtual void SetUp() OVERRIDE {
84 apps_search_box_controller_.reset( 86 apps_search_box_controller_.reset(
85 [[AppsSearchBoxController alloc] initWithFrame: 87 [[AppsSearchBoxController alloc] initWithFrame:
86 NSMakeRect(0, 0, 400, 100)]); 88 NSMakeRect(0, 0, 400, 100)]);
87 delegate_.reset([[TestAppsSearchBoxDelegate alloc] init]); 89 delegate_.reset([[TestAppsSearchBoxDelegate alloc] init]);
88 [apps_search_box_controller_ setDelegate:delegate_]; 90 [apps_search_box_controller_ setDelegate:delegate_];
91 [delegate_ appListModel]->AddObserver(this);
89 92
90 ui::CocoaTest::SetUp(); 93 ui::CocoaTest::SetUp();
91 [[test_window() contentView] addSubview:[apps_search_box_controller_ view]]; 94 [[test_window() contentView] addSubview:[apps_search_box_controller_ view]];
92 } 95 }
93 96
94 virtual void TearDown() OVERRIDE { 97 virtual void TearDown() OVERRIDE {
98 [delegate_ appListModel]->RemoveObserver(this);
95 [apps_search_box_controller_ setDelegate:nil]; 99 [apps_search_box_controller_ setDelegate:nil];
96 ui::CocoaTest::TearDown(); 100 ui::CocoaTest::TearDown();
97 } 101 }
98 102
99 void SimulateKeyAction(SEL c) { 103 void SimulateKeyAction(SEL c) {
100 NSControl* control = [apps_search_box_controller_ searchTextField]; 104 NSControl* control = [apps_search_box_controller_ searchTextField];
101 [apps_search_box_controller_ control:control 105 [apps_search_box_controller_ control:control
102 textView:nil 106 textView:nil
103 doCommandBySelector:c]; 107 doCommandBySelector:c];
104 } 108 }
105 109
106 protected: 110 protected:
111 // Overridden from app_list::AppListModelObserver:
112 virtual void OnAppListModelUsersChanged() OVERRIDE {
113 [apps_search_box_controller_ rebuildMenu];
114 }
115
116 virtual void OnAppListModelSigninStatusChanged() OVERRIDE {}
117
107 base::scoped_nsobject<TestAppsSearchBoxDelegate> delegate_; 118 base::scoped_nsobject<TestAppsSearchBoxDelegate> delegate_;
108 base::scoped_nsobject<AppsSearchBoxController> apps_search_box_controller_; 119 base::scoped_nsobject<AppsSearchBoxController> apps_search_box_controller_;
109 120
110 private: 121 private:
111 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxControllerTest); 122 DISALLOW_COPY_AND_ASSIGN(AppsSearchBoxControllerTest);
112 }; 123 };
113 124
114 TEST_VIEW(AppsSearchBoxControllerTest, [apps_search_box_controller_ view]); 125 TEST_VIEW(AppsSearchBoxControllerTest, [apps_search_box_controller_ view]);
115 126
116 // Test the search box initialization, and search input and clearing. 127 // Test the search box initialization, and search input and clearing.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // has in its popup menus. 174 // has in its popup menus.
164 EXPECT_EQ(menu_model->GetItemCount() + 1, 175 EXPECT_EQ(menu_model->GetItemCount() + 1,
165 [[menu_control menu] numberOfItems]); 176 [[menu_control menu] numberOfItems]);
166 177
167 // All command ids should be less than |SELECT_PROFILE| as no user menu items 178 // All command ids should be less than |SELECT_PROFILE| as no user menu items
168 // are being shown. 179 // are being shown.
169 for (int i = 0; i < menu_model->GetItemCount(); ++i) 180 for (int i = 0; i < menu_model->GetItemCount(); ++i)
170 EXPECT_LT(menu_model->GetCommandIdAt(i), AppListMenu::SELECT_PROFILE); 181 EXPECT_LT(menu_model->GetCommandIdAt(i), AppListMenu::SELECT_PROFILE);
171 182
172 // The number of items should match the index that starts profile items. 183 // The number of items should match the index that starts profile items.
173 EXPECT_EQ(AppListMenu::SELECT_PROFILE, menu_model->GetItemCount()); 184 EXPECT_EQ(AppListMenu::SELECT_PROFILE, menu_model->GetItemCount());
tapted 2013/10/02 03:56:33 This line actually had a bug. Adding the AppListMo
174 } 185 }
175 186
176 // Test the popup menu items for the multi-profile case. 187 // Test the popup menu items for the multi-profile case.
177 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) { 188 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) {
178 const app_list::AppListModel::Users& users = 189 const app_list::AppListModel::Users& users =
179 [delegate_ appListModel]->users(); 190 [delegate_ appListModel]->users();
180 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl]; 191 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl];
181 EXPECT_TRUE([apps_search_box_controller_ appListMenu]); 192 EXPECT_TRUE([apps_search_box_controller_ appListMenu]);
182 ui::MenuModel* menu_model 193 ui::MenuModel* menu_model
183 = [apps_search_box_controller_ appListMenu]->menu_model(); 194 = [apps_search_box_controller_ appListMenu]->menu_model();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // A regular item should have just the label. 226 // A regular item should have just the label.
216 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId( 227 EXPECT_TRUE(ui::MenuModel::GetModelAndIndexForCommandId(
217 AppListMenu::SHOW_SETTINGS, &menu_model, &index)); 228 AppListMenu::SHOW_SETTINGS, &menu_model, &index));
218 EXPECT_EQ(found_menu_model, menu_model); 229 EXPECT_EQ(found_menu_model, menu_model);
219 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1]; 230 NSMenuItem* settings_item = [[menu_control menu] itemAtIndex:index + 1];
220 EXPECT_FALSE([settings_item view]); 231 EXPECT_FALSE([settings_item view]);
221 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)), 232 EXPECT_NSEQ(base::SysUTF16ToNSString(menu_model->GetLabelAt(index)),
222 [settings_item title]); 233 [settings_item title]);
223 } 234 }
224 235
236 // Test adding another user, and changing an existing one.
237 TEST_F(AppsSearchBoxControllerTest, SearchBoxMenuChangingUsers) {
238 app_list::AppListModel::Users users = [delegate_ appListModel]->users();
239 EXPECT_EQ(2u, users.size());
240 ui::MenuModel* menu_model
241 = [apps_search_box_controller_ appListMenu]->menu_model();
242 // Adding one to account for the empty item at index 0 in Cocoa popup menus.
243 int non_user_items = menu_model->GetItemCount() - users.size() + 1;
244
245 NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl];
246 EXPECT_EQ(2, [[menu_control menu] numberOfItems] - non_user_items);
247 EXPECT_NSEQ(base::SysUTF16ToNSString(users[0].name),
248 [[[menu_control menu] itemAtIndex:1] title]);
249
250 users[0].name = ASCIIToUTF16("renamed user");
251 app_list::AppListModel::User new_user;
252 new_user.name = ASCIIToUTF16("user3");
253 users.push_back(new_user);
254 [delegate_ appListModel]->SetUsers(users);
255
256 // Should now be an extra item, and it should have correct titles.
257 EXPECT_EQ(3, [[menu_control menu] numberOfItems] - non_user_items);
258 EXPECT_NSEQ(base::SysUTF16ToNSString(users[0].name),
259 [[[menu_control menu] itemAtIndex:1] title]);
260 EXPECT_NSEQ(base::SysUTF16ToNSString(new_user.name),
261 [[[menu_control menu] itemAtIndex:3] title]);
262 }
263
225 } // namespace test 264 } // namespace test
226 } // namespace app_list 265 } // namespace app_list
OLDNEW
« no previous file with comments | « 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