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/profiles/profile_manager.h"
12#include "chrome/browser/profiles/profiles_state.h"
13#include "chrome/browser/ui/browser.h"
14#include "chrome/browser/ui/browser_commands.h"
15#include "chrome/browser/ui/browser_window_state.h"
16#include "chrome/common/chrome_switches.h"
17#include "chrome/common/pref_names.h"
18#include "chrome/test/base/browser_with_test_window_test.h"
19#include "chrome/test/base/test_browser_window.h"
20#include "chrome/test/base/testing_browser_process.h"
21#include "chrome/test/base/testing_profile_manager.h"
22#include "content/public/browser/native_web_keyboard_event.h"
23#include "ui/events/keycodes/keyboard_codes.h"
24
25typedef BrowserWithTestWindowTest BrowserCommandControllerTest;
26
27TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) {
28#if defined(OS_CHROMEOS)
29  // F1-3 keys are reserved Chrome accelerators on Chrome OS.
30  EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
31      IDC_BACK, content::NativeWebKeyboardEvent(
32          ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_BACK, 0, 0)));
33  EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
34      IDC_FORWARD, content::NativeWebKeyboardEvent(
35          ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_FORWARD, 0, 0)));
36  EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
37      IDC_RELOAD, content::NativeWebKeyboardEvent(
38          ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_REFRESH, 0, 0)));
39
40  // When there are modifier keys pressed, don't reserve.
41  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
42      IDC_RELOAD_IGNORING_CACHE, content::NativeWebKeyboardEvent(
43          ui::ET_KEY_PRESSED, false, ui::VKEY_F3, ui::EF_SHIFT_DOWN, 0)));
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_CONTROL_DOWN, 0)));
47  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
48      IDC_FULLSCREEN, content::NativeWebKeyboardEvent(
49          ui::ET_KEY_PRESSED, false, ui::VKEY_F4, ui::EF_SHIFT_DOWN, 0)));
50
51  // F4-10 keys are not reserved since they are Ash accelerators.
52  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
53      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
54                                          ui::VKEY_F4, 0, 0)));
55  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
56      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
57                                          ui::VKEY_F5, 0, 0)));
58  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
59      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
60                                          ui::VKEY_F6, 0, 0)));
61  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
62      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
63                                          ui::VKEY_F7, 0, 0)));
64  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
65      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
66                                          ui::VKEY_F8, 0, 0)));
67  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
68      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
69                                          ui::VKEY_F9, 0, 0)));
70  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
71      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
72                                          ui::VKEY_F10, 0, 0)));
73
74  // Shift+Control+Alt+F3 is also an Ash accelerator. Don't reserve it.
75  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
76      -1, content::NativeWebKeyboardEvent(
77          ui::ET_KEY_PRESSED, false,
78          ui::VKEY_F3,
79          ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 0)));
80#endif  // OS_CHROMEOS
81
82#if defined(USE_AURA)
83  // Ctrl+n, Ctrl+w are reserved while Ctrl+f is not.
84
85  // The content::NativeWebKeyboardEvent constructor is available only when
86  // USE_AURA is #defined.
87  EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
88      IDC_NEW_WINDOW, content::NativeWebKeyboardEvent(
89          ui::ET_KEY_PRESSED, false, ui::VKEY_N, ui::EF_CONTROL_DOWN, 0)));
90  EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey(
91      IDC_CLOSE_TAB, content::NativeWebKeyboardEvent(
92          ui::ET_KEY_PRESSED, false, ui::VKEY_W, ui::EF_CONTROL_DOWN, 0)));
93  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
94      IDC_FIND, content::NativeWebKeyboardEvent(
95          ui::ET_KEY_PRESSED, false, ui::VKEY_F, ui::EF_CONTROL_DOWN, 0)));
96#endif  // USE_AURA
97}
98
99TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKeyIsApp) {
100  browser()->app_name_ = "app";
101  ASSERT_TRUE(browser()->is_app());
102
103  // When is_app(), no keys are reserved.
104#if defined(OS_CHROMEOS)
105  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
106      IDC_BACK, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
107                                                ui::VKEY_F1, 0, 0)));
108  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
109      IDC_FORWARD, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
110                                                   ui::VKEY_F2, 0, 0)));
111  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
112      IDC_RELOAD, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
113                                                  ui::VKEY_F3, 0, 0)));
114  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
115      -1, content::NativeWebKeyboardEvent(ui::ET_KEY_PRESSED, false,
116                                          ui::VKEY_F4, 0, 0)));
117#endif  // OS_CHROMEOS
118
119#if defined(USE_AURA)
120  // The content::NativeWebKeyboardEvent constructor is available only when
121  // USE_AURA is #defined.
122  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
123      IDC_NEW_WINDOW, content::NativeWebKeyboardEvent(
124          ui::ET_KEY_PRESSED, false, ui::VKEY_N, ui::EF_CONTROL_DOWN, 0)));
125  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
126      IDC_CLOSE_TAB, content::NativeWebKeyboardEvent(
127          ui::ET_KEY_PRESSED, false, ui::VKEY_W, ui::EF_CONTROL_DOWN, 0)));
128  EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey(
129      IDC_FIND, content::NativeWebKeyboardEvent(
130          ui::ET_KEY_PRESSED, false, ui::VKEY_F, ui::EF_CONTROL_DOWN, 0)));
131#endif  // USE_AURA
132}
133
134TEST_F(BrowserCommandControllerTest, AppFullScreen) {
135  // Enable for tabbed browser.
136  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
137
138  // Enabled for app windows.
139  browser()->app_name_ = "app";
140  ASSERT_TRUE(browser()->is_app());
141  browser()->command_controller()->FullscreenStateChanged();
142  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
143}
144
145TEST_F(BrowserCommandControllerTest, OldAvatarMenuDisabledWhenOnlyOneProfile) {
146  if (!profiles::IsMultipleProfilesEnabled())
147    return;
148
149  EXPECT_FALSE(profiles::IsNewProfileManagementEnabled());
150
151  TestingProfileManager testing_profile_manager(
152      TestingBrowserProcess::GetGlobal());
153  ASSERT_TRUE(testing_profile_manager.SetUp());
154  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
155
156  chrome::BrowserCommandController command_controller(browser(),
157                                                      profile_manager);
158  const CommandUpdater* command_updater = command_controller.command_updater();
159
160  testing_profile_manager.CreateTestingProfile("p1");
161  ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
162  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
163
164  testing_profile_manager.CreateTestingProfile("p2");
165  ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles());
166  EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
167
168  testing_profile_manager.DeleteTestingProfile("p1");
169  ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
170  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
171
172  testing_profile_manager.DeleteTestingProfile("p2");
173}
174
175TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) {
176  if (!profiles::IsMultipleProfilesEnabled())
177    return;
178
179  // The command line is reset at the end of every test by the test suite.
180  CommandLine::ForCurrentProcess()->AppendSwitch(
181      switches::kNewProfileManagement);
182  EXPECT_TRUE(profiles::IsNewProfileManagementEnabled());
183
184  TestingProfileManager testing_profile_manager(
185      TestingBrowserProcess::GetGlobal());
186  ASSERT_TRUE(testing_profile_manager.SetUp());
187  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
188
189  chrome::BrowserCommandController command_controller(browser(),
190                                                      profile_manager);
191  const CommandUpdater* command_updater = command_controller.command_updater();
192
193  testing_profile_manager.CreateTestingProfile("p1");
194  ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles());
195  EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
196  testing_profile_manager.DeleteTestingProfile("p1");
197}
198
199TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledInGuestMode) {
200  if (!profiles::IsMultipleProfilesEnabled())
201    return;
202
203  // The command line is reset at the end of every test by the test suite.
204  CommandLine::ForCurrentProcess()->AppendSwitch(
205      switches::kNewProfileManagement);
206  EXPECT_TRUE(profiles::IsNewProfileManagementEnabled());
207
208  TestingProfileManager testing_profile_manager(
209      TestingBrowserProcess::GetGlobal());
210  ASSERT_TRUE(testing_profile_manager.SetUp());
211  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
212
213  // Set up guest a profile.
214  TestingProfile::Builder guest_builder;
215  guest_builder.SetIncognito();  // Guest profiles are off the record.
216  guest_builder.SetGuestSession();
217  guest_builder.SetPath(ProfileManager::GetGuestProfilePath());
218  scoped_ptr<TestingProfile>guest_profile = guest_builder.Build();
219
220  ASSERT_TRUE(guest_profile->IsGuestSession());
221
222  // Create a new browser based on the guest profile.
223  Browser::CreateParams profile_params(guest_profile.get(),
224                                       chrome::GetActiveDesktop());
225  scoped_ptr<Browser> guest_browser(
226      chrome::CreateBrowserWithTestWindowForParams(&profile_params));
227  chrome::BrowserCommandController command_controller(guest_browser.get(),
228                                                      profile_manager);
229  const CommandUpdater* command_updater = command_controller.command_updater();
230  EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
231}
232
233TEST_F(BrowserCommandControllerTest, AvatarMenuAlwaysDisabledInIncognitoMode) {
234  if (!profiles::IsMultipleProfilesEnabled())
235    return;
236
237  TestingProfileManager testing_profile_manager(
238      TestingBrowserProcess::GetGlobal());
239  ASSERT_TRUE(testing_profile_manager.SetUp());
240
241  // Set up a profile with an off the record profile.
242  TestingProfile::Builder otr_builder;
243  otr_builder.SetIncognito();
244  scoped_ptr<TestingProfile> otr_profile(otr_builder.Build());
245
246  TestingProfile::Builder normal_builder;
247  scoped_ptr<TestingProfile> original_profile = normal_builder.Build();
248  otr_profile->SetOriginalProfile(original_profile.get());
249  EXPECT_EQ(otr_profile->GetOriginalProfile(), original_profile.get());
250
251  original_profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>());
252
253  // Create a new browser based on the off the record profile.
254  Browser::CreateParams profile_params(
255      original_profile->GetOffTheRecordProfile(), chrome::GetActiveDesktop());
256  scoped_ptr<Browser> otr_browser(
257      chrome::CreateBrowserWithTestWindowForParams(&profile_params));
258
259  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
260  chrome::BrowserCommandController command_controller(otr_browser.get(),
261                                                      profile_manager);
262  const CommandUpdater* command_updater = command_controller.command_updater();
263
264  // The old style avatar menu should be disabled.
265  EXPECT_FALSE(profiles::IsNewProfileManagementEnabled());
266  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
267
268  // The new style avatar menu should also be disabled.
269  // The command line is reset at the end of every test by the test suite.
270  CommandLine::ForCurrentProcess()->AppendSwitch(
271      switches::kNewProfileManagement);
272  EXPECT_TRUE(profiles::IsNewProfileManagementEnabled());
273  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
274}
275
276//////////////////////////////////////////////////////////////////////////////
277
278// A test browser window that can toggle fullscreen state.
279class FullscreenTestBrowserWindow : public TestBrowserWindow {
280 public:
281  FullscreenTestBrowserWindow() : fullscreen_(false) {}
282  virtual ~FullscreenTestBrowserWindow() {}
283
284  // TestBrowserWindow overrides:
285  virtual bool ShouldHideUIForFullscreen() const OVERRIDE {
286    return fullscreen_;
287  }
288  virtual bool IsFullscreen() const OVERRIDE {
289    return fullscreen_;
290  }
291  virtual void EnterFullscreen(
292      const GURL& url, FullscreenExitBubbleType type) OVERRIDE {
293    fullscreen_ = true;
294  }
295  virtual void ExitFullscreen() OVERRIDE {
296    fullscreen_ = false;
297  }
298
299 private:
300  bool fullscreen_;
301
302  DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow);
303};
304
305// Test that uses FullscreenTestBrowserWindow for its window.
306class BrowserCommandControllerFullscreenTest
307    : public BrowserWithTestWindowTest {
308 public:
309  BrowserCommandControllerFullscreenTest() {}
310  virtual ~BrowserCommandControllerFullscreenTest() {}
311
312  // BrowserWithTestWindowTest overrides:
313  virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
314    return new FullscreenTestBrowserWindow;
315  }
316
317 private:
318  DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest);
319};
320
321TEST_F(BrowserCommandControllerFullscreenTest,
322       UpdateCommandsForFullscreenMode) {
323  // Defaults for a tabbed browser.
324  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
325  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
326  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
327  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
328  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
329  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
330  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
331  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
332  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
333  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
334#if defined(GOOGLE_CHROME_BUILD)
335  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
336#endif
337  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
338  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
339  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
340  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
341  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
342  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
343  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
344
345  // Simulate going fullscreen.
346  chrome::ToggleFullscreenMode(browser());
347  ASSERT_TRUE(browser()->window()->IsFullscreen());
348  browser()->command_controller()->FullscreenStateChanged();
349
350  // Most commands are disabled in fullscreen.
351  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
352  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
353  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
354  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
355  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
356  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
357  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
358  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
359  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
360  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
361#if defined(GOOGLE_CHROME_BUILD)
362  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
363#endif
364  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
365  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
366  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
367  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
368  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
369  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
370  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
371
372  // Exit fullscreen.
373  chrome::ToggleFullscreenMode(browser());
374  ASSERT_FALSE(browser()->window()->IsFullscreen());
375  browser()->command_controller()->FullscreenStateChanged();
376  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL));
377  EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB));
378  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR));
379  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION));
380  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH));
381  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR));
382  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE));
383  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_PREVIOUS_PANE));
384  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_BOOKMARKS));
385  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU));
386#if defined(GOOGLE_CHROME_BUILD)
387  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK));
388#endif
389  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS));
390  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS));
391  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES));
392  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS));
393  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT));
394  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU));
395  EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN));
396}
397
398TEST_F(BrowserCommandControllerTest,
399    IncognitoModeOnSigninAllowedPrefChange) {
400  TestingProfileManager testing_profile_manager(
401      TestingBrowserProcess::GetGlobal());
402  ASSERT_TRUE(testing_profile_manager.SetUp());
403
404  // Set up a profile with an off the record profile.
405  TestingProfile::Builder builder;
406  builder.SetIncognito();
407  scoped_ptr<TestingProfile> profile2(builder.Build());
408  TestingProfile::Builder builder2;
409  scoped_ptr<TestingProfile> profile1 = builder2.Build();
410  profile2->SetOriginalProfile(profile1.get());
411  EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get());
412  profile1->SetOffTheRecordProfile(profile2.PassAs<Profile>());
413
414  // Create a new browser based on the off the record profile.
415  Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(),
416                                       chrome::GetActiveDesktop());
417  scoped_ptr<Browser> browser2(
418      chrome::CreateBrowserWithTestWindowForParams(&profile_params));
419
420  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
421  chrome::BrowserCommandController command_controller(browser2.get(),
422                                                      profile_manager);
423  const CommandUpdater* command_updater = command_controller.command_updater();
424
425  // Check that the SYNC_SETUP command is updated on preference change.
426  EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
427  profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
428  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
429}
430
431TEST_F(BrowserCommandControllerTest,
432    OnSigninAllowedPrefChange) {
433  TestingProfileManager testing_profile_manager(
434      TestingBrowserProcess::GetGlobal());
435  ASSERT_TRUE(testing_profile_manager.SetUp());
436  ProfileManager* profile_manager = testing_profile_manager.profile_manager();
437  chrome::BrowserCommandController command_controller(browser(),
438                                                      profile_manager);
439  const CommandUpdater* command_updater = command_controller.command_updater();
440
441  // Check that the SYNC_SETUP command is updated on preference change.
442  EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
443  profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
444  EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP));
445}
446