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/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/browser_with_test_window_test.h"
20 #include "chrome/test/base/test_browser_window.h"
21 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h"
23 #include "chrome/test/base/testing_profile_manager.h"
24 #include "components/signin/core/common/profile_management_switches.h"
25 #include "content/public/browser/native_web_keyboard_event.h"
26 #include "ui/events/keycodes/keyboard_codes.h"
28 typedef BrowserWithTestWindowTest BrowserCommandControllerTest
;
30 TEST_F(BrowserCommandControllerTest
, IsReservedCommandOrKey
) {
31 #if defined(OS_CHROMEOS)
32 // F1-3 keys are reserved Chrome accelerators on Chrome OS.
33 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
34 IDC_BACK
, content::NativeWebKeyboardEvent(
35 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_BACK
, 0, 0)));
36 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
37 IDC_FORWARD
, content::NativeWebKeyboardEvent(
38 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_FORWARD
, 0, 0)));
39 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
40 IDC_RELOAD
, content::NativeWebKeyboardEvent(
41 ui::ET_KEY_PRESSED
, false, ui::VKEY_BROWSER_REFRESH
, 0, 0)));
43 // When there are modifier keys pressed, don't reserve.
44 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
45 IDC_RELOAD_IGNORING_CACHE
, content::NativeWebKeyboardEvent(
46 ui::ET_KEY_PRESSED
, false, ui::VKEY_F3
, ui::EF_SHIFT_DOWN
, 0)));
47 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
48 IDC_RELOAD_IGNORING_CACHE
, content::NativeWebKeyboardEvent(
49 ui::ET_KEY_PRESSED
, false, ui::VKEY_F3
, ui::EF_CONTROL_DOWN
, 0)));
50 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
51 IDC_FULLSCREEN
, content::NativeWebKeyboardEvent(
52 ui::ET_KEY_PRESSED
, false, ui::VKEY_F4
, ui::EF_SHIFT_DOWN
, 0)));
54 // F4-10 keys are not reserved since they are Ash accelerators.
55 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
56 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
58 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
59 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
61 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
62 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
64 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
65 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
67 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
68 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
70 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
71 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
73 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
74 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
75 ui::VKEY_F10
, 0, 0)));
77 // Shift+Control+Alt+F3 is also an Ash accelerator. Don't reserve it.
78 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
79 -1, content::NativeWebKeyboardEvent(
80 ui::ET_KEY_PRESSED
, false,
82 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
, 0)));
86 // Ctrl+n, Ctrl+w are reserved while Ctrl+f is not.
88 // The content::NativeWebKeyboardEvent constructor is available only when
89 // USE_AURA is #defined.
90 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
91 IDC_NEW_WINDOW
, content::NativeWebKeyboardEvent(
92 ui::ET_KEY_PRESSED
, false, ui::VKEY_N
, ui::EF_CONTROL_DOWN
, 0)));
93 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
94 IDC_CLOSE_TAB
, content::NativeWebKeyboardEvent(
95 ui::ET_KEY_PRESSED
, false, ui::VKEY_W
, ui::EF_CONTROL_DOWN
, 0)));
96 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
97 IDC_FIND
, content::NativeWebKeyboardEvent(
98 ui::ET_KEY_PRESSED
, false, ui::VKEY_F
, ui::EF_CONTROL_DOWN
, 0)));
102 TEST_F(BrowserCommandControllerTest
, IsReservedCommandOrKeyIsApp
) {
103 browser()->app_name_
= "app";
104 ASSERT_TRUE(browser()->is_app());
106 // When is_app(), no keys are reserved.
107 #if defined(OS_CHROMEOS)
108 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
109 IDC_BACK
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
110 ui::VKEY_F1
, 0, 0)));
111 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
112 IDC_FORWARD
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
113 ui::VKEY_F2
, 0, 0)));
114 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
115 IDC_RELOAD
, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
116 ui::VKEY_F3
, 0, 0)));
117 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
118 -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED
, false,
119 ui::VKEY_F4
, 0, 0)));
120 #endif // OS_CHROMEOS
122 #if defined(USE_AURA)
123 // The content::NativeWebKeyboardEvent constructor is available only when
124 // USE_AURA is #defined.
125 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
126 IDC_NEW_WINDOW
, content::NativeWebKeyboardEvent(
127 ui::ET_KEY_PRESSED
, false, ui::VKEY_N
, ui::EF_CONTROL_DOWN
, 0)));
128 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
129 IDC_CLOSE_TAB
, content::NativeWebKeyboardEvent(
130 ui::ET_KEY_PRESSED
, false, ui::VKEY_W
, ui::EF_CONTROL_DOWN
, 0)));
131 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
132 IDC_FIND
, content::NativeWebKeyboardEvent(
133 ui::ET_KEY_PRESSED
, false, ui::VKEY_F
, ui::EF_CONTROL_DOWN
, 0)));
137 TEST_F(BrowserCommandControllerTest
, IncognitoCommands
) {
138 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
139 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
140 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
142 TestingProfile
* testprofile
= browser()->profile()->AsTestingProfile();
143 EXPECT_TRUE(testprofile
);
144 testprofile
->SetGuestSession(true);
145 chrome::BrowserCommandController
146 ::UpdateSharedCommandsForIncognitoAvailability(
147 browser()->command_controller()->command_updater(), testprofile
);
148 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
149 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
150 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
152 testprofile
->SetGuestSession(false);
153 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
154 IncognitoModePrefs::FORCED
);
155 chrome::BrowserCommandController
156 ::UpdateSharedCommandsForIncognitoAvailability(
157 browser()->command_controller()->command_updater(), testprofile
);
158 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
159 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
160 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN
));
163 TEST_F(BrowserCommandControllerTest
, AppFullScreen
) {
164 // Enable for tabbed browser.
165 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
167 // Enabled for app windows.
168 browser()->app_name_
= "app";
169 ASSERT_TRUE(browser()->is_app());
170 browser()->command_controller()->FullscreenStateChanged();
171 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
174 TEST_F(BrowserCommandControllerTest
, OldAvatarMenuDisabledWhenOnlyOneProfile
) {
175 #if defined(OS_CHROMEOS)
176 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by
177 // default on CrOS. http://crbug.com/351655
178 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles
);
181 if (!profiles::IsMultipleProfilesEnabled())
184 EXPECT_FALSE(switches::IsNewProfileManagement());
186 TestingProfileManager
testing_profile_manager(
187 TestingBrowserProcess::GetGlobal());
188 ASSERT_TRUE(testing_profile_manager
.SetUp());
189 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
191 chrome::BrowserCommandController
command_controller(browser(),
193 const CommandUpdater
* command_updater
= command_controller
.command_updater();
195 testing_profile_manager
.CreateTestingProfile("p1");
196 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
197 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
199 testing_profile_manager
.CreateTestingProfile("p2");
200 ASSERT_EQ(2U, profile_manager
->GetNumberOfProfiles());
201 #if defined(OS_CHROMEOS)
202 // Chrome OS uses system tray menu to handle multi-profiles.
203 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
205 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
208 testing_profile_manager
.DeleteTestingProfile("p1");
209 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
210 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
212 testing_profile_manager
.DeleteTestingProfile("p2");
215 TEST_F(BrowserCommandControllerTest
, NewAvatarMenuEnabledWhenOnlyOneProfile
) {
216 #if defined(OS_CHROMEOS)
217 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by
218 // default on CrOS. http://crbug.com/351655
219 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles
);
222 if (!profiles::IsMultipleProfilesEnabled())
225 // The command line is reset at the end of every test by the test suite.
226 CommandLine::ForCurrentProcess()->AppendSwitch(
227 switches::kNewProfileManagement
);
228 EXPECT_TRUE(switches::IsNewProfileManagement());
230 TestingProfileManager
testing_profile_manager(
231 TestingBrowserProcess::GetGlobal());
232 ASSERT_TRUE(testing_profile_manager
.SetUp());
233 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
235 chrome::BrowserCommandController
command_controller(browser(),
237 const CommandUpdater
* command_updater
= command_controller
.command_updater();
239 testing_profile_manager
.CreateTestingProfile("p1");
240 ASSERT_EQ(1U, profile_manager
->GetNumberOfProfiles());
241 #if defined(OS_CHROMEOS)
242 // Chrome OS uses system tray menu to handle multi-profiles.
243 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
245 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
247 testing_profile_manager
.DeleteTestingProfile("p1");
250 TEST_F(BrowserCommandControllerTest
, NewAvatarMenuEnabledInGuestMode
) {
251 #if defined(OS_CHROMEOS)
252 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by
253 // default on CrOS. http://crbug.com/351655
254 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles
);
257 if (!profiles::IsMultipleProfilesEnabled())
260 // The command line is reset at the end of every test by the test suite.
261 CommandLine::ForCurrentProcess()->AppendSwitch(
262 switches::kNewProfileManagement
);
263 EXPECT_TRUE(switches::IsNewProfileManagement());
265 TestingProfileManager
testing_profile_manager(
266 TestingBrowserProcess::GetGlobal());
267 ASSERT_TRUE(testing_profile_manager
.SetUp());
268 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
270 // Set up guest a profile.
271 TestingProfile::Builder guest_builder
;
272 guest_builder
.SetIncognito(); // Guest profiles are off the record.
273 guest_builder
.SetGuestSession();
274 guest_builder
.SetPath(ProfileManager::GetGuestProfilePath());
275 scoped_ptr
<TestingProfile
>guest_profile
= guest_builder
.Build();
277 ASSERT_TRUE(guest_profile
->IsGuestSession());
279 // Create a new browser based on the guest profile.
280 Browser::CreateParams
profile_params(guest_profile
.get(),
281 chrome::GetActiveDesktop());
282 scoped_ptr
<Browser
> guest_browser(
283 chrome::CreateBrowserWithTestWindowForParams(&profile_params
));
284 chrome::BrowserCommandController
command_controller(guest_browser
.get(),
286 const CommandUpdater
* command_updater
= command_controller
.command_updater();
287 #if defined(OS_CHROMEOS)
288 // Chrome OS uses system tray menu to handle multi-profiles.
289 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
291 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
295 TEST_F(BrowserCommandControllerTest
, AvatarMenuAlwaysDisabledInIncognitoMode
) {
296 #if defined(OS_CHROMEOS)
297 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by
298 // default on CrOS. http://crbug.com/351655
299 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles
);
302 if (!profiles::IsMultipleProfilesEnabled())
305 TestingProfileManager
testing_profile_manager(
306 TestingBrowserProcess::GetGlobal());
307 ASSERT_TRUE(testing_profile_manager
.SetUp());
309 // Set up a profile with an off the record profile.
310 TestingProfile::Builder normal_builder
;
311 scoped_ptr
<TestingProfile
> original_profile
= normal_builder
.Build();
313 // Create a new browser based on the off the record profile.
314 Browser::CreateParams
profile_params(
315 original_profile
->GetOffTheRecordProfile(), chrome::GetActiveDesktop());
316 scoped_ptr
<Browser
> otr_browser(
317 chrome::CreateBrowserWithTestWindowForParams(&profile_params
));
319 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
320 chrome::BrowserCommandController
command_controller(otr_browser
.get(),
322 const CommandUpdater
* command_updater
= command_controller
.command_updater();
324 // The old style avatar menu should be disabled.
325 EXPECT_FALSE(switches::IsNewProfileManagement());
326 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
328 // The new style avatar menu should also be disabled.
329 // The command line is reset at the end of every test by the test suite.
330 CommandLine::ForCurrentProcess()->AppendSwitch(
331 switches::kNewProfileManagement
);
332 EXPECT_TRUE(switches::IsNewProfileManagement());
333 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_AVATAR_MENU
));
336 //////////////////////////////////////////////////////////////////////////////
338 // A test browser window that can toggle fullscreen state.
339 class FullscreenTestBrowserWindow
: public TestBrowserWindow
{
341 FullscreenTestBrowserWindow() : fullscreen_(false) {}
342 virtual ~FullscreenTestBrowserWindow() {}
344 // TestBrowserWindow overrides:
345 virtual bool ShouldHideUIForFullscreen() const OVERRIDE
{
348 virtual bool IsFullscreen() const OVERRIDE
{
351 virtual void EnterFullscreen(
352 const GURL
& url
, FullscreenExitBubbleType type
) OVERRIDE
{
355 virtual void ExitFullscreen() OVERRIDE
{
362 DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow
);
365 // Test that uses FullscreenTestBrowserWindow for its window.
366 class BrowserCommandControllerFullscreenTest
367 : public BrowserWithTestWindowTest
{
369 BrowserCommandControllerFullscreenTest() {}
370 virtual ~BrowserCommandControllerFullscreenTest() {}
372 // BrowserWithTestWindowTest overrides:
373 virtual BrowserWindow
* CreateBrowserWindow() OVERRIDE
{
374 return new FullscreenTestBrowserWindow
;
378 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest
);
381 TEST_F(BrowserCommandControllerFullscreenTest
,
382 UpdateCommandsForFullscreenMode
) {
383 // Defaults for a tabbed browser.
384 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
385 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
386 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
387 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
388 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
389 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
390 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
391 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
392 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
393 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
394 #if defined(GOOGLE_CHROME_BUILD)
395 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
397 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
398 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
399 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
400 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
401 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
402 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
403 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
405 // Simulate going fullscreen.
406 chrome::ToggleFullscreenMode(browser());
407 ASSERT_TRUE(browser()->window()->IsFullscreen());
408 browser()->command_controller()->FullscreenStateChanged();
410 // Most commands are disabled in fullscreen.
411 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
412 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
413 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
414 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
415 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
416 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
417 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
418 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
419 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
420 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
421 #if defined(GOOGLE_CHROME_BUILD)
422 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
424 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
425 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
426 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
427 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
428 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
429 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
430 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
433 chrome::ToggleFullscreenMode(browser());
434 ASSERT_FALSE(browser()->window()->IsFullscreen());
435 browser()->command_controller()->FullscreenStateChanged();
436 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL
));
437 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB
));
438 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR
));
439 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION
));
440 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH
));
441 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR
));
442 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE
));
443 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE
));
444 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS
));
445 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU
));
446 #if defined(GOOGLE_CHROME_BUILD)
447 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK
));
449 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
450 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
451 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES
));
452 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS
));
453 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT
));
454 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU
));
455 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN
));
457 // Guest Profiles disallow some options.
458 TestingProfile
* testprofile
= browser()->profile()->AsTestingProfile();
459 EXPECT_TRUE(testprofile
);
460 testprofile
->SetGuestSession(true);
462 browser()->command_controller()->FullscreenStateChanged();
463 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS
));
464 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS
));
467 TEST_F(BrowserCommandControllerTest
, IncognitoModeOnSigninAllowedPrefChange
) {
468 TestingProfileManager
testing_profile_manager(
469 TestingBrowserProcess::GetGlobal());
470 ASSERT_TRUE(testing_profile_manager
.SetUp());
472 // Set up a profile with an off the record profile.
473 TestingProfile::Builder builder
;
474 builder
.SetIncognito();
475 scoped_ptr
<TestingProfile
> profile2(builder
.Build());
476 TestingProfile::Builder builder2
;
477 scoped_ptr
<TestingProfile
> profile1
= builder2
.Build();
478 profile2
->SetOriginalProfile(profile1
.get());
479 EXPECT_EQ(profile2
->GetOriginalProfile(), profile1
.get());
480 profile1
->SetOffTheRecordProfile(profile2
.PassAs
<Profile
>());
482 // Create a new browser based on the off the record profile.
483 Browser::CreateParams
profile_params(profile1
->GetOffTheRecordProfile(),
484 chrome::GetActiveDesktop());
485 scoped_ptr
<Browser
> browser2(
486 chrome::CreateBrowserWithTestWindowForParams(&profile_params
));
488 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
489 chrome::BrowserCommandController
command_controller(browser2
.get(),
491 const CommandUpdater
* command_updater
= command_controller
.command_updater();
493 // Check that the SYNC_SETUP command is updated on preference change.
494 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
495 profile1
->GetPrefs()->SetBoolean(prefs::kSigninAllowed
, false);
496 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
499 TEST_F(BrowserCommandControllerTest
, OnSigninAllowedPrefChange
) {
500 TestingProfileManager
testing_profile_manager(
501 TestingBrowserProcess::GetGlobal());
502 ASSERT_TRUE(testing_profile_manager
.SetUp());
503 ProfileManager
* profile_manager
= testing_profile_manager
.profile_manager();
504 chrome::BrowserCommandController
command_controller(browser(),
506 const CommandUpdater
* command_updater
= command_controller
.command_updater();
508 // Check that the SYNC_SETUP command is updated on preference change.
509 EXPECT_TRUE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));
510 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed
, false);
511 EXPECT_FALSE(command_updater
->IsCommandEnabled(IDC_SHOW_SYNC_SETUP
));