Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / launcher_context_menu_unittest.cc
blobcfb607af2ab386f87cc8c5e10e2e682177621c6d
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
7 #include "ash/launcher/launcher_types.h"
8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_model.h"
10 #include "ash/test/ash_test_base.h"
11 #include "base/prefs/pref_service.h"
12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/prefs/incognito_mode_prefs.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "ui/aura/root_window.h"
19 class TestChromeLauncherController : public ChromeLauncherController {
20 public:
21 TestChromeLauncherController(Profile* profile, ash::ShelfModel* model)
22 : ChromeLauncherController(profile, model) {}
23 virtual bool IsLoggedInAsGuest() OVERRIDE {
24 return false;
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController);
30 class LauncherContextMenuTest : public ash::test::AshTestBase {
31 protected:
32 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
33 DCHECK(menu);
34 return menu->GetIndexOfCommandId(command_id) != -1;
37 LauncherContextMenuTest()
38 : profile_(new TestingProfile()) {}
40 virtual void SetUp() OVERRIDE {
41 ash::test::AshTestBase::SetUp();
42 controller_.reset(
43 new TestChromeLauncherController(profile(), &shelf_model_));
46 virtual void TearDown() OVERRIDE {
47 controller_.reset(NULL);
48 ash::test::AshTestBase::TearDown();
51 LauncherContextMenu* CreateLauncherContextMenu(
52 ash::LauncherItemType launcher_item_type) {
53 ash::LauncherItem item;
54 item.id = 1; // dummy id
55 item.type = launcher_item_type;
56 return new LauncherContextMenu(controller_.get(), &item, CurrentContext());
59 Profile* profile() { return profile_.get(); }
61 private:
62 scoped_ptr<TestingProfile> profile_;
63 ash::ShelfModel shelf_model_;
64 scoped_ptr<ChromeLauncherController> controller_;
66 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
69 // Verifies that "New Incognito window" menu item in the launcher context
70 // menu is disabled when Incognito mode is switched off (by a policy).
71 TEST_F(LauncherContextMenuTest,
72 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
73 // Initially, "New Incognito window" should be enabled.
74 scoped_ptr<LauncherContextMenu> menu(
75 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
76 ASSERT_TRUE(IsItemPresentInMenu(
77 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
78 EXPECT_TRUE(menu->IsCommandIdEnabled(
79 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
81 // Disable Incognito mode.
82 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
83 IncognitoModePrefs::DISABLED);
84 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
85 // The item should be disabled.
86 ASSERT_TRUE(IsItemPresentInMenu(
87 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
88 EXPECT_FALSE(menu->IsCommandIdEnabled(
89 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
92 // Verifies that "New window" menu item in the launcher context
93 // menu is disabled when Incognito mode is forced (by a policy).
94 TEST_F(LauncherContextMenuTest,
95 NewWindowMenuIsDisabledWhenIncognitoModeForced) {
96 // Initially, "New window" should be enabled.
97 scoped_ptr<LauncherContextMenu> menu(
98 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
99 ASSERT_TRUE(IsItemPresentInMenu(
100 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
101 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
103 // Disable Incognito mode.
104 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
105 IncognitoModePrefs::FORCED);
106 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
107 ASSERT_TRUE(IsItemPresentInMenu(
108 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
109 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));