OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/command_updater.h" | 10 #include "chrome/browser/command_updater.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ui::ET_KEY_PRESSED, false, ui::VKEY_W, ui::EF_CONTROL_DOWN, 0))); | 132 ui::ET_KEY_PRESSED, false, ui::VKEY_W, ui::EF_CONTROL_DOWN, 0))); |
133 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( | 133 EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
134 IDC_FIND, content::NativeWebKeyboardEvent( | 134 IDC_FIND, content::NativeWebKeyboardEvent( |
135 ui::ET_KEY_PRESSED, false, ui::VKEY_F, ui::EF_CONTROL_DOWN, 0))); | 135 ui::ET_KEY_PRESSED, false, ui::VKEY_F, ui::EF_CONTROL_DOWN, 0))); |
136 #endif // USE_AURA | 136 #endif // USE_AURA |
137 } | 137 } |
138 | 138 |
139 TEST_F(BrowserCommandControllerTest, IncognitoCommands) { | 139 TEST_F(BrowserCommandControllerTest, IncognitoCommands) { |
140 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 140 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
141 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 141 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
142 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); | |
143 | 142 |
144 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); | 143 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); |
145 EXPECT_TRUE(testprofile); | 144 EXPECT_TRUE(testprofile); |
146 testprofile->SetGuestSession(true); | 145 testprofile->SetGuestSession(true); |
147 chrome::BrowserCommandController | 146 chrome::BrowserCommandController |
148 ::UpdateSharedCommandsForIncognitoAvailability( | 147 ::UpdateSharedCommandsForIncognitoAvailability( |
149 browser()->command_controller()->command_updater(), testprofile); | 148 browser()->command_controller()->command_updater(), testprofile); |
150 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 149 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
151 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 150 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
152 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); | |
153 | 151 |
154 testprofile->SetGuestSession(false); | 152 testprofile->SetGuestSession(false); |
155 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 153 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
156 IncognitoModePrefs::FORCED); | 154 IncognitoModePrefs::FORCED); |
157 chrome::BrowserCommandController | 155 chrome::BrowserCommandController |
158 ::UpdateSharedCommandsForIncognitoAvailability( | 156 ::UpdateSharedCommandsForIncognitoAvailability( |
159 browser()->command_controller()->command_updater(), testprofile); | 157 browser()->command_controller()->command_updater(), testprofile); |
160 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 158 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
161 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 159 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
162 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); | |
163 } | 160 } |
164 | 161 |
165 TEST_F(BrowserCommandControllerTest, AppFullScreen) { | 162 TEST_F(BrowserCommandControllerTest, AppFullScreen) { |
166 // Enable for tabbed browser. | 163 // Enable for tabbed browser. |
167 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 164 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
168 | 165 |
169 // Enabled for app windows. | 166 // Enabled for app windows. |
170 browser()->app_name_ = "app"; | 167 browser()->app_name_ = "app"; |
171 ASSERT_TRUE(browser()->is_app()); | 168 ASSERT_TRUE(browser()->is_app()); |
172 browser()->command_controller()->FullscreenStateChanged(); | 169 browser()->command_controller()->FullscreenStateChanged(); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 411 |
415 // Guest Profiles disallow some options. | 412 // Guest Profiles disallow some options. |
416 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); | 413 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); |
417 EXPECT_TRUE(testprofile); | 414 EXPECT_TRUE(testprofile); |
418 testprofile->SetGuestSession(true); | 415 testprofile->SetGuestSession(true); |
419 | 416 |
420 browser()->command_controller()->FullscreenStateChanged(); | 417 browser()->command_controller()->FullscreenStateChanged(); |
421 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 418 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
422 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 419 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
423 } | 420 } |
424 | |
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(); | |
429 | |
430 EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); | |
431 | |
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)); | |
437 | |
438 chrome::BrowserCommandController command_controller(browser2.get()); | |
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 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | |
444 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | |
445 } | |
446 | |
447 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { | |
448 chrome::BrowserCommandController command_controller(browser()); | |
449 const CommandUpdater* command_updater = command_controller.command_updater(); | |
450 | |
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)); | |
455 } | |
OLD | NEW |