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/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
9 #include "ash/launcher/launcher_types.h" | 9 #include "ash/launcher/launcher_types.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.
h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.
h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/test/test_browser_thread.h" | |
19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
20 | 19 |
21 class TestChromeLauncherControllerPerBrowser : | 20 class TestChromeLauncherControllerPerBrowser : |
22 public ChromeLauncherControllerPerBrowser { | 21 public ChromeLauncherControllerPerBrowser { |
23 public: | 22 public: |
24 TestChromeLauncherControllerPerBrowser( | 23 TestChromeLauncherControllerPerBrowser( |
25 Profile* profile, ash::LauncherModel* model) | 24 Profile* profile, ash::LauncherModel* model) |
26 : ChromeLauncherControllerPerBrowser(profile, model) {} | 25 : ChromeLauncherControllerPerBrowser(profile, model) {} |
27 virtual bool IsLoggedInAsGuest() OVERRIDE { | 26 virtual bool IsLoggedInAsGuest() OVERRIDE { |
28 return false; | 27 return false; |
29 } | 28 } |
30 private: | 29 private: |
31 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser); | 30 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser); |
32 }; | 31 }; |
33 | 32 |
34 class LauncherContextMenuTest : public ash::test::AshTestBase { | 33 class LauncherContextMenuTest : public ash::test::AshTestBase { |
35 protected: | 34 protected: |
36 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 35 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
37 DCHECK(menu); | 36 DCHECK(menu); |
38 return menu->GetIndexOfCommandId(command_id) != -1; | 37 return menu->GetIndexOfCommandId(command_id) != -1; |
39 } | 38 } |
40 | 39 |
41 LauncherContextMenuTest() | 40 LauncherContextMenuTest() |
42 : profile_(new TestingProfile()), | 41 : profile_(new TestingProfile()) {} |
43 browser_thread_(content::BrowserThread::UI, message_loop()) {} | |
44 | 42 |
45 virtual void SetUp() OVERRIDE { | 43 virtual void SetUp() OVERRIDE { |
46 ash::test::AshTestBase::SetUp(); | 44 ash::test::AshTestBase::SetUp(); |
47 controller_.reset( | 45 controller_.reset( |
48 new TestChromeLauncherControllerPerBrowser(profile(), | 46 new TestChromeLauncherControllerPerBrowser(profile(), |
49 &launcher_model_)); | 47 &launcher_model_)); |
50 } | 48 } |
51 | 49 |
52 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
53 controller_.reset(NULL); | 51 controller_.reset(NULL); |
54 ash::test::AshTestBase::TearDown(); | 52 ash::test::AshTestBase::TearDown(); |
55 } | 53 } |
56 | 54 |
57 LauncherContextMenu* CreateLauncherContextMenu( | 55 LauncherContextMenu* CreateLauncherContextMenu( |
58 ash::LauncherItemType launcher_item_type) { | 56 ash::LauncherItemType launcher_item_type) { |
59 ash::LauncherItem item; | 57 ash::LauncherItem item; |
60 item.id = 1; // dummy id | 58 item.id = 1; // dummy id |
61 item.type = launcher_item_type; | 59 item.type = launcher_item_type; |
62 return new LauncherContextMenu(controller_.get(), &item, CurrentContext()); | 60 return new LauncherContextMenu(controller_.get(), &item, CurrentContext()); |
63 } | 61 } |
64 | 62 |
65 Profile* profile() { return profile_.get(); } | 63 Profile* profile() { return profile_.get(); } |
66 | 64 |
67 private: | 65 private: |
68 scoped_ptr<TestingProfile> profile_; | 66 scoped_ptr<TestingProfile> profile_; |
69 content::TestBrowserThread browser_thread_; | |
70 ash::LauncherModel launcher_model_; | 67 ash::LauncherModel launcher_model_; |
71 scoped_ptr<ChromeLauncherController> controller_; | 68 scoped_ptr<ChromeLauncherController> controller_; |
72 | 69 |
73 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); | 70 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); |
74 }; | 71 }; |
75 | 72 |
76 // Verifies that "New Incognito window" menu item in the launcher context | 73 // Verifies that "New Incognito window" menu item in the launcher context |
77 // menu is disabled when Incognito mode is switched off (by a policy). | 74 // menu is disabled when Incognito mode is switched off (by a policy). |
78 TEST_F(LauncherContextMenuTest, | 75 TEST_F(LauncherContextMenuTest, |
79 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) { | 76 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) { |
(...skipping 28 matching lines...) Expand all Loading... |
108 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 105 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
109 | 106 |
110 // Disable Incognito mode. | 107 // Disable Incognito mode. |
111 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 108 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
112 IncognitoModePrefs::FORCED); | 109 IncognitoModePrefs::FORCED); |
113 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); | 110 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); |
114 ASSERT_TRUE(IsItemPresentInMenu( | 111 ASSERT_TRUE(IsItemPresentInMenu( |
115 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); | 112 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); |
116 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 113 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
117 } | 114 } |
OLD | NEW |