This source file includes following definitions.
- IsLoggedInAsGuest
- IsItemPresentInMenu
- SetUp
- TearDown
- CreateLauncherContextMenu
- profile
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_item_types.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/prefs/pref_service.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/test/base/testing_profile.h"
#include "ui/aura/window_event_dispatcher.h"
class TestChromeLauncherController : public ChromeLauncherController {
public:
TestChromeLauncherController(Profile* profile, ash::ShelfModel* model)
: ChromeLauncherController(profile, model) {}
virtual bool IsLoggedInAsGuest() OVERRIDE {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController);
};
class LauncherContextMenuTest : public ash::test::AshTestBase {
protected:
static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
DCHECK(menu);
return menu->GetIndexOfCommandId(command_id) != -1;
}
LauncherContextMenuTest()
: profile_(new TestingProfile()) {}
virtual void SetUp() OVERRIDE {
ash::test::AshTestBase::SetUp();
controller_.reset(
new TestChromeLauncherController(profile(), &shelf_model_));
}
virtual void TearDown() OVERRIDE {
controller_.reset(NULL);
ash::test::AshTestBase::TearDown();
}
LauncherContextMenu* CreateLauncherContextMenu(
ash::ShelfItemType shelf_item_type) {
ash::ShelfItem item;
item.id = 1;
item.type = shelf_item_type;
return new LauncherContextMenu(controller_.get(), &item, CurrentContext());
}
Profile* profile() { return profile_.get(); }
private:
scoped_ptr<TestingProfile> profile_;
ash::ShelfModel shelf_model_;
scoped_ptr<ChromeLauncherController> controller_;
DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
};
TEST_F(LauncherContextMenuTest,
NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
scoped_ptr<LauncherContextMenu> menu(
CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
EXPECT_TRUE(menu->IsCommandIdEnabled(
LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
IncognitoModePrefs::DISABLED);
menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
EXPECT_FALSE(menu->IsCommandIdEnabled(
LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
}
TEST_F(LauncherContextMenuTest,
NewWindowMenuIsDisabledWhenIncognitoModeForced) {
scoped_ptr<LauncherContextMenu> menu(
CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
IncognitoModePrefs::FORCED);
menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
}
TEST_F(LauncherContextMenuTest, NoAutoHideOptionInMaximizedMode) {
{
scoped_ptr<LauncherContextMenu> menu(
CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
}
ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
{
scoped_ptr<LauncherContextMenu> menu(
CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_FALSE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
}
ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
{
scoped_ptr<LauncherContextMenu> menu(
CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
ASSERT_TRUE(IsItemPresentInMenu(
menu.get(), LauncherContextMenu::MENU_AUTO_HIDE));
}
}