• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/browser_command_controller.h"
6 
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"
27 
28 typedef BrowserWithTestWindowTest BrowserCommandControllerTest;
29 
TEST_F(BrowserCommandControllerTest,IsReservedCommandOrKey)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)));
42 
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)));
53 
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,
57                                           ui::VKEY_F4, 0, 0)));
58   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
59       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
60                                           ui::VKEY_F5, 0, 0)));
61   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
62       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
63                                           ui::VKEY_F6, 0, 0)));
64   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
65       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
66                                           ui::VKEY_F7, 0, 0)));
67   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
68       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
69                                           ui::VKEY_F8, 0, 0)));
70   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
71       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
72                                           ui::VKEY_F9, 0, 0)));
73   EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
74       -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
75                                           ui::VKEY_F10, 0, 0)));
76 
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,
81           ui::VKEY_F3,
82           ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 0)));
83 #endif  // OS_CHROMEOS
84 
85 #if defined(USE_AURA)
86   // Ctrl+n, Ctrl+w are reserved while Ctrl+f is not.
87 
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)));
99 #endif  // USE_AURA
100 }
101 
TEST_F(BrowserCommandControllerTest,IsReservedCommandOrKeyIsApp)102 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKeyIsApp) {
103   browser()->app_name_ = "app";
104   ASSERT_TRUE(browser()->is_app());
105 
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
121 
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)));
134 #endif  // USE_AURA
135 }
136 
TEST_F(BrowserCommandControllerTest,IncognitoCommands)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));
141 
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));
151 
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));
161 }
162 
TEST_F(BrowserCommandControllerTest,AppFullScreen)163 TEST_F(BrowserCommandControllerTest, AppFullScreen) {
164   // Enable for tabbed browser.
165   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
166 
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));
172 }
173 
TEST_F(BrowserCommandControllerTest,OldAvatarMenuEnabledForOneOrMoreProfiles)174 TEST_F(BrowserCommandControllerTest, OldAvatarMenuEnabledForOneOrMoreProfiles) {
175   if (!profiles::IsMultipleProfilesEnabled())
176     return;
177 
178   // The command line is reset at the end of every test by the test suite.
179   switches::DisableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
180   ASSERT_FALSE(switches::IsNewAvatarMenu());
181 
182   TestingProfileManager testing_profile_manager(
183       TestingBrowserProcess::GetGlobal());
184   ASSERT_TRUE(testing_profile_manager.SetUp());
185   ProfileManager* profile_manager = testing_profile_manager.profile_manager();
186 
187   chrome::BrowserCommandController command_controller(browser());
188   const CommandUpdater* command_updater = command_controller.command_updater();
189 
190   bool enabled = true;
191 #if defined(OS_CHROMEOS)
192   // Chrome OS uses system tray menu to handle multi-profiles.
193   enabled = false;
194 #endif
195 
196   testing_profile_manager.CreateTestingProfile("p1");
197   ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
198   EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
199 
200   testing_profile_manager.CreateTestingProfile("p2");
201   ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles());
202   EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
203 
204   testing_profile_manager.DeleteTestingProfile("p1");
205   ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
206   EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
207 
208   testing_profile_manager.DeleteTestingProfile("p2");
209 }
210 
TEST_F(BrowserCommandControllerTest,NewAvatarMenuEnabledWhenOnlyOneProfile)211 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) {
212   if (!profiles::IsMultipleProfilesEnabled())
213     return;
214 
215   // The command line is reset at the end of every test by the test suite.
216   switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
217 
218   TestingProfileManager testing_profile_manager(
219       TestingBrowserProcess::GetGlobal());
220   ASSERT_TRUE(testing_profile_manager.SetUp());
221   ProfileManager* profile_manager = testing_profile_manager.profile_manager();
222 
223   chrome::BrowserCommandController command_controller(browser());
224   const CommandUpdater* command_updater = command_controller.command_updater();
225 
226   testing_profile_manager.CreateTestingProfile("p1");
227   ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
228 #if defined(OS_CHROMEOS)
229   // Chrome OS uses system tray menu to handle multi-profiles.
230   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
231 #else
232   EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
233 #endif
234   testing_profile_manager.DeleteTestingProfile("p1");
235 }
236 
TEST_F(BrowserCommandControllerTest,NewAvatarMenuEnabledInGuestMode)237 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledInGuestMode) {
238   if (!profiles::IsMultipleProfilesEnabled())
239     return;
240 
241   // The command line is reset at the end of every test by the test suite.
242   switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
243 
244   TestingProfileManager testing_profile_manager(
245       TestingBrowserProcess::GetGlobal());
246   ASSERT_TRUE(testing_profile_manager.SetUp());
247 
248   // Set up guest a profile.
249   scoped_ptr<TestingProfile> original_profile =
250       TestingProfile::Builder().Build();
251   TestingProfile::Builder guest_builder;
252   guest_builder.SetGuestSession();
253   guest_builder.SetPath(ProfileManager::GetGuestProfilePath());
254   // Browsers in Guest mode must be off the record profiles.
255   TestingProfile* guest_profile =
256       guest_builder.BuildIncognito(original_profile.get());
257 
258   ASSERT_TRUE(guest_profile->IsGuestSession());
259 
260   // Create a new browser based on the guest profile.
261   Browser::CreateParams profile_params(guest_profile,
262                                        chrome::GetActiveDesktop());
263   scoped_ptr<Browser> guest_browser(
264       chrome::CreateBrowserWithTestWindowForParams(&profile_params));
265   chrome::BrowserCommandController command_controller(guest_browser.get());
266   const CommandUpdater* command_updater = command_controller.command_updater();
267 #if defined(OS_CHROMEOS)
268   // Chrome OS uses system tray menu to handle multi-profiles.
269   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
270 #else
271   EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
272 #endif
273 }
274 
TEST_F(BrowserCommandControllerTest,AvatarMenuAlwaysDisabledInIncognitoMode)275 TEST_F(BrowserCommandControllerTest, AvatarMenuAlwaysDisabledInIncognitoMode) {
276   if (!profiles::IsMultipleProfilesEnabled())
277     return;
278 
279   // Set up a profile with an off the record profile.
280   TestingProfile::Builder normal_builder;
281   scoped_ptr<TestingProfile> original_profile = normal_builder.Build();
282 
283   // Create a new browser based on the off the record profile.
284   Browser::CreateParams profile_params(
285       original_profile->GetOffTheRecordProfile(), chrome::GetActiveDesktop());
286   scoped_ptr<Browser> otr_browser(
287       chrome::CreateBrowserWithTestWindowForParams(&profile_params));
288 
289   chrome::BrowserCommandController command_controller(otr_browser.get());
290   const CommandUpdater* command_updater = command_controller.command_updater();
291 
292   // Both the old style and the new style avatar menu should be disabled.
293   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
294   if (switches::IsNewAvatarMenu()) {
295     switches::DisableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
296   } else {
297     switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
298   }
299   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
300   // The command line is reset at the end of every test by the test suite.
301 }
302 
303 //////////////////////////////////////////////////////////////////////////////
304 
305 // A test browser window that can toggle fullscreen state.
306 class FullscreenTestBrowserWindow : public TestBrowserWindow {
307  public:
FullscreenTestBrowserWindow()308   FullscreenTestBrowserWindow() : fullscreen_(false) {}
~FullscreenTestBrowserWindow()309   virtual ~FullscreenTestBrowserWindow() {}
310 
311   // TestBrowserWindow overrides:
ShouldHideUIForFullscreen() const312   virtual bool ShouldHideUIForFullscreen() const OVERRIDE {
313     return fullscreen_;
314   }
IsFullscreen() const315   virtual bool IsFullscreen() const OVERRIDE {
316     return fullscreen_;
317   }
EnterFullscreen(const GURL & url,FullscreenExitBubbleType type)318   virtual void EnterFullscreen(
319       const GURL& url, FullscreenExitBubbleType type) OVERRIDE {
320     fullscreen_ = true;
321   }
ExitFullscreen()322   virtual void ExitFullscreen() OVERRIDE {
323     fullscreen_ = false;
324   }
325 
326  private:
327   bool fullscreen_;
328 
329   DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow);
330 };
331 
332 // Test that uses FullscreenTestBrowserWindow for its window.
333 class BrowserCommandControllerFullscreenTest
334     : public BrowserWithTestWindowTest {
335  public:
BrowserCommandControllerFullscreenTest()336   BrowserCommandControllerFullscreenTest() {}
~BrowserCommandControllerFullscreenTest()337   virtual ~BrowserCommandControllerFullscreenTest() {}
338 
339   // BrowserWithTestWindowTest overrides:
CreateBrowserWindow()340   virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
341     return new FullscreenTestBrowserWindow;
342   }
343 
344  private:
345   DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest);
346 };
347 
TEST_F(BrowserCommandControllerFullscreenTest,UpdateCommandsForFullscreenMode)348 TEST_F(BrowserCommandControllerFullscreenTest,
349        UpdateCommandsForFullscreenMode) {
350   // Defaults for a tabbed browser.
351   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
352   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
353   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
354   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
355   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
356   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
357   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
358   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
359   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
360   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
361 #if defined(GOOGLE_CHROME_BUILD)
362   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
363 #endif
364   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
365   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
366   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
367   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
368   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
369   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
370   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
371 
372   // Simulate going fullscreen.
373   chrome::ToggleFullscreenMode(browser());
374   ASSERT_TRUE(browser()->window()->IsFullscreen());
375   browser()->command_controller()->FullscreenStateChanged();
376 
377   // Most commands are disabled in fullscreen.
378   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
379   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
380   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
381   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
382   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
383   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
384   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
385   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
386   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
387   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
388 #if defined(GOOGLE_CHROME_BUILD)
389   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
390 #endif
391   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
392   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
393   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
394   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
395   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
396   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
397   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
398 
399   // Exit fullscreen.
400   chrome::ToggleFullscreenMode(browser());
401   ASSERT_FALSE(browser()->window()->IsFullscreen());
402   browser()->command_controller()->FullscreenStateChanged();
403   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
404   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
405   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
406   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
407   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
408   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
409   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
410   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
411   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
412   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
413 #if defined(GOOGLE_CHROME_BUILD)
414   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
415 #endif
416   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
417   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
418   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
419   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
420   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
421   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
422   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
423 
424   // Guest Profiles disallow some options.
425   TestingProfile* testprofile = browser()->profile()->AsTestingProfile();
426   EXPECT_TRUE(testprofile);
427   testprofile->SetGuestSession(true);
428 
429   browser()->command_controller()->FullscreenStateChanged();
430   EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
431   EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
432 }
433 
TEST_F(BrowserCommandControllerTest,IncognitoModeOnSigninAllowedPrefChange)434 TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) {
435   // Set up a profile with an off the record profile.
436   scoped_ptr<TestingProfile> profile1 = TestingProfile::Builder().Build();
437   Profile* profile2 = profile1->GetOffTheRecordProfile();
438 
439   EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get());
440 
441   // Create a new browser based on the off the record profile.
442   Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(),
443                                        chrome::GetActiveDesktop());
444   scoped_ptr<Browser> browser2(
445       chrome::CreateBrowserWithTestWindowForParams(&profile_params));
446 
447   chrome::BrowserCommandController command_controller(browser2.get());
448   const CommandUpdater* command_updater = command_controller.command_updater();
449 
450   // Check that the SYNC_SETUP command is updated on preference change.
451   EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
452   profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
453   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
454 }
455 
TEST_F(BrowserCommandControllerTest,OnSigninAllowedPrefChange)456 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) {
457   chrome::BrowserCommandController command_controller(browser());
458   const CommandUpdater* command_updater = command_controller.command_updater();
459 
460   // Check that the SYNC_SETUP command is updated on preference change.
461   EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
462   profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
463   EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
464 }
465