Commit 8d58fd75 authored by tapted@chromium.org's avatar tapted@chromium.org

Fix rebuilding the profile selector on the OSX App Launcher.

rebuildMenu was only rebuilding the NSMenu, not the menu Model. Do both.

Also add tests, and remove the unused AppListMenu::CURRENT_USER, to fix
a broken test related to the test not observing the user model properly.

BUG=302882
TEST=Open the App Launcher on OSX. Go to chrome://settings and add a
user. The new user should appear in the App Lanucher profile selctor.

Review URL: https://codereview.chromium.org/25535006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226435 0039d316-1c4b-4281-b951-d872f2087c98
parent 26b382a2
......@@ -83,8 +83,6 @@ void AppListMenu::ExecuteCommand(int command_id, int event_flags) {
return;
}
switch (command_id) {
case CURRENT_USER:
break; // Do nothing.
case SHOW_SETTINGS:
delegate_->OpenSettings();
break;
......
......@@ -18,7 +18,6 @@ class AppListViewDelegate;
class AppListMenu : public ui::SimpleMenuModel::Delegate {
public:
enum AppListMenuCommands {
CURRENT_USER,
SHOW_SETTINGS,
SHOW_HELP,
SHOW_FEEDBACK,
......
......@@ -159,6 +159,10 @@ void SearchBoxModelObserverBridge::TextChanged() {
if (![delegate_ appListDelegate])
return;
[menuController_ setModel:NULL];
appListMenu_.reset(
new app_list::AppListMenu([delegate_ appListDelegate],
[delegate_ appListModel]->users()));
menuController_.reset([[AppListMenuController alloc]
initWithSearchBoxController:self]);
[menuButton_ setMenu:[menuController_ menu]]; // Menu will populate here.
......@@ -174,12 +178,6 @@ void SearchBoxModelObserverBridge::TextChanged() {
return;
bridge_.reset(new app_list::SearchBoxModelObserverBridge(self));
if (![delegate_ appListDelegate])
return;
appListMenu_.reset(
new app_list::AppListMenu([delegate_ appListDelegate],
[delegate_ appListModel]->users()));
[self rebuildMenu];
}
......
......@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#import "testing/gtest_mac.h"
#include "ui/app_list/app_list_menu.h"
#include "ui/app_list/app_list_model_observer.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"
......@@ -74,7 +75,8 @@
namespace app_list {
namespace test {
class AppsSearchBoxControllerTest : public ui::CocoaTest {
class AppsSearchBoxControllerTest : public ui::CocoaTest,
public AppListModelObserver {
public:
AppsSearchBoxControllerTest() {
Init();
......@@ -86,12 +88,14 @@ class AppsSearchBoxControllerTest : public ui::CocoaTest {
NSMakeRect(0, 0, 400, 100)]);
delegate_.reset([[TestAppsSearchBoxDelegate alloc] init]);
[apps_search_box_controller_ setDelegate:delegate_];
[delegate_ appListModel]->AddObserver(this);
ui::CocoaTest::SetUp();
[[test_window() contentView] addSubview:[apps_search_box_controller_ view]];
}
virtual void TearDown() OVERRIDE {
[delegate_ appListModel]->RemoveObserver(this);
[apps_search_box_controller_ setDelegate:nil];
ui::CocoaTest::TearDown();
}
......@@ -104,6 +108,13 @@ class AppsSearchBoxControllerTest : public ui::CocoaTest {
}
protected:
// Overridden from app_list::AppListModelObserver:
virtual void OnAppListModelUsersChanged() OVERRIDE {
[apps_search_box_controller_ rebuildMenu];
}
virtual void OnAppListModelSigninStatusChanged() OVERRIDE {}
base::scoped_nsobject<TestAppsSearchBoxDelegate> delegate_;
base::scoped_nsobject<AppsSearchBoxController> apps_search_box_controller_;
......@@ -222,5 +233,33 @@ TEST_F(AppsSearchBoxControllerTest, SearchBoxMenu) {
[settings_item title]);
}
// Test adding another user, and changing an existing one.
TEST_F(AppsSearchBoxControllerTest, SearchBoxMenuChangingUsers) {
app_list::AppListModel::Users users = [delegate_ appListModel]->users();
EXPECT_EQ(2u, users.size());
ui::MenuModel* menu_model
= [apps_search_box_controller_ appListMenu]->menu_model();
// Adding one to account for the empty item at index 0 in Cocoa popup menus.
int non_user_items = menu_model->GetItemCount() - users.size() + 1;
NSPopUpButton* menu_control = [apps_search_box_controller_ menuControl];
EXPECT_EQ(2, [[menu_control menu] numberOfItems] - non_user_items);
EXPECT_NSEQ(base::SysUTF16ToNSString(users[0].name),
[[[menu_control menu] itemAtIndex:1] title]);
users[0].name = ASCIIToUTF16("renamed user");
app_list::AppListModel::User new_user;
new_user.name = ASCIIToUTF16("user3");
users.push_back(new_user);
[delegate_ appListModel]->SetUsers(users);
// Should now be an extra item, and it should have correct titles.
EXPECT_EQ(3, [[menu_control menu] numberOfItems] - non_user_items);
EXPECT_NSEQ(base::SysUTF16ToNSString(users[0].name),
[[[menu_control menu] itemAtIndex:1] title]);
EXPECT_NSEQ(base::SysUTF16ToNSString(new_user.name),
[[[menu_control menu] itemAtIndex:3] title]);
}
} // namespace test
} // namespace app_list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment