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