OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
6 | 6 |
7 #include "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
8 #include "ash/shelf/shelf_item_types.h" | 8 #include "ash/shelf/shelf_item_types.h" |
9 #include "ash/shelf/shelf_model.h" | 9 #include "ash/shelf/shelf_model.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 14 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
19 | 19 |
20 class TestChromeLauncherController : public ChromeLauncherController { | 20 class TestChromeLauncherController : public ChromeLauncherController { |
21 public: | 21 public: |
22 TestChromeLauncherController(Profile* profile, ash::ShelfModel* model) | 22 TestChromeLauncherController(Profile* profile, ash::ShelfModel* model) |
23 : ChromeLauncherController(profile, model) {} | 23 : ChromeLauncherController(profile, model) {} |
24 virtual bool IsLoggedInAsGuest() override { | 24 bool IsLoggedInAsGuest() override { return false; } |
25 return false; | |
26 } | |
27 private: | 25 private: |
28 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController); | 26 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController); |
29 }; | 27 }; |
30 | 28 |
31 class LauncherContextMenuTest : public ash::test::AshTestBase { | 29 class LauncherContextMenuTest : public ash::test::AshTestBase { |
32 protected: | 30 protected: |
33 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 31 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
34 DCHECK(menu); | 32 DCHECK(menu); |
35 return menu->GetIndexOfCommandId(command_id) != -1; | 33 return menu->GetIndexOfCommandId(command_id) != -1; |
36 } | 34 } |
37 | 35 |
38 LauncherContextMenuTest() | 36 LauncherContextMenuTest() |
39 : profile_(new TestingProfile()) {} | 37 : profile_(new TestingProfile()) {} |
40 | 38 |
41 virtual void SetUp() override { | 39 void SetUp() override { |
42 ash::test::AshTestBase::SetUp(); | 40 ash::test::AshTestBase::SetUp(); |
43 controller_.reset( | 41 controller_.reset( |
44 new TestChromeLauncherController(profile(), &shelf_model_)); | 42 new TestChromeLauncherController(profile(), &shelf_model_)); |
45 } | 43 } |
46 | 44 |
47 virtual void TearDown() override { | 45 void TearDown() override { |
48 controller_.reset(NULL); | 46 controller_.reset(NULL); |
49 ash::test::AshTestBase::TearDown(); | 47 ash::test::AshTestBase::TearDown(); |
50 } | 48 } |
51 | 49 |
52 LauncherContextMenu* CreateLauncherContextMenu( | 50 LauncherContextMenu* CreateLauncherContextMenu( |
53 ash::ShelfItemType shelf_item_type) { | 51 ash::ShelfItemType shelf_item_type) { |
54 ash::ShelfItem item; | 52 ash::ShelfItem item; |
55 item.id = 1; // dummy id | 53 item.id = 1; // dummy id |
56 item.type = shelf_item_type; | 54 item.type = shelf_item_type; |
57 return new LauncherContextMenu(controller_.get(), &item, CurrentContext()); | 55 return new LauncherContextMenu(controller_.get(), &item, CurrentContext()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 100 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
103 | 101 |
104 // Disable Incognito mode. | 102 // Disable Incognito mode. |
105 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 103 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
106 IncognitoModePrefs::FORCED); | 104 IncognitoModePrefs::FORCED); |
107 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); | 105 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); |
108 ASSERT_TRUE(IsItemPresentInMenu( | 106 ASSERT_TRUE(IsItemPresentInMenu( |
109 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); | 107 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); |
110 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 108 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
111 } | 109 } |
OLD | NEW |