1 // Copyright (c) 2012 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/browser_command_controller.h"
7 #include "base/command_line.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/command_updater.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_window_state.h"
17 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/browser_with_test_window_test.h"
22 #include "chrome/test/base/test_browser_window.h"
23 #include "chrome/test/base/testing_browser_process.h"
24 #include "chrome/test/base/testing_profile.h"
25 #include "chrome/test/base/testing_profile_manager.h"
26 #include "components/signin/core/common/profile_management_switches.h"
27 #include "content/public/browser/native_web_keyboard_event.h"
28 #include "ui/events/keycodes/keyboard_codes.h"
30 typedef BrowserWithTestWindowTest BrowserCommandControllerTest
;
32 TEST_F(BrowserCommandControllerTest
, IsReservedCommandOrKey
) {
33 #if defined(OS_CHROMEOS)
34 // F1-3 keys are reserved Chrome accelerators on Chrome OS.
35 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
36 IDC_BACK
, content::NativeWebKeyboardEvent(
37 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_BACK
, 0, 0)));
38 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
39 IDC_FORWARD
, content::NativeWebKeyboardEvent(
40 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_FORWARD
, 0, 0)));
41 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
42 IDC_RELOAD
, content::NativeWebKeyboardEvent(
43 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_REFRESH
, 0, 0)));
45 // When there are modifier keys pressed, don't reserve.
46 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
47 IDC_RELOAD_IGNORING_CACHE
, content::NativeWebKeyboardEvent(
48 ui::ET_KEY_PRESSED
, false, ui::VKEY_F3
, ui::EF_SHIFT_DOWN
, 0)));
49 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
50 IDC_RELOAD_IGNORING_CACHE
, content::NativeWebKeyboardEvent(
51 ui::ET_KEY_PRESSED
, false, ui::VKEY_F3
, ui::EF_CONTROL_DOWN
, 0)));
52 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
53 IDC_FULLSCREEN
, content::NativeWebKeyboardEvent(
54 ui::ET_KEY_PRESSED
, false, ui::VKEY_F4
, ui::EF_SHIFT_DOWN
, 0)));
56 // F4-10 keys are not reserved since they are Ash accelerators.
57 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
58 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
60 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
61 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
63 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
64 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
66 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
67 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
69 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
70 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
72 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
73 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
75 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
76 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
77 ui::VKEY_F10
, 0, 0)));
79 // Shift+Control+Alt+F3 is also an Ash accelerator. Don't reserve it.
80 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
81 -1, content::NativeWebKeyboardEvent(
82 ui::ET_KEY_PRESSED
, false,
84 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
, 0)));
88 // Ctrl+n, Ctrl+w are reserved while Ctrl+f is not.
90 // The content::NativeWebKeyboardEvent constructor is available only when
91 // USE_AURA is #defined.
92 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
93 IDC_NEW_WINDOW
, content::NativeWebKeyboardEvent(
94 ui::ET_KEY_PRESSED
, false, ui::VKEY_N
, ui::EF_CONTROL_DOWN
, 0)));
95 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
96 IDC_CLOSE_TAB
, content::NativeWebKeyboardEvent(
97 ui::ET_KEY_PRESSED
, false, ui::VKEY_W
, ui::EF_CONTROL_DOWN
, 0)));
98 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
99 IDC_FIND
, content::NativeWebKeyboardEvent(
100 ui::ET_KEY_PRESSED
, false, ui::VKEY_F
, ui::EF_CONTROL_DOWN
, 0)));
104 TEST_F(BrowserCommandControllerTest
, IsReservedCommandOrKeyIsApp
) {
105 browser()->app_name_
= "app";
106 ASSERT_TRUE(browser()->is_app());
108 // When is_app(), no keys are reserved.
109 #if defined(OS_CHROMEOS)
110 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
111 IDC_BACK
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
112 ui::VKEY_F1
, 0, 0)));
113 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
114 IDC_FORWARD
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
115 ui::VKEY_F2
, 0, 0)));
116 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
117 IDC_RELOAD
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
118 ui::VKEY_F3
, 0, 0)));
119 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
120 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
121 ui::VKEY_F4
, 0, 0)));
122 #endif // OS_CHROMEOS
124 #if defined(USE_AURA)
125 // The content::NativeWebKeyboardEvent constructor is available only when
126 // USE_AURA is #defined.
127 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
128 IDC_NEW_WINDOW
, content::NativeWebKeyboardEvent(
129 ui::ET_KEY_PRESSED
, false, ui::VKEY_N
, ui::EF_CONTROL_DOWN
, 0)));
130 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
131 IDC_CLOSE_TAB
, content::NativeWebKeyboardEvent(
132 ui::ET_KEY_PRESSED
, false, ui::VKEY_W
, ui::EF_CONTROL_DOWN
, 0)));
133 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
134 IDC_FIND
, content::NativeWebKeyboardEvent(
135 ui::ET_KEY_PRESSED
, false, ui::VKEY_F
, ui::EF_CONTROL_DOWN
, 0)));
139 TEST_F(BrowserCommandControllerTest
, IncognitoCommands
) {
140 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
141 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
142 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
144 TestingProfile
* testprofile
= browser()->profile()->AsTestingProfile();
145 EXPECT_TRUE(testprofile
);
146 testprofile
->SetGuestSession(true);
147 chrome::BrowserCommandController
148 ::UpdateSharedCommandsForIncognitoAvailability(
149 browser()->command_controller()->command_updater(), testprofile
);
150 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
151 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
152 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
154 testprofile
->SetGuestSession(false);
155 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
156 IncognitoModePrefs::FORCED
);
157 chrome::BrowserCommandController
158 ::UpdateSharedCommandsForIncognitoAvailability(
159 browser()->command_controller()->command_updater(), testprofile
);
160 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
161 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
162 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
165 TEST_F(BrowserCommandControllerTest
, AppFullScreen
) {
166 // Enable for tabbed browser.
167 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
169 // Enabled for app windows.
170 browser()->app_name_
= "app";
171 ASSERT_TRUE(browser()->is_app());
172 browser()->command_controller()->FullscreenStateChanged();
173 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
176 TEST_F(BrowserCommandControllerTest
, OldAvatarMenuEnabledForOneOrMoreProfiles
) {
177 if (!profiles::IsMultipleProfilesEnabled())
180 // The command line is reset at the end of every test by the test suite.
181 switches::DisableNewAvatarMenuForTesting(
182 base::CommandLine::ForCurrentProcess());
183 ASSERT_FALSE(switches::IsNewAvatarMenu());
185 TestingProfileManager
testing_profile_manager(
186 TestingBrowserProcess::GetGlobal());
187 ASSERT_TRUE(testing_profile_manager
.SetUp());
188 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
190 chrome::BrowserCommandController
command_controller(browser());
191 const CommandUpdater
* command_updater
= command_controller
.command_updater();
194 #if defined(OS_CHROMEOS)
195 // Chrome OS uses system tray menu to handle multi-profiles.
199 testing_profile_manager
.CreateTestingProfile("p1");
200 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
201 EXPECT_EQ(enabled
, command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
203 testing_profile_manager
.CreateTestingProfile("p2");
204 ASSERT_EQ(2U, profile_manager
->GetNumberOfProfiles());
205 EXPECT_EQ(enabled
, command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
207 testing_profile_manager
.DeleteTestingProfile("p1");
208 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
209 EXPECT_EQ(enabled
, command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
211 testing_profile_manager
.DeleteTestingProfile("p2");
214 TEST_F(BrowserCommandControllerTest
, NewAvatarMenuEnabledWhenOnlyOneProfile
) {
215 if (!profiles::IsMultipleProfilesEnabled())
218 // The command line is reset at the end of every test by the test suite.
219 switches::EnableNewAvatarMenuForTesting(
220 base::CommandLine::ForCurrentProcess());
222 TestingProfileManager
testing_profile_manager(
223 TestingBrowserProcess::GetGlobal());
224 ASSERT_TRUE(testing_profile_manager
.SetUp());
225 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
227 chrome::BrowserCommandController
command_controller(browser());
228 const CommandUpdater
* command_updater
= command_controller
.command_updater();
230 testing_profile_manager
.CreateTestingProfile("p1");
231 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
232 #if defined(OS_CHROMEOS)
233 // Chrome OS uses system tray menu to handle multi-profiles.
234 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
236 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
238 testing_profile_manager
.DeleteTestingProfile("p1");
241 TEST_F(BrowserCommandControllerTest
, AvatarMenuAlwaysDisabledInIncognitoMode
) {
242 if (!profiles::IsMultipleProfilesEnabled())
245 // Set up a profile with an off the record profile.
246 TestingProfile::Builder normal_builder
;
247 scoped_ptr
<TestingProfile
> original_profile
= normal_builder
.Build();
249 // Create a new browser based on the off the record profile.
250 Browser::CreateParams
profile_params(
251 original_profile
->GetOffTheRecordProfile(), chrome::GetActiveDesktop());
252 scoped_ptr
<Browser
> otr_browser(
253 chrome::CreateBrowserWithTestWindowForParams(&profile_params
));
255 chrome::BrowserCommandController
command_controller(otr_browser
.get());
256 const CommandUpdater
* command_updater
= command_controller
.command_updater();
258 // Both the old style and the new style avatar menu should be disabled.
259 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
260 if (switches::IsNewAvatarMenu()) {
261 switches::DisableNewAvatarMenuForTesting(
262 base::CommandLine::ForCurrentProcess());
264 switches::EnableNewAvatarMenuForTesting(
265 base::CommandLine::ForCurrentProcess());
267 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
268 // The command line is reset at the end of every test by the test suite.
271 //////////////////////////////////////////////////////////////////////////////
272 class BrowserCommandControllerFullscreenTest
;
274 // A test browser window that can toggle fullscreen state.
275 class FullscreenTestBrowserWindow
: public TestBrowserWindow
,
276 ExclusiveAccessContext
{
278 FullscreenTestBrowserWindow(
279 BrowserCommandControllerFullscreenTest
* test_browser
)
280 : fullscreen_(false), test_browser_(test_browser
) {}
282 ~FullscreenTestBrowserWindow() override
{}
284 // TestBrowserWindow overrides:
285 bool ShouldHideUIForFullscreen() const override
{ return fullscreen_
; }
286 bool IsFullscreen() const override
{ return fullscreen_
; }
287 void EnterFullscreen(const GURL
& url
,
288 ExclusiveAccessBubbleType type
,
289 bool with_toolbar
) override
{
292 void ExitFullscreen() override
{ fullscreen_
= false; }
294 ExclusiveAccessContext
* GetExclusiveAccessContext() override
{ return this; }
296 // Exclusive access interface:
297 Profile
* GetProfile() override
;
298 content::WebContents
* GetActiveWebContents() override
;
299 void HideDownloadShelf() override
{}
300 void UnhideDownloadShelf() override
{}
301 void UpdateExclusiveAccessExitBubbleContent(
303 ExclusiveAccessBubbleType bubble_type
) override
{}
304 bool IsFullscreenWithToolbar() const override
{ return IsFullscreen(); }
308 BrowserCommandControllerFullscreenTest
* test_browser_
;
310 DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow
);
313 // Test that uses FullscreenTestBrowserWindow for its window.
314 class BrowserCommandControllerFullscreenTest
315 : public BrowserWithTestWindowTest
{
317 BrowserCommandControllerFullscreenTest() {}
318 ~BrowserCommandControllerFullscreenTest() override
{}
320 Browser
* GetBrowser() { return BrowserWithTestWindowTest::browser(); }
322 // BrowserWithTestWindowTest overrides:
323 BrowserWindow
* CreateBrowserWindow() override
{
324 return new FullscreenTestBrowserWindow(this);
328 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest
);
331 Profile
* FullscreenTestBrowserWindow::GetProfile() {
332 return test_browser_
->GetBrowser()->profile();
335 content::WebContents
* FullscreenTestBrowserWindow::GetActiveWebContents() {
336 return test_browser_
->GetBrowser()->tab_strip_model()->GetActiveWebContents();
339 TEST_F(BrowserCommandControllerFullscreenTest
,
340 UpdateCommandsForFullscreenMode
) {
341 // Defaults for a tabbed browser.
342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
343 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
344 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
345 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
346 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
347 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
348 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
349 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
350 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
351 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
352 #if defined(GOOGLE_CHROME_BUILD)
353 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
355 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
356 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
357 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
358 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
359 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
360 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
361 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
363 // Simulate going fullscreen.
364 chrome::ToggleFullscreenMode(browser());
365 ASSERT_TRUE(browser()->window()->IsFullscreen());
366 browser()->command_controller()->FullscreenStateChanged();
368 // Most commands are disabled in fullscreen.
369 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
370 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
371 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
372 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
373 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
374 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
375 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
376 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
377 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
378 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
379 #if defined(GOOGLE_CHROME_BUILD)
380 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
382 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
383 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
384 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
385 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
386 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
387 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
388 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
391 chrome::ToggleFullscreenMode(browser());
392 ASSERT_FALSE(browser()->window()->IsFullscreen());
393 browser()->command_controller()->FullscreenStateChanged();
394 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
395 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
396 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
397 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
398 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
399 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
400 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
401 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
402 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
403 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
404 #if defined(GOOGLE_CHROME_BUILD)
405 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
407 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
408 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
409 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
410 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
411 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
412 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
413 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
415 // Guest Profiles disallow some options.
416 TestingProfile
* testprofile
= browser()->profile()->AsTestingProfile();
417 EXPECT_TRUE(testprofile
);
418 testprofile
->SetGuestSession(true);
420 browser()->command_controller()->FullscreenStateChanged();
421 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
422 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
425 TEST_F(BrowserCommandControllerTest
, IncognitoModeOnSigninAllowedPrefChange
) {
426 // Set up a profile with an off the record profile.
427 scoped_ptr
<TestingProfile
> profile1
= TestingProfile::Builder().Build();
428 Profile
* profile2
= profile1
->GetOffTheRecordProfile();
430 EXPECT_EQ(profile2
->GetOriginalProfile(), profile1
.get());
432 // Create a new browser based on the off the record profile.
433 Browser::CreateParams
profile_params(profile1
->GetOffTheRecordProfile(),
434 chrome::GetActiveDesktop());
435 scoped_ptr
<Browser
> browser2(
436 chrome::CreateBrowserWithTestWindowForParams(&profile_params
));
438 chrome::BrowserCommandController
command_controller(browser2
.get());
439 const CommandUpdater
* command_updater
= command_controller
.command_updater();
441 // Check that the SYNC_SETUP command is updated on preference change.
442 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
443 profile1
->GetPrefs()->SetBoolean(prefs::kSigninAllowed
, false);
444 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
447 TEST_F(BrowserCommandControllerTest
, OnSigninAllowedPrefChange
) {
448 chrome::BrowserCommandController
command_controller(browser());
449 const CommandUpdater
* command_updater
= command_controller
.command_updater();
451 // Check that the SYNC_SETUP command is updated on preference change.
452 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
453 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed
, false);
454 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));